Search in sources :

Example 41 with Metadata

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);
    }
}
Also used : MultipleHiLoPerTableGenerator(org.hibernate.id.MultipleHiLoPerTableGenerator) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Properties(java.util.Properties) DB2Dialect(org.hibernate.dialect.DB2Dialect) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 42 with Metadata

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);
    }
}
Also used : Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TableGenerator(org.hibernate.id.enhanced.TableGenerator) MultipleHiLoPerTableGenerator(org.hibernate.id.MultipleHiLoPerTableGenerator) Properties(java.util.Properties) DB2Dialect(org.hibernate.dialect.DB2Dialect) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 43 with Metadata

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();
}
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 44 with Metadata

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));
}
Also used : PostgresUUIDType(org.hibernate.type.PostgresUUIDType) UUIDBinaryType(org.hibernate.type.UUIDBinaryType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 45 with Metadata

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);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Aggregations

Metadata (org.hibernate.boot.Metadata)99 MetadataSources (org.hibernate.boot.MetadataSources)88 Test (org.junit.Test)73 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)46 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)41 PersistentClass (org.hibernate.mapping.PersistentClass)29 TestForIssue (org.hibernate.testing.TestForIssue)24 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 Property (org.hibernate.mapping.Property)11 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)11 Collection (org.hibernate.mapping.Collection)10 RootClass (org.hibernate.mapping.RootClass)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 SessionFactory (org.hibernate.SessionFactory)8 Session (org.hibernate.Session)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 Properties (java.util.Properties)5