use of liquibase.database.DatabaseFactory in project spring-boot by spring-projects.
the class LiquibaseEndpoint method invoke.
@Override
public List<LiquibaseReport> invoke() {
List<LiquibaseReport> reports = new ArrayList<>();
DatabaseFactory factory = DatabaseFactory.getInstance();
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
for (Map.Entry<String, SpringLiquibase> entry : this.liquibases.entrySet()) {
try {
DataSource dataSource = entry.getValue().getDataSource();
JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
try {
Database database = factory.findCorrectDatabaseImplementation(connection);
reports.add(new LiquibaseReport(entry.getKey(), service.queryDatabaseChangeLogTable(database)));
} finally {
connection.close();
}
} catch (Exception ex) {
throw new IllegalStateException("Unable to get Liquibase changelog", ex);
}
}
return reports;
}
use of liquibase.database.DatabaseFactory in project liquibase by liquibase.
the class DatabaseType method createDatabase.
public Database createDatabase(ClassLoader classLoader) {
logParameters();
validateParameters();
try {
DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
if (databaseClass != null) {
Database databaseInstance = (Database) ClasspathUtils.newInstance(databaseClass, classLoader, Database.class);
databaseFactory.register(databaseInstance);
}
DatabaseConnection jdbcConnection;
if (getUrl().startsWith("offline:")) {
jdbcConnection = new OfflineConnection(getUrl(), new ClassLoaderResourceAccessor(classLoader));
} else {
Driver driver = (Driver) ClasspathUtils.newInstance(getDriver(), classLoader, Driver.class);
if (driver == null) {
throw new BuildException("Unable to create Liquibase Database instance. Could not instantiate the JDBC driver.");
}
Properties connectionProps = new Properties();
String user = getUser();
if (user != null && !user.isEmpty()) {
connectionProps.setProperty(USER, user);
}
String password = getPassword();
if (password != null && !password.isEmpty()) {
connectionProps.setProperty(PASSWORD, password);
}
ConnectionProperties connectionProperties = getConnectionProperties();
if (connectionProperties != null) {
connectionProps.putAll(connectionProperties.buildProperties());
}
Connection connection = driver.connect(getUrl(), connectionProps);
if (connection == null) {
throw new BuildException("Unable to create Liquibase Database instance. Could not connect to the database.");
}
jdbcConnection = new JdbcConnection(connection);
}
Database database = databaseFactory.findCorrectDatabaseImplementation(jdbcConnection);
String schemaName = getDefaultSchemaName();
if (schemaName != null) {
database.setDefaultSchemaName(schemaName);
}
String catalogName = getDefaultCatalogName();
if (catalogName != null) {
database.setDefaultCatalogName(catalogName);
}
String currentDateTimeFunction = getCurrentDateTimeFunction();
if (currentDateTimeFunction != null) {
database.setCurrentDateTimeFunction(currentDateTimeFunction);
}
database.setOutputDefaultSchema(isOutputDefaultSchema());
database.setOutputDefaultCatalog(isOutputDefaultCatalog());
String liquibaseSchemaName = getLiquibaseSchemaName();
if (liquibaseSchemaName != null) {
database.setLiquibaseSchemaName(liquibaseSchemaName);
}
String liquibaseCatalogName = getLiquibaseCatalogName();
if (liquibaseCatalogName != null) {
database.setLiquibaseCatalogName(liquibaseCatalogName);
}
String databaseChangeLogTableName = getDatabaseChangeLogTableName();
if (databaseChangeLogTableName != null) {
database.setDatabaseChangeLogTableName(databaseChangeLogTableName);
}
String databaseChangeLogLockTableName = getDatabaseChangeLogLockTableName();
if (databaseChangeLogLockTableName != null) {
database.setDatabaseChangeLogLockTableName(databaseChangeLogLockTableName);
}
String liquibaseTablespaceName = getLiquibaseTablespaceName();
if (liquibaseTablespaceName != null) {
database.setLiquibaseTablespaceName(liquibaseTablespaceName);
}
return database;
} catch (SQLException e) {
throw new BuildException("Unable to create Liquibase database instance. A JDBC error occurred. " + e.toString(), e);
} catch (DatabaseException e) {
throw new BuildException("Unable to create Liquibase database instance. " + e.toString(), e);
}
}
use of liquibase.database.DatabaseFactory in project liquibase by liquibase.
the class LockServiceFactoryTest method getLockService.
@Test
public void getLockService() {
final Database oracle1 = new OracleDatabase() {
@Override
public boolean equals(Object o) {
return o == this;
}
};
final Database oracle2 = new OracleDatabase() {
@Override
public boolean equals(Object o) {
return o == this;
}
};
final Database mysql = new MySQLDatabase() {
@Override
public boolean equals(Object o) {
return o == this;
}
};
DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
databaseFactory.register(oracle1);
databaseFactory.register(oracle2);
databaseFactory.register(mysql);
LockServiceFactory lockServiceFactory = LockServiceFactory.getInstance();
assertNotNull(lockServiceFactory.getLockService(oracle1));
assertNotNull(lockServiceFactory.getLockService(oracle2));
assertNotNull(lockServiceFactory.getLockService(mysql));
assertTrue(lockServiceFactory.getLockService(oracle1) == lockServiceFactory.getLockService(oracle1));
assertTrue(lockServiceFactory.getLockService(oracle2) == lockServiceFactory.getLockService(oracle2));
assertTrue(lockServiceFactory.getLockService(mysql) == lockServiceFactory.getLockService(mysql));
assertTrue(lockServiceFactory.getLockService(oracle1) != lockServiceFactory.getLockService(oracle2));
assertTrue(lockServiceFactory.getLockService(oracle1) != lockServiceFactory.getLockService(mysql));
assertTrue(lockServiceFactory.getLockService(getMockDatabase()) instanceof MockLockService);
}
use of liquibase.database.DatabaseFactory in project libresonic by Libresonic.
the class SpringLiquibase method createDatabase.
@Override
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);
}
DatabaseFactory factory = DatabaseFactory.getInstance();
overrideHsqlDbImplementation(factory);
Database database = factory.findCorrectDatabaseImplementation(liquibaseConnection);
if (StringUtils.trimToNull(this.defaultSchema) != null) {
database.setDefaultSchemaName(this.defaultSchema);
}
return database;
}
Aggregations