HHH-6985 - Change up tests for PostgreSQL LockMode issues

This commit is contained in:
Steve Ebersole 2012-01-19 10:40:26 -06:00
parent 66a9f21e89
commit 9ff70a8acf
3 changed files with 30 additions and 21 deletions

View File

@ -43,7 +43,6 @@
import java.util.TreeSet;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
@ -84,11 +83,14 @@
import org.hibernate.jdbc.AbstractWork;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.type.StandardBasicTypes;
import org.junit.Test;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.env.ConnectionProviderBuilder;
import org.hibernate.type.StandardBasicTypes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -1394,7 +1396,7 @@ public void testQueryLockMode() throws Exception {
baz.setFoo(bar);
s.save(baz);
Query q = s.createQuery("from Foo foo, Bar bar");
if ( !(getDialect() instanceof DB2Dialect) ) {
if ( supportsLockingNullableSideOfJoin( getDialect() ) ) {
q.setLockMode("bar", LockMode.UPGRADE);
}
Object[] result = (Object[]) q.uniqueResult();
@ -1423,12 +1425,12 @@ public void testQueryLockMode() throws Exception {
s = openSession();
tx = s.beginTransaction();
q = s.createQuery("from Foo foo, Bar bar, Bar bar2");
if ( !(getDialect() instanceof DB2Dialect) ) {
if ( supportsLockingNullableSideOfJoin( getDialect() ) ) {
q.setLockMode("bar", LockMode.UPGRADE);
}
q.setLockMode("bar2", LockMode.READ);
result = (Object[]) q.list().get(0);
if ( !(getDialect() instanceof DB2Dialect) ) {
if ( supportsLockingNullableSideOfJoin( getDialect() ) ) {
assertTrue( s.getCurrentLockMode( result[0] )==LockMode.UPGRADE && s.getCurrentLockMode( result[1] )==LockMode.UPGRADE );
}
s.delete( result[0] );

View File

@ -30,7 +30,9 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.DefaultNamingStrategy;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -50,6 +52,11 @@ public void checkAntlrParserSetting() {
useAntlrParser = Boolean.valueOf( extractFromSystem( USE_ANTLR_PARSER_PROP ) );
}
protected boolean supportsLockingNullableSideOfJoin(Dialect dialect) {
// db2 and pgsql do *NOT*
return ! ( DB2Dialect.class.isInstance( dialect ) || PostgreSQLDialect.class.isInstance( dialect ) );
}
protected static String extractFromSystem(String systemPropertyName) {
try {
return System.getProperty( systemPropertyName );

View File

@ -34,8 +34,6 @@
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Hibernate;
@ -46,7 +44,6 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.MySQLDialect;
@ -54,9 +51,12 @@
import org.hibernate.internal.SessionImpl;
import org.hibernate.jdbc.AbstractWork;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.FailureExpected;
import org.hibernate.type.StandardBasicTypes;
import org.junit.Test;
import org.hibernate.testing.FailureExpected;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -167,7 +167,7 @@ public void testProxyReuse() throws Exception {
FooProxy foo2 = new Foo();
Serializable id = s.save(foo);
Serializable id2 = s.save(foo2);
foo2.setInt(1234567);
foo2.setInt( 1234567 );
foo.setInt(1234);
t.commit();
s.close();
@ -176,11 +176,11 @@ public void testProxyReuse() throws Exception {
t = s.beginTransaction();
foo = (FooProxy) s.load(Foo.class, id);
foo2 = (FooProxy) s.load(Foo.class, id2);
assertFalse( Hibernate.isInitialized(foo) );
Hibernate.initialize(foo2);
assertFalse( Hibernate.isInitialized( foo ) );
Hibernate.initialize( foo2 );
Hibernate.initialize(foo);
assertTrue( foo.getComponent().getImportantDates().length==4 );
assertTrue( foo2.getComponent().getImportantDates().length==4 );
assertTrue( foo2.getComponent().getImportantDates().length == 4 );
t.commit();
s.close();
@ -189,14 +189,14 @@ public void testProxyReuse() throws Exception {
foo.setKey( "xyzid" );
foo.setFloat( new Float( 1.2f ) );
foo2.setKey( (String) id ); //intentionally id, not id2!
foo2.setFloat( new Float(1.3f) );
foo2.setFloat( new Float( 1.3f ) );
foo2.getDependent().setKey( null );
foo2.getComponent().getSubcomponent().getFee().setKey(null);
assertFalse( foo2.getKey().equals( id ) );
s.save( foo );
s.update( foo2 );
assertEquals( foo2.getKey(), id );
assertTrue( foo2.getInt()==1234567 );
assertTrue( foo2.getInt() == 1234567 );
assertEquals( foo.getKey(), "xyzid" );
t.commit();
s.close();
@ -204,11 +204,11 @@ public void testProxyReuse() throws Exception {
s = openSession();
t = s.beginTransaction();
foo = (FooProxy) s.load(Foo.class, id);
assertTrue( foo.getInt()==1234567 );
assertTrue( foo.getInt() == 1234567 );
assertTrue( foo.getComponent().getImportantDates().length==4 );
String feekey = foo.getDependent().getKey();
String fookey = foo.getKey();
s.delete(foo);
s.delete( foo );
s.delete( s.get(Foo.class, id2) );
s.delete( s.get(Foo.class, "xyzid") );
// here is the issue (HHH-4092). After the deletes above there are 2 Fees and a Glarch unexpectedly hanging around
@ -218,14 +218,14 @@ public void testProxyReuse() throws Exception {
//to account for new id rollback shit
foo.setKey(fookey);
foo.getDependent().setKey(feekey);
foo.getComponent().setGlarch(null);
foo.getDependent().setKey( feekey );
foo.getComponent().setGlarch( null );
foo.getComponent().setSubcomponent(null);
s = openSession();
t = s.beginTransaction();
//foo.getComponent().setGlarch(null); //no id property!
s.replicate(foo, ReplicationMode.OVERWRITE);
s.replicate( foo, ReplicationMode.OVERWRITE );
t.commit();
s.close();
@ -264,7 +264,7 @@ public void testComplexCriteria() throws Exception {
baz.getFooSet().add(foo2);
baz.setFooArray( new FooProxy[] { foo1 } );
LockMode lockMode = (getDialect() instanceof DB2Dialect) ? LockMode.READ : LockMode.UPGRADE;
LockMode lockMode = supportsLockingNullableSideOfJoin( getDialect() ) ? LockMode.UPGRADE : LockMode.READ;
Criteria crit = s.createCriteria(Baz.class);
crit.createCriteria("topGlarchez")