OPENJPA-222 testcases for DB2

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@530554 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David J. Wisneski 2007-04-19 21:33:23 +00:00
parent 30f2042510
commit 0f66458d4c
3 changed files with 131 additions and 23 deletions

View File

@ -252,37 +252,31 @@ public class DB2Dictionary
if (isolationLevel ==
Connection.TRANSACTION_READ_UNCOMMITTED) {
forUpdateString.append(" ").append(withRSClause)
.append(" ").append(forUpdateOfClause).append(" ");
} else {
forUpdateString.append(" ").append(forUpdateOfClause)
.append(" ");
}
.append(" ").append(forUpdateOfClause);
} else
forUpdateString.append(" ").append(forUpdateOfClause);
break;
case db2ZOSV8xOrLater:
case db2UDBV82AndLater:
if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRRClause)
.append(" ").append(useKeepUpdateLockClause)
.append(" ");
.append(" ").append(useKeepUpdateLockClause);
} else {
forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRSClause)
.append(" ").append(useKeepUpdateLockClause)
.append(" ");
.append(" ").append(useKeepUpdateLockClause);
}
break;
case db2ISeriesV5R4AndLater:
if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRRClause)
.append(" ").append(useKeepExclusiveLockClause)
.append(" ");
.append(" ").append(useKeepExclusiveLockClause);
} else {
forUpdateString.append(" ").append(forReadOnlyClause)
.append(" ").append(withRSClause)
.append(" ").append(useKeepExclusiveLockClause)
.append(" ");
.append(" ").append(useKeepExclusiveLockClause);
}
break;
}
@ -413,4 +407,8 @@ public class DB2Dictionary
return sqle.getMessage();
}
}
}
public int getDb2ServerType() {
return db2ServerType;
}
}

View File

@ -82,18 +82,89 @@ 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");
}
else {
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) {
assertEquals(1, sql.size());
assertSQL(".*DB2-specific SQL to test for goes here.*");
} else {
fail("OpenJPA currently only supports per-query isolation " +
"level configuration on the following databases: DB2");
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");
}
else {
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

@ -26,6 +26,7 @@ import org.apache.openjpa.persistence.simple.AllFieldTypes;
import org.apache.openjpa.persistence.OpenJPAPersistence;
import org.apache.openjpa.persistence.FetchPlan;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.jdbc.sql.DB2Dictionary;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.HSQLDictionary;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
@ -58,7 +59,45 @@ public class TestSelectForUpdateOverride
em.find(AllFieldTypes.class, 0);
assertEquals(1, sql.size());
assertSQL(".*FOR UPDATE.*");
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");
}
else {
fail("OpenJPA currently only supports per-query isolation " +
"level configuration on the following databases: DB2");
}
} finally {
em.getTransaction().rollback();
em.close();