Search in sources :

Example 11 with Sequence

use of org.hibernate.boot.model.relational.Sequence in project hibernate-orm by hibernate.

the class SequenceNamingStrategyTest method verify.

private void verify(Class<?> entityType, String strategy, String expectedName) {
    withMetadata(entityType, strategy, (metadata) -> {
        final Namespace defaultNamespace = metadata.getDatabase().getDefaultNamespace();
        final Sequence sequence = defaultNamespace.locateSequence(Identifier.toIdentifier(expectedName));
        assertThat(sequence).isNotNull();
        final PersistentClass entityBinding = metadata.getEntityBinding(entityType.getName());
        final IdentifierGenerator generator = extractGenerator(entityBinding);
        assertThat(generator).isInstanceOf(SequenceStyleGenerator.class);
        final SequenceStyleGenerator sequenceStyleGenerator = (SequenceStyleGenerator) generator;
        assertThat(sequenceStyleGenerator.getDatabaseStructure()).isInstanceOf(SequenceStructure.class);
        final SequenceStructure sequenceStructure = (SequenceStructure) sequenceStyleGenerator.getDatabaseStructure();
        assertThat(sequenceStructure.getPhysicalName().getObjectName().getText()).isEqualTo(expectedName);
    });
}
Also used : SequenceStructure(org.hibernate.id.enhanced.SequenceStructure) Sequence(org.hibernate.boot.model.relational.Sequence) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) Namespace(org.hibernate.boot.model.relational.Namespace) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierGenerator(org.hibernate.id.IdentifierGenerator)

Example 12 with Sequence

use of org.hibernate.boot.model.relational.Sequence in project hibernate-orm by hibernate.

the class SequenceExportTest method testMultipleUsesOfDefaultSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfDefaultSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity1.class).addAnnotatedClass(Entity2.class).buildMetadata();
    metadata.validate();
    int namespaceCount = 0;
    int sequenceCount = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        namespaceCount++;
        for (Sequence sequence : namespace.getSequences()) {
            sequenceCount++;
        }
    }
    assertThat(namespaceCount).isEqualTo(1);
    // 1 per entity
    assertThat(sequenceCount).isEqualTo(2);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with Sequence

use of org.hibernate.boot.model.relational.Sequence in project hibernate-orm by hibernate.

the class SequenceExportTest method testMultipleUsesOfExplicitSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfExplicitSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity3.class).addAnnotatedClass(Entity4.class).buildMetadata();
    metadata.validate();
    int namespaceCount = 0;
    int sequenceCount = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        namespaceCount++;
        for (Sequence sequence : namespace.getSequences()) {
            sequenceCount++;
        }
    }
    assertThat(namespaceCount).isEqualTo(1);
    assertThat(sequenceCount).isEqualTo(1);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with Sequence

use of org.hibernate.boot.model.relational.Sequence in project hibernate-orm by hibernate.

the class LegacySequenceExportTest method testMultipleUsesOfDefaultSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfDefaultSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity1.class).addAnnotatedClass(Entity2.class).buildMetadata();
    metadata.validate();
    assertEquals(0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size());
    int count = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        for (Sequence sequence : namespace.getSequences()) {
            count++;
        }
    }
    assertEquals(1, count);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with Sequence

use of org.hibernate.boot.model.relational.Sequence in project hibernate-orm by hibernate.

the class LegacySequenceExportTest method testMultipleUsesOfExplicitSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfExplicitSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity3.class).addAnnotatedClass(Entity4.class).buildMetadata();
    metadata.validate();
    assertEquals(0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size());
    int count = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        for (Sequence sequence : namespace.getSequences()) {
            count++;
        }
    }
    assertEquals(1, count);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Sequence (org.hibernate.boot.model.relational.Sequence)20 Namespace (org.hibernate.boot.model.relational.Namespace)18 MetadataSources (org.hibernate.boot.MetadataSources)8 Database (org.hibernate.boot.model.relational.Database)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)7 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)7 Table (org.hibernate.mapping.Table)7 Identifier (org.hibernate.boot.model.naming.Identifier)6 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)6 TestForIssue (org.hibernate.testing.TestForIssue)6 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)5 SqlStringGenerationContext (org.hibernate.boot.model.relational.SqlStringGenerationContext)4 SequenceInformation (org.hibernate.tool.schema.extract.spi.SequenceInformation)4 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)3 SequenceStyleGenerator (org.hibernate.id.enhanced.SequenceStyleGenerator)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 HashMap (java.util.HashMap)2 InitCommand (org.hibernate.boot.model.relational.InitCommand)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2