use of org.hibernate.tool.schema.internal.SchemaDropperImpl in project hibernate-orm by hibernate.
the class AbstractMultiTenancyTest method sessionFactory.
protected SessionFactory sessionFactory(Map<String, Object> settings) {
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (Class annotatedClasses : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(annotatedClasses);
}
Metadata metadata = metadataSources.buildMetadata();
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase frontEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(FRONT_END_TENANT)));
final GenerationTargetToDatabase backEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(BACK_END_TENANT)));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
return sessionFactoryBuilder.build();
}
use of org.hibernate.tool.schema.internal.SchemaDropperImpl in project hibernate-orm by hibernate.
the class TableGeneratorQuotingTest method testTableGeneratorQuoting.
@Test
@TestForIssue(jiraKey = "HHH-7927")
public void testTableGeneratorQuoting() {
final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(TestEntity.class).buildMetadata();
final ConnectionProvider connectionProvider = serviceRegistry.getService(ConnectionProvider.class);
final GenerationTarget target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider)));
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, false, target);
try {
new SchemaValidator().validate(metadata);
} catch (HibernateException e) {
fail("The identifier generator table should have validated. " + e.getMessage());
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, target);
}
}
use of org.hibernate.tool.schema.internal.SchemaDropperImpl in project hibernate-orm by hibernate.
the class SequenceFilterTest method doDrop.
private RecordingTarget doDrop(SchemaFilter filter) {
RecordingTarget target = new RecordingTarget();
new SchemaDropperImpl(serviceRegistry, filter).doDrop(metadata, true, target);
return target;
}
use of org.hibernate.tool.schema.internal.SchemaDropperImpl in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.
@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
final Database database = metadata.getDatabase();
final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return configurationValues;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
};
new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
}, buildTargets());
}
use of org.hibernate.tool.schema.internal.SchemaDropperImpl in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplConnectionTest method testMissingEntityContainsUnqualifiedEntityName.
@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
Map<String, Object> settings = new HashMap<>();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties());
final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
try {
new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
SchemaValidator schemaValidator = new IndividuallySchemaValidatorImpl(tool, DefaultSchemaFilter.INSTANCE);
assertFalse(connection.getAutoCommit());
schemaValidator.doValidation(metadata, executionOptions);
assertFalse(connection.getAutoCommit());
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
Aggregations