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

View File

@ -68,7 +68,7 @@ public class TestIsolationLevelOverride
em.getTransaction().begin();
if (useHintsAndQueries) {
Query q = em.createQuery(
"select o from AllFieldTypes o where o.intField = :p");
"select o from AllFieldTypes o where o.intField = :p");
q.setParameter("p", 0);
if (useStringHints) {
q.setHint("openjpa.FetchPlan.Isolation", "SERIALIZABLE");
@ -82,89 +82,88 @@ public class TestIsolationLevelOverride
.getIsolation());
q.getResultList();
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 1) || ((DB2Dictionary)dict)
.getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR UPDATE OF");
}
// it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 3) || ((DB2Dictionary)dict)
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS");
}
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict).
getDb2ServerType() == 5){
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE "
+ "LOCKS");
if (dict instanceof DB2Dictionary) {
if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
|| (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR UPDATE OF");
}
// it is DB2 v82 or later
else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
|| (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR READ ONLY WITH RR USE AND KEEP "
+ "UPDATE LOCKS");
}
else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.id, t0.booleanField, t0.byteField,"
+ " t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField, "
+ "t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE \\(t0.intField = \\?\\) "
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE "
+ "LOCKS");
}
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");
}
} else {
((JDBCFetchPlan) em.getFetchPlan())
.setIsolation(IsolationLevel.SERIALIZABLE);
em.find(AllFieldTypes.class, 0);
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 1) || ((DB2Dictionary)dict)
.getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR UPDATE OF optimize for 1 row");
}
// it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 3) || ((DB2Dictionary)dict)
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row");
}
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict).
getDb2ServerType() == 5) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE LOCKS"
+ " optimize for 1 row");
if (dict instanceof DB2Dictionary ) {
if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
|| (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR UPDATE OF optimize for 1 row");
}
// it is DB2 v82 or later
else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
|| (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row");
}
else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RR USE AND KEEP EXCLUSIVE"
+ " 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) {
// if we're not using DB2, we expect an InvalidStateException.

View File

@ -57,47 +57,46 @@ public class TestSelectForUpdateOverride
OpenJPAPersistence.cast(em).getFetchPlan()
.setReadLockMode(LockModeType.WRITE);
em.find(AllFieldTypes.class, 0);
assertEquals(1, sql.size());
if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 1) || ((DB2Dictionary)dict)
.getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR UPDATE OF optimize for 1 row");
}
// it is DB2 v82 or later
else if (dict instanceof DB2Dictionary &&((((DB2Dictionary)dict).
getDb2ServerType() == 3) || ((DB2Dictionary)dict)
.getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row");
}
else if (dict instanceof DB2Dictionary && ((DB2Dictionary)dict).
getDb2ServerType() == 5) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE LOCKS"
+ " optimize for 1 row");
if (dict instanceof DB2Dictionary) {
if ((((DB2Dictionary)dict).getDb2ServerType() == 1)
|| (((DB2Dictionary)dict).getDb2ServerType()== 2)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR UPDATE OF optimize for 1 row");
}
// it is DB2 v82 or later
else if ((((DB2Dictionary)dict).getDb2ServerType() == 3)
|| (((DB2Dictionary)dict).getDb2ServerType() == 4)) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS"
+ " optimize for 1 row");
}
else if (((DB2Dictionary)dict).getDb2ServerType() == 5) {
assertEquals(1, sql.size());
assertSQL("SELECT t0.booleanField, t0.byteField, "
+ "t0.charField, t0.dateField, t0.doubleField,"
+ " t0.floatField, t0.intField, t0.longField,"
+ " t0.shortField, t0.stringField FROM "
+ "AllFieldTypes t0 WHERE t0.id = \\? "
+ " FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE 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");
}
} finally {
em.getTransaction().rollback();
em.close();