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