Add version to @SkipDialect and @RequiresDialect and re-enabled additional tests

This commit is contained in:
Andrea Boriero 2020-07-22 14:37:14 +01:00 committed by Steve Ebersole
parent 61cd51a4c8
commit 1a6b01a2a8
77 changed files with 789 additions and 571 deletions

View File

@ -32,6 +32,7 @@ import static org.hibernate.query.TemporalUnit.*;
* @author Seok Jeong Il
*/
public class CUBRIDDialect extends Dialect {
/**
* Constructs a CUBRIDDialect
*/
@ -87,6 +88,11 @@ public class CUBRIDDialect extends Dialect {
registerKeyword( "SEARCH" );
}
@Override
public int getVersion() {
return 0;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -71,6 +71,11 @@ public class CacheDialect extends Dialect {
);
}
@Override
public int getVersion() {
return 0;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -11,6 +11,7 @@ import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.type.StandardBasicTypes;
@ -33,9 +34,21 @@ public class CockroachDialect extends Dialect {
// * no support for java.sql.Clob
private int version;
public CockroachDialect() {
this(192);
}
public CockroachDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
public CockroachDialect(int version) {
super();
this.version = version;
registerColumnType( Types.TINYINT, "smallint" ); //no tinyint
//no binary/varbinary
@ -57,6 +70,11 @@ public class CockroachDialect extends Dialect {
registerColumnType( Types.JAVA_OBJECT, "json" );
}
@Override
public int getVersion() {
return version;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry(queryEngine);

View File

@ -10,15 +10,13 @@ package org.hibernate.dialect;
* An SQL dialect for DB2 9.7.
*
* @author Gail Badner
*
* @deprecated use {@code DB2Dialect(970)}
*/
@Deprecated
public class DB297Dialect extends DB2Dialect {
@Override
int getVersion() {
return 970;
public DB297Dialect() {
super( 970 );
}
}

View File

@ -61,10 +61,6 @@ public class DB2Dialect extends Dialect {
private LimitHandler limitHandler;
int getVersion() {
return version;
}
private final UniqueDelegate uniqueDelegate;
public DB2Dialect(DialectResolutionInfo info) {
@ -119,11 +115,17 @@ public class DB2Dialect extends Dialect {
: DB2LimitHandler.INSTANCE;
}
@Override
public int getDefaultDecimalPrecision() {
//this is the maximum allowed in DB2
return 31;
}
@Override
public int getVersion() {
return version;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -70,10 +70,6 @@ public class DerbyDialect extends Dialect {
private final int version;
int getVersion() {
return version;
}
private final LimitHandler limitHandler;
public DerbyDialect(DialectResolutionInfo info) {
@ -116,11 +112,17 @@ public class DerbyDialect extends Dialect {
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}
@Override
public int getDefaultDecimalPrecision() {
//this is the maximum allowed in Derby
return 31;
}
@Override
public int getVersion() {
return version;
}
@Override
public int getFloatPrecision() {
return 23;

View File

@ -135,7 +135,6 @@ public abstract class Dialect implements ConversionContext {
private DefaultSizeStrategy defaultSizeStrategy;
// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
protected Dialect() {
@ -240,6 +239,8 @@ public abstract class Dialect implements ConversionContext {
: size;
}
public abstract int getVersion();
/**
* Initialize the given registry with any dialect-specific functions.
*

View File

@ -66,10 +66,6 @@ public class FirebirdDialect extends Dialect {
private final int version;
public int getVersion() {
return version;
}
public FirebirdDialect() {
this(250);
}
@ -132,6 +128,11 @@ public class FirebirdDialect extends Dialect {
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
}
@Override
public int getVersion() {
return version;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return getVersion() < 300

View File

@ -59,6 +59,8 @@ public class H2Dialect extends Dialect {
private final boolean cascadeConstraints;
private final int version;
private final SequenceInformationExtractor sequenceInformationExtractor;
private final String querySequenceString;
@ -68,7 +70,7 @@ public class H2Dialect extends Dialect {
public H2Dialect(int version, int buildId) {
super();
this.version = version;
//TODO: actually I think all builds of 1.4 support OFFSET FETCH
limitHandler = version > 140 || version == 140 && buildId >= 199
? OffsetFetchLimitHandler.INSTANCE
@ -114,6 +116,11 @@ public class H2Dialect extends Dialect {
);
}
@Override
public int getVersion() {
return version;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -27,85 +27,10 @@ import org.hibernate.type.StandardBasicTypes;
* @deprecated use HANAColumnStoreDialect(400)
*/
@Deprecated
public class HANACloudColumnStoreDialect extends AbstractHANADialect {
public class HANACloudColumnStoreDialect extends HANAColumnStoreDialect {
public HANACloudColumnStoreDialect() {
super();
registerColumnType( Types.CHAR, "nvarchar(1)" );
registerColumnType( Types.VARCHAR, 5000, "nvarchar($l)" );
registerColumnType( Types.LONGVARCHAR, 5000, "nvarchar($l)" );
// for longer values map to clob/nclob
registerColumnType( Types.LONGVARCHAR, "nclob" );
registerColumnType( Types.VARCHAR, "nclob" );
registerColumnType( Types.CLOB, "nclob" );
registerHibernateType( Types.CLOB, StandardBasicTypes.MATERIALIZED_NCLOB.getName() );
registerHibernateType( Types.NCHAR, StandardBasicTypes.NSTRING.getName() );
registerHibernateType( Types.CHAR, StandardBasicTypes.CHARACTER.getName() );
registerHibernateType( Types.CHAR, 1, StandardBasicTypes.CHARACTER.getName() );
registerHibernateType( Types.CHAR, 5000, StandardBasicTypes.NSTRING.getName() );
registerHibernateType( Types.VARCHAR, StandardBasicTypes.NSTRING.getName() );
registerHibernateType( Types.LONGVARCHAR, StandardBasicTypes.NTEXT.getName() );
// register additional keywords
registerHanaCloudKeywords();
super( 400 );
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );
// full-text search functions
queryEngine.getSqmFunctionRegistry().registerNamed( "score", StandardBasicTypes.DOUBLE );
queryEngine.getSqmFunctionRegistry().registerNamed( "snippets" );
queryEngine.getSqmFunctionRegistry().registerNamed( "highlighted" );
// queryEngine.getSqmFunctionRegistry().registerVarArgs( "contains", StandardSpiBasicTypes.BOOLEAN, "contains(", ",", ") /*" );
// queryEngine.getSqmFunctionRegistry().registerPattern( "contains_rhs", "*/", StandardSpiBasicTypes.BOOLEAN );
// queryEngine.getSqmFunctionRegistry().registerVarArgs( "not_contains", StandardSpiBasicTypes.BOOLEAN, "not_contains(", ",", ") /*" );
}
private void registerHanaCloudKeywords() {
registerKeyword( "array" );
registerKeyword( "at" );
registerKeyword( "authorization" );
registerKeyword( "between" );
registerKeyword( "by" );
registerKeyword( "collate" );
registerKeyword( "empty" );
registerKeyword( "filter" );
registerKeyword( "grouping" );
registerKeyword( "no" );
registerKeyword( "not" );
registerKeyword( "of" );
registerKeyword( "over" );
registerKeyword( "recursive" );
registerKeyword( "row" );
registerKeyword( "table" );
registerKeyword( "to" );
registerKeyword( "window" );
registerKeyword( "within" );
}
@Override
public String getCreateTableString() {
return "create column table";
}
@Override
protected boolean supportsAsciiStringTypes() {
return false;
}
@Override
protected Boolean useUnicodeStringTypesDefault() {
return Boolean.TRUE;
}
@Override
public boolean isUseUnicodeStringTypes() {
return true;
}
}

View File

@ -36,10 +36,6 @@ import org.hibernate.type.StandardBasicTypes;
public class HANAColumnStoreDialect extends AbstractHANADialect {
private int version;
public int getVersion(){
return version;
}
public HANAColumnStoreDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
@ -74,6 +70,11 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
}
}
@Override
public int getVersion(){
return version;
}
private void registerHanaCloudKeywords() {
registerKeyword( "array" );
registerKeyword( "at" );

View File

@ -56,6 +56,11 @@ public class HANARowStoreDialect extends AbstractHANADialect {
);
}
@Override
public int getVersion() {
return 0;
}
@Override
protected boolean supportsAsciiStringTypes() {
return true;

View File

@ -78,10 +78,6 @@ public class HSQLDialect extends Dialect {
*/
private final int version;
int getVersion() {
return version;
}
public HSQLDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion()*100 + info.getDatabaseMinorVersion()*10 );
}
@ -143,6 +139,11 @@ public class HSQLDialect extends Dialect {
}
}
@Override
public int getVersion() {
return version;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -48,10 +48,6 @@ public class InformixDialect extends Dialect {
private final int version;
int getVersion() {
return version;
}
public InformixDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
}
@ -105,6 +101,12 @@ public class InformixDialect extends Dialect {
: new SkipFirstLimitHandler( getVersion() >= 11 );
}
@Override
public int getVersion() {
return version;
}
@Override
public int getDefaultDecimalPrecision() {
//the maximum
return 32;

View File

@ -64,10 +64,6 @@ public class IngresDialect extends Dialect {
private final SequenceSupport sequenceSupport;
int getVersion() {
return version;
}
public IngresDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
@ -151,6 +147,11 @@ public class IngresDialect extends Dialect {
};
}
@Override
public int getVersion() {
return version;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return getVersion() < 1000 ? Types.BIT : Types.BOOLEAN;

View File

@ -55,6 +55,11 @@ public class MaxDBDialect extends Dialect {
}
@Override
public int getVersion() {
return 0;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -85,6 +85,11 @@ public class MimerSQLDialect extends Dialect {
// return 45;
// }
@Override
public int getVersion() {
return 0;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -59,10 +59,6 @@ public class MySQLDialect extends Dialect {
private MySQLStorageEngine storageEngine;
private int version;
int getVersion() {
return version;
}
public MySQLDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
@ -159,6 +155,11 @@ public class MySQLDialect extends Dialect {
uniqueDelegate = new MySQLUniqueDelegate( this );
}
@Override
public int getVersion() {
return version;
}
@Override
public long getDefaultLobLength() {
//max length for mediumblob or mediumtext

View File

@ -68,10 +68,6 @@ public class OracleDialect extends Dialect {
private final int version;
int getVersion() {
return version;
}
public OracleDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
}
@ -112,6 +108,11 @@ public class OracleDialect extends Dialect {
: OffsetFetchLimitHandler.INSTANCE;
}
@Override
public int getVersion() {
return version;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -73,10 +73,6 @@ public class PostgreSQLDialect extends Dialect {
private final int version;
int getVersion() {
return version;
}
public PostgreSQLDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
@ -117,6 +113,11 @@ public class PostgreSQLDialect extends Dialect {
getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
}
@Override
public int getVersion() {
return version;
}
/**
* The {@code extract()} function returns {@link TemporalUnit#DAY_OF_WEEK}
* numbered from 0 to 6. This isn't consistent with what most other

View File

@ -96,6 +96,11 @@ public class RDMSOS2200Dialect extends Dialect {
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp($p)");
}
@Override
public int getVersion() {
return 0;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -43,10 +43,6 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
private final int version;
int getVersion() {
return version;
}
public SQLServerDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() );
}
@ -103,6 +99,11 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
registerKeyword( "key" );
}
@Override
public int getVersion() {
return version;
}
@Override
public long getDefaultLobLength() {
// this is essentially the only legal length for

View File

@ -93,6 +93,11 @@ public class SpannerDialect extends Dialect {
registerColumnType( Types.BLOB, "bytes(max)" );
}
@Override
public int getVersion() {
return 0;
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );

View File

@ -16,6 +16,6 @@ package org.hibernate.dialect;
@Deprecated
public class Sybase11Dialect extends SybaseASEDialect {
public Sybase11Dialect() {
super();
super(1100);
}
}

View File

@ -30,12 +30,6 @@ import java.util.Map;
*/
public class SybaseASEDialect extends SybaseDialect {
private final int version;
int getVersion() {
return version;
}
public SybaseASEDialect(DialectResolutionInfo info) {
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
@ -45,8 +39,7 @@ public class SybaseASEDialect extends SybaseDialect {
}
public SybaseASEDialect(int version) {
super();
this.version = version;
super(version);
//On Sybase ASE, the 'bit' type cannot be null,
//and cannot have indexes (while we don't use
@ -55,6 +48,7 @@ public class SybaseASEDialect extends SybaseDialect {
registerColumnType( Types.BOOLEAN, "tinyint" );
registerColumnType( Types.BIT, 1, "tinyint" );
if ( getVersion() >= 1500 ) {
//bigint was added in version 15
registerColumnType( Types.BIGINT, "bigint" );

View File

@ -11,6 +11,7 @@ import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.SybaseAnywhereIdentityColumnSupport;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.TopLimitHandler;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.type.descriptor.sql.BitTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -23,7 +24,15 @@ import java.sql.Types;
public class SybaseAnywhereDialect extends SybaseDialect {
public SybaseAnywhereDialect() {
super();
this(8);
}
public SybaseAnywhereDialect(DialectResolutionInfo info){
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
public SybaseAnywhereDialect(int version) {
super( version );
registerColumnType( Types.BIGINT, "bigint" );
registerColumnType( Types.DATE, "date" );

View File

@ -7,6 +7,7 @@
package org.hibernate.dialect;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.type.descriptor.sql.BlobTypeDescriptor;
@ -23,16 +24,31 @@ import java.sql.Types;
*/
public class SybaseDialect extends AbstractTransactSQLDialect {
private final int version;
//All Sybase dialects share an IN list size limit.
private static final int PARAM_LIST_SIZE_LIMIT = 250000;
public SybaseDialect() {
super();
public SybaseDialect(){
this(1100);
}
public SybaseDialect(DialectResolutionInfo info){
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
}
public SybaseDialect(int version) {
super();
this.version = version;
//Sybase ASE didn't introduce bigint until version 15.0
registerColumnType( Types.BIGINT, "numeric(19,0)" );
}
@Override
public int getVersion() {
return version;
}
@Override
public int getInExpressionCountLimit() {
return PARAM_LIST_SIZE_LIMIT;

View File

@ -57,10 +57,6 @@ public class TeradataDialect extends Dialect {
private int version;
int getVersion() {
return version;
}
private static final int PARAM_LIST_SIZE_LIMIT = 1024;
public TeradataDialect(DialectResolutionInfo info) {
@ -118,6 +114,11 @@ public class TeradataDialect extends Dialect {
}
@Override
public int getVersion() {
return version;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -85,6 +85,11 @@ public class TimesTenDialect extends Dialect {
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
}
@Override
public int getVersion() {
return 0;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
return Types.BIT;

View File

@ -15,22 +15,30 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
*/
public class TestingDialects {
public static class MyDialect1 extends Dialect {
public static class MyDialect extends Dialect {
@Override
public int getVersion() {
return 0;
}
}
public static class MyDialect21 extends Dialect {
public static class MyDialect1 extends MyDialect {
}
public static class MyDialect22 extends Dialect {
public static class MyDialect21 extends MyDialect {
}
public static class MyDialect311 extends Dialect {
public static class MyDialect22 extends MyDialect {
}
public static class MyDialect312 extends Dialect {
public static class MyDialect311 extends MyDialect {
}
public static class MySpecialDB2Dialect extends Dialect {
public static class MyDialect312 extends MyDialect {
}
public static class MySpecialDB2Dialect extends MyDialect {
}
public static class MyDialectResolver1 implements DialectResolver {

View File

@ -1,42 +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.id;
import org.hibernate.FlushMode;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
@TestForIssue(jiraKey = "HHH-12464")
public class CreateDeleteTest extends BaseCoreFunctionalTestCase {
@Test
@SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column")
public void createAndDeleteAnEntityInTheSameTransactionTest() {
doInHibernate( this::sessionFactory, session -> {
session.setHibernateFlushMode( FlushMode.COMMIT );
RootEntity entity = new RootEntity();
session.persist( entity );
session.delete( entity );
} );
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
RootEntity.class,
RelatedEntity.class,
};
}
}

View File

@ -1,46 +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.id;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@TestForIssue(jiraKey = "HHH-8611")
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class FlushIdGenTest extends BaseCoreFunctionalTestCase {
@Test
@SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column")
public void testPersistBeforeTransaction() {
Session session = openSession();
RootEntity ent1_0 = new RootEntity();
RootEntity ent1_1 = new RootEntity();
session.persist( ent1_0 );
session.persist( ent1_1 );
Transaction tx = session.beginTransaction();
tx.commit(); // flush
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
RootEntity.class,
RelatedEntity.class,
};
}
}

View File

@ -1,71 +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.id;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.dialect.Oracle12cDialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
/**
* @author Vlad Mihalcea
*/
@RequiresDialectFeature( value = DialectChecks.SupportsIdentityColumns.class, jiraKey = "HHH-9271")
@SkipForDialect(value = Oracle12cDialect.class, comment = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes")
public class QuotedIdentifierTest extends BaseCoreFunctionalTestCase {
@Test
public void testDirectIdPropertyAccess() {
QuotedIdentifier quotedIdentifier = new QuotedIdentifier();
doInHibernate( this::sessionFactory, session -> {
quotedIdentifier.timestamp = System.currentTimeMillis();
quotedIdentifier.from = "HHH-9271";
session.persist( quotedIdentifier );
} );
doInHibernate( this::sessionFactory, session -> {
QuotedIdentifier result = session.get( QuotedIdentifier.class, quotedIdentifier.index );
assertNotNull( result );
} );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
QuotedIdentifier.class
};
}
@Entity(name = "QuotedIdentifier")
@Table( name = "`table`")
public static class QuotedIdentifier {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "`index`")
private int index;
@Column(name = "`timestamp`")
private long timestamp;
@Column(name = "`from`")
private String from;
}
}

View File

@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
@ServiceRegistry(settings = @ServiceRegistry.Setting(name = Environment.AUTO_CLOSE_SESSION, value = "true"))
public class GenericsTest {
@SkipForDialect(dialectClass = AbstractHANADialect.class, reason = "known bug in HANA: rs.next() returns false for org.hibernate.id.enhanced.SequenceStructure$1.getNextValue() for this test")
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = "known bug in HANA: rs.next() returns false for org.hibernate.id.enhanced.SequenceStructure$1.getNextValue() for this test")
@Test
public void testManyToOneGenerics(SessionFactoryScope scope) {
Paper white = new Paper();

View File

@ -59,6 +59,7 @@ public class EntityInheritanceAttributeOverrideTest extends EntityManagerFactory
@Test
public void test() {
produceEntityManagerFactory();
}
@Entity(name = "AbstractEntity")

View File

@ -484,10 +484,18 @@ public class PersistenceUnitOverridesTests extends BaseUnitTestCase {
}
public static class PersistenceUnitDialect extends Dialect {
@Override
public int getVersion() {
return 0;
}
}
@SuppressWarnings("WeakerAccess")
public static class IntegrationDialect extends Dialect {
@Override
public int getVersion() {
return 0;
}
}
@Entity

View File

@ -4,116 +4,118 @@
* 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.id;
package org.hibernate.orm.test.id;
import org.junit.Test;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.id.IntegralDataTypeHolder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Steve Ebersole
*/
@SuppressWarnings( {"UnusedDeclaration"})
public abstract class AbstractHolderTest extends BaseUnitTestCase {
@SuppressWarnings({ "UnusedDeclaration" })
public abstract class AbstractHolderTest extends BaseUnitTest {
protected abstract IntegralDataTypeHolder makeHolder();
@Test
@SuppressWarnings( {"EmptyCatchBlock"})
@SuppressWarnings({ "EmptyCatchBlock" })
public void testInitializationChecking() {
IntegralDataTypeHolder holder = makeHolder();
try {
holder.increment();
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.add( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.decrement();
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.subtract( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.multiplyBy( holder );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.multiplyBy( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.eq( holder );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.eq( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.lt( holder );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.lt( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.gt( holder );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.gt( 1 );
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
try {
holder.makeValue();
fail();
}
catch ( IdentifierGenerationException expected ) {
catch (IdentifierGenerationException expected) {
}
}
@ -126,7 +128,8 @@ public abstract class AbstractHolderTest extends BaseUnitTestCase {
}
assertEquals( holder.copy().initialize( i ), holder );
}
@Test
@Test
public void testBasicHiloAlgorithm() {
// mimic an initialValue of 1 and increment of 20
final long initialValue = 1;

View File

@ -4,9 +4,13 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.math.BigDecimal;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder;
/**
* @author Steve Ebersole
*/

View File

@ -4,9 +4,13 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.math.BigInteger;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder;
/**
* @author Steve Ebersole
*/

View File

@ -0,0 +1,44 @@
/*
* 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.id;
import org.hibernate.FlushMode;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@TestForIssue(jiraKey = "HHH-12464")
@DomainModel(
annotatedClasses = {
RootEntity.class,
RelatedEntity.class,
}
)
@SessionFactory
public class CreateDeleteTest {
@Test
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = " HANA doesn't support tables consisting of only a single auto-generated column")
public void createAndDeleteAnEntityInTheSameTransactionTest(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.setHibernateFlushMode( FlushMode.COMMIT );
RootEntity entity = new RootEntity();
session.persist( entity );
session.delete( entity );
} );
}
}

View File

@ -0,0 +1,55 @@
/*
* 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.id;
import org.hibernate.Transaction;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsIdentityColumns;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
@TestForIssue(jiraKey = "HHH-8611")
@RequiresDialectFeature(feature = SupportsIdentityColumns.class)
@DomainModel(
annotatedClasses = {
RootEntity.class,
RelatedEntity.class,
}
)
@SessionFactory
public class FlushIdGenTest {
@Test
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = " HANA doesn't support tables consisting of only a single auto-generated column")
public void testPersistBeforeTransaction(SessionFactoryScope scope) {
scope.inSession(
session -> {
RootEntity ent1_0 = new RootEntity();
RootEntity ent1_1 = new RootEntity();
session.persist( ent1_0 );
session.persist( ent1_1 );
Transaction tx = session.beginTransaction();
try {
tx.commit(); // flush
}
catch (Exception e) {
tx.rollback();
}
}
);
}
}

View File

@ -4,9 +4,12 @@
* 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.id;
package org.hibernate.orm.test.id;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder;
/**
* @author Steve Ebersole
*/

View File

@ -0,0 +1,71 @@
/*
* 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.id;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsIdentityColumns;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Vlad Mihalcea
*/
@RequiresDialectFeature(feature = SupportsIdentityColumns.class, jiraKey = "HHH-9271")
@SkipForDialect(dialectClass = OracleDialect.class, version = 12, matchSubTypes = true, reason = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes")
@DomainModel(
annotatedClasses = {
QuotedIdentifierTest.QuotedIdentifier.class
}
)
@SessionFactory
public class QuotedIdentifierTest {
@Test
public void testDirectIdPropertyAccess(SessionFactoryScope scope) {
QuotedIdentifier quotedIdentifier = new QuotedIdentifier();
scope.inTransaction( session -> {
quotedIdentifier.timestamp = System.currentTimeMillis();
quotedIdentifier.from = "HHH-9271";
session.persist( quotedIdentifier );
} );
scope.inTransaction( session -> {
QuotedIdentifier result = session.get( QuotedIdentifier.class, quotedIdentifier.index );
assertNotNull( result );
} );
}
@Entity(name = "QuotedIdentifier")
@Table(name = "`table`")
public static class QuotedIdentifier {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "`index`")
private int index;
@Column(name = "`timestamp`")
private long timestamp;
@Column(name = "`from`")
private String from;
}
}

View File

@ -5,7 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id;
package org.hibernate.orm.test.id;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;

View File

@ -5,7 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id;
package org.hibernate.orm.test.id;
import java.io.Serializable;

View File

@ -4,34 +4,35 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.util.Properties;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
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.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.SequenceGenerator;
import org.hibernate.id.SequenceHiLoGenerator;
import org.hibernate.internal.SessionImpl;
import org.hibernate.type.StandardBasicTypes;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsSequences;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -40,8 +41,8 @@ import static org.junit.Assert.assertEquals;
* @author Steve Ebersole
*/
@SuppressWarnings({"deprecation"})
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
@RequiresDialectFeature(feature = SupportsSequences.class)
public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTest {
private static final String TEST_SEQUENCE = "test_sequence";
private StandardServiceRegistry serviceRegistry;
@ -50,7 +51,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
private SessionImplementor sessionImpl;
private SequenceValueExtractor sequenceValueExtractor;
@Before
@BeforeEach
public void setUp() throws Exception {
serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -79,7 +80,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
}
@After
@AfterEach
public void tearDown() {
if ( sessionImpl != null && !sessionImpl.isClosed() ) {
sessionImpl.close();

View File

@ -4,7 +4,7 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.util.Properties;
@ -17,18 +17,22 @@ import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.SequenceGenerator;
import org.hibernate.id.SequenceHiLoGenerator;
import org.hibernate.internal.SessionImpl;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsSequences;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -37,8 +41,8 @@ import static org.junit.Assert.assertEquals;
* @author Steve Ebersole
*/
@SuppressWarnings({"deprecation"})
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
@RequiresDialectFeature(feature = SupportsSequences.class)
public class SequenceHiLoGeneratorTest extends BaseUnitTest {
private static final String TEST_SEQUENCE = "test_sequence";
private StandardServiceRegistry serviceRegistry;
@ -47,7 +51,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
private SessionImplementor sessionImpl;
private SequenceValueExtractor sequenceValueExtractor;
@Before
@BeforeEach
public void setUp() throws Exception {
serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -74,8 +78,8 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
}
@After
public void tearDown() throws Exception {
@AfterEach
public void tearDown() {
if ( sessionFactory != null ) {
sessionFactory.close();
}

View File

@ -4,7 +4,7 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.util.Properties;
@ -18,25 +18,26 @@ import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.SessionImpl;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsSequences;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Andrea Boriero
*/
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceStyleGeneratorBehavesLikeSequeceHiloGeneratorWitZeroIncrementSizeTest extends BaseUnitTestCase {
@RequiresDialectFeature(feature = SupportsSequences.class)
public class SequenceStyleGeneratorBehavesLikeSequeceHiloGeneratorWitZeroIncrementSizeTest extends BaseUnitTest {
private static final String TEST_SEQUENCE = "test_sequence";
private StandardServiceRegistry serviceRegistry;
@ -45,7 +46,7 @@ public class SequenceStyleGeneratorBehavesLikeSequeceHiloGeneratorWitZeroIncreme
private SessionImplementor sessionImpl;
private SequenceValueExtractor sequenceValueExtractor;
@Before
@BeforeEach
public void setUp() throws Exception {
serviceRegistry = new StandardServiceRegistryBuilder()
.enableAutoClose()
@ -77,7 +78,7 @@ public class SequenceStyleGeneratorBehavesLikeSequeceHiloGeneratorWitZeroIncreme
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
}
@After
@AfterEach
public void tearDown() {
if ( sessionImpl != null && !sessionImpl.isClosed() ) {
sessionImpl.close();

View File

@ -4,7 +4,7 @@
* 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.id;
package org.hibernate.orm.test.id;
import java.sql.Connection;
import java.sql.PreparedStatement;

View File

@ -4,23 +4,26 @@
* 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.id.enhanced;
import org.junit.Ignore;
import org.junit.Test;
package org.hibernate.orm.test.id.enhanced;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.id.enhanced.AccessCallback;
import org.hibernate.id.enhanced.Optimizer;
import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.id.enhanced.StandardOptimizerDescriptor;
import static org.junit.Assert.assertEquals;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@inheritDoc}
*
* @author Steve Ebersole
*/
public class OptimizerUnitTest extends BaseUnitTestCase {
public class OptimizerUnitTest extends BaseUnitTest {
@Test
public void testBasicNoOptimizerUsage() {
// test historic sequence behavior, where the initial values start at 1...
@ -44,6 +47,7 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
assertEquals( 10, sequence.getTimesCalled() ); // an extra time to get to 1 initially
assertEquals( 9, sequence.getCurrentValue() );
}
@Test
public void testBasicNoOptimizerUsageWithNegativeValues() {
// test historic sequence behavior, where the initial values start at 1...

View File

@ -4,7 +4,7 @@
* 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.id.enhanced;
package org.hibernate.orm.test.id.enhanced;
import java.util.Properties;
@ -17,21 +17,30 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.enhanced.HiLoOptimizer;
import org.hibernate.id.enhanced.NoopOptimizer;
import org.hibernate.id.enhanced.PooledLoOptimizer;
import org.hibernate.id.enhanced.PooledLoThreadLocalOptimizer;
import org.hibernate.id.enhanced.PooledOptimizer;
import org.hibernate.id.enhanced.SequenceStructure;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.StandardOptimizerDescriptor;
import org.hibernate.id.enhanced.TableStructure;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
import static org.junit.Assert.assertEquals;
import static org.hibernate.testing.junit5.ExtraAssertions.assertClassAssignability;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests that SequenceStyleGenerator configures itself as expected in various scenarios
*
* @author Steve Ebersole
*/
public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
public class SequenceStyleConfigUnitTest extends BaseUnitTest {
/**
* Test all params defaulted with a dialect supporting sequences
@ -310,18 +319,31 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
}
public static class TableDialect extends Dialect {
@Override
public int getVersion() {
return 0;
}
@Override
public boolean supportsSequences() {
return false;
}
}
public static class SequenceDialect extends Dialect {
@Override
public int getVersion() {
return 0;
}
@Override
public boolean supportsSequences() {
return true;
}
@Override
public boolean supportsPooledSequences() {
return false;
}
@Override
public String getSequenceNextValString(String sequenceName) throws MappingException {
return "";
}

View File

@ -4,13 +4,14 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.io.StringReader;
import java.sql.Statement;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -22,32 +23,32 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialect(PostgreSQL82Dialect.class)
public class PostgreSQLSequenceGeneratorWithSerialTest extends BaseEntityManagerFunctionalTestCase {
@RequiresDialect(value = PostgreSQLDialect.class, version = 820)
public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule( Logger.getMessageLogger( CoreMessageLogger.class,
@ -69,7 +70,7 @@ public class PostgreSQLSequenceGeneratorWithSerialTest extends BaseEntityManager
private static final String CREATE_TABLE = "CREATE TABLE application_configurations (id BIGSERIAL NOT NULL PRIMARY KEY)";
@Override
protected void addMappings(Map settings) {
protected void addConfigOptions(Map settings) {
triggerable.reset();
assertFalse( triggerable.wasTriggered() );
@ -107,7 +108,7 @@ public class PostgreSQLSequenceGeneratorWithSerialTest extends BaseEntityManager
}
@Override
protected void afterEntityManagerFactoryBuilt() {
protected void entityManagerFactoryBuilt(EntityManagerFactory factory) {
assertTrue( triggerable.wasTriggered() );
}

View File

@ -4,12 +4,12 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -20,42 +20,33 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Rule;
import org.junit.Test;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceMismatchStrategyDefaultExceptionTest extends BaseEntityManagerFunctionalTestCase {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceMismatchStrategyDefaultExceptionTest extends EntityManagerFactoryBasedFunctionalTest {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
@Override
public void buildEntityManagerFactory() {
public EntityManagerFactory produceEntityManagerFactory() {
serviceRegistry = new StandardServiceRegistryBuilder().build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( ApplicationConfigurationHBM2DDL.class )
@ -63,7 +54,7 @@ public class SequenceMismatchStrategyDefaultExceptionTest extends BaseEntityMana
new SchemaExport().create( EnumSet.of( TargetType.DATABASE ), metadata );
try {
super.buildEntityManagerFactory();
super.produceEntityManagerFactory();
fail("Should throw MappingException!");
}
@ -71,15 +62,10 @@ public class SequenceMismatchStrategyDefaultExceptionTest extends BaseEntityMana
Throwable rootCause = ExceptionUtil.rootCause( e );
assertTrue( rootCause instanceof MappingException );
assertTrue( rootCause.getMessage().contains( "in the entity mapping while the associated database sequence increment size is" ) );
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@Override
public void releaseResources() {
super.releaseResources();
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
return null;
}
@Override
@ -90,13 +76,13 @@ public class SequenceMismatchStrategyDefaultExceptionTest extends BaseEntityMana
}
@Override
protected void addMappings(Map settings) {
settings.put( AvailableSettings.HBM2DDL_AUTO, "none" );
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.HBM2DDL_AUTO, "none" );
}
@Test
public void test() {
produceEntityManagerFactory();
}
@Entity

View File

@ -4,28 +4,28 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceMismatchStrategyExceptionEnumTest extends SequenceMismatchStrategyDefaultExceptionTest {
@Override
protected void addMappings(Map settings) {
super.addMappings( settings );
settings.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, SequenceMismatchStrategy.EXCEPTION );
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, SequenceMismatchStrategy.EXCEPTION );
}
}

View File

@ -4,12 +4,13 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -19,41 +20,34 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.test.schemaupdate.SchemaExportWithGlobalQuotingEnabledTest;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceMismatchStrategyFixWithSequenceGeneratorTest extends BaseEntityManagerFunctionalTestCase {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceMismatchStrategyFixWithSequenceGeneratorTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
@ -69,20 +63,18 @@ public class SequenceMismatchStrategyFixWithSequenceGeneratorTest extends BaseEn
protected MetadataImplementor metadata;
@Override
public void buildEntityManagerFactory() {
public EntityManagerFactory produceEntityManagerFactory() {
serviceRegistry = new StandardServiceRegistryBuilder().build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( ApplicationConfigurationHBM2DDL.class )
.buildMetadata();
new SchemaExport().create( EnumSet.of( TargetType.DATABASE ), metadata );
super.buildEntityManagerFactory();
return super.produceEntityManagerFactory();
}
@Override
@AfterAll
public void releaseResources() {
super.releaseResources();
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@ -95,14 +87,14 @@ public class SequenceMismatchStrategyFixWithSequenceGeneratorTest extends BaseEn
}
@Override
protected void addMappings(Map settings) {
settings.put( AvailableSettings.HBM2DDL_AUTO, "none" );
settings.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, "fix" );
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.HBM2DDL_AUTO, "none" );
options.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, "fix" );
triggerable.reset();
}
@Override
protected void afterEntityManagerFactoryBuilt() {
protected void entityManagerFactoryBuilt(EntityManagerFactory factory) {
assertTrue( triggerable.wasTriggered() );
}
@ -113,7 +105,7 @@ public class SequenceMismatchStrategyFixWithSequenceGeneratorTest extends BaseEn
final int ITERATIONS = 51;
doInJPA( this::entityManagerFactory, entityManager -> {
inTransaction( entityManager -> {
for ( int i = 1; i <= ITERATIONS; i++ ) {
ApplicationConfiguration model = new ApplicationConfiguration();

View File

@ -4,11 +4,12 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.util.EnumSet;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -20,30 +21,31 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceMismatchStrategyLogTest extends BaseEntityManagerFunctionalTestCase {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceMismatchStrategyLogTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
@ -59,20 +61,18 @@ public class SequenceMismatchStrategyLogTest extends BaseEntityManagerFunctional
protected MetadataImplementor metadata;
@Override
public void buildEntityManagerFactory() {
public EntityManagerFactory produceEntityManagerFactory() {
serviceRegistry = new StandardServiceRegistryBuilder().build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( ApplicationConfigurationHBM2DDL.class )
.buildMetadata();
new SchemaExport().create( EnumSet.of( TargetType.DATABASE ), metadata );
super.buildEntityManagerFactory();
return super.produceEntityManagerFactory();
}
@Override
@AfterAll
public void releaseResources() {
super.releaseResources();
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@ -85,20 +85,21 @@ public class SequenceMismatchStrategyLogTest extends BaseEntityManagerFunctional
}
@Override
protected void addMappings(Map settings) {
settings.put( AvailableSettings.HBM2DDL_AUTO, "none" );
settings.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, "log" );
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.HBM2DDL_AUTO, "none" );
options.put( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, "log" );
triggerable.reset();
assertFalse( triggerable.wasTriggered() );
}
@Override
protected void afterEntityManagerFactoryBuilt() {
protected void entityManagerFactoryBuilt(EntityManagerFactory factory) {
assertTrue( triggerable.wasTriggered() );
}
@Test
public void test() {
produceEntityManagerFactory();
}
@Entity

View File

@ -4,23 +4,21 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
public class SequenceMismatchStrategyLowerCaseStringValueTest extends BaseUnitTestCase {
public class SequenceMismatchStrategyLowerCaseStringValueTest extends BaseUnitTest {
@Test
public void test() {

View File

@ -4,21 +4,22 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
public class SequenceMismatchStrategyNullValueTest extends BaseUnitTestCase {
public class SequenceMismatchStrategyNullValueTest extends BaseUnitTest {
@Test
public void test() {

View File

@ -4,25 +4,25 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import org.hibernate.HibernateException;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
public class SequenceMismatchStrategyUnknownEnumValueTest extends BaseUnitTestCase {
public class SequenceMismatchStrategyUnknownEnumValueTest extends BaseUnitTest {
@Test
public void test() {

View File

@ -4,21 +4,21 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import org.hibernate.id.SequenceMismatchStrategy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
public class SequenceMismatchStrategyUpperCaseStringValueTest extends BaseUnitTestCase {
public class SequenceMismatchStrategyUpperCaseStringValueTest extends BaseUnitTest {
@Test
public void test() {

View File

@ -4,12 +4,13 @@
* 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.id.hhh12973;
package org.hibernate.orm.test.id.hhh12973;
import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -21,32 +22,31 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-12973")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class SequenceMismatchStrategyWithoutSequenceGeneratorTest extends BaseEntityManagerFunctionalTestCase {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceMismatchStrategyWithoutSequenceGeneratorTest extends EntityManagerFactoryBasedFunctionalTest {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
@ -62,20 +62,18 @@ public class SequenceMismatchStrategyWithoutSequenceGeneratorTest extends BaseEn
protected MetadataImplementor metadata;
@Override
public void buildEntityManagerFactory() {
public EntityManagerFactory produceEntityManagerFactory() {
serviceRegistry = new StandardServiceRegistryBuilder().build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( ApplicationConfigurationHBM2DDL.class )
.buildMetadata();
new SchemaExport().create( EnumSet.of( TargetType.DATABASE ), metadata );
super.buildEntityManagerFactory();
return super.produceEntityManagerFactory();
}
@Override
@AfterAll
public void releaseResources() {
super.releaseResources();
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@ -88,13 +86,13 @@ public class SequenceMismatchStrategyWithoutSequenceGeneratorTest extends BaseEn
}
@Override
protected void addMappings(Map settings) {
settings.put( AvailableSettings.HBM2DDL_AUTO, "none" );
protected void addConfigOptions(Map options) {
options.put( AvailableSettings.HBM2DDL_AUTO, "none" );
triggerable.reset();
}
@Override
protected void afterEntityManagerFactoryBuilt() {
protected void entityManagerFactoryBuilt(EntityManagerFactory factory) {
assertFalse( triggerable.wasTriggered() );
}
@ -105,7 +103,7 @@ public class SequenceMismatchStrategyWithoutSequenceGeneratorTest extends BaseEn
final int ITERATIONS = 51;
doInJPA( this::entityManagerFactory, entityManager -> {
inTransaction( entityManager -> {
for ( int i = 1; i <= ITERATIONS; i++ ) {
ApplicationConfiguration model = new ApplicationConfiguration();

View File

@ -4,20 +4,24 @@
* 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.id.uuid;
package org.hibernate.orm.test.id.uuid;
import java.util.UUID;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.id.uuid.CustomVersionOneStrategy;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* @author Steve Ebersole
*/
public class CustomVersionOneStrategyTest extends BaseUnitTestCase {
public class CustomVersionOneStrategyTest extends BaseUnitTest {
@Test
public void testUniqueCounter() {
CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();

View File

@ -4,7 +4,7 @@
* 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.id.uuid;
package org.hibernate.orm.test.id.uuid;
import java.util.UUID;
import javax.persistence.Column;
@ -26,19 +26,19 @@ import org.hibernate.id.UUIDGenerator;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit5.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.hibernate.testing.junit5.ExtraAssertions.assertTyping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Tests a UUID attribute annotated as a generated id value.
*
* @author Steve Ebersole
*/
public class GeneratedValueTest extends BaseUnitTestCase {
public class GeneratedValueTest extends BaseUnitTest {
@Test
public void testGeneratedUuidId() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
@ -66,15 +66,16 @@ public class GeneratedValueTest extends BaseUnitTestCase {
Session s = sf.openSession();
s.beginTransaction();
s.save( theEntity );
s.getTransaction().commit();
s.close();
assertNotNull( theEntity.id );
s = sf.openSession();
s.beginTransaction();
try {
s.save( theEntity );
s.getTransaction().commit();
s.close();
assertNotNull( theEntity.id );
s = sf.openSession();
s.beginTransaction();
s.delete( theEntity );
s.getTransaction().commit();
}

View File

@ -22,9 +22,7 @@ import org.junit.jupiter.api.Test;
/**
* @author Pawel Stawicki
*/
@RequiresDialects(value = {
@RequiresDialect(value = PostgreSQL81Dialect.class), @RequiresDialect(value = PostgreSQLDialect.class)
})
@RequiresDialect(value = PostgreSQLDialect.class, version = 800)
@DomainModel(annotatedClasses = {
ParentEntity.class, InheritingEntity.class
})

View File

@ -55,7 +55,7 @@ public class CriteriaLiteralWithSingleQuoteTest extends EntityManagerFactoryBase
}
@Test
@SkipForDialect(dialectClass = PostgreSQLDialect.class, reason = "PostgreSQL does not support literals in group by statement")
@SkipForDialect(dialectClass = PostgreSQLDialect.class, matchSubTypes = true, reason = "PostgreSQL does not support literals in group by statement")
public void testLiteralProjectionAndGroupBy() {
inTransaction(
entityManager -> {

View File

@ -13,7 +13,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.RowId;
import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.orm.junit.DomainModel;
@ -33,7 +33,7 @@ import static org.junit.Assert.assertThat;
*/
@DomainModel( annotatedClasses = RowIdTest.Product.class )
@SessionFactory(statementInspectorClass = SQLStatementInspector.class)
@RequiresDialect( value = Oracle9iDialect.class )
@RequiresDialect( value = OracleDialect.class, version = 9)
public class RowIdTest {
@BeforeEach

View File

@ -89,6 +89,11 @@ public class QualifiedTableNamingTest extends BaseNonConfigCoreFunctionalTestCas
public NameQualifierSupport getNameQualifierSupport() {
return NameQualifierSupport.BOTH;
}
@Override
public int getVersion() {
return 0;
}
}
public static class MockedConnectionProvider implements ConnectionProvider {

View File

@ -35,6 +35,10 @@ public class DefaultSchemaNameResolverTest {
String schemaName = DefaultSchemaNameResolver.INSTANCE.resolveSchemaName(
connectionSupportsGetSchemaName,
new Dialect() {
@Override
public int getVersion() {
return 0;
}
}
);
assertEquals( SCHEMA_NAME, schemaName );
@ -44,6 +48,12 @@ public class DefaultSchemaNameResolverTest {
schemaName = DefaultSchemaNameResolver.INSTANCE.resolveSchemaName(
connectionNotSupportGetSchemaName,
new Dialect() {
@Override
public int getVersion() {
return 0;
}
@Override
public String getCurrentSchemaCommand() {
return GET_CURRENT_SCHEMA_NAME_COMMAND ;

View File

@ -85,6 +85,11 @@ public class NoDatabaseMetaDataTest extends BaseUnitTestCase {
public boolean supportsNamedParameters(java.sql.DatabaseMetaData databaseMetaData) {
return true;
}
@Override
public int getVersion() {
return 0;
}
}
}

View File

@ -68,5 +68,10 @@ public class CommentGenerationTest {
public boolean supportsCommentOn() {
return true;
}
@Override
public int getVersion() {
return 0;
}
}
}

View File

@ -57,6 +57,10 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
}
catch (Exception e) {
return new Dialect() {
@Override
public int getVersion(){
return 0;
}
};
}
}

View File

@ -230,6 +230,10 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
}
catch (Exception e) {
return new Dialect() {
@Override
public int getVersion() {
return 0;
}
};
}
}

View File

@ -65,14 +65,16 @@ public class DialectFilterExtension implements ExecutionCondition {
for ( RequiresDialect requiresDialect : effectiveRequiresDialects ) {
requiredDialects.append( requiresDialect.value() );
requiredDialects.append( " " );
if ( requiresDialect.matchSubTypes() ) {
if ( requiresDialect.value().isInstance( dialect ) ) {
return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
if ( requiresDialect.value().isInstance( dialect ) ) {
if ( requiresDialect.matchSubTypes() ) {
if ( dialect.getVersion() >= requiresDialect.version() ) {
return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
}
}
}
else {
if ( requiresDialect.value().equals( dialect.getClass() ) ) {
return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
else {
if ( requiresDialect.version() == dialect.getVersion() ) {
return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" );
}
}
}
}
@ -94,14 +96,31 @@ public class DialectFilterExtension implements ExecutionCondition {
);
for ( SkipForDialect effectiveSkipForDialect : effectiveSkips ) {
if ( effectiveSkipForDialect.matchSubTypes() ) {
int version = effectiveSkipForDialect.version();
if ( version > -1 ) {
if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
if ( effectiveSkipForDialect.matchSubTypes() ) {
if ( dialect.getVersion() <= version ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
}
}
else {
if ( dialect.getVersion() == version ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
}
}
}
}
else {
if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
if ( effectiveSkipForDialect.matchSubTypes() ) {
if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
}
}
else {
if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
}
}
}
}
@ -118,7 +137,7 @@ public class DialectFilterExtension implements ExecutionCondition {
.newInstance();
final boolean applicable = dialectFeatureCheck.apply( getDialect( context ) );
final boolean reverse = effectiveRequiresDialectFeature.reverse();
if ( applicable ^ reverse ) {
if ( !( applicable ^ reverse ) ) {
return ConditionEvaluationResult.disabled(
String.format(
Locale.ROOT,

View File

@ -21,6 +21,6 @@ public interface EntityManagerFactoryAccess extends DialectAccess {
@Override
default Dialect getDialect() {
return getEntityManagerFactory().unwrap( SessionFactoryImplementor.class ).getJdbcServices().getDialect();
return Dialect.getDialect();
}
}

View File

@ -0,0 +1,82 @@
/*
* 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.testing.junit5;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Steve Ebersole
*/
public final class ExtraAssertions {
private ExtraAssertions() {
}
public static void assertClassAssignability(Class expected, Class actual) {
if ( !expected.isAssignableFrom( actual ) ) {
fail( "Expected class [" + expected.getName() + "] was not assignable from actual [" + actual.getName() + "]" );
}
}
@SuppressWarnings("unchecked")
public static <T> T assertTyping(Class<T> expectedType, Object value) {
if ( !expectedType.isInstance( value ) ) {
fail(
String.format(
"Expecting value of type [%s], but found [%s]",
expectedType.getName(),
value == null ? "<null>" : value
)
);
}
return (T) value;
}
public static void assertJdbcTypeCode(int expected, int actual) {
if ( expected != actual ) {
final String message = String.format(
"JDBC type codes did not match...\n" +
"Expected: %s (%s)\n" +
"Actual : %s (%s)",
jdbcTypeCodeMap().get( expected ),
expected,
jdbcTypeCodeMap().get( actual ),
actual
);
fail( message );
}
}
private static Map<Integer, String> jdbcTypeCodeMap;
private static synchronized Map<Integer, String> jdbcTypeCodeMap() {
if ( jdbcTypeCodeMap == null ) {
jdbcTypeCodeMap = generateJdbcTypeCache();
}
return jdbcTypeCodeMap;
}
private static Map generateJdbcTypeCache() {
final Field[] fields = Types.class.getFields();
Map cache = new HashMap( (int) ( fields.length * .75 ) + 1 );
for ( Field field : fields ) {
if ( Modifier.isStatic( field.getModifiers() ) ) {
try {
cache.put( field.get( null ), field.getName() );
}
catch (Throwable ignore) {
}
}
}
return cache;
}
}

View File

@ -39,4 +39,9 @@ public @interface RequiresDialect {
* Should subtypes of {@link #value()} be matched?
*/
boolean matchSubTypes() default true;
/**
* the Dialect version
*/
int version();
}

View File

@ -37,4 +37,5 @@ public @interface SkipForDialect {
Class<? extends Dialect> dialectClass();
boolean matchSubTypes() default false;
String reason() default "<undefined>";
int version() default -1;
}