| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PlatformMckoiImpl |
|
| 2.5;2.5 |
| 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 | 0 | 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 | 0 | switch (sqlType) |
| 58 | { | |
| 59 | case Types.BLOB : | |
| 60 | case Types.LONGVARBINARY : | |
| 61 | case Types.VARBINARY : | |
| 62 | 0 | if (value instanceof byte[]) |
| 63 | { | |
| 64 | 0 | byte[] buf = (byte[])value; |
| 65 | 0 | ByteArrayInputStream inputStream = new ByteArrayInputStream(buf); |
| 66 | 0 | statement.setBinaryStream(index, inputStream, buf.length); |
| 67 | ||
| 68 | 0 | break; |
| 69 | } | |
| 70 | ||
| 71 | case Types.CLOB : | |
| 72 | 0 | Reader reader = null; |
| 73 | 0 | int length = 0; |
| 74 | ||
| 75 | 0 | if (value instanceof String) |
| 76 | { | |
| 77 | 0 | reader = new StringReader((String)value); |
| 78 | 0 | length = (((String)value)).length(); |
| 79 | } | |
| 80 | 0 | else if (value instanceof char[]) |
| 81 | { | |
| 82 | 0 | String string = new String((char[])value); |
| 83 | ||
| 84 | 0 | reader = new StringReader(string); |
| 85 | 0 | length = string.length(); |
| 86 | 0 | } |
| 87 | 0 | else if (value instanceof byte[]) |
| 88 | { | |
| 89 | 0 | ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[])value); |
| 90 | ||
| 91 | 0 | reader = new InputStreamReader(inputStream); |
| 92 | } | |
| 93 | 0 | statement.setCharacterStream(index, reader, length); |
| 94 | 0 | break; |
| 95 | ||
| 96 | default : | |
| 97 | 0 | super.setObjectForStatement(statement, index, value, sqlType); |
| 98 | ||
| 99 | } | |
| 100 | 0 | } |
| 101 | ||
| 102 | /* (non-Javadoc) | |
| 103 | * @see org.apache.ojb.broker.platforms.Platform#createSequenceQuery(String) | |
| 104 | */ | |
| 105 | public String createSequenceQuery(String sequenceName) | |
| 106 | { | |
| 107 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | if (columns.length == 1) |
| 149 | { | |
| 150 | 0 | return columns[0]; |
| 151 | } | |
| 152 | ||
| 153 | 0 | StringBuffer buf = new StringBuffer(); |
| 154 | ||
| 155 | 0 | buf.append("concat("); |
| 156 | 0 | for (int idx = 0; idx < columns.length; idx++) |
| 157 | { | |
| 158 | 0 | if (idx > 0) |
| 159 | { | |
| 160 | 0 | buf.append(","); |
| 161 | } | |
| 162 | 0 | buf.append(columns[idx]); |
| 163 | } | |
| 164 | 0 | buf.append(")"); |
| 165 | ||
| 166 | 0 | 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 | 0 | return ""; |
| 177 | } | |
| 178 | } |