use of liquibase.database.DatabaseConnection in project liquibase by liquibase.
the class HsqlDatabaseTest method testNotUsingOracleSyntax.
public void testNotUsingOracleSyntax() {
HsqlDatabase database = new HsqlDatabase();
DatabaseConnection conn = mock(DatabaseConnection.class);
when(conn.getURL()).thenReturn("jdbc:hsqldb:mem:testdb");
database.setConnection(conn);
assertFalse("Using oracle syntax", database.isUsingOracleSyntax());
}
use of liquibase.database.DatabaseConnection in project opennms by OpenNMS.
the class Migrator method migrate.
/**
* <p>migrate</p>
*
* @param migration a {@link org.opennms.core.schema.Migration} object.
* @throws org.opennms.core.schema.MigrationException if any.
*/
public void migrate(final Migration migration) throws MigrationException {
Connection connection = null;
DatabaseConnection dbConnection = null;
try {
connection = m_dataSource.getConnection();
dbConnection = new JdbcConnection(connection);
ResourceAccessor accessor = migration.getAccessor();
if (accessor == null)
accessor = new SpringResourceAccessor();
final Liquibase liquibase = new Liquibase(migration.getChangeLog(), accessor, dbConnection);
liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
final String contexts = System.getProperty("opennms.contexts", "production");
liquibase.update(contexts);
} catch (final Throwable e) {
throw new MigrationException("unable to migrate the database", e);
} finally {
cleanUpDatabase(connection, dbConnection, null, null);
}
}
use of liquibase.database.DatabaseConnection in project webcert by sklintyg.
the class DbChecker method checkDb.
@PostConstruct
public void checkDb() {
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
Liquibase liquibase = new Liquibase(script, new ClassLoaderResourceAccessor(), database);
LOG.info("Checking database: {} URL:{}", database.getDatabaseProductName(), database.getConnection().getURL());
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(null, liquibase.getChangeLogParameters().getLabels());
if (!changeSets.isEmpty()) {
StringBuilder errors = new StringBuilder();
for (ChangeSet changeSet : changeSets) {
errors.append('>').append(changeSet.toString()).append('\n');
}
throw new Error("Database version mismatch. Check liquibase status. Errors:\n" + errors.toString() + database.getDatabaseProductName() + ", " + database);
}
} catch (liquibase.exception.LiquibaseException | SQLException e) {
throw new Error("Database not ok, aborting startup.", e);
}
LOG.info("Liquibase ok");
}
use of liquibase.database.DatabaseConnection in project dropwizard by dropwizard.
the class AbstractLiquibaseCommand method createDatabase.
private Database createDatabase(ManagedDataSource dataSource, Namespace namespace) throws SQLException, LiquibaseException {
final DatabaseConnection conn = new JdbcConnection(dataSource.getConnection());
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(conn);
final String catalogName = namespace.getString("catalog");
final String schemaName = namespace.getString("schema");
if (database.supportsCatalogs() && catalogName != null) {
database.setDefaultCatalogName(catalogName);
database.setOutputDefaultCatalog(true);
}
if (database.supportsSchemas() && schemaName != null) {
database.setDefaultSchemaName(schemaName);
database.setOutputDefaultSchema(true);
}
return database;
}
use of liquibase.database.DatabaseConnection in project liquibase by liquibase.
the class JdbcExecutor method execute.
public Object execute(StatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException {
Scope.getCurrentScope().getLog(getClass()).fine("Executing with the '" + getName() + "' executor");
DatabaseConnection con = database.getConnection();
Statement stmt = null;
try {
if (con instanceof OfflineConnection) {
throw new DatabaseException("Cannot execute commands against an offline database");
}
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
Statement stmtToUse = stmt;
return action.doInStatement(stmtToUse);
} catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
JdbcUtil.closeStatement(stmt);
stmt = null;
String url;
if (con.isClosed()) {
url = "CLOSED CONNECTION";
} else {
url = con.getURL();
}
throw new DatabaseException("Error executing SQL " + StringUtil.join(applyVisitors(action.getStatement(), sqlVisitors), "; on " + url) + ": " + ex.getMessage(), ex);
} finally {
JdbcUtil.closeStatement(stmt);
}
}
Aggregations