use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class ForeignKeyNameTest method testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided.
@Test
@TestForIssue(jiraKey = "HHH-10247")
public void testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() 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).addResource("org/hibernate/test/schemaupdate/manytomany/UserGroup.hbm.xml").buildMetadata();
metadata.validate();
new SchemaExport().setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).create(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent.toLowerCase().contains("fk_user_group"), is(true));
assertThat(fileContent.toLowerCase().contains("fk_group_user"), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class UniqueConstraintDropTest method setUp.
@Before
public void setUp() throws Exception {
output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").applySetting(Environment.FORMAT_SQL, "false").applySetting(Environment.SHOW_SQL, "true").build();
metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/uniqueconstraint/TestEntity.hbm.xml").buildMetadata();
metadata.validate();
tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return configurationValues;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
};
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class JoinTableWithDefaultSchemaTest method testGetTableDataForJoinTableWithDefaultSchema.
@Test
@TestForIssue(jiraKey = "HHH-10978")
@RequiresDialect(SQLServerDialect.class)
public void testGetTableDataForJoinTableWithDefaultSchema() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false").build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Task.class).addAnnotatedClass(Project.class).buildMetadata();
metadata.validate();
// first create the schema...
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
try {
// validate the schema
new SchemaValidator().validate(metadata);
} finally {
// cleanup
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SynonymValidationTest method testSynonymUsingIndividuallySchemaValidator.
@Test
public void testSynonymUsingIndividuallySchemaValidator() {
ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.ENABLE_SYNONYMS, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, JdbcMetadaAccessStrategy.INDIVIDUALLY).build();
try {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(TestEntityWithSynonym.class);
metadataSources.addAnnotatedClass(TestEntity.class);
new SchemaValidator().validate(metadataSources.buildMetadata());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class ClassLoaderServiceImplTest method testStoppableClassLoaderService.
/**
* HHH-8363 discovered multiple leaks within CLS. Most notably, it wasn't getting GC'd due to holding
* references to ServiceLoaders. Ensure that the addition of Stoppable functionality cleans up properly.
*
* TODO: Is there a way to test that the ServiceLoader was actually reset?
*/
@Test
@TestForIssue(jiraKey = "HHH-8363")
public void testStoppableClassLoaderService() {
final BootstrapServiceRegistryBuilder bootstrapBuilder = new BootstrapServiceRegistryBuilder();
bootstrapBuilder.applyClassLoader(new TestClassLoader());
final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bootstrapBuilder.build()).build();
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
TestIntegrator testIntegrator1 = findTestIntegrator(classLoaderService);
assertNotNull(testIntegrator1);
TestIntegrator testIntegrator2 = findTestIntegrator(classLoaderService);
assertNotNull(testIntegrator2);
assertSame(testIntegrator1, testIntegrator2);
StandardServiceRegistryBuilder.destroy(serviceRegistry);
try {
findTestIntegrator(classLoaderService);
Assert.fail("Should have thrown an HibernateException -- the ClassLoaderService instance was closed.");
} catch (HibernateException e) {
String message = e.getMessage();
Assert.assertEquals("HHH000469: The ClassLoaderService can not be reused. This instance was stopped already.", message);
}
}
Aggregations