use of org.hibernate.tool.schema.spi.SchemaManagementException in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingEntityContainsQualifiedEntityName.
@Test
public void testMissingEntityContainsQualifiedEntityName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(MissingEntity.class);
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing table [SomeCatalog.SomeSchema.MissingEntity]", e.getMessage());
}
}
use of org.hibernate.tool.schema.spi.SchemaManagementException 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.spi.SchemaManagementException in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingEntityContainsUnqualifiedEntityName.
@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing table [UnqualifiedMissingEntity]", e.getMessage());
}
}
use of org.hibernate.tool.schema.spi.SchemaManagementException in project hibernate-orm by hibernate.
the class TargetDatabaseImpl method prepare.
@Override
public void prepare() {
try {
connection = connectionAccess.obtainConnection();
connection.setAutoCommit(true);
} catch (SQLException e) {
throw new SchemaManagementException("Unable to open JDBC connection for schema management target", e);
}
try {
statement = connection.createStatement();
} catch (SQLException e) {
throw new SchemaManagementException("Unable to create JDBC Statement for schema management target", e);
}
}
use of org.hibernate.tool.schema.spi.SchemaManagementException 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;
}
Aggregations