Skip to content

Commit 5cbefff

Browse files
committed
HHH-9995 - Finish pgsql database profile
1 parent cfbdef1 commit 5cbefff

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

databases/pgsql/matrix.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
7-
jdbcDependency 'org.postgresql:postgresql:9.4-1201-jdbc41'
7+
jdbcDependency 'org.postgresql:postgresql:9.4-1203-jdbc41'

databases/pgsql/resources/hibernate.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ hibernate.max_fetch_depth 5
2121
hibernate.cache.region_prefix hibernate.test
2222
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
2323

24-
javax.persistence.validation.mode=NONE
2524
hibernate.service.allow_crawling=false
2625
hibernate.session.events.log=true

hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1818
import org.hibernate.boot.spi.MetadataBuildingContext;
1919
import org.hibernate.cfg.AvailableSettings;
20+
import org.hibernate.dialect.PostgreSQL81Dialect;
2021
import org.hibernate.engine.spi.SessionFactoryImplementor;
2122
import org.hibernate.engine.spi.SessionImplementor;
23+
import org.hibernate.exception.GenericJDBCException;
2224
import org.hibernate.id.enhanced.SequenceStyleGenerator;
2325
import org.hibernate.internal.SessionImpl;
2426
import org.hibernate.type.StandardBasicTypes;
@@ -102,37 +104,46 @@ public void testHiLoAlgorithm() {
102104

103105
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104106
// initially sequence should be uninitialized
105-
assertEquals( 0L, extractSequenceValue( (sessionImpl) ) );
106-
107+
if ( sessionFactory.getDialect() instanceof PostgreSQL81Dialect ) {
108+
try {
109+
assertEquals( 0L, extractSequenceValue() );
110+
}
111+
catch (GenericJDBCException ge) {
112+
// PostgreSQL throws an exception if currval is called before nextval for this sequence in this session
113+
}
114+
}
115+
else {
116+
assertEquals( 0L, extractSequenceValue() );
117+
}
107118

108119
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109120
// historically the hilo generators skipped the initial block of values;
110121
// so the first generated id value is maxlo + 1, here be 4
111122
assertEquals( 1L, generateValue() );
112123

113124
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
114-
assertEquals( 1L, extractSequenceValue( (sessionImpl) ) );
125+
assertEquals( 1L, extractSequenceValue() );
115126

116127
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117128
assertEquals( 2L, generateValue() );
118-
assertEquals( 2L, extractSequenceValue( (sessionImpl) ) );
129+
assertEquals( 2L, extractSequenceValue() );
119130

120131
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121132
assertEquals( 3L, generateValue() );
122-
assertEquals( 3L, extractSequenceValue( (sessionImpl) ) );
133+
assertEquals( 3L, extractSequenceValue() );
123134

124135
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125136
assertEquals( 4L, generateValue() );
126-
assertEquals( 4L, extractSequenceValue( (sessionImpl) ) );
137+
assertEquals( 4L, extractSequenceValue() );
127138

128139
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129140
assertEquals( 5L, generateValue() );
130-
assertEquals( 5L, extractSequenceValue( (sessionImpl) ) );
141+
assertEquals( 5L, extractSequenceValue() );
131142

132143
((Session) sessionImpl).close();
133144
}
134145

