Search in sources :

Example 1 with Namespace

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

the class QualifiedTableNamingTest method testQualifiedNameSeparator.

@Test
public void testQualifiedNameSeparator() throws Exception {
    Namespace.Name namespaceName = new Namespace.Name(Identifier.toIdentifier("DB1"), Identifier.toIdentifier("PUBLIC"));
    String expectedName = null;
    for (Namespace namespace : metadata().getDatabase().getNamespaces()) {
        if (!namespace.getName().equals(namespaceName)) {
            continue;
        }
        assertEquals(1, namespace.getTables().size());
        expectedName = metadata().getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format(namespace.getTables().iterator().next().getQualifiedTableName(), getDialect());
    }
    assertNotNull(expectedName);
    SingleTableEntityPersister persister = (SingleTableEntityPersister) sessionFactory().getEntityPersister(Box.class.getName());
    assertEquals(expectedName, persister.getTableName());
}
Also used : SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test)

Example 2 with Namespace

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

the class ForeignKeyConstraintTest method assertForeignKey.

private void assertForeignKey(String foreignKeyName, String... columns) {
    Set<String> columnSet = new LinkedHashSet<>(Arrays.asList(columns));
    for (Namespace namespace : metadata().getDatabase().getNamespaces()) {
        for (org.hibernate.mapping.Table table : namespace.getTables()) {
            Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeyIterator();
            while (fkItr.hasNext()) {
                org.hibernate.mapping.ForeignKey fk = fkItr.next();
                if (foreignKeyName.equals(fk.getName())) {
                    assertEquals("ForeignKey column count not like expected", columnSet.size(), fk.getColumnSpan());
                    List<String> columnNames = fk.getColumns().stream().map(Column::getName).collect(Collectors.toList());
                    assertTrue("ForeignKey columns [" + columnNames + "] do not match expected columns [" + columnSet + "]", columnSet.containsAll(columnNames));
                    return;
                }
            }
        }
    }
    fail("ForeignKey '" + foreignKeyName + "' could not be found!");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ForeignKey(javax.persistence.ForeignKey) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 3 with Namespace

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

the class ForeignKeyConstraintTest method assertNoForeignKey.

private void assertNoForeignKey(String foreignKeyName, String... columns) {
    Set<String> columnSet = new LinkedHashSet<>(Arrays.asList(columns));
    for (Namespace namespace : metadata().getDatabase().getNamespaces()) {
        for (org.hibernate.mapping.Table table : namespace.getTables()) {
            Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeyIterator();
            while (fkItr.hasNext()) {
                org.hibernate.mapping.ForeignKey fk = fkItr.next();
                assertFalse("ForeignKey [" + foreignKeyName + "] defined and shouldn't have been.", foreignKeyName.equals(fk.getName()));
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ForeignKey(javax.persistence.ForeignKey) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 4 with Namespace

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

the class IdentityGeneratorExtendsTest method testIdentifierGeneratorExtendsIdentityGenerator.

@Test
public void testIdentifierGeneratorExtendsIdentityGenerator() {
    final MetadataSources sources = new MetadataSources(serviceRegistry());
    sources.addAnnotatedClass(EntityBean.class);
    final MetadataBuilder builder = sources.getMetadataBuilder();
    final Metadata metadata = builder.build();
    for (final Namespace ns : metadata.getDatabase().getNamespaces()) {
        for (final org.hibernate.mapping.Table table : ns.getTables()) {
            final KeyValue value = table.getIdentifierValue();
            assertNotNull("IdentifierValue was null", value);
            assertTrue(value.isIdentityColumn(metadata.getIdentifierGeneratorFactory(), getDialect()));
        }
    }
    Session s = openSession();
    s.beginTransaction();
    s.save(new EntityBean());
    s.getTransaction().commit();
    s.close();
}
Also used : KeyValue(org.hibernate.mapping.KeyValue) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Namespace(org.hibernate.boot.model.relational.Namespace) Session(org.hibernate.Session) Test(org.junit.Test)

Example 5 with Namespace

use of org.hibernate.boot.model.relational.Namespace 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++;
        }
    }
    assertEquals(1, namespaceCount);
    assertEquals(1, sequenceCount);
}
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

Namespace (org.hibernate.boot.model.relational.Namespace)24 Table (org.hibernate.mapping.Table)11 Sequence (org.hibernate.boot.model.relational.Sequence)10 Test (org.junit.Test)8 Identifier (org.hibernate.boot.model.naming.Identifier)7 MetadataSources (org.hibernate.boot.MetadataSources)6 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)5 TestForIssue (org.hibernate.testing.TestForIssue)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 Column (org.hibernate.mapping.Column)4 DenormalizedTable (org.hibernate.mapping.DenormalizedTable)4 HashSet (java.util.HashSet)3 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)3 Database (org.hibernate.boot.model.relational.Database)3 Dialect (org.hibernate.dialect.Dialect)3 Iterator (java.util.Iterator)2 LinkedHashSet (java.util.LinkedHashSet)2 ForeignKey (javax.persistence.ForeignKey)2 Session (org.hibernate.Session)2 Metadata (org.hibernate.boot.Metadata)2