@Override public String getViewDefinition(CatalogAndSchema schema, final String viewName) throws DatabaseException { schema = schema.customize(this); String definition = (String) ExecutorService.getInstance() .getExecutor(this) .queryForObject( new GetViewDefinitionStatement( schema.getCatalogName(), schema.getSchemaName(), viewName), String.class); if (definition == null) { return null; } return CREATE_VIEW_AS_PATTERN.matcher(definition).replaceFirst(""); }
@Override public String getViewDefinition(CatalogAndSchema schema, final String viewName) throws DatabaseException { schema = correctSchema(schema); List<Map> retList = ExecutorService.getInstance() .getExecutor(this) .queryForList( new GetViewDefinitionStatement( schema.getCatalogName(), schema.getSchemaName(), viewName)); // building the view definition from the multiple rows StringBuilder sb = new StringBuilder(); for (Map rowMap : retList) { String s = (String) rowMap.get("VIEWTEXT"); sb.append(s); } return CREATE_VIEW_AS_PATTERN.matcher(sb.toString()).replaceFirst(""); }
protected Table readTable(CachedRow tableMetadataResultSet, Database database) throws SQLException, DatabaseException { String rawTableName = tableMetadataResultSet.getString("TABLE_NAME"); String rawSchemaName = StringUtils.trimToNull(tableMetadataResultSet.getString("TABLE_SCHEM")); String rawCatalogName = StringUtils.trimToNull(tableMetadataResultSet.getString("TABLE_CAT")); String remarks = StringUtils.trimToNull(tableMetadataResultSet.getString("REMARKS")); if (remarks != null) { remarks = remarks.replace("''", "'"); // come back escaped sometimes } Table table = new Table().setName(cleanNameFromDatabase(rawTableName, database)); table.setRemarks(remarks); CatalogAndSchema schemaFromJdbcInfo = ((AbstractJdbcDatabase) database).getSchemaFromJdbcInfo(rawCatalogName, rawSchemaName); table.setSchema( new Schema(schemaFromJdbcInfo.getCatalogName(), schemaFromJdbcInfo.getSchemaName())); return table; }
@Override public String getJdbcSchemaName(CatalogAndSchema schema) { return correctObjectName( schema.getCatalogName() == null ? schema.getSchemaName() : schema.getCatalogName(), Schema.class); }
public String getJdbcCatalogName(final CatalogAndSchema schema) { return correctObjectName(schema.getCatalogName(), Catalog.class); }
@Override public Change[] fixMissing( DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { List<Change> returnList = new ArrayList<Change>(); PrimaryKey pk = (PrimaryKey) missingObject; AddPrimaryKeyChange change = new AddPrimaryKeyChange(); change.setTableName(pk.getTable().getName()); if (control.getIncludeCatalog()) { change.setCatalogName(pk.getTable().getSchema().getCatalogName()); } if (control.getIncludeSchema()) { change.setSchemaName(pk.getTable().getSchema().getName()); } change.setConstraintName(pk.getName()); change.setColumnNames(pk.getColumnNames()); if (control.getIncludeTablespace()) { change.setTablespace(pk.getTablespace()); } if (referenceDatabase instanceof MSSQLDatabase && pk.getBackingIndex() != null && pk.getBackingIndex().getClustered() != null && !pk.getBackingIndex().getClustered()) { change.setClustered(false); } if (comparisonDatabase instanceof OracleDatabase || (comparisonDatabase instanceof DB2Database && pk.getBackingIndex() != null && !comparisonDatabase.isSystemObject(pk.getBackingIndex()))) { Index backingIndex = pk.getBackingIndex(); if (backingIndex != null && backingIndex.getName() != null) { try { if (!control.getIncludeCatalog() && !control.getIncludeSchema()) { CatalogAndSchema schema = comparisonDatabase.getDefaultSchema().customize(comparisonDatabase); backingIndex .getTable() .setSchema( schema.getCatalogName(), schema .getSchemaName()); // set table schema so it is found in the correct schema } if (referenceDatabase.equals(comparisonDatabase) || !SnapshotGeneratorFactory.getInstance().has(backingIndex, comparisonDatabase)) { Change[] fixes = ChangeGeneratorFactory.getInstance() .fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase); if (fixes != null) { for (Change fix : fixes) { if (fix != null) { returnList.add(fix); } } } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } change.setForIndexName(backingIndex.getName()); Schema schema = backingIndex.getSchema(); if (schema != null) { if (control.getIncludeCatalog()) { change.setForIndexCatalogName(schema.getCatalogName()); } if (control.getIncludeSchema()) { change.setForIndexSchemaName(schema.getName()); } } } } control.setAlreadyHandledMissing(pk.getBackingIndex()); returnList.add(change); return returnList.toArray(new Change[returnList.size()]); }