135-
private long extractSequenceValue(SessionImplementor sessionImpl) {
146+
private long extractSequenceValue() {
136147
return sequenceValueExtractor.extractSequenceValue( sessionImpl );
137148
}
138149

hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1717
import org.hibernate.boot.spi.MetadataBuildingContext;
1818
import org.hibernate.cfg.AvailableSettings;
19+
import org.hibernate.dialect.PostgreSQL81Dialect;
1920
import org.hibernate.engine.spi.SessionFactoryImplementor;
2021
import org.hibernate.engine.spi.SessionImplementor;
22+
import org.hibernate.exception.GenericJDBCException;
2123
import org.hibernate.internal.SessionImpl;
2224
import org.hibernate.type.StandardBasicTypes;
2325

@@ -92,38 +94,48 @@ public void testHiLoAlgorithm() {
9294

9395
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9496
// initially sequence should be uninitialized
95-
assertEquals( 0L, extractSequenceValue( sessionImpl ) );
97+
if ( sessionFactory.getDialect() instanceof PostgreSQL81Dialect ) {
98+
try {
99+
assertEquals( 0L, extractSequenceValue() );
100+
}
101+
catch (GenericJDBCException ge) {
102+
// PostgreSQL throws an exception if currval is called before nextval for this sequence in this session
103+
}
104+
}
105+
else {
106+
assertEquals( 0L, extractSequenceValue() );
107+
}
96108

97109
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98110
// historically the hilo generators skipped the initial block of values;
99111
// so the first generated id value is maxlo + 1, here be 4
100112
assertEquals( 4L, generateValue() );
101113
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
102-
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
114+
assertEquals( 1L, extractSequenceValue() );
103115

104116
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105117
assertEquals( 5L, generateValue() );
106-
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
118+
assertEquals( 1L, extractSequenceValue() );
107119

108120
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109121
assertEquals( 6L, generateValue() );
110-
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
122+
assertEquals( 1L, extractSequenceValue() );
111123

112124
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113125
assertEquals( 7L, generateValue() );
114126
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
115127
// after a clock over
116-
assertEquals( 1L, extractSequenceValue( sessionImpl ) );
128+
assertEquals( 1L, extractSequenceValue() );
117129

118130
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119131
assertEquals( 8L, generateValue() );
120132
// this should force an increment in the sequence value
121-
assertEquals( 2L, extractSequenceValue( sessionImpl ) );
133+
assertEquals( 2L, extractSequenceValue() );
122134

123135
((Session) sessionImpl).close();
124136
}
125137

126-
private long extractSequenceValue(SessionImplementor sessionImpl) {
138+
private long extractSequenceValue() {
127139
return sequenceValueExtractor.extractSequenceValue( sessionImpl );
128140
}
129141

hibernate-core/src/test/java/org/hibernate/id/SequenceValueExtractor.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hibernate.dialect.DerbyDialect;
1717
import org.hibernate.dialect.Dialect;
1818
import org.hibernate.engine.spi.SessionImplementor;
19+
import org.hibernate.exception.GenericJDBCException;
1920
import org.hibernate.jdbc.Work;
2021

2122
/**
@@ -43,16 +44,20 @@ class WorkImpl implements Work {
4344
public void execute(Connection connection) throws SQLException {
4445
Session session = (Session) sessionImpl;
4546
Transaction transaction = session.beginTransaction();
46-
final PreparedStatement query = sessionImpl.getJdbcCoordinator()
47-
.getStatementPreparer()
48-
.prepareStatement( queryString );
49-
ResultSet resultSet = sessionImpl.getJdbcCoordinator().getResultSetReturn().extract( query );
50-
resultSet.next();
51-
value = resultSet.getLong( 1 );
52-
53-
resultSet.close();
54-
transaction.commit();
47+
try {
48+
final PreparedStatement query = sessionImpl.getJdbcCoordinator()
49+
.getStatementPreparer()
50+
.prepareStatement( queryString );
51+
ResultSet resultSet = sessionImpl.getJdbcCoordinator().getResultSetReturn().extract( query );
52+
resultSet.next();
53+
value = resultSet.getLong( 1 );
5554

55+
resultSet.close();
56+
transaction.commit();
57+
}catch (GenericJDBCException e){
58+
transaction.rollback();
59+
throw e;
60+
}
5661
if ( dialect instanceof DerbyDialect ) {
5762
value--;
5863
}

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testLazyCollectionHandling() {
7070
EnhancerTestUtils.runEnhancerTestTask( LazyCollectionLoadingTestTask.class );
7171
}
7272

73-
@Test
73+
@Test(timeout = 10000)
7474
@TestForIssue( jiraKey = "HHH-10055" )
7575
@FailureExpected( jiraKey = "HHH-10055" )
7676
public void testOnDemand() {

hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaUpdateTableBackedSequenceTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void accept(String action) {
8181
if ( action.startsWith( "insert into test_seq" ) ) {
8282
found = true;
8383
}
84+
8485
}
8586
}
8687

@@ -102,5 +103,11 @@ public void accept(String action) {
102103
);
103104

104105
assertTrue( target.found );
106+
107+
ssr.getService( SchemaManagementTool.class ).getSchemaDropper( null ).doDrop(
108+
metadata,
109+
false,
110+
Arrays.asList( target, new TargetDatabaseImpl( ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess() ) )
111+
);
105112
}
106113
}

0 commit comments

Comments
 (0)