org.hibernate.tool.schema.spi.ExecutionOptions Java Examples
The following examples show how to use
org.hibernate.tool.schema.spi.ExecutionOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSchemaValidator.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void doValidation(Metadata metadata, ExecutionOptions options) { final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() ); final DdlTransactionIsolator isolator = tool.getDdlTransactionIsolator( jdbcContext ); final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation( tool.getServiceRegistry(), isolator, metadata.getDatabase().getDefaultNamespace().getName() ); try { performValidation( metadata, databaseInformation, options, jdbcContext.getDialect() ); } finally { try { databaseInformation.cleanup(); } catch (Exception e) { log.debug( "Problem releasing DatabaseInformation : " + e.getMessage() ); } isolator.release(); } }
Example #2
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void dropFromScript( ScriptSourceInput scriptSourceInput, ImportSqlCommandExtractor commandExtractor, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { scriptSourceInput.prepare(); try { for ( String command : scriptSourceInput.read( commandExtractor ) ) { applySqlString( command, formatter, options, targets ); } } finally { scriptSourceInput.release(); } }
Example #3
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void performDrop( Metadata metadata, ExecutionOptions options, Dialect dialect, SourceDescriptor sourceDescriptor, GenerationTarget... targets) { final ImportSqlCommandExtractor commandExtractor = tool.getServiceRegistry().getService( ImportSqlCommandExtractor.class ); final boolean format = Helper.interpretFormattingEnabled( options.getConfigurationValues() ); final Formatter formatter = format ? FormatStyle.DDL.getFormatter() : FormatStyle.NONE.getFormatter(); if ( sourceDescriptor.getSourceType() == SourceType.SCRIPT ) { dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets ); } else if ( sourceDescriptor.getSourceType() == SourceType.METADATA ) { dropFromMetadata( metadata, options, dialect, formatter, targets ); } else if ( sourceDescriptor.getSourceType() == SourceType.METADATA_THEN_SCRIPT ) { dropFromMetadata( metadata, options, dialect, formatter, targets ); dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets ); } else { dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets ); dropFromMetadata( metadata, options, dialect, formatter, targets ); } }
Example #4
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void doDrop( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) { if ( targetDescriptor.getTargetTypes().isEmpty() ) { return; } final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() ); final GenerationTarget[] targets = tool.buildGenerationTargets( targetDescriptor, jdbcContext, options.getConfigurationValues(), true ); doDrop( metadata, options, jdbcContext.getDialect(), sourceDescriptor, targets ); }
Example #5
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applySqlString( boolean quiet, String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( !StringHelper.isEmpty( sqlString ) ) { String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { try { target.accept( sqlStringFormatted ); } catch (CommandAcceptanceException e) { if ( !quiet ) { options.getExceptionHandler().handleException( e ); } // otherwise ignore the exception } } } }
Example #6
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 6 votes |
protected void migrateTable( Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { final Database database = metadata.getDatabase(); //noinspection unchecked applySqlStrings( false, table.sqlAlterStrings( dialect, metadata, tableInformation, getDefaultCatalogName( database, dialect ), getDefaultSchemaName( database, dialect ) ), formatter, options, targets ); }
Example #7
Source File: IndividuallySchemaValidatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void validateTables( Metadata metadata, DatabaseInformation databaseInformation, ExecutionOptions options, Dialect dialect, Namespace namespace) { for ( Table table : namespace.getTables() ) { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { final TableInformation tableInformation = databaseInformation.getTableInformation( table.getQualifiedTableName() ); validateTable( table, tableInformation, metadata, options, dialect ); } } }
Example #8
Source File: GroupedSchemaValidatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void validateTables( Metadata metadata, DatabaseInformation databaseInformation, ExecutionOptions options, Dialect dialect, Namespace namespace) { final NameSpaceTablesInformation tables = databaseInformation.getTablesInformation( namespace ); for ( Table table : namespace.getTables() ) { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { validateTable( table, tables.getTableInformation( table ), metadata, options, dialect ); } } }
Example #9
Source File: SchemaCreatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applySqlString( String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( StringHelper.isEmpty( sqlString ) ) { return; } try { String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { target.accept( sqlStringFormatted ); } } catch (CommandAcceptanceException e) { options.getExceptionHandler().handleException( e ); } }
Example #10
Source File: SchemaCreatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
public void createFromScript( ScriptSourceInput scriptSourceInput, ImportSqlCommandExtractor commandExtractor, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { scriptSourceInput.prepare(); try { for ( String command : scriptSourceInput.read( commandExtractor ) ) { applySqlString( command, formatter, options, targets ); } } finally { scriptSourceInput.release(); } }
Example #11
Source File: SchemaCreatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void doCreation( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) { if ( targetDescriptor.getTargetTypes().isEmpty() ) { return; } final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() ); final GenerationTarget[] targets = tool.buildGenerationTargets( targetDescriptor, jdbcContext, options.getConfigurationValues(), true ); doCreation( metadata, jdbcContext.getDialect(), options, sourceDescriptor, targets ); }
Example #12
Source File: SpannerSchemaCreator.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void doCreation( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) { // Add auxiliary database objects to batch DDL statements metadata.getDatabase().addAuxiliaryDatabaseObject(new StartBatchDdl(Action.CREATE)); metadata.getDatabase().addAuxiliaryDatabaseObject(new RunBatchDdl(Action.CREATE)); try (Connection connection = tool.getDatabaseMetadataConnection(options)) { SpannerDatabaseInfo spannerDatabaseInfo = new SpannerDatabaseInfo(connection.getMetaData()); tool.getSpannerTableExporter(options).init(metadata, spannerDatabaseInfo, Action.CREATE); tool.getForeignKeyExporter(options).init(spannerDatabaseInfo); schemaCreator.doCreation(metadata, options, sourceDescriptor, targetDescriptor); } catch (SQLException e) { throw new RuntimeException("Failed to update Spanner table schema.", e); } }
Example #13
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private static void applySqlString( String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( StringHelper.isEmpty( sqlString ) ) { return; } String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { try { target.accept( sqlStringFormatted ); } catch (CommandAcceptanceException e) { options.getExceptionHandler().handleException( e ); } } }
Example #14
Source File: SpannerSchemaDropper.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void doDrop( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) { // Initialize auxiliary database objects to enable DDL statement batching. metadata.getDatabase().addAuxiliaryDatabaseObject(new StartBatchDdl(Action.DROP)); metadata.getDatabase().addAuxiliaryDatabaseObject(new RunBatchDdl(Action.DROP)); try (Connection connection = tool.getDatabaseMetadataConnection(options)) { // Initialize exporters with drop table dependencies so tables are dropped in the right order. SpannerDatabaseInfo spannerDatabaseInfo = new SpannerDatabaseInfo(connection.getMetaData()); tool.getSpannerTableExporter(options).init(metadata, spannerDatabaseInfo, Action.DROP); tool.getForeignKeyExporter(options).init(spannerDatabaseInfo); schemaDropper.doDrop(metadata, options, sourceDescriptor, targetDescriptor); } catch (SQLException e) { throw new RuntimeException("Failed to update Spanner table schema.", e); } }
Example #15
Source File: SpannerSchemaMigrator.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void doMigration( Metadata metadata, ExecutionOptions options, TargetDescriptor targetDescriptor) { // Add auxiliary database objects to batch DDL statements metadata.getDatabase().addAuxiliaryDatabaseObject(new StartBatchDdl(Action.UPDATE)); metadata.getDatabase().addAuxiliaryDatabaseObject(new RunBatchDdl(Action.UPDATE)); try (Connection connection = tool.getDatabaseMetadataConnection(options)) { SpannerDatabaseInfo spannerDatabaseInfo = new SpannerDatabaseInfo(connection.getMetaData()); tool.getSpannerTableExporter(options).init(metadata, spannerDatabaseInfo, Action.UPDATE); tool.getForeignKeyExporter(options).init(spannerDatabaseInfo); schemaMigrator.doMigration(metadata, options, targetDescriptor); } catch (SQLException e) { throw new RuntimeException("Failed to update Spanner table schema.", e); } }
Example #16
Source File: SchemaValidator.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") public void validate(Metadata metadata, ServiceRegistry serviceRegistry) { LOG.runningSchemaValidator(); Map config = new HashMap(); config.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() ); final SchemaManagementTool tool = serviceRegistry.getService( SchemaManagementTool.class ); final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions( config, ExceptionHandlerHaltImpl.INSTANCE ); tool.getSchemaValidator( config ).doValidation( metadata, executionOptions ); }
Example #17
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected abstract NameSpaceTablesInformation performTablesMigration( Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets);
Example #18
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public DelayedDropAction buildDelayedAction( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor) { final JournalingGenerationTarget target = new JournalingGenerationTarget(); doDrop( metadata, options, tool.getServiceRegistry().getService( JdbcEnvironment.class ).getDialect(), sourceDescriptor, target ); return new DelayedDropActionImpl( target.commands ); }
Example #19
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * For testing... * * @param metadata The metadata for which to generate the creation commands. * * @return The generation commands */ public List<String> generateDropCommands(Metadata metadata, final boolean manageNamespaces) { final JournalingGenerationTarget target = new JournalingGenerationTarget(); final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions() .getServiceRegistry(); final Dialect dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect(); final ExecutionOptions options = new ExecutionOptions() { @Override public boolean shouldManageNamespaces() { return manageNamespaces; } @Override public Map getConfigurationValues() { return Collections.emptyMap(); } @Override public ExceptionHandler getExceptionHandler() { return ExceptionHandlerHaltImpl.INSTANCE; } }; dropFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target ); return target.commands; }
Example #20
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
private static void applySqlStrings( boolean quiet, Iterator<String> sqlStrings, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( sqlStrings != null ) { while ( sqlStrings.hasNext() ) { final String sqlString = sqlStrings.next(); applySqlString( quiet, sqlString, formatter, options, targets ); } } }
Example #21
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void createSchemaAndCatalog( DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) { if ( tryToCreateCatalogs || tryToCreateSchemas ) { if ( tryToCreateCatalogs ) { final Identifier catalogLogicalName = namespace.getName().getCatalog(); final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog(); if ( catalogPhysicalName != null && !exportedCatalogs.contains( catalogLogicalName ) && !existingDatabase.catalogExists( catalogLogicalName ) ) { applySqlStrings( false, dialect.getCreateCatalogCommand( catalogPhysicalName.render( dialect ) ), formatter, options, targets ); exportedCatalogs.add( catalogLogicalName ); } } if ( tryToCreateSchemas && namespace.getPhysicalName().getSchema() != null && !existingDatabase.schemaExists( namespace.getName() ) ) { applySqlStrings( false, dialect.getCreateSchemaCommand( namespace.getPhysicalName().getSchema().render( dialect ) ), formatter, options, targets ); } } }
Example #22
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected static void applySqlStrings( boolean quiet, String[] sqlStrings, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( sqlStrings != null ) { for ( String sqlString : sqlStrings ) { applySqlString( quiet, sqlString, formatter, options, targets ); } } }
Example #23
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void applyForeignKeys( Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( dialect.hasAlterTable() ) { final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter(); @SuppressWarnings("unchecked") final Iterator<ForeignKey> fkItr = table.getForeignKeyIterator(); while ( fkItr.hasNext() ) { final ForeignKey foreignKey = fkItr.next(); if ( foreignKey.isPhysicalConstraint() && foreignKey.isCreationEnabled() ) { boolean existingForeignKeyFound = false; if ( tableInformation != null ) { existingForeignKeyFound = checkForExistingForeignKey( foreignKey, tableInformation ); } if ( !existingForeignKeyFound ) { // todo : shouldn't we just drop+recreate if FK exists? // this follows the existing code from legacy SchemaUpdate which just skipped // in old SchemaUpdate code, this was the trigger to "create" applySqlStrings( false, exporter.getSqlCreateStrings( foreignKey, metadata ), formatter, options, targets ); } } } } }
Example #24
Source File: SchemaDropperImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void applyConstraintDropping( Namespace namespace, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { final Dialect dialect = metadata.getDatabase().getJdbcEnvironment().getDialect(); if ( !dialect.dropConstraints() ) { return; } for ( Table table : namespace.getTables() ) { if ( !table.isPhysicalTable() ) { continue; } if ( !schemaFilter.includeTable( table ) ) { continue; } final Iterator fks = table.getForeignKeyIterator(); while ( fks.hasNext() ) { final ForeignKey foreignKey = (ForeignKey) fks.next(); applySqlStrings( dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata ), formatter, options, targets ); } } }
Example #25
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void applyIndexes( Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { final Exporter<Index> exporter = dialect.getIndexExporter(); final Iterator<Index> indexItr = table.getIndexIterator(); while ( indexItr.hasNext() ) { final Index index = indexItr.next(); if ( !StringHelper.isEmpty( index.getName() ) ) { IndexInformation existingIndex = null; if ( tableInformation != null ) { existingIndex = findMatchingIndex( index, tableInformation ); } if ( existingIndex == null ) { applySqlStrings( false, exporter.getSqlCreateStrings( index, metadata ), formatter, options, targets ); } } } }
Example #26
Source File: SpannerSchemaDropper.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 5 votes |
@Override public DelayedDropAction buildDelayedAction( Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor) { try (Connection connection = tool.getDatabaseMetadataConnection(options)) { // Initialize exporters with drop table dependencies so tables are dropped in the right order. SpannerDatabaseInfo spannerDatabaseInfo = new SpannerDatabaseInfo(connection.getMetaData()); tool.getSpannerTableExporter(options).init( metadata, spannerDatabaseInfo, Action.DROP); tool.getForeignKeyExporter(options).init(spannerDatabaseInfo); return schemaDropper.buildDelayedAction(metadata, options, sourceDescriptor); } catch (SQLException e) { throw new RuntimeException("Failed to update Spanner table schema.", e); } }
Example #27
Source File: AbstractSchemaMigrator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void createTable( Table table, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { applySqlStrings( false, dialect.getTableExporter().getSqlCreateStrings( table, metadata ), formatter, options, targets ); }
Example #28
Source File: RedirectionSchemaInitializer.java From teiid-spring-boot with Apache License 2.0 | 5 votes |
List<String> createScript(Metadata metadata, Dialect d, boolean includeDrops) { final JournalingGenerationTarget target = new JournalingGenerationTarget(); final ExecutionOptions options = new ExecutionOptions() { @Override public boolean shouldManageNamespaces() { return false; } @Override public Map getConfigurationValues() { return Collections.emptyMap(); } @Override public ExceptionHandler getExceptionHandler() { return ExceptionHandlerHaltImpl.INSTANCE; } }; HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool(); tool.injectServices((ServiceRegistryImplementor) this.registry); SourceDescriptor sd = new SourceDescriptor() { @Override public SourceType getSourceType() { return SourceType.METADATA; } @Override public ScriptSourceInput getScriptSourceInput() { return null; } }; if (includeDrops) { new SchemaDropperImpl(tool).doDrop(metadata, options, d, sd, target); } new SchemaCreatorImpl(tool).doCreation(metadata, d, options, sd, target); return target.commands; }
Example #29
Source File: AbstractSchemaValidator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void validateColumnType( Table table, Column column, ColumnInformation columnInformation, Metadata metadata, ExecutionOptions options, Dialect dialect) { boolean typesMatch = column.getSqlTypeCode( metadata ) == columnInformation.getTypeCode() || column.getSqlType( dialect, metadata ).toLowerCase(Locale.ROOT).startsWith( columnInformation.getTypeName().toLowerCase(Locale.ROOT) ); if ( !typesMatch ) { throw new SchemaManagementException( String.format( "Schema-validation: wrong column type encountered in column [%s] in " + "table [%s]; found [%s (Types#%s)], but expecting [%s (Types#%s)]", column.getName(), table.getQualifiedTableName(), columnInformation.getTypeName().toLowerCase(Locale.ROOT), JdbcTypeNameMapper.getTypeName( columnInformation.getTypeCode() ), column.getSqlType().toLowerCase(Locale.ROOT), JdbcTypeNameMapper.getTypeName( column.getSqlTypeCode( metadata ) ) ) ); } // this is the old Hibernate check... // // but I think a better check involves checks against type code and then the type code family, not // just the type name. // // See org.hibernate.type.descriptor.sql.JdbcTypeFamilyInformation // todo : this ^^ }
Example #30
Source File: AbstractSchemaValidator.java From lams with GNU General Public License v2.0 | 5 votes |
protected void validateTable( Table table, TableInformation tableInformation, Metadata metadata, ExecutionOptions options, Dialect dialect) { if ( tableInformation == null ) { throw new SchemaManagementException( String.format( "Schema-validation: missing table [%s]", table.getQualifiedTableName().toString() ) ); } final Iterator selectableItr = table.getColumnIterator(); while ( selectableItr.hasNext() ) { final Selectable selectable = (Selectable) selectableItr.next(); if ( Column.class.isInstance( selectable ) ) { final Column column = (Column) selectable; final ColumnInformation existingColumn = tableInformation.getColumn( Identifier.toIdentifier( column.getQuotedName() ) ); if ( existingColumn == null ) { throw new SchemaManagementException( String.format( "Schema-validation: missing column [%s] in table [%s]", column.getName(), table.getQualifiedTableName() ) ); } validateColumnType( table, column, existingColumn, metadata, options, dialect ); } } }