View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /* Created on Sep 13, 2005 */
17  package org.apache.ojb.broker.platforms;
18  
19  
20  
21  import java.io.ByteArrayInputStream;
22  import java.io.InputStreamReader;
23  import java.io.Reader;
24  import java.io.StringReader;
25  import java.sql.PreparedStatement;
26  import java.sql.SQLException;
27  import java.sql.Types;
28  
29  import org.apache.ojb.broker.query.LikeCriteria;
30  
31  /**
32   * DatabasePlatform implementation for the Mckoi database.
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   * @see http://www.mckoi.com/database
36   */
37  public class PlatformMckoiImpl extends PlatformDefaultImpl
38  {
39      /* (non-Javadoc)
40       * @see DatabasePlatform#setObjectForStatement(PreparedStatement, int, Object, int)
41       */
42      public void setObjectForStatement(PreparedStatement statement, int index, Object value, int sqlType) throws SQLException
43      {
44          switch (sqlType)
45          {
46              case Types.BLOB :
47              case Types.LONGVARBINARY :
48              case Types.VARBINARY :
49                  if (value instanceof byte[])
50                  {
51                      byte[]               buf         = (byte[])value;
52                      ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
53                      statement.setBinaryStream(index, inputStream, buf.length);
54  
55                      break;
56                  }
57  
58              case Types.CLOB :
59                  Reader reader = null;
60                  int    length = 0;
61  
62                  if (value instanceof String)
63                  {
64                      reader = new StringReader((String)value);
65                      length = (((String)value)).length();
66                  }
67                  else if (value instanceof char[])
68                  {
69                      String string = new String((char[])value);
70  
71                      reader = new StringReader(string);
72                      length = string.length();
73                  }
74                  else if (value instanceof byte[])
75                  {
76                      ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[])value);
77  
78                      reader = new InputStreamReader(inputStream);
79                  }
80                  statement.setCharacterStream(index, reader, length);
81                  break;
82  
83              default :
84                  super.setObjectForStatement(statement, index, value, sqlType);
85  
86          }
87      }
88  
89      /* (non-Javadoc)
90       * @see org.apache.ojb.broker.platforms.Platform#createSequenceQuery(String)
91       */
92      public String createSequenceQuery(String sequenceName)
93      {
94          return "create sequence " + sequenceName;
95      }
96  
97      /* (non-Javadoc)
98       * @see org.apache.ojb.broker.platforms.Platform#nextSequenceQuery(String)
99       */
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 }