View Javadoc

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