Search in sources :

Example 1 with SchemaManagementException

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());
    }
}
Also used : SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test)

Example 2 with SchemaManagementException

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();
    }
}
Also used : JdbcConnectionAccessImpl(org.hibernate.testing.boot.JdbcConnectionAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Example 3 with SchemaManagementException

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());
    }
}
Also used : SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test)

Example 4 with SchemaManagementException

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);
    }
}
Also used : SQLException(java.sql.SQLException) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException)

Example 5 with SchemaManagementException

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;
}
Also used : GenerationTargetToStdout(org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) GenerationTargetToScript(org.hibernate.tool.schema.internal.exec.GenerationTargetToScript) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)

Aggregations

SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)9 MetadataSources (org.hibernate.boot.MetadataSources)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)2 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)2 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)2 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)2 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)2 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)2 GenerationTarget (org.hibernate.tool.schema.internal.exec.GenerationTarget)2 GenerationTargetToScript (org.hibernate.tool.schema.internal.exec.GenerationTargetToScript)2 GenerationTargetToStdout (org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 SQLException (java.sql.SQLException)1