Search in sources :

Example 11 with SequenceStyleGenerator

use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.

the class GeneratedValueTests method testImplicitSequenceGenerator.

@Test
public void testImplicitSequenceGenerator() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false").build();
    final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ImplicitSequenceGeneratorEntity.class).buildMetadata();
    final PersistentClass entityMapping = bootModel.getEntityBinding(ImplicitSequenceGeneratorEntity.class.getName());
    final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
    final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
    // PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
    // default (hibernate_sequence) should be used
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is("hibernate_sequence"));
    // the JPA defaults since they were not defined
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(1));
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(50));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 12 with SequenceStyleGenerator

use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.

the class GeneratedValueTests method testExplicitSequenceGeneratorImplicitName.

@Test
public void testExplicitSequenceGeneratorImplicitName() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false").build();
    final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitSequenceGeneratorImplicitNameEntity.class).buildMetadata();
    final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitSequenceGeneratorImplicitNameEntity.class.getName());
    final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
    final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
    // all the JPA defaults since they were not defined
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is(SequenceStyleGenerator.DEF_SEQUENCE_NAME));
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(100));
    assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(500));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 13 with SequenceStyleGenerator

use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.

the class NewGeneratorMappingsTest method testSequencePerEntity.

@Test
@TestForIssue(jiraKey = "HHH-6790")
public void testSequencePerEntity() {
    // Checking first entity.
    EntityPersister persister = sessionFactory().getEntityPersister(DedicatedSequenceEntity1.class.getName());
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue(SequenceStyleGenerator.class.isInstance(generator));
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals(StringHelper.unqualifyEntityName(DedicatedSequenceEntity1.class.getName()) + DedicatedSequenceEntity1.SEQUENCE_SUFFIX, seqGenerator.getDatabaseStructure().getName());
    // Checking second entity.
    persister = sessionFactory().getEntityPersister(DedicatedSequenceEntity2.class.getName());
    generator = persister.getIdentifierGenerator();
    assertTrue(SequenceStyleGenerator.class.isInstance(generator));
    seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals(DedicatedSequenceEntity2.ENTITY_NAME + DedicatedSequenceEntity1.SEQUENCE_SUFFIX, seqGenerator.getDatabaseStructure().getName());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with SequenceStyleGenerator

use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.

the class NewGeneratorMappingsTest method testMinimalSequenceEntity.

@Test
public void testMinimalSequenceEntity() {
    final EntityPersister persister = sessionFactory().getEntityPersister(MinimalSequenceEntity.class.getName());
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue(SequenceStyleGenerator.class.isInstance(generator));
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals(MinimalSequenceEntity.SEQ_NAME, seqGenerator.getDatabaseStructure().getName());
    // 1 is the annotation default
    assertEquals(1, seqGenerator.getDatabaseStructure().getInitialValue());
    // 50 is the annotation default
    assertEquals(50, seqGenerator.getDatabaseStructure().getIncrementSize());
    assertFalse(NoopOptimizer.class.isInstance(seqGenerator.getOptimizer()));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) NoopOptimizer(org.hibernate.id.enhanced.NoopOptimizer) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Example 15 with SequenceStyleGenerator

use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.

the class NewGeneratorMappingsTest method testAutoEntity.

@Test
public void testAutoEntity() {
    final EntityPersister persister = sessionFactory().getEntityPersister(AutoEntity.class.getName());
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    assertTrue(SequenceStyleGenerator.class.isInstance(generator));
    SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
    assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, seqGenerator.getDatabaseStructure().getName());
    assertEquals(SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue());
    assertEquals(SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Aggregations

SequenceStyleGenerator (org.hibernate.id.enhanced.SequenceStyleGenerator)20 Test (org.junit.Test)18 EntityPersister (org.hibernate.persister.entity.EntityPersister)12 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)10 Session (org.hibernate.Session)7 Metadata (org.hibernate.boot.Metadata)6 MetadataSources (org.hibernate.boot.MetadataSources)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)6 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)5 PersistentClass (org.hibernate.mapping.PersistentClass)5 NoopOptimizer (org.hibernate.id.enhanced.NoopOptimizer)3 TableStructure (org.hibernate.id.enhanced.TableStructure)3 Properties (java.util.Properties)2 HiLoOptimizer (org.hibernate.id.enhanced.HiLoOptimizer)2 PooledOptimizer (org.hibernate.id.enhanced.PooledOptimizer)2 TestForIssue (org.hibernate.testing.TestForIssue)2 ATest (de.invesdwin.context.test.ATest)1 ObjectNameNormalizer (org.hibernate.boot.model.naming.ObjectNameNormalizer)1 Sequence (org.hibernate.boot.model.relational.Sequence)1 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)1