diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java index fc4403f938..45d12f0219 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java @@ -55,6 +55,7 @@ public class SchemaUpdate { private final JdbcConnectionAccess jdbcConnectionAccess; private final List exceptions = new ArrayList(); private String outputFile; + private String delimiter; /** * Creates a SchemaUpdate object. This form is intended for use from tooling @@ -133,7 +134,7 @@ public class SchemaUpdate { List toolTargets = new ArrayList(); if ( target.doScript() ) { - toolTargets.add( new TargetStdoutImpl() ); + toolTargets.add( new TargetStdoutImpl( delimiter ) ); } if ( target.doExport() ) { @@ -142,7 +143,7 @@ public class SchemaUpdate { if ( outputFile != null ) { LOG.writingGeneratedSchemaToFile( outputFile ); - toolTargets.add( new TargetFileImpl( outputFile ) ); + toolTargets.add( new TargetFileImpl( outputFile, delimiter ) ); } return toolTargets; @@ -167,7 +168,14 @@ public class SchemaUpdate { this.outputFile = outputFile; } + /** + * Set the end of statement delimiter + * + * @param delimiter The delimiter + * + */ public void setDelimiter(String delimiter) { + this.delimiter = delimiter; } public static void main(String[] args) { @@ -180,6 +188,7 @@ public class SchemaUpdate { final SchemaUpdate schemaUpdate = new SchemaUpdate( metadata ); schemaUpdate.setOutputFile( parsedArgs.outFile ); + schemaUpdate.setDelimiter( parsedArgs.delimiter ); schemaUpdate.execute( parsedArgs.script, parsedArgs.doUpdate ); } finally { @@ -252,6 +261,7 @@ public class SchemaUpdate { String propertiesFile = null; String cfgXmlFile = null; String outFile = null; + String delimiter = null; String implicitNamingStrategyImplName = null; String physicalNamingStrategyImplName = null; @@ -282,6 +292,9 @@ public class SchemaUpdate { else if ( arg.startsWith( "--naming=" ) ) { DeprecationLogger.DEPRECATION_LOGGER.logDeprecatedNamingStrategyArgument(); } + else if ( arg.startsWith( "--delimiter=" ) ) { + parsedArgs.delimiter = arg.substring( 12 ); + } else if ( arg.startsWith( "--implicit-naming=" ) ) { parsedArgs.implicitNamingStrategyImplName = arg.substring( 18 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetFileImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetFileImpl.java index fd4ae7f15e..65b0982191 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetFileImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetFileImpl.java @@ -16,10 +16,12 @@ import org.hibernate.tool.schema.spi.Target; * @author Steve Ebersole */ public class TargetFileImpl implements Target { - private FileWriter fileWriter; + final private FileWriter fileWriter; + final private String delimiter; - public TargetFileImpl(String outputFile) { + public TargetFileImpl(String outputFile, String delimter) { try { + this.delimiter = delimter; this.fileWriter = new FileWriter( outputFile ); } catch (IOException e) { @@ -40,6 +42,9 @@ public class TargetFileImpl implements Target { public void accept(String action) { try { fileWriter.write( action ); + if ( delimiter != null ) { + fileWriter.write( delimiter ); + } fileWriter.write( "\n" ); } catch (IOException e) { @@ -57,4 +62,5 @@ public class TargetFileImpl implements Target { } } } + } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetStdoutImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetStdoutImpl.java index c2440b25c8..6da44666db 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetStdoutImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/TargetStdoutImpl.java @@ -12,6 +12,16 @@ import org.hibernate.tool.schema.spi.Target; * @author Steve Ebersole */ public class TargetStdoutImpl implements Target { + final private String delimiter; + + public TargetStdoutImpl() { + this( null ); + } + + public TargetStdoutImpl(String delimiter) { + this.delimiter = delimiter; + } + @Override public boolean acceptsImportScriptActions() { return true; @@ -23,10 +33,14 @@ public class TargetStdoutImpl implements Target { @Override public void accept(String action) { + if ( delimiter != null ) { + action += delimiter; + } System.out.println( action ); } @Override public void release() { } + }