OPENJPA-222 clean up

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@530860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David J. Wisneski 2007-04-20 17:24:32 +00:00
parent 0bc9685aa7
commit 129360ace9
3 changed files with 130 additions and 132 deletions

View File

@ -37,11 +37,11 @@ public class DB2Dictionary
public String optimizeClause = "optimize for"; public String optimizeClause = "optimize for";
public String rowClause = "row"; public String rowClause = "row";
private int db2ServerType = 0; private int db2ServerType = 0;
private static final int db2ISeriesV5R3AndEarlier = 1; private static final int db2ISeriesV5R3OrEarlier = 1;
private static final int db2UDBV81OrEarlier = 2; private static final int db2UDBV81OrEarlier = 2;
private static final int db2ZOSV8xOrLater = 3; private static final int db2ZOSV8xOrLater = 3;
private static final int db2UDBV82AndLater = 4; private static final int db2UDBV82OrLater = 4;
private static final int db2ISeriesV5R4AndLater = 5; private static final int db2ISeriesV5R4OrLater = 5;
private static final String forUpdateOfClause = "FOR UPDATE OF"; private static final String forUpdateOfClause = "FOR UPDATE OF";
private static final String withRSClause = "WITH RS"; private static final String withRSClause = "WITH RS";
private static final String withRRClause = "WITH RR"; private static final String withRRClause = "WITH RR";
@ -191,16 +191,16 @@ public class DB2Dictionary
int min = metaData.getDatabaseMinorVersion(); int min = metaData.getDatabaseMinorVersion();
// Determine the type of DB2 database // Determine the type of DB2 database
if (isDB2ISeriesV5R3AndEarlier(metaData)) if (isDB2ISeriesV5R3OrEarlier(metaData))
db2ServerType = db2ISeriesV5R3AndEarlier; db2ServerType = db2ISeriesV5R3OrEarlier;
else if (isDB2UDBV81OrEarlier(metaData,maj,min)) else if (isDB2UDBV81OrEarlier(metaData,maj,min))
db2ServerType = db2UDBV81OrEarlier; db2ServerType = db2UDBV81OrEarlier;
else if (isDB2ZOSV8xOrLater(metaData,maj)) else if (isDB2ZOSV8xOrLater(metaData,maj))
db2ServerType = db2ZOSV8xOrLater; db2ServerType = db2ZOSV8xOrLater;
else if (isDB2UDBV82AndLater(metaData,maj,min)) else if (isDB2UDBV82OrLater(metaData,maj,min))
db2ServerType = db2UDBV82AndLater; db2ServerType = db2UDBV82OrLater;
else if (isDB2ISeriesV5R4AndLater(metaData)) else if (isDB2ISeriesV5R4OrLater(metaData))
db2ServerType = db2ISeriesV5R4AndLater; db2ServerType = db2ISeriesV5R4OrLater;
if (maj >= 9 || (maj == 8 && min >= 2)) { if (maj >= 9 || (maj == 8 && min >= 2)) {
supportsLockingWithMultipleTables = true; supportsLockingWithMultipleTables = true;
@ -247,7 +247,7 @@ public class DB2Dictionary
if (forUpdate) { if (forUpdate) {
switch(db2ServerType) { switch(db2ServerType) {
case db2ISeriesV5R3AndEarlier: case db2ISeriesV5R3OrEarlier:
case db2UDBV81OrEarlier: case db2UDBV81OrEarlier:
if (isolationLevel == if (isolationLevel ==
Connection.TRANSACTION_READ_UNCOMMITTED) { Connection.TRANSACTION_READ_UNCOMMITTED) {
@ -257,7 +257,7 @@ public class DB2Dictionary
forUpdateString.append(" ").append(forUpdateOfClause); forUpdateString.append(" ").append(forUpdateOfClause);
break; break;
case db2ZOSV8xOrLater: case db2ZOSV8xOrLater:
case db2UDBV82AndLater: case db2UDBV82OrLater:
if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) { if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
forUpdateString.append(" ").append(forReadOnlyClause) forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRRClause) .append(" ").append(withRRClause)
@ -268,7 +268,7 @@ public class DB2Dictionary
.append(" ").append(useKeepUpdateLockClause); .append(" ").append(useKeepUpdateLockClause);
} }
break; break;
case db2ISeriesV5R4AndLater: case db2ISeriesV5R4OrLater:
if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) { if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
forUpdateString.append(" ").append(forReadOnlyClause) forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRRClause) .append(" ").append(withRRClause)
@ -289,7 +289,7 @@ public class DB2Dictionary
return forUpdateString.toString(); return forUpdateString.toString();
} }
public boolean isDB2UDBV82AndLater(DatabaseMetaData metadata, int maj, public boolean isDB2UDBV82OrLater(DatabaseMetaData metadata, int maj,
int min) throws SQLException { int min) throws SQLException {
boolean match = false; boolean match = false;
if (metadata.getDatabaseProductVersion().indexOf("SQL") != -1 if (metadata.getDatabaseProductVersion().indexOf("SQL") != -1
@ -307,7 +307,7 @@ public class DB2Dictionary
return match; return match;
} }
public boolean isDB2ISeriesV5R3AndEarlier(DatabaseMetaData metadata) public boolean isDB2ISeriesV5R3OrEarlier(DatabaseMetaData metadata)
throws SQLException { throws SQLException {
boolean match = false; boolean match = false;
if (metadata.getDatabaseProductVersion().indexOf("AS") != -1 if (metadata.getDatabaseProductVersion().indexOf("AS") != -1
@ -317,7 +317,7 @@ public class DB2Dictionary
return match; return match;
} }
public boolean isDB2ISeriesV5R4AndLater(DatabaseMetaData metadata) public boolean isDB2ISeriesV5R4OrLater(DatabaseMetaData metadata)
throws SQLException { throws SQLException {
boolean match = false; boolean match = false;
if (metadata.getDatabaseProductVersion().indexOf("AS") != -1 if (metadata.getDatabaseProductVersion().indexOf("AS") != -1

View File

@ -82,9 +82,9 @@ public class TestIsolationLevelOverride
.getIsolation()); .getIsolation());
q.getResultList(); q.getResultList();
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). if (dict instanceof DB2Dictionary) {
getDb2ServerType() == 1) || ((DB2Dictionary)dict) if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
.getDb2ServerType()== 2)) { || (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField," assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField," + " t0.charField, t0.dateField, t0.doubleField,"
@ -93,22 +93,19 @@ public class TestIsolationLevelOverride
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) " + "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR UPDATE OF"); + " FOR UPDATE OF");
} }
// it is DB2 v82 or later // it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
getDb2ServerType() == 3) || ((DB2Dictionary)dict) || (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField," assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField," + " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, " + " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM " + "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) " + "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS"); + " FOR READ ONLY WITH RR USE AND KEEP "
+ "UPDATE LOCKS");
} }
else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict).
getDb2ServerType() == 5){
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField," assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField," + " t0.charField, t0.dateField, t0.doubleField,"
@ -118,17 +115,19 @@ public class TestIsolationLevelOverride
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE " + " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE "
+ "LOCKS"); + "LOCKS");
} }
else if (dict instanceof DB2Dictionary) { else {
fail("OpenJPA currently only supports per-query isolation " fail("OpenJPA currently only supports "
+ "level configuration on the following databases: DB2"); +"per-query isolation level configuration on the"
+" following databases: DB2");
}
} }
} else { } else {
((JDBCFetchPlan) em.getFetchPlan()) ((JDBCFetchPlan) em.getFetchPlan())
.setIsolation(IsolationLevel.SERIALIZABLE); .setIsolation(IsolationLevel.SERIALIZABLE);
em.find(AllFieldTypes.class, 0); em.find(AllFieldTypes.class, 0);
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). if (dict instanceof DB2Dictionary ) {
getDb2ServerType() == 1) || ((DB2Dictionary)dict) if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
.getDb2ServerType()== 2)) { || (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
@ -138,9 +137,8 @@ public class TestIsolationLevelOverride
+ " FOR UPDATE OF optimize for 1 row"); + " FOR UPDATE OF optimize for 1 row");
} }
// it is DB2 v82 or later // it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
getDb2ServerType() == 3) || ((DB2Dictionary)dict) || (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
@ -150,20 +148,21 @@ public class TestIsolationLevelOverride
+ " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS" + " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row"); + " optimize for 1 row");
} }
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict). else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
getDb2ServerType() == 5) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField," + " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM " + " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? " + "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE LOCKS" + " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE"
+ " optimize for 1 row"); + " LOCKS optimize for 1 row");
}
else {
fail("OpenJPA currently only supports per-query"
+" isolation level configuration on the following"
+" databases: DB2");
} }
else if (dict instanceof DB2Dictionary) {
fail("OpenJPA currently only supports per-query isolation "
+ "level configuration on the following databases: DB2");
} }
} }
} catch (InvalidStateException pe) { } catch (InvalidStateException pe) {

View File

@ -57,11 +57,10 @@ public class TestSelectForUpdateOverride
OpenJPAPersistence.cast(em).getFetchPlan() OpenJPAPersistence.cast(em).getFetchPlan()
.setReadLockMode(LockModeType.WRITE); .setReadLockMode(LockModeType.WRITE);
em.find(AllFieldTypes.class, 0); em.find(AllFieldTypes.class, 0);
assertEquals(1, sql.size()); assertEquals(1, sql.size());
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). if (dict instanceof DB2Dictionary) {
getDb2ServerType() == 1) || ((DB2Dictionary)dict) if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
.getDb2ServerType()== 2)) { || (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
@ -71,9 +70,8 @@ public class TestSelectForUpdateOverride
+ " FOR UPDATE OF optimize for 1 row"); + " FOR UPDATE OF optimize for 1 row");
} }
// it is DB2 v82 or later // it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict). else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
getDb2ServerType() == 3) || ((DB2Dictionary)dict) || (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
@ -83,8 +81,7 @@ public class TestSelectForUpdateOverride
+ " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS" + " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row"); + " optimize for 1 row");
} }
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict). else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
getDb2ServerType() == 5) {
assertEquals(1, sql.size()); assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, " assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField," + "t0.charField, t0.dateField, t0.doubleField,"
@ -94,9 +91,11 @@ public class TestSelectForUpdateOverride
+ " FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE LOCKS" + " FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE LOCKS"
+ " optimize for 1 row"); + " optimize for 1 row");
} }
else if (dict instanceof DB2Dictionary) { else {
fail("OpenJPA currently only supports per-query isolation " + fail("OpenJPA currently only supports per-query isolation "
"level configuration on the following databases: DB2"); + "level configuration on the following databases: "
+ "DB2");
}
} }
} finally { } finally {
em.getTransaction().rollback(); em.getTransaction().rollback();