001    /**
002     * Copyright 2005-2014 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    
020    
021    import java.io.ByteArrayInputStream;
022    import java.io.InputStreamReader;
023    import java.io.Reader;
024    import java.io.StringReader;
025    import java.sql.PreparedStatement;
026    import java.sql.SQLException;
027    import java.sql.Types;
028    
029    import org.apache.ojb.broker.query.LikeCriteria;
030    
031    /**
032     * DatabasePlatform implementation for the Mckoi database.
033     * 
034     * @author Kuali Rice Team (rice.collab@kuali.org)
035     * @see http://www.mckoi.com/database
036     */
037    public class PlatformMckoiImpl extends PlatformDefaultImpl
038    {
039        /* (non-Javadoc)
040         * @see DatabasePlatform#setObjectForStatement(PreparedStatement, int, Object, int)
041         */
042        public void setObjectForStatement(PreparedStatement statement, int index, Object value, int sqlType) throws SQLException
043        {
044            switch (sqlType)
045            {
046                case Types.BLOB :
047                case Types.LONGVARBINARY :
048                case Types.VARBINARY :
049                    if (value instanceof byte[])
050                    {
051                        byte[]               buf         = (byte[])value;
052                        ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
053                        statement.setBinaryStream(index, inputStream, buf.length);
054    
055                        break;
056                    }
057    
058                case Types.CLOB :
059                    Reader reader = null;
060                    int    length = 0;
061    
062                    if (value instanceof String)
063                    {
064                        reader = new StringReader((String)value);
065                        length = (((String)value)).length();
066                    }
067                    else if (value instanceof char[])
068                    {
069                        String string = new String((char[])value);
070    
071                        reader = new StringReader(string);
072                        length = string.length();
073                    }
074                    else if (value instanceof byte[])
075                    {
076                        ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[])value);
077    
078                        reader = new InputStreamReader(inputStream);
079                    }
080                    statement.setCharacterStream(index, reader, length);
081                    break;
082    
083                default :
084                    super.setObjectForStatement(statement, index, value, sqlType);
085    
086            }
087        }
088    
089        /* (non-Javadoc)
090         * @see org.apache.ojb.broker.platforms.Platform#createSequenceQuery(String)
091         */
092        public String createSequenceQuery(String sequenceName)
093        {
094            return "create sequence " + sequenceName;
095        }
096    
097        /* (non-Javadoc)
098         * @see org.apache.ojb.broker.platforms.Platform#nextSequenceQuery(String)
099         */
100        public String nextSequenceQuery(String sequenceName)
101        {
102            return "select nextval('" + sequenceName + "')";
103        }
104    
105        /* (non-Javadoc)
106         * @see org.apache.ojb.broker.platforms.Platform#dropSequenceQuery(String)
107         */
108        public String dropSequenceQuery(String sequenceName)
109        {
110            return "drop sequence " + sequenceName;
111        }
112    
113        /* (non-Javadoc)
114         * @see org.apache.ojb.broker.platforms.Platform#getJoinSyntaxType()
115         */
116        public byte getJoinSyntaxType()
117        {
118            return SQL92_NOPAREN_JOIN_SYNTAX;
119        }
120    
121        /* (non-Javadoc)
122         * @see org.apache.ojb.broker.platforms.Platform#supportsPaging()
123         */
124        public boolean supportsPaging()
125        {
126            // [tomdz] there is no explicit paging support a la LIMIT in Mckoi (yet ?)
127            return false;
128        }
129    
130        /* (non-Javadoc)
131         * @see org.apache.ojb.broker.platforms.Platform#concatenate(java.lang.String[])
132         */
133        public String concatenate(String[] columns)
134        {
135            if (columns.length == 1)
136            {
137                return columns[0];
138            }
139            
140            StringBuffer buf = new StringBuffer();
141            
142            buf.append("concat(");
143            for (int idx = 0; idx < columns.length; idx++)
144            {
145                if (idx > 0)
146                {
147                    buf.append(",");
148                }
149                buf.append(columns[idx]);
150            }
151            buf.append(")");
152    
153            return buf.toString();
154        }    
155        
156        /* (non-Javadoc)
157         * @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)
158         */
159        public String getEscapeClause(LikeCriteria criteria)
160        {
161            // [tomdz] Mckoi does not support escape characters other than \
162            // TODO    Shold we throw some kind of exception here if the escape character is different ?
163            return "";
164        }    
165    }