liquibase.structure.core.Schema Java Examples
The following examples show how to use
liquibase.structure.core.Schema.
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: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean isLiquibaseObject(final DatabaseObject object) { if (object instanceof Table) { Schema liquibaseSchema = new Schema(getLiquibaseCatalogName(), getLiquibaseSchemaName()); if (DatabaseObjectComparatorFactory.getInstance().isSameObject(object, new Table().setName(getDatabaseChangeLogTableName()).setSchema(liquibaseSchema), null, this)) { return true; } return DatabaseObjectComparatorFactory.getInstance().isSameObject(object, new Table().setName(getDatabaseChangeLogLockTableName()).setSchema(liquibaseSchema), null, this); } else if (object instanceof Column) { return isLiquibaseObject(((Column) object).getRelation()); } else if (object instanceof Index) { return isLiquibaseObject(((Index) object).getRelation()); } else if (object instanceof PrimaryKey) { return isLiquibaseObject(((PrimaryKey) object).getTable()); } return false; }
Example #2
Source File: SpatialIndexExistsPrecondition.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Generates the {@link Index} example (taken from {@link IndexExistsPrecondition}). * * @param database * the database instance. * @param schema * the schema instance. * @param tableName * the table name of the index. * @return the index example. */ protected Index getIndexExample(final Database database, final Schema schema, final String tableName) { final Index example = new Index(); if (tableName != null) { example.setTable((Table) new Table().setName( database.correctObjectName(getTableName(), Table.class)).setSchema(schema)); } example.setName(database.correctObjectName(getIndexName(), Index.class)); if (StringUtils.trimToNull(getColumnNames()) != null) { for (final String columnName : getColumnNames().split("\\s*,\\s*")) { final Column column = new Column(database.correctObjectName(columnName, Column.class)); example.getColumns().add(column); } } return example; }
Example #3
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Override public void setDefaultSchemaName(final String schemaName) { this.defaultSchemaName = correctObjectName(schemaName, Schema.class); if (!supportsSchemas()) { defaultCatalogSet = schemaName != null; } }
Example #4
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public final String getJdbcCatalogName(final Schema schema) { if (schema == null) { return getJdbcCatalogName(getDefaultSchema()); } else { return getJdbcCatalogName(new CatalogAndSchema(schema.getCatalogName(), schema.getName())); } }
Example #5
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public final String getJdbcSchemaName(final Schema schema) { if (schema == null) { return getJdbcSchemaName(getDefaultSchema()); } else { return getJdbcSchemaName(new CatalogAndSchema(schema.getCatalogName(), schema.getName())); } }
Example #6
Source File: SpatialIndexExistsPrecondition.java From liquibase-spatial with Apache License 2.0 | 5 votes |
/** * Creates an example of the database object for which to check. * * @param database * the database instance. * @param tableName * the table name of the index. * @return the database object example. */ public DatabaseObject getExample(final Database database, final String tableName) { final Schema schema = new Schema(getCatalogName(), getSchemaName()); final DatabaseObject example; // For GeoDB, the index is another table. if (database instanceof DerbyDatabase || database instanceof H2Database) { final String correctedTableName = database.correctObjectName(getHatboxTableName(), Table.class); example = new Table().setName(correctedTableName).setSchema(schema); } else { example = getIndexExample(database, schema, tableName); } return example; }
Example #7
Source File: AddRealmCodeSecret.java From keycloak with Apache License 2.0 | 5 votes |
@Override public SqlStatement[] generateStatements(Database database) throws CustomChangeException { try { StringBuilder sb = new StringBuilder(); sb.append("Generated codeSecret for realms: "); Connection connection = ((JdbcConnection) (database.getConnection())).getWrappedConnection(); ArrayList<SqlStatement> statements = new ArrayList<SqlStatement>(); String correctedTableName = database.correctObjectName("REALM", Table.class); String correctedSchemaName = database.escapeObjectName(database.getDefaultSchemaName(), Schema.class); if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(correctedTableName), database)) { try (Statement st = connection.createStatement(); ResultSet resultSet = st.executeQuery("SELECT ID FROM " + LiquibaseJpaUpdaterProvider.getTable(correctedTableName, correctedSchemaName) + " WHERE CODE_SECRET IS NULL")) { while (resultSet.next()) { String id = resultSet.getString(1); UpdateStatement statement = new UpdateStatement(null, null, correctedTableName) .addNewColumnValue("CODE_SECRET", KeycloakModelUtils.generateCodeSecret()) .setWhereClause("ID=?").addWhereParameters(id); statements.add(statement); if (!resultSet.isFirst()) { sb.append(", "); } sb.append(id); } if (!statements.isEmpty()) { confirmationMessage = sb.toString(); } } } return statements.toArray(new SqlStatement[statements.size()]); } catch (Exception e) { throw new CustomChangeException("Failed to add realm code secret", e); } }
Example #8
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 4 votes |
@Override public String escapeObjectName(String catalogName, String schemaName, final String objectName, final Class<? extends DatabaseObject> objectType) { if (supportsSchemas()) { catalogName = StringUtils.trimToNull(catalogName); schemaName = StringUtils.trimToNull(schemaName); if (catalogName == null) { catalogName = this.getDefaultCatalogName(); } if (schemaName == null) { schemaName = this.getDefaultSchemaName(); } if (!supportsCatalogInObjectName(objectType)) { catalogName = null; } if ((catalogName == null) && (schemaName == null)) { return escapeObjectName(objectName, objectType); } else if ((catalogName == null) || !this.supportsCatalogInObjectName(objectType)) { if (isDefaultSchema(catalogName, schemaName) && !getOutputDefaultSchema()) { return escapeObjectName(objectName, objectType); } else { return escapeObjectName(schemaName, Schema.class) + "." + escapeObjectName(objectName, objectType); } } else { if (isDefaultSchema(catalogName, schemaName) && !getOutputDefaultSchema() && !getOutputDefaultCatalog ()) { return escapeObjectName(objectName, objectType); } else if (isDefaultSchema(catalogName, schemaName) && !getOutputDefaultCatalog()) { return escapeObjectName(schemaName, Schema.class) + "." + escapeObjectName(objectName, objectType); } else { return escapeObjectName(catalogName, Catalog.class) + "." + escapeObjectName(schemaName, Schema.class) + "." + escapeObjectName(objectName, objectType); } } } else if (supportsCatalogs()) { catalogName = StringUtils.trimToNull(catalogName); schemaName = StringUtils.trimToNull(schemaName); if (catalogName != null) { if (getOutputDefaultCatalog()) { return escapeObjectName(catalogName, Catalog.class) + "." + escapeObjectName(objectName, objectType); } else { if (!defaultCatalogSet && isDefaultCatalog(catalogName)) { return escapeObjectName(objectName, objectType); } else { return escapeObjectName(catalogName, Catalog.class) + "." + escapeObjectName(objectName, objectType); } } } else { //they actually mean catalog name if (schemaName != null) { if (getOutputDefaultCatalog()) { return escapeObjectName(schemaName, Catalog.class) + "." + escapeObjectName(objectName, objectType); } else { if (!defaultCatalogSet && isDefaultCatalog(schemaName)) { return escapeObjectName(objectName, objectType); } else { return escapeObjectName(schemaName, Catalog.class) + "." + escapeObjectName(objectName, objectType); } } } else { catalogName = this.getDefaultCatalogName(); if (catalogName == null) { return escapeObjectName(objectName, objectType); } else { if (defaultCatalogSet || (isDefaultCatalog(catalogName) && getOutputDefaultCatalog())) { return escapeObjectName(catalogName, Catalog.class) + "." + escapeObjectName(objectName, objectType); } else { return escapeObjectName(objectName, objectType); } } } } } else { return escapeObjectName(objectName, objectType); } }
Example #9
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 4 votes |
public String getJdbcSchemaName(final CatalogAndSchema schema) { return correctObjectName(schema.getSchemaName(), Schema.class); }
Example #10
Source File: SetGenerator.java From liquibase-impala with Apache License 2.0 | 4 votes |
@Override public Sql[] generateSql(SetStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql = "SET " + statement.getQueryOption() + "=" + statement.getOptionValue(); return new Sql[]{new UnparsedSql(sql, new Schema().getName())}; }
Example #11
Source File: CustomKeycloakTask.java From keycloak with Apache License 2.0 | 4 votes |
protected String getTableName(String tableName) { String correctedSchemaName = database.escapeObjectName(database.getDefaultSchemaName(), Schema.class); return LiquibaseJpaUpdaterProvider.getTable(tableName, correctedSchemaName); }