HHH-13783 Fix test failing on Oracle
This commit is contained in:
parent
0c8e3056dc
commit
c5581e6759
|
@ -8,7 +8,15 @@ package org.hibernate.test.idgen.enhanced.sequence;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLSyntaxErrorException;
|
||||
import java.sql.Statement;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -17,13 +25,14 @@ import org.hibernate.id.SequenceMismatchStrategy;
|
|||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.AfterClassOnce;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
@ -34,16 +43,18 @@ import static org.junit.Assert.fail;
|
|||
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
|
||||
public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private String sequenceName = "ID_SEQ_HILO_SEQ";
|
||||
public final static String sequenceName = "ID_SEQ_HILO_SEQ";
|
||||
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/sequence/HiLo.hbm.xml" };
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { TestEntity.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty(AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, SequenceMismatchStrategy.EXCEPTION.toString());
|
||||
configuration.setProperty(
|
||||
AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY,
|
||||
SequenceMismatchStrategy.EXCEPTION.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,9 +67,14 @@ public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
try (Connection connection = connectionProvider.getConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
try {
|
||||
for ( String dropSequenceStatement : dropSequenceStatements ) {
|
||||
statement.execute( dropSequenceStatement );
|
||||
}
|
||||
}
|
||||
catch (SQLSyntaxErrorException e) {
|
||||
//ignore
|
||||
}
|
||||
for ( String createSequenceStatement : createSequenceStatements ) {
|
||||
statement.execute( createSequenceStatement );
|
||||
}
|
||||
|
@ -68,28 +84,10 @@ public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
}
|
||||
|
||||
@AfterClassOnce
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
protected void releaseSessionFactory() {
|
||||
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
|
||||
connectionProvider.configure( Environment.getProperties() );
|
||||
|
||||
String[] dropSequenceStatements = getDialect().getDropSequenceStrings( sequenceName );
|
||||
try ( Connection connection = connectionProvider.getConnection();
|
||||
Statement statement = connection.createStatement() ) {
|
||||
for ( String dropSequenceStatement : dropSequenceStatements ) {
|
||||
statement.execute( dropSequenceStatement );
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
super.releaseSessionFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceMismatchStrategyNotApplied() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( TestEntity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
|
||||
SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
|
@ -102,4 +100,22 @@ public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase
|
|||
Assert.assertNotEquals( 1, incrementSize );
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
public static class TestEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator")
|
||||
@GenericGenerator(
|
||||
name = "hilo_sequence_generator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {
|
||||
@Parameter(name = "sequence_name", value = sequenceName),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "10"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
})
|
||||
private Long id;
|
||||
|
||||
private String aString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue