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());
}
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!");
}
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()));
}
}
}
}
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();
}
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);
}
Aggregations