Search in sources :

Example 46 with StandardServiceRegistryBuilder

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

the class SequenceReadingTest method testSequenceReading.

@Test
public void testSequenceReading() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, MyExtendedH2Dialect.class).build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
        metadata.validate();
        try {
            // try to update the schema
            new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
        } finally {
            try {
                // clean up
                new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
            } catch (Exception ignore) {
            }
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 47 with StandardServiceRegistryBuilder

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

the class SchemaExportWithGlobalQuotingEnabledTest method setUp.

@Before
public void setUp() {
    serviceRegistry = new StandardServiceRegistryBuilder().applySetting(Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true").build();
    metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(MyEntity.class).addAnnotatedClass(Role.class).buildMetadata();
    System.out.println("********* Starting SchemaExport for START-UP *************************");
    new SchemaExport().create(EnumSet.of(TargetType.STDOUT, TargetType.DATABASE), metadata);
    System.out.println("********* Completed SchemaExport for START-UP *************************");
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Before(org.junit.Before)

Example 48 with StandardServiceRegistryBuilder

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

the class SchemaExportWithIndexAndDefaultSchema method setUp.

@Before
public void setUp() {
    serviceRegistry = new StandardServiceRegistryBuilder().applySetting(Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true").applySetting(Environment.DEFAULT_SCHEMA, "public").build();
    metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(MyEntity.class).buildMetadata();
    System.out.println("********* Starting SchemaExport for START-UP *************************");
    new SchemaExport().create(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
    System.out.println("********* Completed SchemaExport for START-UP *************************");
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Before(org.junit.Before)

Example 49 with StandardServiceRegistryBuilder

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

the class SchemaUpdateFormatterTest method testSetFormat.

@Test
public void testSetFormat() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
    try {
        File output = File.createTempFile("update_script", ".sql");
        output.deleteOnExit();
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
        metadata.validate();
        new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(DELIMITER).setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
        String outputContent = new String(Files.readAllBytes(output.toPath()));
        //Old Macs use \r as a new line delimiter
        outputContent = outputContent.replaceAll("\r", "\n");
        //On Windows, \r\n would become \n\n, so we eliminate duplicates
        outputContent = outputContent.replaceAll("\n\n", "\n");
        Assert.assertTrue(Pattern.compile(AFTER_FORMAT).matcher(outputContent).matches());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) File(java.io.File) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 50 with StandardServiceRegistryBuilder

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

the class SchemaUpdateSchemaNameTest method buildInitialSchema.

@Before
public void buildInitialSchema() throws Exception {
    // Builds the initial table in the schema.
    StandardServiceRegistry ssr = null;
    try {
        final Configuration cfg = buildConfiguration(SimpleFirst.class);
        ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
        cfg.buildSessionFactory(ssr).close();
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Before(org.junit.Before)

Aggregations

StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)167 MetadataSources (org.hibernate.boot.MetadataSources)106 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)94 Test (org.junit.Test)92 Metadata (org.hibernate.boot.Metadata)46 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)34 PersistentClass (org.hibernate.mapping.PersistentClass)27 Before (org.junit.Before)26 Properties (java.util.Properties)24 TestForIssue (org.hibernate.testing.TestForIssue)23 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)17 SessionFactory (org.hibernate.SessionFactory)15 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)14 Property (org.hibernate.mapping.Property)14 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)14 File (java.io.File)13 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)13 Map (java.util.Map)12 HashMap (java.util.HashMap)11 ServiceRegistry (org.hibernate.service.ServiceRegistry)11