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
|
||||
*/
|
||||
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
|
||||
|
@ -224,7 +224,7 @@ public interface AvailableSettings {
|
|||
*
|
||||
* @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
|
||||
|
@ -233,7 +233,7 @@ public interface AvailableSettings {
|
|||
* @see #SCHEMA_GEN_CREATE_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
|
||||
|
@ -242,7 +242,7 @@ public interface AvailableSettings {
|
|||
* @see #SCHEMA_GEN_DROP_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
|
||||
|
|
|
@ -40,7 +40,7 @@ public enum SchemaGenSource {
|
|||
*/
|
||||
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
|
||||
* {@value AvailableSettings#SCHEMA_GEN_CREATE_SCRIPT_SOURCE} setting; the drop DDL script is identified by the
|
||||
* {@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_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,
|
||||
* with the O/RM metadata being applied first.
|
||||
*
|
||||
* @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,
|
||||
* with the commands from the external DDL script(s) being applied first
|
||||
*
|
||||
* @see #SCRIPTS
|
||||
* @see #SCRIPT
|
||||
* @see #METADATA
|
||||
*/
|
||||
SCRIPTS_THEN_METADATA( "scripts-then-metadata" );
|
||||
SCRIPT_THEN_METADATA( "script-then-metadata" );
|
||||
|
||||
private final String externalName;
|
||||
|
||||
|
@ -90,14 +90,14 @@ public enum SchemaGenSource {
|
|||
if ( METADATA.externalName.equals( value ) ) {
|
||||
return METADATA;
|
||||
}
|
||||
else if ( SCRIPTS.externalName.equals( value ) ) {
|
||||
return SCRIPTS;
|
||||
else if ( SCRIPT.externalName.equals( value ) ) {
|
||||
return SCRIPT;
|
||||
}
|
||||
else if ( METADATA_THEN_SCRIPTS.externalName.equals( value ) ) {
|
||||
return METADATA_THEN_SCRIPTS;
|
||||
else if ( METADATA_THEN_SCRIPT.externalName.equals( value ) ) {
|
||||
return METADATA_THEN_SCRIPT;
|
||||
}
|
||||
else if ( SCRIPTS_THEN_METADATA.externalName.equals( value ) ) {
|
||||
return SCRIPTS_THEN_METADATA;
|
||||
else if ( SCRIPT_THEN_METADATA.externalName.equals( value ) ) {
|
||||
return SCRIPT_THEN_METADATA;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "Unrecognized schema generation source value : " + value );
|
||||
|
|
|
@ -29,14 +29,16 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* Handle schema generation source from (annotation/xml) metadata.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MetadataSource implements GenerationSource {
|
||||
public class GenerationSourceFromMetadata implements GenerationSource {
|
||||
private final Configuration hibernateConfiguration;
|
||||
private final Dialect dialect;
|
||||
private final boolean creation;
|
||||
|
||||
public MetadataSource(Configuration hibernateConfiguration, Dialect dialect, boolean creation) {
|
||||
public GenerationSourceFromMetadata(Configuration hibernateConfiguration, Dialect dialect, boolean creation) {
|
||||
this.hibernateConfiguration = hibernateConfiguration;
|
||||
this.dialect = dialect;
|
||||
this.creation = creation;
|
|
@ -28,20 +28,22 @@ import java.io.Reader;
|
|||
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
||||
|
||||
/**
|
||||
* Handles schema generation source from a "script"
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ScriptSource implements GenerationSource {
|
||||
private final SqlScriptReader reader;
|
||||
public class GenerationSourceFromScript implements GenerationSource {
|
||||
private final SqlScriptInput reader;
|
||||
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
||||
|
||||
public ScriptSource(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
||||
public GenerationSourceFromScript(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
||||
this.scriptCommandExtractor = scriptCommandExtractor;
|
||||
|
||||
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
||||
reader = new ReaderScriptSource( (Reader) scriptSourceSetting );
|
||||
reader = new SqlScriptReaderInput( (Reader) scriptSourceSetting );
|
||||
}
|
||||
else {
|
||||
reader = new FileScriptSource( scriptSourceSetting.toString() );
|
||||
reader = new SqlScriptFileInput( scriptSourceSetting.toString() );
|
||||
}
|
||||
}
|
||||
|
|
@ -26,8 +26,9 @@ package org.hibernate.jpa.internal.schemagen;
|
|||
/**
|
||||
* Describes a schema generation target
|
||||
*
|
||||
* @see org.hibernate.jpa.SchemaGenTarget
|
||||
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_TARGET
|
||||
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_ACTION
|
||||
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_CREATE_TARGET
|
||||
* @see org.hibernate.jpa.AvailableSettings#SCHEMA_GEN_SCRIPTS_DROP_TARGET
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
|
@ -36,15 +36,15 @@ import org.hibernate.jpa.SchemaGenAction;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class DatabaseTarget implements GenerationTarget {
|
||||
private static final Logger log = Logger.getLogger( DatabaseTarget.class );
|
||||
class GenerationTargetToDatabase implements GenerationTarget {
|
||||
private static final Logger log = Logger.getLogger( GenerationTargetToDatabase.class );
|
||||
|
||||
private final JdbcConnectionContext jdbcConnectionContext;
|
||||
private final SchemaGenAction databaseAction;
|
||||
|
||||
private Statement jdbcStatement;
|
||||
|
||||
DatabaseTarget(JdbcConnectionContext jdbcConnectionContext, SchemaGenAction databaseAction) {
|
||||
GenerationTargetToDatabase(JdbcConnectionContext jdbcConnectionContext, SchemaGenAction databaseAction) {
|
||||
this.jdbcConnectionContext = jdbcConnectionContext;
|
||||
this.databaseAction = databaseAction;
|
||||
}
|
|
@ -39,14 +39,14 @@ import org.hibernate.jpa.SchemaGenAction;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class ScriptsTarget implements GenerationTarget {
|
||||
private static final Logger log = Logger.getLogger( ScriptsTarget.class );
|
||||
class GenerationTargetToScript implements GenerationTarget {
|
||||
private static final Logger log = Logger.getLogger( GenerationTargetToScript.class );
|
||||
|
||||
private final ScriptTargetTarget createScriptTarget;
|
||||
private final ScriptTargetTarget dropScriptTarget;
|
||||
private final SchemaGenAction scriptsAction;
|
||||
|
||||
public ScriptsTarget(
|
||||
public GenerationTargetToScript(
|
||||
Object createScriptTargetSetting,
|
||||
Object dropScriptTargetSetting,
|
||||
SchemaGenAction scriptsAction) {
|
|
@ -105,7 +105,7 @@ public class JpaSchemaGenerator {
|
|||
|
||||
// determine targets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
final GenerationTarget databaseTarget = new DatabaseTarget( jdbcConnectionContext, databaseAction );
|
||||
final GenerationTarget databaseTarget = new GenerationTargetToDatabase( jdbcConnectionContext, databaseAction );
|
||||
|
||||
final Object createScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
||||
AvailableSettings.SCHEMA_GEN_SCRIPTS_CREATE_TARGET
|
||||
|
@ -113,7 +113,7 @@ public class JpaSchemaGenerator {
|
|||
final Object dropScriptTargetSetting = hibernateConfiguration.getProperties().get(
|
||||
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 );
|
||||
|
||||
|
@ -171,7 +171,7 @@ public class JpaSchemaGenerator {
|
|||
|
||||
if ( sourceType == null ) {
|
||||
if ( createScriptSourceSetting != null ) {
|
||||
sourceType = SchemaGenSource.SCRIPTS;
|
||||
sourceType = SchemaGenSource.SCRIPT;
|
||||
}
|
||||
else {
|
||||
sourceType = SchemaGenSource.METADATA;
|
||||
|
@ -181,18 +181,18 @@ public class JpaSchemaGenerator {
|
|||
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
||||
|
||||
if ( sourceType == SchemaGenSource.METADATA ) {
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.SCRIPTS ) {
|
||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
else if ( sourceType == SchemaGenSource.SCRIPT ) {
|
||||
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPTS ) {
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPT ) {
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.SCRIPTS_THEN_METADATA ) {
|
||||
generationSourceList.add( new ScriptSource( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, true ) );
|
||||
else if ( sourceType == SchemaGenSource.SCRIPT_THEN_METADATA ) {
|
||||
generationSourceList.add( new GenerationSourceFromScript( createScriptSourceSetting, scriptCommandExtractor ) );
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, true ) );
|
||||
}
|
||||
|
||||
final Object importScriptSetting = hibernateConfiguration.getProperties().get(
|
||||
|
@ -221,7 +221,7 @@ public class JpaSchemaGenerator {
|
|||
|
||||
if ( sourceType == null ) {
|
||||
if ( dropScriptSourceSetting != null ) {
|
||||
sourceType = SchemaGenSource.SCRIPTS;
|
||||
sourceType = SchemaGenSource.SCRIPT;
|
||||
}
|
||||
else {
|
||||
sourceType = SchemaGenSource.METADATA;
|
||||
|
@ -231,18 +231,18 @@ public class JpaSchemaGenerator {
|
|||
final ImportSqlCommandExtractor scriptCommandExtractor = serviceRegistry.getService( ImportSqlCommandExtractor.class );
|
||||
|
||||
if ( sourceType == SchemaGenSource.METADATA ) {
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.SCRIPTS ) {
|
||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
else if ( sourceType == SchemaGenSource.SCRIPT ) {
|
||||
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPTS ) {
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
else if ( sourceType == SchemaGenSource.METADATA_THEN_SCRIPT ) {
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
}
|
||||
else if ( sourceType == SchemaGenSource.SCRIPTS_THEN_METADATA ) {
|
||||
generationSourceList.add( new ScriptSource( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
generationSourceList.add( new MetadataSource( hibernateConfiguration, dialect, false ) );
|
||||
else if ( sourceType == SchemaGenSource.SCRIPT_THEN_METADATA ) {
|
||||
generationSourceList.add( new GenerationSourceFromScript( dropScriptSourceSetting, scriptCommandExtractor ) );
|
||||
generationSourceList.add( new GenerationSourceFromMetadata( hibernateConfiguration, dialect, false ) );
|
||||
}
|
||||
|
||||
return generationSourceList;
|
||||
|
@ -508,17 +508,17 @@ public class JpaSchemaGenerator {
|
|||
}
|
||||
|
||||
private static class ImportScriptSource implements GenerationSource {
|
||||
private final SqlScriptReader sourceReader;
|
||||
private final SqlScriptInput sourceReader;
|
||||
private final ImportSqlCommandExtractor scriptCommandExtractor;
|
||||
|
||||
public ImportScriptSource(Object scriptSourceSetting, ImportSqlCommandExtractor scriptCommandExtractor) {
|
||||
this.scriptCommandExtractor = scriptCommandExtractor;
|
||||
|
||||
if ( Reader.class.isInstance( scriptSourceSetting ) ) {
|
||||
sourceReader = new ReaderScriptSource( (Reader) scriptSourceSetting );
|
||||
sourceReader = new SqlScriptReaderInput( (Reader) scriptSourceSetting );
|
||||
}
|
||||
else {
|
||||
sourceReader = new FileScriptSource( scriptSourceSetting.toString() );
|
||||
sourceReader = new SqlScriptFileInput( scriptSourceSetting.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,15 +32,15 @@ import java.io.Reader;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* SqlScriptReader implementation for File references. A reader is opened here and then explicitly closed on
|
||||
* {@link #reader}.
|
||||
* SqlScriptInput implementation for File references. A reader is opened here and then explicitly closed on
|
||||
* {@link #release}.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class FileScriptSource extends ReaderScriptSource implements SqlScriptReader {
|
||||
private static final Logger log = Logger.getLogger( FileScriptSource.class );
|
||||
class SqlScriptFileInput extends SqlScriptReaderInput implements SqlScriptInput {
|
||||
private static final Logger log = Logger.getLogger( SqlScriptFileInput.class );
|
||||
|
||||
public FileScriptSource(String fileUrl) {
|
||||
public SqlScriptFileInput(String fileUrl) {
|
||||
super( toFileReader( fileUrl ) );
|
||||
}
|
||||
|
||||
|
@ -57,18 +57,28 @@ class FileScriptSource extends ReaderScriptSource implements SqlScriptReader {
|
|||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private static Reader toFileReader(String fileUrl) {
|
||||
final File file = new File( fileUrl );
|
||||
try {
|
||||
// best effort, since this is very well not allowed in EE environments
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug( "Exception calling File#createNewFile : " + e.toString() );
|
||||
if ( ! file.exists() ) {
|
||||
log.warnf( "Specified schema generation script file [%s] did not exist for reading", fileUrl );
|
||||
return new Reader() {
|
||||
@Override
|
||||
public int read(char[] cbuf, int off, int len) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
return new FileReader( file );
|
||||
}
|
||||
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 @@ import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SqlScriptReader {
|
||||
public interface SqlScriptInput {
|
||||
public Iterable<String> read(ImportSqlCommandExtractor commandExtractor);
|
||||
public void release();
|
||||
}
|
|
@ -30,14 +30,14 @@ import java.util.Collections;
|
|||
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
|
||||
*/
|
||||
class ReaderScriptSource implements SqlScriptReader {
|
||||
class SqlScriptReaderInput implements SqlScriptInput {
|
||||
private final Reader reader;
|
||||
|
||||
public ReaderScriptSource(Reader reader) {
|
||||
public SqlScriptReaderInput(Reader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
Loading…
Reference in New Issue