HHH-15487 - Remove support for PostgreSQL versions older than 10
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
893e1b096e
commit
bb5aa62927
|
@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
public class SingleTableDiscriminatorFormulaTest {
|
||||
|
||||
@Test
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
DebitAccount debitAccount = new DebitAccount("123-debit");
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.hibernate.testing.orm.junit.RequiresDialect;
|
|||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
BaseSchemaGeneratorTest.Person.class,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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 ''" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,6 @@ import org.hibernate.dialect.function.CommonFunctionFactory;
|
|||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.PostgreSQLIdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
|
||||
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
|
||||
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
|
||||
import org.hibernate.dialect.sequence.SequenceSupport;
|
||||
|
@ -121,13 +120,13 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class PostgreSQLDialect extends Dialect {
|
||||
|
||||
private final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 10 );
|
||||
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
|
||||
|
||||
private final PostgreSQLDriverKind driverKind;
|
||||
|
||||
public PostgreSQLDialect() {
|
||||
this( DatabaseVersion.make( 8, 0 ) );
|
||||
this( MINIMUM_VERSION );
|
||||
}
|
||||
|
||||
public PostgreSQLDialect(DialectResolutionInfo info) {
|
||||
|
@ -145,6 +144,11 @@ public class PostgreSQLDialect extends Dialect {
|
|||
this.driverKind = driverKind;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DatabaseVersion getMinimumSupportedVersion() {
|
||||
return MINIMUM_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDefaultNonContextualLobCreation() {
|
||||
return true;
|
||||
|
@ -220,9 +224,7 @@ public class PostgreSQLDialect extends Dialect {
|
|||
);
|
||||
|
||||
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() ) {
|
||||
// The following DDL types require that the PGobject class is usable/visible
|
||||
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( INET, "inet", this ) );
|
||||
|
@ -230,15 +232,8 @@ public class PostgreSQLDialect extends Dialect {
|
|||
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( GEOGRAPHY, "geography", this ) );
|
||||
ddlTypeRegistry.addDescriptor( new Scale6IntervalSecondDdlType( this ) );
|
||||
|
||||
if ( getVersion().isSameOrAfter( 9, 2 ) ) {
|
||||
// Prefer jsonb if possible
|
||||
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
|
||||
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "jsonb", this ) );
|
||||
}
|
||||
else {
|
||||
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
|
||||
}
|
||||
}
|
||||
// Prefer jsonb if possible
|
||||
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "jsonb", this ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,12 +538,10 @@ public class PostgreSQLDialect extends Dialect {
|
|||
functionFactory.windowFunctions();
|
||||
functionFactory.listagg_stringAgg( "varchar" );
|
||||
|
||||
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
|
||||
functionFactory.makeDateTimeTimestamp();
|
||||
// Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions
|
||||
functionFactory.inverseDistributionOrderedSetAggregates();
|
||||
functionFactory.hypotheticalOrderedSetAggregates();
|
||||
}
|
||||
functionFactory.makeDateTimeTimestamp();
|
||||
// Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions
|
||||
functionFactory.inverseDistributionOrderedSetAggregates();
|
||||
functionFactory.hypotheticalOrderedSetAggregates();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -570,39 +563,37 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
@Override
|
||||
public boolean supportsIfExistsBeforeTableName() {
|
||||
return getVersion().isSameOrAfter( 8, 2 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIfExistsBeforeConstraintName() {
|
||||
return getVersion().isSameOrAfter( 9 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIfExistsAfterAlterTable() {
|
||||
return getVersion().isSameOrAfter( 9, 2 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsValuesList() {
|
||||
return getVersion().isSameOrAfter( 8, 2 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPartitionBy() {
|
||||
return getVersion().isSameOrAfter( 9, 1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsNonQueryWithCTE() {
|
||||
return getVersion().isSameOrAfter( 9, 1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceSupport getSequenceSupport() {
|
||||
return getVersion().isBefore( 8, 2 )
|
||||
? PostgreSQLSequenceSupport.LEGACY_INSTANCE
|
||||
: PostgreSQLSequenceSupport.INSTANCE;
|
||||
return PostgreSQLSequenceSupport.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -617,9 +608,7 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
@Override
|
||||
public LimitHandler getLimitHandler() {
|
||||
return getVersion().isBefore( 8, 4 )
|
||||
? LimitOffsetLimitHandler.INSTANCE
|
||||
: OffsetFetchLimitHandler.INSTANCE;
|
||||
return OffsetFetchLimitHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -780,7 +769,7 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
/**
|
||||
* Constraint-name extractor for Postgres constraint violation exceptions.
|
||||
* Orginally contributed by Denny Bartelt.
|
||||
* Originally contributed by Denny Bartelt.
|
||||
*/
|
||||
private static final ViolatedConstraintNameExtractor EXTRACTOR =
|
||||
new TemplatedViolatedConstraintNameExtractor( sqle -> {
|
||||
|
@ -1084,7 +1073,7 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
@Override
|
||||
public boolean supportsNoWait() {
|
||||
return getVersion().isSameOrAfter( 8, 1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1094,7 +1083,7 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
@Override
|
||||
public boolean supportsSkipLocked() {
|
||||
return getVersion().isSameOrAfter( 9, 5 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1109,14 +1098,14 @@ public class PostgreSQLDialect extends Dialect {
|
|||
|
||||
@Override
|
||||
public boolean supportsLateral() {
|
||||
return getVersion().isSameOrAfter( 9, 3 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFetchClause(FetchClauseType type) {
|
||||
switch ( type ) {
|
||||
case ROWS_ONLY:
|
||||
return getVersion().isSameOrAfter( 8, 4 );
|
||||
return true;
|
||||
case PERCENT_ONLY:
|
||||
case PERCENT_WITH_TIES:
|
||||
return false;
|
||||
|
@ -1134,16 +1123,12 @@ public class PostgreSQLDialect extends Dialect {
|
|||
@Override
|
||||
public void augmentRecognizedTableTypes(List<String> 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.
|
||||
*/
|
||||
if ( getVersion().isSameOrAfter( 10 ) ) {
|
||||
tableTypesList.add( "PARTITIONED TABLE" );
|
||||
}
|
||||
}
|
||||
/*
|
||||
PostgreSQL 10 and later adds support for Partition table.
|
||||
*/
|
||||
tableTypesList.add( "PARTITIONED TABLE" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1171,14 +1156,10 @@ public class PostgreSQLDialect extends Dialect {
|
|||
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLIntervalSecondJdbcType.INSTANCE );
|
||||
}
|
||||
|
||||
if ( getVersion().isSameOrAfter( 8, 2 ) ) {
|
||||
// HHH-9562
|
||||
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
|
||||
if ( getVersion().isSameOrAfter( 9, 2 ) ) {
|
||||
if ( PostgreSQLPGObjectJdbcType.isUsable() ) {
|
||||
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE );
|
||||
}
|
||||
}
|
||||
// HHH-9562
|
||||
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
|
||||
if ( PostgreSQLPGObjectJdbcType.isUsable() ) {
|
||||
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLJsonbJdbcType.INSTANCE );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,6 @@ public class PostgreSQLSequenceSupport implements SequenceSupport {
|
|||
|
||||
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
|
||||
public String getSelectSequenceNextValString(String sequenceName) {
|
||||
return "nextval('" + sequenceName + "')";
|
||||
|
|
|
@ -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" ));
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import org.hibernate.JDBCException;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.PessimisticLockException;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.QueryTimeoutException;
|
||||
import org.hibernate.exception.LockAcquisitionException;
|
||||
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
||||
|
@ -25,23 +25,24 @@ import org.junit.Test;
|
|||
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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 Christoph Dreis
|
||||
*/
|
||||
public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
||||
public class PostgreSQLDialectTestCase extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7251")
|
||||
public void testDeadlockException() {
|
||||
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||
PostgreSQLDialect dialect = new PostgreSQLDialect();
|
||||
SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
|
||||
assertNotNull(delegate);
|
||||
|
||||
|
@ -50,8 +51,9 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7251")
|
||||
public void testTimeoutException() {
|
||||
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||
PostgreSQLDialect dialect = new PostgreSQLDialect();
|
||||
SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
|
||||
assertNotNull(delegate);
|
||||
|
||||
|
@ -62,7 +64,7 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
|||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13661")
|
||||
public void testQueryTimeoutException() {
|
||||
final PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||
final PostgreSQLDialect dialect = new PostgreSQLDialect();
|
||||
final SQLExceptionConversionDelegate delegate = dialect.buildSQLExceptionConversionDelegate();
|
||||
assertNotNull( delegate );
|
||||
|
||||
|
@ -76,21 +78,21 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
|||
*/
|
||||
@TestForIssue( jiraKey = "HHH-5654" )
|
||||
public void testGetForUpdateStringWithAliasesAndLockOptions() {
|
||||
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||
PostgreSQLDialect dialect = new PostgreSQLDialect();
|
||||
LockOptions lockOptions = new LockOptions();
|
||||
lockOptions.setAliasSpecificLockMode("tableAlias1", LockMode.PESSIMISTIC_WRITE);
|
||||
|
||||
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);
|
||||
forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions);
|
||||
assertTrue("for update of tableAlias1,tableAlias2".equals(forUpdateClause));
|
||||
assertEquals("for update of tableAlias1,tableAlias2", forUpdateClause);
|
||||
}
|
||||
|
||||
@Test
|
||||
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");
|
||||
BatchUpdateException batchUpdateException = new BatchUpdateException("Concurrent Error", "23505", null);
|
||||
batchUpdateException.setNextException(psqlException);
|
||||
|
@ -100,8 +102,8 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8687")
|
||||
public void testMessageException() throws SQLException {
|
||||
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||
public void testMessageException() {
|
||||
PostgreSQLDialect dialect = new PostgreSQLDialect();
|
||||
try {
|
||||
dialect.getResultSet( Mockito.mock( CallableStatement.class), "abc" );
|
||||
fail( "Expected UnsupportedOperationException" );
|
||||
|
@ -111,4 +113,15 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
|||
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" ));
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
|
|||
*/
|
||||
public class PostgreSQLLockTimeoutTest extends BaseUnitTestCase {
|
||||
|
||||
private final Dialect dialect = new PostgreSQLDialect( DatabaseVersion.make( 9, 5 ) );
|
||||
private final Dialect dialect = new PostgreSQLDialect();
|
||||
|
||||
@Test
|
||||
public void testLockTimeoutNoAliasNoTimeout() {
|
||||
|
|
|
@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12973")
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFactoryBasedFunctionalTest {
|
||||
|
||||
@Rule
|
||||
|
|
|
@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
* @author Vlad Mhalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-13106")
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 10)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@Jpa(
|
||||
annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class
|
||||
)
|
||||
|
|
|
@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@DomainModel(annotatedClasses = { PostgreSQLUUIDGeneratedValueTest.Book.class })
|
||||
@SessionFactory
|
||||
public class PostgreSQLUUIDGeneratedValueTest {
|
||||
|
|
|
@ -66,7 +66,7 @@ public class UUIDBasedIdInterpretationTest {
|
|||
|
||||
@Test
|
||||
@JiraKey( "HHH-10564" )
|
||||
@RequiresDialect( value = PostgreSQLDialect.class, majorVersion = 9, minorVersion = 4 )
|
||||
@RequiresDialect( value = PostgreSQLDialect.class )
|
||||
public void testPostgreSQL(DomainModelScope scope) {
|
||||
checkUuidTypeUsed( scope, UUIDJdbcType.class );
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|||
* @author Pawel Stawicki
|
||||
*/
|
||||
@SessionFactory
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@DomainModel(annotatedClasses = {
|
||||
ParentEntity.class, InheritingEntity.class
|
||||
})
|
||||
|
@ -34,14 +34,14 @@ public class PersistChildEntitiesWithDiscriminatorTest {
|
|||
session -> {
|
||||
// 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
|
||||
session.save( new InheritingEntity( "yabba" ) );
|
||||
session.save( new InheritingEntity( "dabba" ) );
|
||||
session.persist( new InheritingEntity( "yabba" ) );
|
||||
session.persist( new InheritingEntity( "dabba" ) );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete ParentEntity" ).executeUpdate();
|
||||
session.createQuery( "delete ParentEntity", null ).executeUpdate();
|
||||
|
||||
}
|
||||
);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.orm.test.jpa.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -123,7 +124,7 @@ public class NativeQueryOrdinalParametersTest {
|
|||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12532")
|
||||
// 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 )
|
||||
public void testCteNativeQueryOrdinalParameter(EntityManagerFactoryScope scope) {
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import static org.hamcrest.core.Is.is;
|
|||
@RequiresDialects(
|
||||
value = {
|
||||
@RequiresDialect(value = OracleDialect.class),
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
})
|
||||
@DomainModel(
|
||||
annotatedClasses = StringNationalizedTest.NationalizedEntity.class
|
||||
|
@ -48,7 +48,7 @@ public class StringNationalizedTest {
|
|||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from NationalizedEntity" ).executeUpdate();
|
||||
session.createQuery( "delete from NationalizedEntity", null ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ public class StringNationalizedTest {
|
|||
session -> {
|
||||
NationalizedEntity ne = new NationalizedEntity();
|
||||
ne.name = "Hello";
|
||||
session.save( ne );
|
||||
session.persist( ne );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inSession(
|
||||
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" );
|
||||
final List list = query.list();
|
||||
assertThat( list.size(), is( 1 ) );
|
||||
|
|
|
@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12939")
|
||||
@RequiresDialect(value = H2Dialect.class)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
|
||||
public class AlterTableQuoteDefaultSchemaTest extends AbstractAlterTableQuoteSchemaTest {
|
||||
|
|
|
@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12939")
|
||||
@RequiresDialect(value = H2Dialect.class)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
@RequiresDialect(value = SQLServerDialect.class, majorVersion = 11)
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportSchemaCreation.class)
|
||||
public class AlterTableQuoteSpecifiedSchemaTest extends AbstractAlterTableQuoteSchemaTest {
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class JdbcTimestampUTCTimeZoneTest extends JdbcTimestampWithoutUTCTimeZoneTest {
|
||||
|
||||
private TimeZoneConnectionProvider connectionProvider;
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class JdbcTimestampWithDefaultUTCTimeZoneTest
|
||||
extends JdbcTimestampWithoutUTCTimeZoneTest {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class JdbcTimestampWithoutUTCTimeZoneTest extends BaseSessionFactoryFunctionalTest {
|
||||
|
||||
private TimeZoneConnectionProvider connectionProvider;
|
||||
|
|
|
@ -259,7 +259,7 @@ abstract public class DialectFeatureChecks {
|
|||
public boolean apply(Dialect dialect) {
|
||||
return dialect instanceof DB2Dialect
|
||||
|| dialect instanceof OracleDialect
|
||||
|| dialect instanceof PostgreSQLDialect && dialect.getVersion().isSameOrAfter( 9, 5 )
|
||||
|| dialect instanceof PostgreSQLDialect
|
||||
|| dialect instanceof SQLServerDialect
|
||||
|| dialect instanceof DerbyDialect
|
||||
|| dialect instanceof MySQLDialect && !(dialect instanceof TiDBDialect)
|
||||
|
@ -271,7 +271,7 @@ abstract public class DialectFeatureChecks {
|
|||
public boolean apply(Dialect dialect) {
|
||||
return dialect instanceof DB2Dialect
|
||||
|| dialect instanceof OracleDialect
|
||||
|| dialect instanceof PostgreSQLDialect && dialect.getVersion().isSameOrAfter( 9, 5 )
|
||||
|| dialect instanceof PostgreSQLDialect
|
||||
|| dialect instanceof SQLServerDialect;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue