001    /*
002     * Copyright 2007 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    /* Created on Sep 13, 2005 */
017    package org.apache.ojb.broker.platforms;
018    
019    /* Copyright 2002-2004 The Apache Software Foundation
020     *
021     * Licensed under the Apache License, Version 2.0 (the "License");
022     * you may not use this file except in compliance with the License.
023     * You may obtain a copy of the License at
024     *
025     *     http://www.apache.org/licenses/LICENSE-2.0
026     *
027     * Unless required by applicable law or agreed to in writing, software
028     * distributed under the License is distributed on an "AS IS" BASIS,
029     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
030     * See the License for the specific language governing permissions and
031     * limitations under the License.
032     */
033    
034    import java.io.ByteArrayInputStream;
035    import java.io.InputStreamReader;
036    import java.io.Reader;
037    import java.io.StringReader;
038    import java.sql.PreparedStatement;
039    import java.sql.SQLException;
040    import java.sql.Types;
041    
042    import org.apache.ojb.broker.query.LikeCriteria;
043    
044    /**
045     * DatabasePlatform implementation for the Mckoi database.
046     * 
047     * @author Kuali Rice Team (rice.collab@kuali.org)
048     * @see http://www.mckoi.com/database
049     */
050    public class PlatformMckoiImpl extends PlatformDefaultImpl
051    {
052        /* (non-Javadoc)
053         * @see DatabasePlatform#setObjectForStatement(PreparedStatement, int, Object, int)
054         */
055        public void setObjectForStatement(PreparedStatement statement, int index, Object value, int sqlType) throws SQLException
056        {
057            switch (sqlType)
058            {
059                case Types.BLOB :
060                case Types.LONGVARBINARY :
061                case Types.VARBINARY :
062                    if (value instanceof byte[])
063                    {
064                        byte[]               buf         = (byte[])value;
065                        ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
066                        statement.setBinaryStream(index, inputStream, buf.length);
067    
068                        break;
069                    }
070    
071                case Types.CLOB :
072                    Reader reader = null;
073                    int    length = 0;
074    
075                    if (value instanceof String)
076                    {
077                        reader = new StringReader((String)value);
078                        length = (((String)value)).length();
079                    }
080                    else if (value instanceof char[])
081                    {
082                        String string = new String((char[])value);
083    
084                        reader = new StringReader(string);
085                        length = string.length();
086                    }
087                    else if (value instanceof byte[])
088                    {
089                        ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[])value);
090    
091                        reader = new InputStreamReader(inputStream);
092                    }
093                    statement.setCharacterStream(index, reader, length);
094                    break;
095    
096                default :
097                    super.setObjectForStatement(statement, index, value, sqlType);
098    
099            }
100        }
101    
102        /* (non-Javadoc)
103         * @see org.apache.ojb.broker.platforms.Platform#createSequenceQuery(String)
104         */
105        public String createSequenceQuery(String sequenceName)
106        {
107            return "create sequence " + sequenceName;
108        }
109    
110        /* (non-Javadoc)
111         * @see org.apache.ojb.broker.platforms.Platform#nextSequenceQuery(String)
112         */
113        public String nextSequenceQuery(String sequenceName)
114        {
115            return "select nextval('" + sequenceName + "')";
116        }
117    
118        /* (non-Javadoc)
119         * @see org.apache.ojb.broker.platforms.Platform#dropSequenceQuery(String)
120         */
121        public String dropSequenceQuery(String sequenceName)
122        {
123            return "drop sequence " + sequenceName;
124        }
125    
126        /* (non-Javadoc)
127         * @see org.apache.ojb.broker.platforms.Platform#getJoinSyntaxType()
128         */
129        public byte getJoinSyntaxType()
130        {
131            return SQL92_NOPAREN_JOIN_SYNTAX;
132        }
133    
134        /* (non-Javadoc)
135         * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
136         */
137        public boolean supportsPaging()
138        {
139            // [tomdz] there is no explicit paging support a la LIMIT in Mckoi (yet ?)
140            return false;
141        }
142    
143        /* (non-Javadoc)
144         * @see org.apache.ojb.broker.platforms.Platform#concatenate(java.lang.String[])
145         */
146        public String concatenate(String[] columns)
147        {
148            if (columns.length == 1)
149            {
150                return columns[0];
151            }
152            
153            StringBuffer buf = new StringBuffer();
154            
155            buf.append("concat(");
156            for (int idx = 0; idx < columns.length; idx++)
157            {
158                if (idx > 0)
159                {
160                    buf.append(",");
161                }
162                buf.append(columns[idx]);
163            }
164            buf.append(")");
165    
166            return buf.toString();
167        }    
168        
169        /* (non-Javadoc)
170         * @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)
171         */
172        public String getEscapeClause(LikeCriteria criteria)
173        {
174            // [tomdz] Mckoi does not support escape characters other than \
175            // TODO    Shold we throw some kind of exception here if the escape character is different ?
176            return "";
177        }    
178    }