HHH-15487 - Remove support for PostgreSQL versions older than 10

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2022-09-14 23:55:50 +02:00 committed by Jan Schatteman
parent 893e1b096e
commit bb5aa62927
23 changed files with 1543 additions and 136 deletions

View File

@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class SingleTableDiscriminatorFormulaTest { public class SingleTableDiscriminatorFormulaTest {
@Test @Test
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1) @RequiresDialect(value = PostgreSQLDialect.class)
public void test(EntityManagerFactoryScope scope) { public void test(EntityManagerFactoryScope scope) {
scope.inTransaction(entityManager -> { scope.inTransaction(entityManager -> {
DebitAccount debitAccount = new DebitAccount("123-debit"); DebitAccount debitAccount = new DebitAccount("123-debit");

View File

@ -14,7 +14,7 @@ import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8) @RequiresDialect(value = PostgreSQLDialect.class)
@Jpa( @Jpa(
annotatedClasses = { annotatedClasses = {
BaseSchemaGeneratorTest.Person.class, BaseSchemaGeneratorTest.Person.class,

View File

@ -0,0 +1,191 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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
*/
package org.hibernate.community.dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.cte.CteMaterialization;
import org.hibernate.sql.ast.tree.cte.CteStatement;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.Literal;
import org.hibernate.sql.ast.tree.expression.Summarization;
import org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate;
import org.hibernate.sql.ast.tree.predicate.LikePredicate;
import org.hibernate.sql.ast.tree.select.QueryGroup;
import org.hibernate.sql.ast.tree.select.QueryPart;
import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.exec.spi.JdbcOperation;
/**
* A SQL AST translator for PostgreSQL.
*
* @author Christian Beikov
*/
public class PostgreSQLLegacySqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAstTranslator<T> {
public PostgreSQLLegacySqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement) {
super( sessionFactory, statement );
}
@Override
protected void renderExpressionAsClauseItem(Expression expression) {
expression.accept( this );
}
@Override
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
final boolean isNegated = booleanExpressionPredicate.isNegated();
if ( isNegated ) {
appendSql( "not(" );
}
booleanExpressionPredicate.getExpression().accept( this );
if ( isNegated ) {
appendSql( CLOSE_PARENTHESIS );
}
}
@Override
protected void renderMaterializationHint(CteMaterialization materialization) {
if ( getDialect().getVersion().isSameOrAfter( 12 ) ) {
if ( materialization == CteMaterialization.NOT_MATERIALIZED ) {
appendSql( "not " );
}
appendSql( "materialized " );
}
}
@Override
public boolean supportsFilterClause() {
return getDialect().getVersion().isSameOrAfter( 9, 4 );
}
@Override
protected String getForUpdate() {
return getDialect().getVersion().isSameOrAfter( 9, 3 ) ? " for no key update" : " for update";
}
@Override
protected String getForShare(int timeoutMillis) {
// Note that `for key share` is inappropriate as that only means "prevent PK changes"
return " for share";
}
protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
// Check if current query part is already row numbering to avoid infinite recursion
if ( getQueryPartForRowNumbering() == queryPart || isRowsOnlyFetchClauseType( queryPart ) ) {
return false;
}
return !getDialect().supportsFetchClause( queryPart.getFetchClauseType() );
}
@Override
public void visitQueryGroup(QueryGroup queryGroup) {
if ( shouldEmulateFetchClause( queryGroup ) ) {
emulateFetchOffsetWithWindowFunctions( queryGroup, true );
}
else {
super.visitQueryGroup( queryGroup );
}
}
@Override
public void visitQuerySpec(QuerySpec querySpec) {
if ( shouldEmulateFetchClause( querySpec ) ) {
emulateFetchOffsetWithWindowFunctions( querySpec, true );
}
else {
super.visitQuerySpec( querySpec );
}
}
@Override
public void visitOffsetFetchClause(QueryPart queryPart) {
if ( !isRowNumberingCurrentQueryPart() ) {
if ( getDialect().supportsFetchClause( FetchClauseType.ROWS_ONLY ) ) {
renderOffsetFetchClause( queryPart, true );
}
else {
renderLimitOffsetClause( queryPart );
}
}
}
@Override
protected void renderSearchClause(CteStatement cte) {
// PostgreSQL does not support this, but it's just a hint anyway
}
@Override
protected void renderCycleClause(CteStatement cte) {
// PostgreSQL does not support this, but it can be emulated
}
@Override
protected void renderPartitionItem(Expression expression) {
// We render an empty group instead of literals as some DBs don't support grouping by literals
// Note that integer literals, which refer to select item positions, are handled in #visitGroupByClause
if ( expression instanceof Literal ) {
if ( getDialect().getVersion().isSameOrAfter( 9, 5 ) ) {
appendSql( "()" );
}
else {
appendSql( "(select 1" );
appendSql( getFromDualForSelectOnly() );
appendSql( ')' );
}
}
else if ( expression instanceof Summarization ) {
Summarization summarization = (Summarization) expression;
if ( getDialect().getVersion().isSameOrAfter( 9, 5 ) ) {
appendSql( summarization.getKind().sqlText() );
appendSql( OPEN_PARENTHESIS );
renderCommaSeparated( summarization.getGroupings() );
appendSql( CLOSE_PARENTHESIS );
}
else {
// This could theoretically be emulated by rendering all grouping variations of the query and
// connect them via union all but that's probably pretty inefficient and would have to happen
// on the query spec level
throw new UnsupportedOperationException( "Summarization is not supported by DBMS" );
}
}
else {
expression.accept( this );
}
}
@Override
public void visitLikePredicate(LikePredicate likePredicate) {
// We need a custom implementation here because PostgreSQL
// uses the backslash character as default escape character
// According to the documentation, we can overcome this by specifying an empty escape character
// See https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE
likePredicate.getMatchExpression().accept( this );
if ( likePredicate.isNegated() ) {
appendSql( " not" );
}
if ( likePredicate.isCaseSensitive() ) {
appendSql( " like " );
}
else {
appendSql( WHITESPACE );
appendSql( getDialect().getCaseInsensitiveLike() );
appendSql( WHITESPACE );
}
likePredicate.getPattern().accept( this );
if ( likePredicate.getEscapeCharacter() != null ) {
appendSql( " escape " );
likePredicate.getEscapeCharacter().accept( this );
}
else {
appendSql( " escape ''" );
}
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.community.dialect.sequence;
import org.hibernate.MappingException;
import org.hibernate.dialect.sequence.SequenceSupport;
/**
* Sequence support for {@link org.hibernate.dialect.PostgreSQLDialect}.
*
* @author Gavin King
*/
public class PostgreSQLLegacySequenceSupport implements SequenceSupport {
public static final SequenceSupport INSTANCE = new PostgreSQLLegacySequenceSupport();
public static final SequenceSupport LEGACY_INSTANCE = new PostgreSQLLegacySequenceSupport() {
@Override
public String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName;
}
};
@Override
public String getSelectSequenceNextValString(String sequenceName) {
return "nextval('" + sequenceName + "')";
}
@Override
public String getSelectSequencePreviousValString(String sequenceName) throws MappingException {
return "currval('" + sequenceName + "')";
}
@Override
public boolean sometimesNeedsStartingValue() {
return true;
}
@Override
public String getDropSequenceString(String sequenceName) {
return "drop sequence if exists " + sequenceName;
}
}

View File

@ -28,7 +28,6 @@ import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.PostgreSQLIdentityColumnSupport; import org.hibernate.dialect.identity.PostgreSQLIdentityColumnSupport;
import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler; import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport; import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport; import org.hibernate.dialect.sequence.SequenceSupport;
@ -121,13 +120,13 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
* @author Gavin King * @author Gavin King
*/ */
public class PostgreSQLDialect extends Dialect { public class PostgreSQLDialect extends Dialect {
private final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 10 );
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport(); private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
private final PostgreSQLDriverKind driverKind; private final PostgreSQLDriverKind driverKind;
public PostgreSQLDialect() { public PostgreSQLDialect() {
this( DatabaseVersion.make( 8, 0 ) ); this( MINIMUM_VERSION );
} }
public PostgreSQLDialect(DialectResolutionInfo info) { public PostgreSQLDialect(DialectResolutionInfo info) {
@ -145,6 +144,11 @@ public class PostgreSQLDialect extends Dialect {
this.driverKind = driverKind; this.driverKind = driverKind;
} }
@Override
protected DatabaseVersion getMinimumSupportedVersion() {
return MINIMUM_VERSION;
}
@Override @Override
public boolean getDefaultNonContextualLobCreation() { public boolean getDefaultNonContextualLobCreation() {
return true; return true;
@ -220,9 +224,7 @@ public class PostgreSQLDialect extends Dialect {
); );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( SQLXML, "xml", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( SQLXML, "xml", this ) );
if ( getVersion().isSameOrAfter( 8, 2 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( UUID, "uuid", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( UUID, "uuid", this ) );
}
if ( PostgreSQLPGObjectJdbcType.isUsable() ) { if ( PostgreSQLPGObjectJdbcType.isUsable() ) {
// The following DDL types require that the PGobject class is usable/visible // The following DDL types require that the PGobject class is usable/visible
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( INET, "inet", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( INET, "inet", this ) );
@ -230,16 +232,9 @@ public class PostgreSQLDialect extends Dialect {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( GEOGRAPHY, "geography", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( GEOGRAPHY, "geography", this ) );
ddlTypeRegistry.addDescriptor( new Scale6IntervalSecondDdlType( this ) ); ddlTypeRegistry.addDescriptor( new Scale6IntervalSecondDdlType( this ) );
if ( getVersion().isSameOrAfter( 9, 2 ) ) {
// Prefer jsonb if possible // Prefer jsonb if possible
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "jsonb", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "jsonb", this ) );
} }
else {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
}
}
}
} }
@Override @Override
@ -543,13 +538,11 @@ public class PostgreSQLDialect extends Dialect {
functionFactory.windowFunctions(); functionFactory.windowFunctions();
functionFactory.listagg_stringAgg( "varchar" ); functionFactory.listagg_stringAgg( "varchar" );
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
functionFactory.makeDateTimeTimestamp(); functionFactory.makeDateTimeTimestamp();
// Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions // Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions
functionFactory.inverseDistributionOrderedSetAggregates(); functionFactory.inverseDistributionOrderedSetAggregates();
functionFactory.hypotheticalOrderedSetAggregates(); functionFactory.hypotheticalOrderedSetAggregates();
} }
}
@Override @Override
public NameQualifierSupport getNameQualifierSupport() { public NameQualifierSupport getNameQualifierSupport() {
@ -570,39 +563,37 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public boolean supportsIfExistsBeforeTableName() { public boolean supportsIfExistsBeforeTableName() {
return getVersion().isSameOrAfter( 8, 2 ); return true;
} }
@Override @Override
public boolean supportsIfExistsBeforeConstraintName() { public boolean supportsIfExistsBeforeConstraintName() {
return getVersion().isSameOrAfter( 9 ); return true;
} }
@Override @Override
public boolean supportsIfExistsAfterAlterTable() { public boolean supportsIfExistsAfterAlterTable() {
return getVersion().isSameOrAfter( 9, 2 ); return true;
} }
@Override @Override
public boolean supportsValuesList() { public boolean supportsValuesList() {
return getVersion().isSameOrAfter( 8, 2 ); return true;
} }
@Override @Override
public boolean supportsPartitionBy() { public boolean supportsPartitionBy() {
return getVersion().isSameOrAfter( 9, 1 ); return true;
} }
@Override @Override
public boolean supportsNonQueryWithCTE() { public boolean supportsNonQueryWithCTE() {
return getVersion().isSameOrAfter( 9, 1 ); return true;
} }
@Override @Override
public SequenceSupport getSequenceSupport() { public SequenceSupport getSequenceSupport() {
return getVersion().isBefore( 8, 2 ) return PostgreSQLSequenceSupport.INSTANCE;
? PostgreSQLSequenceSupport.LEGACY_INSTANCE
: PostgreSQLSequenceSupport.INSTANCE;
} }
@Override @Override
@ -617,9 +608,7 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public LimitHandler getLimitHandler() { public LimitHandler getLimitHandler() {
return getVersion().isBefore( 8, 4 ) return OffsetFetchLimitHandler.INSTANCE;
? LimitOffsetLimitHandler.INSTANCE
: OffsetFetchLimitHandler.INSTANCE;
} }
@Override @Override
@ -780,7 +769,7 @@ public class PostgreSQLDialect extends Dialect {
/** /**
* Constraint-name extractor for Postgres constraint violation exceptions. * Constraint-name extractor for Postgres constraint violation exceptions.
* Orginally contributed by Denny Bartelt. * Originally contributed by Denny Bartelt.
*/ */
private static final ViolatedConstraintNameExtractor EXTRACTOR = private static final ViolatedConstraintNameExtractor EXTRACTOR =
new TemplatedViolatedConstraintNameExtractor( sqle -> { new TemplatedViolatedConstraintNameExtractor( sqle -> {
@ -1084,7 +1073,7 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public boolean supportsNoWait() { public boolean supportsNoWait() {
return getVersion().isSameOrAfter( 8, 1 ); return true;
} }
@Override @Override
@ -1094,7 +1083,7 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public boolean supportsSkipLocked() { public boolean supportsSkipLocked() {
return getVersion().isSameOrAfter( 9, 5 ); return true;
} }
@Override @Override
@ -1109,14 +1098,14 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public boolean supportsLateral() { public boolean supportsLateral() {
return getVersion().isSameOrAfter( 9, 3 ); return true;
} }
@Override @Override
public boolean supportsFetchClause(FetchClauseType type) { public boolean supportsFetchClause(FetchClauseType type) {
switch ( type ) { switch ( type ) {
case ROWS_ONLY: case ROWS_ONLY:
return getVersion().isSameOrAfter( 8, 4 ); return true;
case PERCENT_ONLY: case PERCENT_ONLY:
case PERCENT_WITH_TIES: case PERCENT_WITH_TIES:
return false; return false;
@ -1134,17 +1123,13 @@ public class PostgreSQLDialect extends Dialect {
@Override @Override
public void augmentRecognizedTableTypes(List<String> tableTypesList) { public void augmentRecognizedTableTypes(List<String> tableTypesList) {
super.augmentRecognizedTableTypes( tableTypesList ); super.augmentRecognizedTableTypes( tableTypesList );
if ( getVersion().isSameOrAfter( 9, 3 ) ) {
tableTypesList.add( "MATERIALIZED VIEW" ); tableTypesList.add( "MATERIALIZED VIEW" );
/* /*
PostgreSQL 10 and later adds support for Partition table. PostgreSQL 10 and later adds support for Partition table.
*/ */
if ( getVersion().isSameOrAfter( 10 ) ) {
tableTypesList.add( "PARTITIONED TABLE" ); tableTypesList.add( "PARTITIONED TABLE" );
} }
}
}
@Override @Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
@ -1171,16 +1156,12 @@ public class PostgreSQLDialect extends Dialect {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLIntervalSecondJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLIntervalSecondJdbcType.INSTANCE );
} }
if ( getVersion().isSameOrAfter( 8, 2 ) ) {
// HHH-9562 // HHH-9562
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
if ( getVersion().isSameOrAfter( 9, 2 ) ) {
if ( PostgreSQLPGObjectJdbcType.isUsable() ) { if ( PostgreSQLPGObjectJdbcType.isUsable() ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE );
} }
} }
}
}
// PostgreSQL requires a custom binder for binding untyped nulls as VARBINARY // PostgreSQL requires a custom binder for binding untyped nulls as VARBINARY
typeContributions.contributeJdbcType( ObjectNullAsBinaryTypeJdbcType.INSTANCE ); typeContributions.contributeJdbcType( ObjectNullAsBinaryTypeJdbcType.INSTANCE );

View File

@ -17,13 +17,6 @@ public class PostgreSQLSequenceSupport implements SequenceSupport {
public static final SequenceSupport INSTANCE = new PostgreSQLSequenceSupport(); public static final SequenceSupport INSTANCE = new PostgreSQLSequenceSupport();
public static final SequenceSupport LEGACY_INSTANCE = new PostgreSQLSequenceSupport() {
@Override
public String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName;
}
};
@Override @Override
public String getSelectSequenceNextValString(String sequenceName) { public String getSelectSequenceNextValString(String sequenceName) {
return "nextval('" + sequenceName + "')"; return "nextval('" + sequenceName + "')";

View File

@ -1,37 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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>.
*/
package org.hibernate.orm.test.dialect;
import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Test case for PostgreSQL 9.2 specific things.
*
* @author Christoph Dreis
*/
@TestForIssue( jiraKey = "HHH-11647")
public class PostgreSQL92DialectTestCase extends BaseUnitTestCase {
/**
* Tests that getAlterTableString() will make use of IF EXISTS syntax
*/
@Test
@TestForIssue( jiraKey = "HHH-11647" )
public void testGetAlterTableString() {
PostgreSQLDialect dialect = new PostgreSQLDialect( DatabaseVersion.make( 9, 2 ) );
assertEquals("alter table if exists table_name", dialect.getAlterTableString( "table_name" ));
}
}

View File

@ -14,7 +14,7 @@ import org.hibernate.JDBCException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.PessimisticLockException; import org.hibernate.PessimisticLockException;
import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.QueryTimeoutException; import org.hibernate.QueryTimeoutException;
import org.hibernate.exception.LockAcquisitionException; import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate; import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
@ -25,23 +25,24 @@ import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
/** /**
* Testing of patched support for PostgreSQL Lock error detection. HHH-7251 * Test case for PostgreSQL specific things.
*
* @author Bryan Varner * @author Bryan Varner
* @author Christoph Dreis
*/ */
public class PostgreSQL81DialectTestCase extends BaseUnitTestCase { public class PostgreSQLDialectTestCase extends BaseUnitTestCase {
@Test @Test
@TestForIssue( jiraKey = "HHH-7251")
public void testDeadlockException() { public void testDeadlockException() {
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); PostgreSQLDialect dialect = new PostgreSQLDialect();
SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate(); SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
assertNotNull(delegate); assertNotNull(delegate);
@ -50,8 +51,9 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-7251")
public void testTimeoutException() { public void testTimeoutException() {
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); PostgreSQLDialect dialect = new PostgreSQLDialect();
SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate(); SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
assertNotNull(delegate); assertNotNull(delegate);
@ -62,7 +64,7 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
@Test @Test
@TestForIssue( jiraKey = "HHH-13661") @TestForIssue( jiraKey = "HHH-13661")
public void testQueryTimeoutException() { public void testQueryTimeoutException() {
final PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); final PostgreSQLDialect dialect = new PostgreSQLDialect();
final SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate(); final SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
assertNotNull( delegate ); assertNotNull( delegate );
@ -76,21 +78,21 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
*/ */
@TestForIssue( jiraKey = "HHH-5654" ) @TestForIssue( jiraKey = "HHH-5654" )
public void testGetForUpdateStringWithAliasesAndLockOptions() { public void testGetForUpdateStringWithAliasesAndLockOptions() {
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); PostgreSQLDialect dialect = new PostgreSQLDialect();
LockOptions lockOptions = new LockOptions(); LockOptions lockOptions = new LockOptions();
lockOptions.setAliasSpecificLockMode("tableAlias1", LockMode.PESSIMISTIC_WRITE); lockOptions.setAliasSpecificLockMode("tableAlias1", LockMode.PESSIMISTIC_WRITE);
String forUpdateClause = dialect.getForUpdateString("tableAlias1", lockOptions); String forUpdateClause = dialect.getForUpdateString("tableAlias1", lockOptions);
assertTrue("for update of tableAlias1".equals(forUpdateClause)); assertEquals( "for update of tableAlias1", forUpdateClause );
lockOptions.setAliasSpecificLockMode("tableAlias2", LockMode.PESSIMISTIC_WRITE); lockOptions.setAliasSpecificLockMode("tableAlias2", LockMode.PESSIMISTIC_WRITE);
forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions); forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions);
assertTrue("for update of tableAlias1,tableAlias2".equals(forUpdateClause)); assertEquals("for update of tableAlias1,tableAlias2", forUpdateClause);
} }
@Test @Test
public void testExtractConstraintName() { public void testExtractConstraintName() {
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); PostgreSQLDialect dialect = new PostgreSQLDialect();
SQLException psqlException = new SQLException("ERROR: duplicate key value violates unique constraint \"uk_4bm1x2ultdmq63y3h5r3eg0ej\" Detail: Key (username, server_config)=(user, 1) already exists.", "23505"); SQLException psqlException = new SQLException("ERROR: duplicate key value violates unique constraint \"uk_4bm1x2ultdmq63y3h5r3eg0ej\" Detail: Key (username, server_config)=(user, 1) already exists.", "23505");
BatchUpdateException batchUpdateException = new BatchUpdateException("Concurrent Error", "23505", null); BatchUpdateException batchUpdateException = new BatchUpdateException("Concurrent Error", "23505", null);
batchUpdateException.setNextException(psqlException); batchUpdateException.setNextException(psqlException);
@ -100,8 +102,8 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
@Test @Test
@TestForIssue(jiraKey = "HHH-8687") @TestForIssue(jiraKey = "HHH-8687")
public void testMessageException() throws SQLException { public void testMessageException() {
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect(); PostgreSQLDialect dialect = new PostgreSQLDialect();
try { try {
dialect.getResultSet( Mockito.mock( CallableStatement.class), "abc" ); dialect.getResultSet( Mockito.mock( CallableStatement.class), "abc" );
fail( "Expected UnsupportedOperationException" ); fail( "Expected UnsupportedOperationException" );
@ -111,4 +113,15 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
assertEquals( "PostgreSQL only supports accessing REF_CURSOR parameters by position", e.getMessage() ); assertEquals( "PostgreSQL only supports accessing REF_CURSOR parameters by position", e.getMessage() );
} }
} }
/**
* Tests that getAlterTableString() will make use of IF EXISTS syntax
*/
@Test
@TestForIssue( jiraKey = "HHH-11647" )
public void testGetAlterTableString() {
PostgreSQLDialect dialect = new PostgreSQLDialect();
assertEquals("alter table if exists table_name", dialect.getAlterTableString( "table_name" ));
}
} }

View File

@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
*/ */
public class PostgreSQLLockTimeoutTest extends BaseUnitTestCase { public class PostgreSQLLockTimeoutTest extends BaseUnitTestCase {
private final Dialect dialect = new PostgreSQLDialect( DatabaseVersion.make( 9, 5 ) ); private final Dialect dialect = new PostgreSQLDialect();
@Test @Test
public void testLockTimeoutNoAliasNoTimeout() { public void testLockTimeoutNoAliasNoTimeout() {

View File

@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@TestForIssue(jiraKey = "HHH-12973") @TestForIssue(jiraKey = "HHH-12973")
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFactoryBasedFunctionalTest { public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule @Rule

View File

@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author Vlad Mhalcea * @author Vlad Mhalcea
*/ */
@TestForIssue(jiraKey = "HHH-13106") @TestForIssue(jiraKey = "HHH-13106")
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 10) @RequiresDialect(value = PostgreSQLDialect.class)
@Jpa( @Jpa(
annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class
) )

View File

@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.notNullValue;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4) @RequiresDialect(value = PostgreSQLDialect.class)
@DomainModel(annotatedClasses = { PostgreSQLUUIDGeneratedValueTest.Book.class }) @DomainModel(annotatedClasses = { PostgreSQLUUIDGeneratedValueTest.Book.class })
@SessionFactory @SessionFactory
public class PostgreSQLUUIDGeneratedValueTest { public class PostgreSQLUUIDGeneratedValueTest {

View File

@ -66,7 +66,7 @@ public class UUIDBasedIdInterpretationTest {
@Test @Test
@JiraKey( "HHH-10564" ) @JiraKey( "HHH-10564" )
@RequiresDialect( value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4 ) @RequiresDialect( value = PostgreSQLDialect.class )
public void testPostgreSQL(DomainModelScope scope) { public void testPostgreSQL(DomainModelScope scope) {
checkUuidTypeUsed( scope, UUIDJdbcType.class ); checkUuidTypeUsed( scope, UUIDJdbcType.class );
} }

View File

@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
* @author Pawel Stawicki * @author Pawel Stawicki
*/ */
@SessionFactory @SessionFactory
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8) @RequiresDialect(value = PostgreSQLDialect.class)
@DomainModel(annotatedClasses = { @DomainModel(annotatedClasses = {
ParentEntity.class, InheritingEntity.class ParentEntity.class, InheritingEntity.class
}) })
@ -34,14 +34,14 @@ public class PersistChildEntitiesWithDiscriminatorTest {
session -> { session -> {
// we need the 2 inserts so that the id is incremented on the second get-generated-keys-result set, since // we need the 2 inserts so that the id is incremented on the second get-generated-keys-result set, since
// on the first insert both the pk and the discriminator values are 1 // on the first insert both the pk and the discriminator values are 1
session.save( new InheritingEntity( "yabba" ) ); session.persist( new InheritingEntity( "yabba" ) );
session.save( new InheritingEntity( "dabba" ) ); session.persist( new InheritingEntity( "dabba" ) );
} }
); );
scope.inTransaction( scope.inTransaction(
session -> { session -> {
session.createQuery( "delete ParentEntity" ).executeUpdate(); session.createQuery( "delete ParentEntity", null ).executeUpdate();
} }
); );

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.jpa.query; package org.hibernate.orm.test.jpa.query;
import java.util.List; import java.util.List;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -123,7 +124,7 @@ public class NativeQueryOrdinalParametersTest {
@Test @Test
@TestForIssue(jiraKey = "HHH-12532") @TestForIssue(jiraKey = "HHH-12532")
// Add RequiresDialect be Cockroach version 201 // Add RequiresDialect be Cockroach version 201
@RequiresDialect( value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2 ) @RequiresDialect( value = PostgreSQLDialect.class )
@RequiresDialect( value = CockroachDialect.class, majorVersion = 20, minorVersion = 1 ) @RequiresDialect( value = CockroachDialect.class, majorVersion = 20, minorVersion = 1 )
public void testCteNativeQueryOrdinalParameter(EntityManagerFactoryScope scope) { public void testCteNativeQueryOrdinalParameter(EntityManagerFactoryScope scope) {

View File

@ -36,7 +36,7 @@ import static org.hamcrest.core.Is.is;
@RequiresDialects( @RequiresDialects(
value = { value = {
@RequiresDialect(value = OracleDialect.class), @RequiresDialect(value = OracleDialect.class),
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1) @RequiresDialect(value = PostgreSQLDialect.class)
}) })
@DomainModel( @DomainModel(
annotatedClasses = StringNationalizedTest.NationalizedEntity.class annotatedClasses = StringNationalizedTest.NationalizedEntity.class
@ -48,7 +48,7 @@ public class StringNationalizedTest {
public void tearDown(SessionFactoryScope scope) { public void tearDown(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> { session -> {
session.createQuery( "delete from NationalizedEntity" ).executeUpdate(); session.createQuery( "delete from NationalizedEntity", null ).executeUpdate();
} }
); );
} }
@ -59,13 +59,13 @@ public class StringNationalizedTest {
session -> { session -> {
NationalizedEntity ne = new NationalizedEntity(); NationalizedEntity ne = new NationalizedEntity();
ne.name = "Hello"; ne.name = "Hello";
session.save( ne ); session.persist( ne );
} }
); );
scope.inSession( scope.inSession(
session -> { session -> {
final Query query = session.createQuery( "from NationalizedEntity where name = :name" ); final Query query = session.createQuery( "from NationalizedEntity where name = :name", null );
query.setParameter( "name", "Hello" ); query.setParameter( "name", "Hello" );
final List list = query.list(); final List list = query.list();
assertThat( list.size(), is( 1 ) ); assertThat( list.size(), is( 1 ) );

View File

@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
@TestForIssue(jiraKey = "HHH-12939") @TestForIssue(jiraKey = "HHH-12939")
@RequiresDialect(value = H2Dialect.class) @RequiresDialect(value = H2Dialect.class)
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11) @RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class) @RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
public class AlterTableQuoteDefaultSchemaTest extends AbstractAlterTableQuoteSchemaTest { public class AlterTableQuoteDefaultSchemaTest extends AbstractAlterTableQuoteSchemaTest {

View File

@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
@TestForIssue(jiraKey = "HHH-12939") @TestForIssue(jiraKey = "HHH-12939")
@RequiresDialect(value = H2Dialect.class) @RequiresDialect(value = H2Dialect.class)
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11) @RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class) @RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
public class AlterTableQuoteSpecifiedSchemaTest extends AbstractAlterTableQuoteSchemaTest { public class AlterTableQuoteSpecifiedSchemaTest extends AbstractAlterTableQuoteSchemaTest {

View File

@ -20,7 +20,7 @@ import org.junit.jupiter.api.AfterAll;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
public class JdbcTimestampUTCTimeZoneTest extends JdbcTimestampWithoutUTCTimeZoneTest { public class JdbcTimestampUTCTimeZoneTest extends JdbcTimestampWithoutUTCTimeZoneTest {
private TimeZoneConnectionProvider connectionProvider; private TimeZoneConnectionProvider connectionProvider;

View File

@ -18,7 +18,7 @@ import org.junit.jupiter.api.AfterAll;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
public class JdbcTimestampWithDefaultUTCTimeZoneTest public class JdbcTimestampWithDefaultUTCTimeZoneTest
extends JdbcTimestampWithoutUTCTimeZoneTest { extends JdbcTimestampWithoutUTCTimeZoneTest {

View File

@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2) @RequiresDialect(value = PostgreSQLDialect.class)
public class JdbcTimestampWithoutUTCTimeZoneTest extends BaseSessionFactoryFunctionalTest { public class JdbcTimestampWithoutUTCTimeZoneTest extends BaseSessionFactoryFunctionalTest {
private TimeZoneConnectionProvider connectionProvider; private TimeZoneConnectionProvider connectionProvider;

View File

@ -259,7 +259,7 @@ abstract public class DialectFeatureChecks {
public boolean apply(Dialect dialect) { public boolean apply(Dialect dialect) {
return dialect instanceof DB2Dialect return dialect instanceof DB2Dialect
|| dialect instanceof OracleDialect || dialect instanceof OracleDialect
|| dialect instanceof PostgreSQLDialect && dialect.getVersion().isSameOrAfter( 9, 5 ) || dialect instanceof PostgreSQLDialect
|| dialect instanceof SQLServerDialect || dialect instanceof SQLServerDialect
|| dialect instanceof DerbyDialect || dialect instanceof DerbyDialect
|| dialect instanceof MySQLDialect && !(dialect instanceof TiDBDialect) || dialect instanceof MySQLDialect && !(dialect instanceof TiDBDialect)
@ -271,7 +271,7 @@ abstract public class DialectFeatureChecks {
public boolean apply(Dialect dialect) { public boolean apply(Dialect dialect) {
return dialect instanceof DB2Dialect return dialect instanceof DB2Dialect
|| dialect instanceof OracleDialect || dialect instanceof OracleDialect
|| dialect instanceof PostgreSQLDialect && dialect.getVersion().isSameOrAfter( 9, 5 ) || dialect instanceof PostgreSQLDialect
|| dialect instanceof SQLServerDialect; || dialect instanceof SQLServerDialect;
} }
} }