protected Collection<String> getScripts( Map<Schema, Collection<String>> schemaScripts, ScriptGeneratorManager scriptGeneratorManager, boolean dropSchema, boolean useSchema) { Collection<String> scripts = newArrayList(); if (schemaScripts.size() == 1) { Map.Entry<Schema, Collection<String>> schemaScript = schemaScripts.entrySet().iterator().next(); Schema schema = schemaScript.getKey(); if (dropSchema) { scripts.add(getDropSchema(schema, scriptGeneratorManager)); } if (useSchema) { scripts.add(getUseSchema(schema, scriptGeneratorManager)); } scripts.addAll(schemaScript.getValue()); } else { for (Map.Entry<Schema, Collection<String>> schemaScript : schemaScripts.entrySet()) { Schema schema = schemaScript.getKey(); Dialect dialect = scriptGeneratorManager.getTargetDialect(); if (dropSchema) { scripts.add(getDropSchema(schema, scriptGeneratorManager)); } if (useSchema) { scripts.add( schema.getIdentifier() != null ? dialect.getUseSchema(scriptGeneratorManager.getName(schema)) : dialect.getUseSchema(scriptGeneratorManager.getName(schema.getCatalog()))); } scripts.addAll(schemaScript.getValue()); } } return scripts; }
protected boolean addScripts(Schema schema, ScriptGeneratorManager manager) { boolean generate = true; Identifier catalogId = valueOf(manager.getSourceCatalog()); if (catalogId != null) { generate = ObjectUtils.equals(catalogId, schema.getCatalog().getIdentifier()); } Identifier schemaId = valueOf(manager.getSourceSchema()); if (generate && schemaId != null) { generate = ObjectUtils.equals(schemaId, schema.getIdentifier()); } return generate; }
public static Collection<String> getCreateMultipleIndexes( Collection<Index> indexes, final ScriptGeneratorManager scriptGeneratorManager) { Collection<String> multipleIndexesScripts = newArrayList(); for (Index index : indexes) { Collection<String> indexScripts = scriptGeneratorManager.getCreateScripts(index); if (size(indexScripts) > 0) { multipleIndexesScripts.add(get(indexScripts, 0)); } } return singleton(join(multipleIndexesScripts, COMMA)); }
public static String getDropSchema(Schema schema, ScriptGeneratorManager scriptGeneratorManager) { String dropSchema = null; Dialect dialect = scriptGeneratorManager.getTargetDialect(); if (scriptGeneratorManager.getTargetSchema() != null) { dropSchema = dialect.getDropSchema(scriptGeneratorManager.getTargetSchema(), true); } else if (scriptGeneratorManager.getTargetCatalog() != null) { dropSchema = dialect.getDropSchema(scriptGeneratorManager.getTargetCatalog(), true); } if (dropSchema == null) { dropSchema = schema.getIdentifier() != null ? dialect.getDropSchema(scriptGeneratorManager.getName(schema)) : dialect.getDropSchema(scriptGeneratorManager.getName(schema.getCatalog())); } return dropSchema; }