mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-25 04:45:32 +00:00
HHH-6985 - Change up tests for PostgreSQL LockMode issues
This commit is contained in:
parent
66a9f21e89
commit
9ff70a8acf
@ -43,7 +43,6 @@
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
@ -84,11 +83,14 @@
|
|||||||
import org.hibernate.jdbc.AbstractWork;
|
import org.hibernate.jdbc.AbstractWork;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
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.DialectChecks;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@ -1394,7 +1396,7 @@ public void testQueryLockMode() throws Exception {
|
|||||||
baz.setFoo(bar);
|
baz.setFoo(bar);
|
||||||
s.save(baz);
|
s.save(baz);
|
||||||
Query q = s.createQuery("from Foo foo, Bar bar");
|
Query q = s.createQuery("from Foo foo, Bar bar");
|
||||||
if ( !(getDialect() instanceof DB2Dialect) ) {
|
if ( supportsLockingNullableSideOfJoin( getDialect() ) ) {
|
||||||
q.setLockMode("bar", LockMode.UPGRADE);
|
q.setLockMode("bar", LockMode.UPGRADE);
|
||||||
}
|
}
|
||||||
Object[] result = (Object[]) q.uniqueResult();
|
Object[] result = (Object[]) q.uniqueResult();
|
||||||
@ -1423,12 +1425,12 @@ public void testQueryLockMode() throws Exception {
|
|||||||
s = openSession();
|
s = openSession();
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
q = s.createQuery("from Foo foo, Bar bar, Bar bar2");
|
q = s.createQuery("from Foo foo, Bar bar, Bar bar2");
|
||||||
if ( !(getDialect() instanceof DB2Dialect) ) {
|
if ( supportsLockingNullableSideOfJoin( getDialect() ) ) {
|
||||||
q.setLockMode("bar", LockMode.UPGRADE);
|
q.setLockMode("bar", LockMode.UPGRADE);
|
||||||
}
|
}
|
||||||
q.setLockMode("bar2", LockMode.READ);
|
q.setLockMode("bar2", LockMode.READ);
|
||||||
result = (Object[]) q.list().get(0);
|
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 );
|
assertTrue( s.getCurrentLockMode( result[0] )==LockMode.UPGRADE && s.getCurrentLockMode( result[1] )==LockMode.UPGRADE );
|
||||||
}
|
}
|
||||||
s.delete( result[0] );
|
s.delete( result[0] );
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.DefaultNamingStrategy;
|
import org.hibernate.cfg.DefaultNamingStrategy;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.dialect.DB2Dialect;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory;
|
import org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
@ -50,6 +52,11 @@ public void checkAntlrParserSetting() {
|
|||||||
useAntlrParser = Boolean.valueOf( extractFromSystem( USE_ANTLR_PARSER_PROP ) );
|
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) {
|
protected static String extractFromSystem(String systemPropertyName) {
|
||||||
try {
|
try {
|
||||||
return System.getProperty( systemPropertyName );
|
return System.getProperty( systemPropertyName );
|
||||||
|
@ -34,8 +34,6 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
@ -46,7 +44,6 @@
|
|||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.dialect.DB2Dialect;
|
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.IngresDialect;
|
import org.hibernate.dialect.IngresDialect;
|
||||||
import org.hibernate.dialect.MySQLDialect;
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
@ -54,9 +51,12 @@
|
|||||||
import org.hibernate.internal.SessionImpl;
|
import org.hibernate.internal.SessionImpl;
|
||||||
import org.hibernate.jdbc.AbstractWork;
|
import org.hibernate.jdbc.AbstractWork;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.testing.FailureExpected;
|
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@ -167,7 +167,7 @@ public void testProxyReuse() throws Exception {
|
|||||||
FooProxy foo2 = new Foo();
|
FooProxy foo2 = new Foo();
|
||||||
Serializable id = s.save(foo);
|
Serializable id = s.save(foo);
|
||||||
Serializable id2 = s.save(foo2);
|
Serializable id2 = s.save(foo2);
|
||||||
foo2.setInt(1234567);
|
foo2.setInt( 1234567 );
|
||||||
foo.setInt(1234);
|
foo.setInt(1234);
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
@ -176,11 +176,11 @@ public void testProxyReuse() throws Exception {
|
|||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
foo = (FooProxy) s.load(Foo.class, id);
|
foo = (FooProxy) s.load(Foo.class, id);
|
||||||
foo2 = (FooProxy) s.load(Foo.class, id2);
|
foo2 = (FooProxy) s.load(Foo.class, id2);
|
||||||
assertFalse( Hibernate.isInitialized(foo) );
|
assertFalse( Hibernate.isInitialized( foo ) );
|
||||||
Hibernate.initialize(foo2);
|
Hibernate.initialize( foo2 );
|
||||||
Hibernate.initialize(foo);
|
Hibernate.initialize(foo);
|
||||||
assertTrue( foo.getComponent().getImportantDates().length==4 );
|
assertTrue( foo.getComponent().getImportantDates().length==4 );
|
||||||
assertTrue( foo2.getComponent().getImportantDates().length==4 );
|
assertTrue( foo2.getComponent().getImportantDates().length == 4 );
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
@ -189,14 +189,14 @@ public void testProxyReuse() throws Exception {
|
|||||||
foo.setKey( "xyzid" );
|
foo.setKey( "xyzid" );
|
||||||
foo.setFloat( new Float( 1.2f ) );
|
foo.setFloat( new Float( 1.2f ) );
|
||||||
foo2.setKey( (String) id ); //intentionally id, not id2!
|
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.getDependent().setKey( null );
|
||||||
foo2.getComponent().getSubcomponent().getFee().setKey(null);
|
foo2.getComponent().getSubcomponent().getFee().setKey(null);
|
||||||
assertFalse( foo2.getKey().equals( id ) );
|
assertFalse( foo2.getKey().equals( id ) );
|
||||||
s.save( foo );
|
s.save( foo );
|
||||||
s.update( foo2 );
|
s.update( foo2 );
|
||||||
assertEquals( foo2.getKey(), id );
|
assertEquals( foo2.getKey(), id );
|
||||||
assertTrue( foo2.getInt()==1234567 );
|
assertTrue( foo2.getInt() == 1234567 );
|
||||||
assertEquals( foo.getKey(), "xyzid" );
|
assertEquals( foo.getKey(), "xyzid" );
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
@ -204,11 +204,11 @@ public void testProxyReuse() throws Exception {
|
|||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
foo = (FooProxy) s.load(Foo.class, id);
|
foo = (FooProxy) s.load(Foo.class, id);
|
||||||
assertTrue( foo.getInt()==1234567 );
|
assertTrue( foo.getInt() == 1234567 );
|
||||||
assertTrue( foo.getComponent().getImportantDates().length==4 );
|
assertTrue( foo.getComponent().getImportantDates().length==4 );
|
||||||
String feekey = foo.getDependent().getKey();
|
String feekey = foo.getDependent().getKey();
|
||||||
String fookey = foo.getKey();
|
String fookey = foo.getKey();
|
||||||
s.delete(foo);
|
s.delete( foo );
|
||||||
s.delete( s.get(Foo.class, id2) );
|
s.delete( s.get(Foo.class, id2) );
|
||||||
s.delete( s.get(Foo.class, "xyzid") );
|
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
|
// 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
|
//to account for new id rollback shit
|
||||||
foo.setKey(fookey);
|
foo.setKey(fookey);
|
||||||
foo.getDependent().setKey(feekey);
|
foo.getDependent().setKey( feekey );
|
||||||
foo.getComponent().setGlarch(null);
|
foo.getComponent().setGlarch( null );
|
||||||
foo.getComponent().setSubcomponent(null);
|
foo.getComponent().setSubcomponent(null);
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
//foo.getComponent().setGlarch(null); //no id property!
|
//foo.getComponent().setGlarch(null); //no id property!
|
||||||
s.replicate(foo, ReplicationMode.OVERWRITE);
|
s.replicate( foo, ReplicationMode.OVERWRITE );
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ public void testComplexCriteria() throws Exception {
|
|||||||
baz.getFooSet().add(foo2);
|
baz.getFooSet().add(foo2);
|
||||||
baz.setFooArray( new FooProxy[] { foo1 } );
|
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);
|
Criteria crit = s.createCriteria(Baz.class);
|
||||||
crit.createCriteria("topGlarchez")
|
crit.createCriteria("topGlarchez")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user