HHH-1122 - Fix hbm2ddl.SchemaUpdate has no delimiter

This commit is contained in:
Andrea Boriero 2015-12-03 09:52:13 +00:00
parent bf892ef354
commit 8bfaaea4b6
3 changed files with 37 additions and 4 deletions

View File

@ -55,6 +55,7 @@ public class SchemaUpdate {
private final JdbcConnectionAccess jdbcConnectionAccess;
private final List<Exception> exceptions = new ArrayList<Exception>();
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<org.hibernate.tool.schema.spi.Target> toolTargets = new ArrayList<org.hibernate.tool.schema.spi.Target>();
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 );
}

View File

@ -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 {
}
}
}
}

View File

@ -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() {
}
}