HHH-9995 - Finish pgsql database profile
This commit is contained in:
parent
ca0eee08a0
commit
bac4cd2128
|
@ -4,4 +4,4 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency 'org.postgresql:postgresql:9.4-1201-jdbc41'
|
||||
jdbcDependency 'org.postgresql:postgresql:9.4-1203-jdbc41'
|
||||
|
|
|
@ -21,6 +21,5 @@ hibernate.max_fetch_depth 5
|
|||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
javax.persistence.validation.mode=NONE
|
||||
hibernate.service.allow_crawling=false
|
||||
hibernate.session.events.log=true
|
|
@ -17,8 +17,10 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.GenericJDBCException;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.internal.SessionImpl;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
@ -102,8 +104,17 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
|
|||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// initially sequence should be uninitialized
|
||||
assertEquals( 0L, extractSequenceValue( (sessionImpl) ) );
|
||||
|
||||
if ( sessionFactory.getDialect() instanceof PostgreSQL81Dialect ) {
|
||||
try {
|
||||
assertEquals( 0L, extractSequenceValue() );
|
||||
}
|
||||
catch (GenericJDBCException ge) {
|
||||
// PostgreSQL throws an exception if currval is called before nextval for this sequence in this session
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertEquals( 0L, extractSequenceValue() );
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
|
@ -111,28 +122,28 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
|
|||
assertEquals( 1L, generateValue() );
|
||||
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals( 1L, extractSequenceValue( (sessionImpl) ) );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 2L, generateValue() );
|
||||
assertEquals( 2L, extractSequenceValue( (sessionImpl) ) );
|
||||
assertEquals( 2L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 3L, generateValue() );
|
||||
assertEquals( 3L, extractSequenceValue( (sessionImpl) ) );
|
||||
assertEquals( 3L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 4L, generateValue() );
|
||||
assertEquals( 4L, extractSequenceValue( (sessionImpl) ) );
|
||||
assertEquals( 4L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 5L, generateValue() );
|
||||
assertEquals( 5L, extractSequenceValue( (sessionImpl) ) );
|
||||
assertEquals( 5L, extractSequenceValue() );
|
||||
|
||||
((Session) sessionImpl).close();
|
||||
}
|
||||
|
||||
private long extractSequenceValue(SessionImplementor sessionImpl) {
|
||||
private long extractSequenceValue() {
|
||||
return sequenceValueExtractor.extractSequenceValue( sessionImpl );
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.GenericJDBCException;
|
||||
import org.hibernate.internal.SessionImpl;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
|
@ -92,38 +94,48 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// initially sequence should be uninitialized
|
||||
assertEquals( 0L, extractSequenceValue( sessionImpl ) );
|
||||
if ( sessionFactory.getDialect() instanceof PostgreSQL81Dialect ) {
|
||||
try {
|
||||
assertEquals( 0L, extractSequenceValue() );
|
||||
}
|
||||
catch (GenericJDBCException ge) {
|
||||
// PostgreSQL throws an exception if currval is called before nextval for this sequence in this session
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertEquals( 0L, extractSequenceValue() );
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
assertEquals( 4L, generateValue() );
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 5L, generateValue() );
|
||||
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 6L, generateValue() );
|
||||
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 7L, generateValue() );
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// after a clock over
|
||||
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 8L, generateValue() );
|
||||
// this should force an increment in the sequence value
|
||||
assertEquals( 2L, extractSequenceValue( sessionImpl ) );
|
||||
assertEquals( 2L, extractSequenceValue() );
|
||||
|
||||
((Session) sessionImpl).close();
|
||||
}
|
||||
|
||||
private long extractSequenceValue(SessionImplementor sessionImpl) {
|
||||
private long extractSequenceValue() {
|
||||
return sequenceValueExtractor.extractSequenceValue( sessionImpl );
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.hibernate.Transaction;
|
|||
import org.hibernate.dialect.DerbyDialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.GenericJDBCException;
|
||||
import org.hibernate.jdbc.Work;
|
||||
|
||||
/**
|
||||
|
@ -43,16 +44,20 @@ public class SequenceValueExtractor {
|
|||
public void execute(Connection connection) throws SQLException {
|
||||
Session session = (Session) sessionImpl;
|
||||
Transaction transaction = session.beginTransaction();
|
||||
final PreparedStatement query = sessionImpl.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( queryString );
|
||||
ResultSet resultSet = sessionImpl.getJdbcCoordinator().getResultSetReturn().extract( query );
|
||||
resultSet.next();
|
||||
value = resultSet.getLong( 1 );
|
||||
|
||||
resultSet.close();
|
||||
transaction.commit();
|
||||
try {
|
||||
final PreparedStatement query = sessionImpl.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( queryString );
|
||||
ResultSet resultSet = sessionImpl.getJdbcCoordinator().getResultSetReturn().extract( query );
|
||||
resultSet.next();
|
||||
value = resultSet.getLong( 1 );
|
||||
|
||||
resultSet.close();
|
||||
transaction.commit();
|
||||
}catch (GenericJDBCException e){
|
||||
transaction.rollback();
|
||||
throw e;
|
||||
}
|
||||
if ( dialect instanceof DerbyDialect ) {
|
||||
value--;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class EnhancerTest extends BaseUnitTestCase {
|
|||
EnhancerTestUtils.runEnhancerTestTask( LazyCollectionLoadingTestTask.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(timeout = 10000)
|
||||
@TestForIssue( jiraKey = "HHH-10055" )
|
||||
@FailureExpected( jiraKey = "HHH-10055" )
|
||||
public void testOnDemand() {
|
||||
|
|
|
@ -81,6 +81,7 @@ public class SchemaUpdateTableBackedSequenceTest extends BaseUnitTestCase {
|
|||
if ( action.startsWith( "insert into test_seq" ) ) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,5 +103,11 @@ public class SchemaUpdateTableBackedSequenceTest extends BaseUnitTestCase {
|
|||
);
|
||||
|
||||
assertTrue( target.found );
|
||||
|
||||
ssr.getService( SchemaManagementTool.class ).getSchemaDropper( null ).doDrop(
|
||||
metadata,
|
||||
false,
|
||||
Arrays.asList( target, new TargetDatabaseImpl( ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess() ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue