use of org.hibernate.engine.jdbc.internal.Formatter in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method performCreation.
private void performCreation(Metadata metadata, Dialect dialect, ExecutionOptions options, 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();
switch(sourceDescriptor.getSourceType()) {
case SCRIPT:
{
createFromScript(sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets);
break;
}
case METADATA:
{
createFromMetadata(metadata, options, dialect, formatter, targets);
break;
}
case METADATA_THEN_SCRIPT:
{
createFromMetadata(metadata, options, dialect, formatter, targets);
createFromScript(sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets);
break;
}
case SCRIPT_THEN_METADATA:
{
createFromScript(sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, options, targets);
createFromMetadata(metadata, options, dialect, formatter, targets);
}
}
applyImportSources(options, commandExtractor, format, targets);
}
use of org.hibernate.engine.jdbc.internal.Formatter in project hibernate-orm by hibernate.
the class AbstractSchemaMigrator method performMigration.
private void performMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, GenerationTarget... targets) {
final boolean format = Helper.interpretFormattingEnabled(options.getConfigurationValues());
final Formatter formatter = format ? FormatStyle.DDL.getFormatter() : FormatStyle.NONE.getFormatter();
final Set<String> exportIdentifiers = new HashSet<String>(50);
final Database database = metadata.getDatabase();
// Drop all AuxiliaryDatabaseObjects
for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects()) {
if (auxiliaryDatabaseObject.appliesToDialect(dialect)) {
applySqlStrings(true, dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings(auxiliaryDatabaseObject, metadata), formatter, options, targets);
}
}
// Create beforeQuery-table AuxiliaryDatabaseObjects
for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects()) {
if (!auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect(dialect)) {
applySqlStrings(true, auxiliaryDatabaseObject.sqlCreateStrings(dialect), formatter, options, targets);
}
}
boolean tryToCreateCatalogs = false;
boolean tryToCreateSchemas = false;
if (options.shouldManageNamespaces()) {
if (dialect.canCreateSchema()) {
tryToCreateSchemas = true;
}
if (dialect.canCreateCatalog()) {
tryToCreateCatalogs = true;
}
}
final Map<Namespace, NameSpaceTablesInformation> tablesInformation = new HashMap<>();
Set<Identifier> exportedCatalogs = new HashSet<>();
for (Namespace namespace : database.getNamespaces()) {
final NameSpaceTablesInformation nameSpaceTablesInformation = performTablesMigration(metadata, existingDatabase, options, dialect, formatter, exportIdentifiers, tryToCreateCatalogs, tryToCreateSchemas, exportedCatalogs, namespace, targets);
tablesInformation.put(namespace, nameSpaceTablesInformation);
if (schemaFilter.includeNamespace(namespace)) {
for (Sequence sequence : namespace.getSequences()) {
checkExportIdentifier(sequence, exportIdentifiers);
final SequenceInformation sequenceInformation = existingDatabase.getSequenceInformation(sequence.getName());
if (sequenceInformation == null) {
applySqlStrings(false, dialect.getSequenceExporter().getSqlCreateStrings(sequence, metadata), formatter, options, targets);
}
}
}
}
//NOTE : Foreign keys must be created *afterQuery* all tables of all namespaces for cross namespace fks. see HHH-10420
for (Namespace namespace : database.getNamespaces()) {
if (schemaFilter.includeNamespace(namespace)) {
final NameSpaceTablesInformation nameSpaceTablesInformation = tablesInformation.get(namespace);
for (Table table : namespace.getTables()) {
if (schemaFilter.includeTable(table)) {
final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation(table);
if (tableInformation == null || (tableInformation != null && tableInformation.isPhysicalTable())) {
applyForeignKeys(table, tableInformation, dialect, metadata, formatter, options, targets);
}
}
}
}
}
// Create afterQuery-table AuxiliaryDatabaseObjects
for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects()) {
if (auxiliaryDatabaseObject.beforeTablesOnCreation() && auxiliaryDatabaseObject.appliesToDialect(dialect)) {
applySqlStrings(true, auxiliaryDatabaseObject.sqlCreateStrings(dialect), formatter, options, targets);
}
}
}
use of org.hibernate.engine.jdbc.internal.Formatter in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method applyImportSources.
private void applyImportSources(ExecutionOptions options, ImportSqlCommandExtractor commandExtractor, boolean format, GenerationTarget... targets) {
final ServiceRegistry serviceRegistry = tool.getServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
// I have had problems applying the formatter to these imported statements.
// and legacy SchemaExport did not format them, so doing same here
//final Formatter formatter = format ? DDLFormatterImpl.INSTANCE : FormatStyle.NONE.getFormatter();
final Formatter formatter = FormatStyle.NONE.getFormatter();
final Object importScriptSetting = options.getConfigurationValues().get(HBM2DDL_LOAD_SCRIPT_SOURCE);
String charsetName = (String) options.getConfigurationValues().get(HBM2DDL_CHARSET_NAME);
if (importScriptSetting != null) {
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting(importScriptSetting, classLoaderService, charsetName);
log.executingImportScript(importScriptInput.toString());
importScriptInput.prepare();
try {
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
final String importFiles = ConfigurationHelper.getString(AvailableSettings.HBM2DDL_IMPORT_FILES, options.getConfigurationValues(), DEFAULT_IMPORT_FILE);
for (String currentFile : importFiles.split(",")) {
final String resourceName = currentFile.trim();
final ScriptSourceInput importScriptInput = interpretLegacyImportScriptSetting(resourceName, classLoaderService, charsetName);
importScriptInput.prepare();
try {
log.executingImportScript(importScriptInput.toString());
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
}
use of org.hibernate.engine.jdbc.internal.Formatter in project hibernate-orm by hibernate.
the class SchemaDropperImpl method performDrop.
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);
}
}
Aggregations