mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-8173 - AvailableSettings constants for javax.persistence.schema-generation contain space
This commit is contained in:
parent
a906d1ffb2
commit
8429d2bcb8
@ -208,7 +208,7 @@ public interface AvailableSettings {
|
|||||||
*
|
*
|
||||||
* @see SchemaGenSource
|
* @see SchemaGenSource
|
||||||
*/
|
*/
|
||||||
public static final String SCHEMA_GEN_CREATE_SOURCE = "javax.persistence.schema-generation.create-source ";
|
public static final String SCHEMA_GEN_CREATE_SOURCE = "javax.persistence.schema-generation.create-source";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether schema generation commands for schema dropping are to be determine based on object/relational
|
* Specifies whether schema generation commands for schema dropping are to be determine based on object/relational
|
||||||
@ -224,7 +224,7 @@ public interface AvailableSettings {
|
|||||||
*
|
*
|
||||||
* @see SchemaGenSource
|
* @see SchemaGenSource
|
||||||
*/
|
*/
|
||||||
public static final String SCHEMA_GEN_DROP_SOURCE = "javax.persistence.schema-generation.drop-source ";
|
public static final String SCHEMA_GEN_DROP_SOURCE = "javax.persistence.schema-generation.drop-source";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the CREATE script file as either a {@link java.io.Reader} configured for reading of the DDL script
|
* Specifies the CREATE script file as either a {@link java.io.Reader} configured for reading of the DDL script
|
||||||
@ -233,7 +233,7 @@ public interface AvailableSettings {
|
|||||||
* @see #SCHEMA_GEN_CREATE_SOURCE
|
* @see #SCHEMA_GEN_CREATE_SOURCE
|
||||||
* @see #SCHEMA_GEN_DROP_SCRIPT_SOURCE
|
* @see #SCHEMA_GEN_DROP_SCRIPT_SOURCE
|
||||||
*/
|
*/
|
||||||
public static final String SCHEMA_GEN_CREATE_SCRIPT_SOURCE = "javax.persistence.schema-generation.create-script-source ";
|
public static final String SCHEMA_GEN_CREATE_SCRIPT_SOURCE = "javax.persistence.schema-generation.create-script-source";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the DROP script file as either a {@link java.io.Reader} configured for reading of the DDL script
|
* Specifies the DROP script file as either a {@link java.io.Reader} configured for reading of the DDL script
|
||||||
@ -242,7 +242,7 @@ public interface AvailableSettings {
|
|||||||
* @see #SCHEMA_GEN_DROP_SOURCE
|
* @see #SCHEMA_GEN_DROP_SOURCE
|
||||||
* @see #SCHEMA_GEN_CREATE_SCRIPT_SOURCE
|
* @see #SCHEMA_GEN_CREATE_SCRIPT_SOURCE
|
||||||
*/
|
*/
|
||||||
public static final String SCHEMA_GEN_DROP_SCRIPT_SOURCE = "javax.persistence.schema-generation.drop-script-source ";
|
public static final String SCHEMA_GEN_DROP_SCRIPT_SOURCE = "javax.persistence.schema-generation.drop-script-source";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the type of schema generation action to be taken by the persistence provider in regards to sending
|
* Specifies the type of schema generation action to be taken by the persistence provider in regards to sending
|
||||||
|
@ -40,7 +40,7 @@ public enum SchemaGenSource {
|
|||||||
*/
|
*/
|
||||||
METADATA( "metadata" ),
|
METADATA( "metadata" ),
|
||||||
/**
|
/**
|
||||||
* "scripts" - External DDL script(s) are used as the exclusive source for generation. The scripts for schema
|
* "script" - External DDL script(s) are used as the exclusive source for generation. The scripts for schema
|
||||||
* creation and dropping come from different sources. The creation DDL script is identified by the
|
* creation and dropping come from different sources. The creation DDL script is identified by the
|
||||||
* {@value AvailableSettings#SCHEMA_GEN_CREATE_SCRIPT_SOURCE} setting; the drop DDL script is identified by the
|
* {@value AvailableSettings#SCHEMA_GEN_CREATE_SCRIPT_SOURCE} setting; the drop DDL script is identified by the
|
||||||
* {@value AvailableSettings#SCHEMA_GEN_DROP_SCRIPT_SOURCE} setting.
|
* {@value AvailableSettings#SCHEMA_GEN_DROP_SCRIPT_SOURCE} setting.
|
||||||
@ -48,23 +48,23 @@ public enum SchemaGenSource {
|
|||||||
* @see AvailableSettings#SCHEMA_GEN_CREATE_SCRIPT_SOURCE
|
* @see AvailableSettings#SCHEMA_GEN_CREATE_SCRIPT_SOURCE
|
||||||
* @see AvailableSettings#SCHEMA_GEN_DROP_SCRIPT_SOURCE
|
* @see AvailableSettings#SCHEMA_GEN_DROP_SCRIPT_SOURCE
|
||||||
*/
|
*/
|
||||||
SCRIPTS( "scripts" ),
|
SCRIPT( "script" ),
|
||||||
/**
|
/**
|
||||||
* "metadata-then-scripts" - Both the O/RM metadata and external DDL scripts are used as sources for generation,
|
* "metadata-then-scripts" - Both the O/RM metadata and external DDL scripts are used as sources for generation,
|
||||||
* with the O/RM metadata being applied first.
|
* with the O/RM metadata being applied first.
|
||||||
*
|
*
|
||||||
* @see #METADATA
|
* @see #METADATA
|
||||||
* @see #SCRIPTS
|
* @see #SCRIPT
|
||||||
*/
|
*/
|
||||||
METADATA_THEN_SCRIPTS( "metadata-then-scripts" ),
|
METADATA_THEN_SCRIPT( "metadata-then-script" ),
|
||||||
/**
|
/**
|
||||||
* "scripts-then-metadata" - Both the O/RM metadata and external DDL scripts are used as sources for generation,
|
* "scripts-then-metadata" - Both the O/RM metadata and external DDL scripts are used as sources for generation,
|
||||||
* with the commands from the external DDL script(s) being applied first
|
* with the commands from the external DDL script(s) being applied first
|
||||||
*
|
*
|
||||||
* @see #SCRIPTS
|
* @see #SCRIPT
|
||||||
* @see #METADATA
|
* @see #METADATA
|
||||||
*/
|
*/
|
||||||
SCRIPTS_THEN_METADATA( "scripts-then-metadata" );
|
SCRIPT_THEN_METADATA( "script-then-metadata" );
|
||||||
|
|
||||||
private final String externalName;
|
private final String externalName;
|
||||||
|
|
||||||
@ -90,14 +90,14 @@ public static SchemaGenSource interpret(String value) {
|
|||||||
if ( METADATA.externalName.equals( value ) ) {
|
if ( METADATA.externalName.equals( value ) ) {
|
||||||
return METADATA;
|
return METADATA;
|
||||||
}
|
}
|
||||||
else if ( SCRIPTS.externalName.equals( value ) ) {
|
else if ( SCRIPT.externalName.equals( value ) ) {
|
||||||
return SCRIPTS;
|
return SCRIPT;
|
||||||
}
|
}
|
||||||
else if ( METADATA_THEN_SCRIPTS.externalName.equals( value ) ) {
|
else if ( METADATA_THEN_SCRIPT.externalName.equals( value ) ) {
|
||||||
return METADATA_THEN_SCRIPTS;
|
return METADATA_THEN_SCRIPT;
|
||||||
}
|
}
|
||||||
else if ( SCRIPTS_THEN_METADATA.externalName.equals( value ) ) {
|
else if ( SCRIPT_THEN_METADATA.externalName.equals( value ) ) {
|
||||||
return SCRIPTS_THEN_METADATA;
|
return SCRIPT_THEN_METADATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException( "Unrecognized schema generation source value : " + value );
|
throw new IllegalArgumentException( "Unrecognized schema generation source value : " + value );
|
||||||
|
@ -29,14 +29,16 @@
|
|||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Handle schema generation source from (annotation/xml) metadata.
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class MetadataSource implements GenerationSource {
|
public class GenerationSourceFromMetadata implements GenerationSource {
|
||||||
private final Configuration hibernateConfiguration;
|
private final Configuration hibernateConfiguration;
|
||||||
private final Dialect dialect;
|
private final Dialect dialect;
|
||||||
private final boolean creation;
|
private final boolean creation;
|
||||||
|
|
||||||
public MetadataSource(Configuration hibernateConfiguration, Dialect dialect, boolean creation) {
|
public GenerationSourceFromMetadata(Configuration hibernateConfiguration, Dialect dialect, boolean creation) {
|
||||||
this.hibernateConfiguration = hibernateConfiguration;
|
this.hibernateConfiguration = hibernateConfiguration;
|
||||||
this.dialect = dialect;
|
this.dialect = dialect;
|
||||||
this.creation = creation;
|
this.creation = creation;
|
@ -28,20 +28,22 @@
|
|||||||
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Handles schema generation source from a "script"
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ScriptSource implements GenerationSource {
|
public class GenerationSourceFromScript implements GenerationSource {
|
||||||
private final SqlScriptReader reader;
|
private final SqlScriptInput reader;
|
||||||
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
||||||
|
|
||||||
public ScriptSource(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
public GenerationSourceFromScript(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
||||||
this.scriptCommandExtractor = scriptCommandExtractor;
|
this.scriptCommandExtractor = scriptCommandExtractor;
|
||||||
|
|
||||||
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
||||||
reader = new ReaderScriptSource( (Reader) scriptSourceSetting );
|
reader = new SqlScriptReaderInput( (Reader) scriptSourceSetting );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reader = new FileScriptSource( scriptSourceSetting.toString() );
|
reader = new SqlScriptFileInput( scriptSourceSetting.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,8 +26,9 @@
|
|||||||
/**
|
/**
|
||||||
* Describes a schema generation target
|
* Describes a schema generation target
|
||||||
*
|
*
|
||||||
* @see org.hibernate.jpa.SchemaGenTarget
|
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_ACTION
|
||||||
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_TARGET
|
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_CREATE_TARGET
|
||||||
|
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_DROP_TARGET
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -36,15 +36,15 @@
|
|||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
class DatabaseTarget implements GenerationTarget {
|
class GenerationTargetToDatabase implements GenerationTarget {
|
||||||
private static final Logger log = Logger.getLogger( DatabaseTarget.class );
|
private static final Logger log = Logger.getLogger( GenerationTargetToDatabase.class );
|
||||||
|
|
||||||
private final JdbcConnectionContext jdbcConnectionContext;
|
private final JdbcConnectionContext jdbcConnectionContext;
|
||||||
private final SchemaGenAction databaseAction;
|
private final SchemaGenAction databaseAction;
|
||||||
|
|
||||||
private Statement jdbcStatement;
|
private Statement jdbcStatement;
|
||||||
|
|
||||||
DatabaseTarget(JdbcConnectionContext jdbcConnectionContext, SchemaGenAction databaseAction) {
|
GenerationTargetToDatabase(JdbcConnectionContext jdbcConnectionContext, SchemaGenAction databaseAction) {
|
||||||
this.jdbcConnectionContext = jdbcConnectionContext;
|
this.jdbcConnectionContext = jdbcConnectionContext;
|
||||||
this.databaseAction = databaseAction;
|
this.databaseAction = databaseAction;
|
||||||
}
|
}
|
@ -39,14 +39,14 @@
|
|||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
class ScriptsTarget implements GenerationTarget {
|
class GenerationTargetToScript implements GenerationTarget {
|
||||||
private static final Logger log = Logger.getLogger( ScriptsTarget.class );
|
private static final Logger log = Logger.getLogger( GenerationTargetToScript.class );
|
||||||
|
|
||||||
private final ScriptTargetTarget createScriptTarget;
|
private final ScriptTargetTarget createScriptTarget;
|
||||||
private final ScriptTargetTarget dropScriptTarget;
|
private final ScriptTargetTarget dropScriptTarget;
|
||||||
private final SchemaGenAction scriptsAction;
|
private final SchemaGenAction scriptsAction;
|
||||||
|
|
||||||
public ScriptsTarget(
|
public GenerationTargetToScript(
|
||||||
Object createScriptTargetSetting,
|
Object createScriptTargetSetting,
|
||||||
Object dropScriptTargetSetting,
|
Object dropScriptTargetSetting,
|
||||||
SchemaGenAction scriptsAction) {
|
SchemaGenAction scriptsAction) {
|
@ -105,7 +105,7 @@ public static void performGeneration(Configuration hibernateConfiguration, Servi
|
|||||||
|
|
||||||
// determine targets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// determine targets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
final GenerationTarget databaseTarget = new DatabaseTarget( jdbcConnectionContext, databaseAction );
|
final GenerationTarget databaseTarget = new GenerationTargetToDatabase( jdbcConnectionContext, databaseAction );
|
||||||
|
|
||||||
final Object createScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
final Object createScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
||||||
AvailableSettings.SCHEMA_GEN_SCRIPTS_CREATE_TARGET
|
AvailableSettings.SCHEMA_GEN_SCRIPTS_CREATE_TARGET
|
||||||
@ -113,7 +113,7 @@ public static void performGeneration(Configuration hibernateConfiguration, Servi
|
|||||||
final Object dropScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
final Object dropScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
||||||
AvailableSettings.SCHEMA_GEN_SCRIPTS_DROP_TARGET
|
AvailableSettings.SCHEMA_GEN_SCRIPTS_DROP_TARGET
|
||||||
);
|
);
|
||||||
final GenerationTarget scriptsTarget = new ScriptsTarget( createScriptTargetSetting, dropScriptTargetSetting, scriptsAction );
|
final GenerationTarget scriptsTarget = new GenerationTargetToScript( createScriptTargetSetting, dropScriptTargetSetting, scriptsAction );
|
||||||
|
|
||||||
final List<GenerationTarget> targets = Arrays.asList( databaseTarget, scriptsTarget );
|
final List<GenerationTarget> targets = Arrays.asList( databaseTarget, scriptsTarget );
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ private static List<GenerationSource> buildCreateSourceList(
|
|||||||
|
|
||||||
if ( sourceType == null ) {
|
if ( sourceType == null ) {
|
||||||
if ( createScriptSourceSetting != null ) {
|
if ( createScriptSourceSetting != null ) {
|
||||||
sourceType = SchemaGenSource.SCRIPTS;
|
sourceType = SchemaGenSource.SCRIPT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sourceType = SchemaGenSource.METADATA;
|
sourceType = SchemaGenSource.METADATA;
|
||||||
@ -181,18 +181,18 @@ private static List<GenerationSource> buildCreateSourceList(
|
|||||||
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
||||||
|
|
||||||
if ( sourceType == SchemaGenSource.METADATA ) {
|
if ( sourceType == SchemaGenSource.METADATA ) {
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.SCRIPTS ) {
|
else if ( sourceType == SchemaGenSource.SCRIPT ) {
|
||||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPTS ) {
|
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPT ) {
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.SCRIPTS_THEN_METADATA ) {
|
else if ( sourceType == SchemaGenSource.SCRIPT_THEN_METADATA ) {
|
||||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object importScriptSetting = hibernateConfiguration.getProperties().get(
|
final Object importScriptSetting = hibernateConfiguration.getProperties().get(
|
||||||
@ -221,7 +221,7 @@ private static List<GenerationSource> buildDropSourceList(
|
|||||||
|
|
||||||
if ( sourceType == null ) {
|
if ( sourceType == null ) {
|
||||||
if ( dropScriptSourceSetting != null ) {
|
if ( dropScriptSourceSetting != null ) {
|
||||||
sourceType = SchemaGenSource.SCRIPTS;
|
sourceType = SchemaGenSource.SCRIPT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sourceType = SchemaGenSource.METADATA;
|
sourceType = SchemaGenSource.METADATA;
|
||||||
@ -231,18 +231,18 @@ private static List<GenerationSource> buildDropSourceList(
|
|||||||
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
||||||
|
|
||||||
if ( sourceType == SchemaGenSource.METADATA ) {
|
if ( sourceType == SchemaGenSource.METADATA ) {
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.SCRIPTS ) {
|
else if ( sourceType == SchemaGenSource.SCRIPT ) {
|
||||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPTS ) {
|
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPT ) {
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
}
|
}
|
||||||
else if ( sourceType == SchemaGenSource.SCRIPTS_THEN_METADATA ) {
|
else if ( sourceType == SchemaGenSource.SCRIPT_THEN_METADATA ) {
|
||||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return generationSourceList;
|
return generationSourceList;
|
||||||
@ -508,17 +508,17 @@ public void release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class ImportScriptSource implements GenerationSource {
|
private static class ImportScriptSource implements GenerationSource {
|
||||||
private final SqlScriptReader sourceReader;
|
private final SqlScriptInput sourceReader;
|
||||||
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
||||||
|
|
||||||
public ImportScriptSource(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
public ImportScriptSource(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
||||||
this.scriptCommandExtractor = scriptCommandExtractor;
|
this.scriptCommandExtractor = scriptCommandExtractor;
|
||||||
|
|
||||||
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
||||||
sourceReader = new ReaderScriptSource( (Reader) scriptSourceSetting );
|
sourceReader = new SqlScriptReaderInput( (Reader) scriptSourceSetting );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sourceReader = new FileScriptSource( scriptSourceSetting.toString() );
|
sourceReader = new SqlScriptFileInput( scriptSourceSetting.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,15 +32,15 @@
|
|||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SqlScriptReader implementation for File references. A reader is opened here and then explicitly closed on
|
* SqlScriptInput implementation for File references. A reader is opened here and then explicitly closed on
|
||||||
* {@link #reader}.
|
* {@link #release}.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
class FileScriptSource extends ReaderScriptSource implements SqlScriptReader {
|
class SqlScriptFileInput extends SqlScriptReaderInput implements SqlScriptInput {
|
||||||
private static final Logger log = Logger.getLogger( FileScriptSource.class );
|
private static final Logger log = Logger.getLogger( SqlScriptFileInput.class );
|
||||||
|
|
||||||
public FileScriptSource(String fileUrl) {
|
public SqlScriptFileInput(String fileUrl) {
|
||||||
super( toFileReader( fileUrl ) );
|
super( toFileReader( fileUrl ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,18 +57,28 @@ public void release() {
|
|||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
private static Reader toFileReader(String fileUrl) {
|
private static Reader toFileReader(String fileUrl) {
|
||||||
final File file = new File( fileUrl );
|
final File file = new File( fileUrl );
|
||||||
try {
|
if ( ! file.exists() ) {
|
||||||
// best effort, since this is very well not allowed in EE environments
|
log.warnf( "Specified schema generation script file [%s] did not exist for reading", fileUrl );
|
||||||
file.createNewFile();
|
return new Reader() {
|
||||||
}
|
@Override
|
||||||
catch (Exception e) {
|
public int read(char[] cbuf, int off, int len) throws IOException {
|
||||||
log.debug( "Exception calling File#createNewFile : " + e.toString() );
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new FileReader( file );
|
return new FileReader( file );
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new PersistenceException( "Unable to open specified script target file for writing : " + fileUrl );
|
throw new PersistenceException(
|
||||||
|
"Unable to open specified script target file [" + fileUrl + "] for reading",
|
||||||
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface SqlScriptReader {
|
public interface SqlScriptInput {
|
||||||
public Iterable<String> read(ImportSqlCommandExtractor commandExtractor);
|
public Iterable<String> read(ImportSqlCommandExtractor commandExtractor);
|
||||||
public void release();
|
public void release();
|
||||||
}
|
}
|
@ -30,14 +30,14 @@
|
|||||||
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SqlScriptReader implementation for explicitly given Readers. The readers are not released by this class.
|
* SqlScriptInput implementation for explicitly given Readers. The readers are not released by this class.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
class ReaderScriptSource implements SqlScriptReader {
|
class SqlScriptReaderInput implements SqlScriptInput {
|
||||||
private final Reader reader;
|
private final Reader reader;
|
||||||
|
|
||||||
public ReaderScriptSource(Reader reader) {
|
public SqlScriptReaderInput(Reader reader) {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user