use of liquibase.database.OfflineConnection in project liquibase by liquibase.
the class AbstractDb2Database method getDefaultCatalogName.
@Override
public String getDefaultCatalogName() {
if (defaultCatalogName != null) {
return defaultCatalogName;
}
if (defaultSchemaName != null) {
return defaultSchemaName;
}
if (getConnection() == null) {
return null;
}
if (getConnection() instanceof OfflineConnection) {
return ((OfflineConnection) getConnection()).getSchema();
}
Statement stmt = null;
ResultSet rs = null;
try {
stmt = ((JdbcConnection) getConnection()).createStatement();
rs = stmt.executeQuery("select current schema from sysibm.sysdummy1");
if (rs.next()) {
String result = rs.getString(1);
if (result != null) {
this.defaultSchemaName = StringUtil.trimToNull(result);
} else {
this.defaultSchemaName = StringUtil.trimToNull(super.getDefaultSchemaName());
}
}
} catch (Exception e) {
throw new RuntimeException("Could not determine current schema", e);
} finally {
JdbcUtil.close(rs, stmt);
}
return defaultSchemaName;
}
use of liquibase.database.OfflineConnection in project liquibase by liquibase.
the class YamlSnapshotParser method parse.
@Override
public DatabaseSnapshot parse(String path, ResourceAccessor resourceAccessor) throws LiquibaseParseException {
Yaml yaml = new Yaml(new SafeConstructor());
try (InputStream stream = resourceAccessor.openStream(null, path)) {
if (stream == null) {
throw new LiquibaseParseException(path + " does not exist");
}
Map parsedYaml = getParsedYamlFromInputStream(yaml, stream);
Map rootList = (Map) parsedYaml.get("snapshot");
if (rootList == null) {
throw new LiquibaseParseException("Could not find root snapshot node");
}
String shortName = (String) ((Map) rootList.get("database")).get("shortName");
Database database = DatabaseFactory.getInstance().getDatabase(shortName).getClass().getConstructor().newInstance();
database.setConnection(new OfflineConnection("offline:" + shortName, null));
DatabaseSnapshot snapshot = new RestoredDatabaseSnapshot(database);
ParsedNode snapshotNode = new ParsedNode(null, "snapshot");
snapshotNode.setValue(rootList);
Map metadata = (Map) rootList.get("metadata");
if (metadata != null) {
snapshot.getMetadata().putAll(metadata);
}
snapshot.load(snapshotNode, resourceAccessor);
return snapshot;
} catch (LiquibaseParseException e) {
throw (LiquibaseParseException) e;
} catch (Exception e) {
throw new LiquibaseParseException(e);
}
}
use of liquibase.database.OfflineConnection in project liquibase by liquibase.
the class SpringLiquibase method createDatabase.
/**
* Subclasses may override this method add change some database settings such as
* default schema before returning the database object.
*
* @param c
* @return a Database implementation retrieved from the {@link DatabaseFactory}.
* @throws DatabaseException
*/
protected Database createDatabase(Connection c, ResourceAccessor resourceAccessor) throws DatabaseException {
DatabaseConnection liquibaseConnection;
if (c == null) {
log.warning("Null connection returned by liquibase datasource. Using offline unknown database");
liquibaseConnection = new OfflineConnection("offline:unknown", resourceAccessor);
} else {
liquibaseConnection = new JdbcConnection(c);
}
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(liquibaseConnection);
if (StringUtil.trimToNull(this.defaultSchema) != null) {
if (database.supportsSchemas()) {
database.setDefaultSchemaName(this.defaultSchema);
} else if (database.supportsCatalogs()) {
database.setDefaultCatalogName(this.defaultSchema);
}
}
if (StringUtil.trimToNull(this.liquibaseSchema) != null) {
if (database.supportsSchemas()) {
database.setLiquibaseSchemaName(this.liquibaseSchema);
} else if (database.supportsCatalogs()) {
database.setLiquibaseCatalogName(this.liquibaseSchema);
}
}
if (StringUtil.trimToNull(this.liquibaseTablespace) != null && database.supportsTablespaces()) {
database.setLiquibaseTablespaceName(this.liquibaseTablespace);
}
if (StringUtil.trimToNull(this.databaseChangeLogTable) != null) {
database.setDatabaseChangeLogTableName(this.databaseChangeLogTable);
}
if (StringUtil.trimToNull(this.databaseChangeLogLockTable) != null) {
database.setDatabaseChangeLogLockTableName(this.databaseChangeLogLockTable);
}
return database;
}
Aggregations