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