use of org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingColumn.
@Test
public void testMissingColumn() throws Exception {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NoNameColumn.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(NameColumn.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing column [name] in table [SomeSchema.ColumnEntity]", e.getMessage());
}
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
use of org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase in project hibernate-orm by hibernate.
the class HibernateSchemaManagementTool method buildGenerationTargets.
GenerationTarget[] buildGenerationTargets(TargetDescriptor targetDescriptor, DdlTransactionIsolator ddlTransactionIsolator, Map options) {
final String scriptDelimiter = ConfigurationHelper.getString(HBM2DDL_DELIMITER, options);
final GenerationTarget[] targets = new GenerationTarget[targetDescriptor.getTargetTypes().size()];
int index = 0;
if (targetDescriptor.getTargetTypes().contains(TargetType.STDOUT)) {
targets[index] = new GenerationTargetToStdout(scriptDelimiter);
index++;
}
if (targetDescriptor.getTargetTypes().contains(TargetType.SCRIPT)) {
if (targetDescriptor.getScriptTargetOutput() == null) {
throw new SchemaManagementException("Writing to script was requested, but no script file was specified");
}
targets[index] = new GenerationTargetToScript(targetDescriptor.getScriptTargetOutput(), scriptDelimiter);
index++;
}
if (targetDescriptor.getTargetTypes().contains(TargetType.DATABASE)) {
targets[index] = new GenerationTargetToDatabase(ddlTransactionIsolator, false);
}
return targets;
}
use of org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase in project hibernate-orm by hibernate.
the class HibernateSchemaManagementTool method buildGenerationTargets.
GenerationTarget[] buildGenerationTargets(TargetDescriptor targetDescriptor, JdbcContext jdbcContext, Map options, boolean needsAutoCommit) {
final String scriptDelimiter = ConfigurationHelper.getString(HBM2DDL_DELIMITER, options);
final GenerationTarget[] targets = new GenerationTarget[targetDescriptor.getTargetTypes().size()];
int index = 0;
if (targetDescriptor.getTargetTypes().contains(TargetType.STDOUT)) {
targets[index] = new GenerationTargetToStdout(scriptDelimiter);
index++;
}
if (targetDescriptor.getTargetTypes().contains(TargetType.SCRIPT)) {
if (targetDescriptor.getScriptTargetOutput() == null) {
throw new SchemaManagementException("Writing to script was requested, but no script file was specified");
}
targets[index] = new GenerationTargetToScript(targetDescriptor.getScriptTargetOutput(), scriptDelimiter);
index++;
}
if (targetDescriptor.getTargetTypes().contains(TargetType.DATABASE)) {
targets[index] = new GenerationTargetToDatabase(getDdlTransactionIsolator(jdbcContext), true);
}
return targets;
}
use of org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase in project hibernate-orm by hibernate.
the class SchemaDropperImpl method doDrop.
/**
* For tests
*/
public void doDrop(Metadata metadata, final ServiceRegistry serviceRegistry, final Map settings, final boolean manageNamespaces, GenerationTarget... targets) {
if (targets == null || targets.length == 0) {
final JdbcContext jdbcContext = tool.resolveJdbcContext(settings);
targets = new GenerationTarget[] { new GenerationTargetToDatabase(serviceRegistry.getService(TransactionCoordinatorBuilder.class).buildDdlTransactionIsolator(jdbcContext), true) };
}
doDrop(metadata, new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return manageNamespaces;
}
@Override
public Map getConfigurationValues() {
return settings;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
}, serviceRegistry.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
}, targets);
}
use of org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase in project hibernate-orm by hibernate.
the class SuppliedConnectionTest method cleanupTest.
@Override
protected void cleanupTest() throws Exception {
try {
Connection conn = cp.getConnection();
try {
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry(), conn), true);
new SchemaDropperImpl(serviceRegistry()).doDrop(metadata(), false, target);
} finally {
cp.closeConnection(conn);
}
} catch (Throwable ignore) {
}
super.cleanupTest();
}
Aggregations