001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.jdbc.sql;
020:
021: import java.sql.Types;
022:
023: import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
024: import org.apache.openjpa.jdbc.schema.Column;
025: import org.apache.openjpa.jdbc.schema.Index;
026: import org.apache.openjpa.lib.util.Localizer;
027: import org.apache.openjpa.util.StoreException;
028:
029: /**
030: * Dictionary for Borland Interbase.
031: */
032: public class InterbaseDictionary extends DBDictionary {
033:
034: private static final Localizer _loc = Localizer
035: .forPackage(InterbaseDictionary.class);
036:
037: public InterbaseDictionary() {
038: platform = "Borland Interbase";
039: validationSQL = "SELECT 1 FROM RDB$DATABASE";
040: supportsDeferredConstraints = false;
041:
042: useGetStringForClobs = true;
043: useSetStringForClobs = true;
044: useGetBytesForBlobs = true;
045: useSetBytesForBlobs = true;
046:
047: // the JDBC driver claims 31, but that causes exceptions
048: maxTableNameLength = 30;
049:
050: bigintTypeName = "NUMERIC(18,0)";
051: integerTypeName = "INTEGER";
052: doubleTypeName = "DOUBLE PRECISION";
053: charTypeName = "CHAR(1)";
054: blobTypeName = "BLOB";
055: clobTypeName = "BLOB SUB_TYPE 1";
056: bitTypeName = "SMALLINT";
057: smallintTypeName = "SMALLINT";
058: tinyintTypeName = "SMALLINT";
059:
060: // no support for lower-casing or finding the length of strings
061: // (although it can be added to the database; see
062: // http://bdn.borland.com/article/0,1410,27563,00.html )
063: toLowerCaseFunction = null;
064: stringLengthFunction = null;
065: }
066:
067: protected String getTableNameForMetadata(String tableName) {
068: return (tableName == null) ? "%" : super
069: .getTableNameForMetadata(tableName);
070: }
071:
072: protected String getColumnNameForMetadata(String columnName) {
073: return (columnName == null) ? "%" : super
074: .getColumnNameForMetadata(columnName);
075: }
076:
077: protected String appendSize(Column col, String typeName) {
078: if (col.isPrimaryKey() && col.getType() == Types.VARCHAR) {
079: // reduce size of varchar primary key cols proportional to the
080: // number of cols, because interbase caps the total pk size
081: int numKeys = 1;
082: if (col.getTable() != null
083: && col.getTable().getPrimaryKey() != null)
084: numKeys = col.getTable().getPrimaryKey().getColumns().length;
085: col.setSize(Math.min(col.getSize(), 200 / numKeys));
086: } else if (col.getType() == Types.VARCHAR
087: && col.getSize() > 200 && col.getTable() != null) {
088: // indexed varchar cols have to be <= 250 chars
089: Index[] idx = col.getTable().getIndexes();
090: for (int i = 0; i < idx.length; i++) {
091: if (idx[i].containsColumn(col)) {
092: col.setSize(Math.min(col.getSize(), 200));
093: break;
094: }
095: }
096: }
097: return super .appendSize(col, typeName);
098: }
099:
100: public void indexOf(SQLBuffer buf, FilterValue str,
101: FilterValue find, FilterValue start) {
102: throw new StoreException(_loc.get("indexof-not-supported",
103: platform));
104: }
105:
106: public void substring(SQLBuffer buf, FilterValue str,
107: FilterValue start, FilterValue end) {
108: throw new StoreException(_loc.get("substring-not-supported",
109: platform));
110: }
111:
112: public String[] getDropColumnSQL(Column column) {
113: // Interbase uses "ALTER TABLE DROP <COLUMN_NAME>" rather than the
114: // usual "ALTER TABLE DROP COLUMN <COLUMN_NAME>"
115: return new String[] { "ALTER TABLE "
116: + getFullName(column.getTable(), false) + " DROP "
117: + column };
118: }
119: }
|