Search in sources :

Example 1 with GenerationTargetToStdout

use of org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout 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)

Example 2 with GenerationTargetToStdout

use of org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout 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;
}
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)

Example 3 with GenerationTargetToStdout

use of org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout in project hibernate-orm by hibernate.

the class ListMappingTest method testOrderColumnInNormalBiDirectonalModel.

@Test
public void testOrderColumnInNormalBiDirectonalModel() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Order.class).addAnnotatedClass(LineItem.class).buildMetadata();
    Collection lineItemsBinding = metadata.getCollectionBindings().iterator().next();
    // make sure it was interpreted as a List (aka, as having an OrderColumn at all)
    assertThat(lineItemsBinding, instanceOf(org.hibernate.mapping.List.class));
    org.hibernate.mapping.List asList = (org.hibernate.mapping.List) lineItemsBinding;
    // assert the OrderColumn details
    final Column positionColumn = (Column) asList.getIndex().getColumnIterator().next();
    assertThat(positionColumn.getName(), equalTo("position"));
    // make sure the OrderColumn is part of the collection table
    assertTrue(asList.getCollectionTable().containsColumn(positionColumn));
    class TargetImpl extends GenerationTargetToStdout {

        boolean found = false;

        @Override
        public void accept(String action) {
            super.accept(action);
            if (action.startsWith("create table t_line_item")) {
                if (action.contains("position")) {
                    found = true;
                }
            }
        }
    }
    TargetImpl target = new TargetImpl();
    new SchemaCreatorImpl(ssr).doCreation(metadata, true, target);
    assertTrue(target.found);
}
Also used : GenerationTargetToStdout(org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) JoinColumn(javax.persistence.JoinColumn) Column(org.hibernate.mapping.Column) OrderColumn(javax.persistence.OrderColumn) Collection(org.hibernate.mapping.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

GenerationTargetToStdout (org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout)3 GenerationTarget (org.hibernate.tool.schema.internal.exec.GenerationTarget)2 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)2 GenerationTargetToScript (org.hibernate.tool.schema.internal.exec.GenerationTargetToScript)2 SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JoinColumn (javax.persistence.JoinColumn)1 OrderColumn (javax.persistence.OrderColumn)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 Collection (org.hibernate.mapping.Collection)1 Column (org.hibernate.mapping.Column)1 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)1 Test (org.junit.Test)1