Added property svn:eol-style=native

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@482327 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Craig Russell 2006-12-04 19:59:52 +00:00
parent eb9a626945
commit b8710bea03
2 changed files with 1285 additions and 1285 deletions

View File

@ -1,162 +1,162 @@
/* /*
* Copyright 2006 The Apache Software Foundation. * Copyright 2006 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.openjpa.jdbc.sql; package org.apache.openjpa.jdbc.sql;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.apache.openjpa.jdbc.schema.Sequence; import org.apache.openjpa.jdbc.schema.Sequence;
/** /**
* Dictionary for IBM DB2 database. * Dictionary for IBM DB2 database.
*/ */
public class DB2Dictionary public class DB2Dictionary
extends AbstractDB2Dictionary { extends AbstractDB2Dictionary {
public DB2Dictionary() { public DB2Dictionary() {
platform = "DB2"; platform = "DB2";
validationSQL = "SELECT DISTINCT(CURRENT TIMESTAMP) FROM " validationSQL = "SELECT DISTINCT(CURRENT TIMESTAMP) FROM "
+ "SYSIBM.SYSTABLES"; + "SYSIBM.SYSTABLES";
supportsSelectEndIndex = true; supportsSelectEndIndex = true;
nextSequenceQuery = "VALUES NEXTVAL FOR {0}"; nextSequenceQuery = "VALUES NEXTVAL FOR {0}";
binaryTypeName = "BLOB(1M)"; binaryTypeName = "BLOB(1M)";
longVarbinaryTypeName = "BLOB(1M)"; longVarbinaryTypeName = "BLOB(1M)";
varbinaryTypeName = "BLOB(1M)"; varbinaryTypeName = "BLOB(1M)";
clobTypeName = "CLOB(1M)"; clobTypeName = "CLOB(1M)";
longVarcharTypeName = "LONG VARCHAR"; longVarcharTypeName = "LONG VARCHAR";
fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{ fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{
"LONG VARCHAR FOR BIT DATA", "LONG VARCHAR", "LONG VARGRAPHIC", "LONG VARCHAR FOR BIT DATA", "LONG VARCHAR", "LONG VARGRAPHIC",
})); }));
maxConstraintNameLength = 18; maxConstraintNameLength = 18;
maxIndexNameLength = 18; maxIndexNameLength = 18;
maxColumnNameLength = 30; maxColumnNameLength = 30;
supportsDeferredConstraints = false; supportsDeferredConstraints = false;
supportsDefaultDeleteAction = false; supportsDefaultDeleteAction = false;
supportsAlterTableWithDropColumn = false; supportsAlterTableWithDropColumn = false;
supportsNullTableForGetColumns = false; supportsNullTableForGetColumns = false;
reservedWordSet.addAll(Arrays.asList(new String[]{ reservedWordSet.addAll(Arrays.asList(new String[]{
"AFTER", "ALIAS", "ALLOW", "APPLICATION", "ASSOCIATE", "ASUTIME", "AFTER", "ALIAS", "ALLOW", "APPLICATION", "ASSOCIATE", "ASUTIME",
"AUDIT", "AUX", "AUXILIARY", "BEFORE", "BINARY", "BUFFERPOOL", "AUDIT", "AUX", "AUXILIARY", "BEFORE", "BINARY", "BUFFERPOOL",
"CACHE", "CALL", "CALLED", "CAPTURE", "CARDINALITY", "CCSID", "CACHE", "CALL", "CALLED", "CAPTURE", "CARDINALITY", "CCSID",
"CLUSTER", "COLLECTION", "COLLID", "COMMENT", "CONCAT", "CLUSTER", "COLLECTION", "COLLID", "COMMENT", "CONCAT",
"CONDITION", "CONTAINS", "COUNT_BIG", "CURRENT_LC_CTYPE", "CONDITION", "CONTAINS", "COUNT_BIG", "CURRENT_LC_CTYPE",
"CURRENT_PATH", "CURRENT_SERVER", "CURRENT_TIMEZONE", "CYCLE", "CURRENT_PATH", "CURRENT_SERVER", "CURRENT_TIMEZONE", "CYCLE",
"DATA", "DATABASE", "DAYS", "DB2GENERAL", "DB2GENRL", "DB2SQL", "DATA", "DATABASE", "DAYS", "DB2GENERAL", "DB2GENRL", "DB2SQL",
"DBINFO", "DEFAULTS", "DEFINITION", "DETERMINISTIC", "DISALLOW", "DBINFO", "DEFAULTS", "DEFINITION", "DETERMINISTIC", "DISALLOW",
"DO", "DSNHATTR", "DSSIZE", "DYNAMIC", "EACH", "EDITPROC", "ELSEIF", "DO", "DSNHATTR", "DSSIZE", "DYNAMIC", "EACH", "EDITPROC", "ELSEIF",
"ENCODING", "END-EXEC1", "ERASE", "EXCLUDING", "EXIT", "FENCED", "ENCODING", "END-EXEC1", "ERASE", "EXCLUDING", "EXIT", "FENCED",
"FIELDPROC", "FILE", "FINAL", "FREE", "FUNCTION", "GENERAL", "FIELDPROC", "FILE", "FINAL", "FREE", "FUNCTION", "GENERAL",
"GENERATED", "GRAPHIC", "HANDLER", "HOLD", "HOURS", "IF", "GENERATED", "GRAPHIC", "HANDLER", "HOLD", "HOURS", "IF",
"INCLUDING", "INCREMENT", "INDEX", "INHERIT", "INOUT", "INTEGRITY", "INCLUDING", "INCREMENT", "INDEX", "INHERIT", "INOUT", "INTEGRITY",
"ISOBID", "ITERATE", "JAR", "JAVA", "LABEL", "LC_CTYPE", "LEAVE", "ISOBID", "ITERATE", "JAR", "JAVA", "LABEL", "LC_CTYPE", "LEAVE",
"LINKTYPE", "LOCALE", "LOCATOR", "LOCATORS", "LOCK", "LOCKMAX", "LINKTYPE", "LOCALE", "LOCATOR", "LOCATORS", "LOCK", "LOCKMAX",
"LOCKSIZE", "LONG", "LOOP", "MAXVALUE", "MICROSECOND", "LOCKSIZE", "LONG", "LOOP", "MAXVALUE", "MICROSECOND",
"MICROSECONDS", "MINUTES", "MINVALUE", "MODE", "MODIFIES", "MONTHS", "MICROSECONDS", "MINUTES", "MINVALUE", "MODE", "MODIFIES", "MONTHS",
"NEW", "NEW_TABLE", "NOCACHE", "NOCYCLE", "NODENAME", "NODENUMBER", "NEW", "NEW_TABLE", "NOCACHE", "NOCYCLE", "NODENAME", "NODENUMBER",
"NOMAXVALUE", "NOMINVALUE", "NOORDER", "NULLS", "NUMPARTS", "OBID", "NOMAXVALUE", "NOMINVALUE", "NOORDER", "NULLS", "NUMPARTS", "OBID",
"OLD", "OLD_TABLE", "OPTIMIZATION", "OPTIMIZE", "OUT", "OVERRIDING", "OLD", "OLD_TABLE", "OPTIMIZATION", "OPTIMIZE", "OUT", "OVERRIDING",
"PACKAGE", "PARAMETER", "PART", "PARTITION", "PATH", "PIECESIZE", "PACKAGE", "PARAMETER", "PART", "PARTITION", "PATH", "PIECESIZE",
"PLAN", "PRIQTY", "PROGRAM", "PSID", "QUERYNO", "READS", "RECOVERY", "PLAN", "PRIQTY", "PROGRAM", "PSID", "QUERYNO", "READS", "RECOVERY",
"REFERENCING", "RELEASE", "RENAME", "REPEAT", "RESET", "RESIGNAL", "REFERENCING", "RELEASE", "RENAME", "REPEAT", "RESET", "RESIGNAL",
"RESTART", "RESULT", "RESULT_SET_LOCATOR", "RETURN", "RETURNS", "RESTART", "RESULT", "RESULT_SET_LOCATOR", "RETURN", "RETURNS",
"ROUTINE", "ROW", "RRN", "RUN", "SAVEPOINT", "SCRATCHPAD", "ROUTINE", "ROW", "RRN", "RUN", "SAVEPOINT", "SCRATCHPAD",
"SECONDS", "SECQTY", "SECURITY", "SENSITIVE", "SIGNAL", "SIMPLE", "SECONDS", "SECQTY", "SECURITY", "SENSITIVE", "SIGNAL", "SIMPLE",
"SOURCE", "SPECIFIC", "SQLID", "STANDARD", "START", "STATIC", "SOURCE", "SPECIFIC", "SQLID", "STANDARD", "START", "STATIC",
"STAY", "STOGROUP", "STORES", "STYLE", "SUBPAGES", "SYNONYM", "STAY", "STOGROUP", "STORES", "STYLE", "SUBPAGES", "SYNONYM",
"SYSFUN", "SYSIBM", "SYSPROC", "SYSTEM", "TABLESPACE", "TRIGGER", "SYSFUN", "SYSIBM", "SYSPROC", "SYSTEM", "TABLESPACE", "TRIGGER",
"TYPE", "UNDO", "UNTIL", "VALIDPROC", "VARIABLE", "VARIANT", "VCAT", "TYPE", "UNDO", "UNTIL", "VALIDPROC", "VARIABLE", "VARIANT", "VCAT",
"VOLUMES", "WHILE", "WLM", "YEARS", "VOLUMES", "WHILE", "WLM", "YEARS",
})); }));
} }
public boolean supportsRandomAccessResultSet(Select sel, public boolean supportsRandomAccessResultSet(Select sel,
boolean forUpdate) { boolean forUpdate) {
return !forUpdate return !forUpdate
&& super.supportsRandomAccessResultSet(sel, forUpdate); && super.supportsRandomAccessResultSet(sel, forUpdate);
} }
protected void appendSelectRange(SQLBuffer buf, long start, long end) { protected void appendSelectRange(SQLBuffer buf, long start, long end) {
// appends the literal range string, since DB2 is unable to handle // appends the literal range string, since DB2 is unable to handle
// a bound parameter for it // a bound parameter for it
buf.append(" FETCH FIRST ").append(Long.toString(end)). buf.append(" FETCH FIRST ").append(Long.toString(end)).
append(" ROWS ONLY"); append(" ROWS ONLY");
} }
public String[] getCreateSequenceSQL(Sequence seq) { public String[] getCreateSequenceSQL(Sequence seq) {
String[] sql = super.getCreateSequenceSQL(seq); String[] sql = super.getCreateSequenceSQL(seq);
if (seq.getAllocate() > 1) if (seq.getAllocate() > 1)
sql[0] += " CACHE " + seq.getAllocate(); sql[0] += " CACHE " + seq.getAllocate();
return sql; return sql;
} }
protected String getSequencesSQL(String schemaName, String sequenceName) { protected String getSequencesSQL(String schemaName, String sequenceName) {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
buf.append("SELECT SEQSCHEMA AS SEQUENCE_SCHEMA, "). buf.append("SELECT SEQSCHEMA AS SEQUENCE_SCHEMA, ").
append("SEQNAME AS SEQUENCE_NAME FROM SYSCAT.SEQUENCES"); append("SEQNAME AS SEQUENCE_NAME FROM SYSCAT.SEQUENCES");
if (schemaName != null || sequenceName != null) if (schemaName != null || sequenceName != null)
buf.append(" WHERE "); buf.append(" WHERE ");
if (schemaName != null) { if (schemaName != null) {
buf.append("SEQSCHEMA = ?"); buf.append("SEQSCHEMA = ?");
if (sequenceName != null) if (sequenceName != null)
buf.append(" AND "); buf.append(" AND ");
} }
if (sequenceName != null) if (sequenceName != null)
buf.append("SEQNAME = ?"); buf.append("SEQNAME = ?");
return buf.toString(); return buf.toString();
} }
public Connection decorate(Connection conn) public Connection decorate(Connection conn)
throws SQLException { throws SQLException {
// some versions of the DB2 driver seem to default to // some versions of the DB2 driver seem to default to
// READ_UNCOMMITTED, which will prevent locking from working // READ_UNCOMMITTED, which will prevent locking from working
// (multiple SELECT ... FOR UPDATE statements are allowed on // (multiple SELECT ... FOR UPDATE statements are allowed on
// the same instance); if we have not overridden the // the same instance); if we have not overridden the
// transaction isolation in the configuration, default to // transaction isolation in the configuration, default to
// TRANSACTION_READ_COMMITTED // TRANSACTION_READ_COMMITTED
conn = super.decorate(conn); conn = super.decorate(conn);
if (conf.getTransactionIsolationConstant() == -1 if (conf.getTransactionIsolationConstant() == -1
&& conn.getTransactionIsolation() < conn.TRANSACTION_READ_COMMITTED) && conn.getTransactionIsolation() < conn.TRANSACTION_READ_COMMITTED)
conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED); conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED);
return conn; return conn;
} }
public void connectedConfiguration(Connection conn) throws SQLException { public void connectedConfiguration(Connection conn) throws SQLException {
super.connectedConfiguration(conn); super.connectedConfiguration(conn);
DatabaseMetaData metaData = conn.getMetaData(); DatabaseMetaData metaData = conn.getMetaData();
if (metaData.getJDBCMajorVersion() >= 3) { if (metaData.getJDBCMajorVersion() >= 3) {
int maj = metaData.getDatabaseMajorVersion(); int maj = metaData.getDatabaseMajorVersion();
int min = metaData.getDatabaseMinorVersion(); int min = metaData.getDatabaseMinorVersion();
if (maj >= 9 || (maj == 8 && min >= 2)) { if (maj >= 9 || (maj == 8 && min >= 2)) {
supportsLockingWithMultipleTables = true; supportsLockingWithMultipleTables = true;
supportsLockingWithInnerJoin = true; supportsLockingWithInnerJoin = true;
supportsLockingWithOuterJoin = true; supportsLockingWithOuterJoin = true;
forUpdateClause = "WITH RR USE AND KEEP UPDATE LOCKS"; forUpdateClause = "WITH RR USE AND KEEP UPDATE LOCKS";
} }
} }
} }
} }