Search in sources :

Example 21 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class MySQLDropConstraintThrowsExceptionTest method setUp.

@Before
public void setUp() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
    SessionFactoryImplementor sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Before(org.junit.Before)

Example 22 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class MySQLDropConstraintThrowsExceptionTest method tearDown.

@After
public void tearDown() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
    SessionFactoryImplementor sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) After(org.junit.After)

Example 23 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class MySQLDropConstraintThrowsExceptionTest method testEnumTypeInterpretation.

@Test
public void testEnumTypeInterpretation() {
    final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "update").applySetting(AvailableSettings.CONNECTION_PROVIDER, connectionProvider).build();
    SessionFactory sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
        List<String> alterStatements = connectionProvider.getExecuteStatements().stream().filter(sql -> sql.toLowerCase().contains("alter ")).map(String::trim).collect(Collectors.toList());
        assertTrue(alterStatements.get(0).matches("alter table CUSTOMER\\s+drop index .*?"));
        assertTrue(alterStatements.get(1).matches("alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)"));
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PreparedStatementSpyConnectionProvider(org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 24 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class UniqueConstraintUnitTests method testUnNamedConstraints.

@Test
@TestForIssue(jiraKey = "HHH-8026")
public void testUnNamedConstraints() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UniqueNoNameA.class).addAnnotatedClass(UniqueNoNameB.class).buildMetadata();
        org.hibernate.mapping.Table tableA = null;
        org.hibernate.mapping.Table tableB = null;
        for (org.hibernate.mapping.Table table : metadata.collectTableMappings()) {
            if (table.getName().equals("UniqueNoNameA")) {
                tableA = table;
            } else if (table.getName().equals("UniqueNoNameB")) {
                tableB = table;
            }
        }
        assertTrue("Could not find the expected tables.", tableA != null && tableB != null);
        assertFalse(tableA.getUniqueKeyIterator().next().getName().equals(tableB.getUniqueKeyIterator().next().getName()));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 25 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class MultipleBagFetchTest method testEntityWithMultipleJoinFetchedBags.

@Test
public void testEntityWithMultipleJoinFetchedBags() {
    StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
    Metadata metadata = new MetadataSources(standardRegistry).addAnnotatedClass(Post.class).addAnnotatedClass(PostComment.class).addAnnotatedClass(Tag.class).getMetadataBuilder().build();
    try {
        metadata.buildSessionFactory();
        fail("MultipleBagFetchException should have been thrown.");
    } catch (MultipleBagFetchException expected) {
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)169 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)152 Test (org.junit.Test)121 MetadataSources (org.hibernate.boot.MetadataSources)118 Metadata (org.hibernate.boot.Metadata)56 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)39 PersistentClass (org.hibernate.mapping.PersistentClass)39 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)25 TestForIssue (org.hibernate.testing.TestForIssue)24 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)23 Properties (java.util.Properties)20 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)15 SessionFactory (org.hibernate.SessionFactory)14 Column (org.hibernate.mapping.Column)14 Property (org.hibernate.mapping.Property)14 Session (org.hibernate.Session)13 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)12 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 RootClass (org.hibernate.mapping.RootClass)11