use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class Db2GenerationTest method testLegacyGeneratorTableCreationOnDb2.
@Test
@TestForIssue(jiraKey = "HHH-9850")
public void testLegacyGeneratorTableCreationOnDb2() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, DB2Dialect.class.getName()).build();
try {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
assertEquals(0, metadata.getDatabase().getDefaultNamespace().getTables().size());
MultipleHiLoPerTableGenerator generator = new MultipleHiLoPerTableGenerator();
Properties properties = new Properties();
generator.configure(IntegerType.INSTANCE, properties, ssr);
generator.registerExportables(metadata.getDatabase());
assertEquals(1, metadata.getDatabase().getDefaultNamespace().getTables().size());
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings(table, metadata);
assertContains("sequence_name varchar(255) not null", createCommands[0]);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class Db2GenerationTest method testNewGeneratorTableCreationOnDb2.
@Test
@TestForIssue(jiraKey = "HHH-9850")
public void testNewGeneratorTableCreationOnDb2() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, DB2Dialect.class.getName()).build();
try {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
assertEquals(0, metadata.getDatabase().getDefaultNamespace().getTables().size());
TableGenerator generator = new TableGenerator();
Properties properties = new Properties();
generator.configure(IntegerType.INSTANCE, properties, ssr);
generator.registerExportables(metadata.getDatabase());
assertEquals(1, metadata.getDatabase().getDefaultNamespace().getTables().size());
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings(table, metadata);
assertContains("sequence_name varchar(255) not null", createCommands[0]);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.Metadata 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.Metadata in project hibernate-orm by hibernate.
the class UUIDBasedIdInterpretationTest method checkUuidTypeUsed.
private void checkUuidTypeUsed(StandardServiceRegistry ssr, Class<? extends Type> uuidTypeClass) {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UuidIdEntity.class).buildMetadata();
final PersistentClass entityBinding = metadata.getEntityBinding(UuidIdEntity.class.getName());
final Type idPropertyType = entityBinding.getIdentifier().getType();
assertThat(idPropertyType, instanceOf(uuidTypeClass));
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class UUIDBasedIdInterpretationTest method testBinaryRuntimeUsage.
@Test
@TestForIssue(jiraKey = "HHH-10564")
@RequiresDialect(H2Dialect.class)
public void testBinaryRuntimeUsage() {
StandardServiceRegistry ssr = buildStandardServiceRegistry(H2Dialect.class, true);
try {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UuidIdEntity.class).buildMetadata();
final SessionFactory sf = metadata.buildSessionFactory();
try {
Session s = sf.openSession();
try {
s.beginTransaction();
s.byId(UuidIdEntity.class).load(UUID.randomUUID());
s.getTransaction().commit();
} finally {
s.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations