Java Code Examples for liquibase.database.Database#getLiquibaseCatalogName()

The following examples show how to use liquibase.database.Database#getLiquibaseCatalogName() . 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: HiveRemoveChangeSetRanStatusGenerator.java    From liquibase-impala with Apache License 2.0 6 votes vote down vote up
@Override
public Sql[] generateSql(RemoveChangeSetRanStatusStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ChangeSet changeSet = statement.getChangeSet();
    String tmpTable = UUID.randomUUID().toString().replaceAll("-", "");
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogTableName();
    CreateTableAsSelectStatement createTableAsSelectStatement = new CreateTableAsSelectStatement(catalogName, schemaName, tableName, tmpTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "TAG", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(database.escapeObjectName("ID", Column.class) + " != ? " +
                    "AND " + database.escapeObjectName("FILENAME", Column.class) + " != ?")
            .addWhereParameters(changeSet.getId(), changeSet.getFilePath());

    return CustomSqlGenerator.generateSql(database,
            createTableAsSelectStatement,
            new DropTableStatement(catalogName, schemaName, tableName, false),
            new RenameTableStatement(catalogName, schemaName, tmpTable, tableName));
}
 
Example 2
Source File: HiveTagDatabaseGenerator.java    From liquibase-impala with Apache License 2.0 6 votes vote down vote up
@Override
public Sql[] generateSql(TagDatabaseStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogTableName();
    String tableNameEscaped = database.escapeObjectName(tableName, Table.class);
    String dateColumnNameEscaped = database.escapeObjectName("DATEEXECUTED", Column.class);
    String tagColumnNameEscaped = database.escapeObjectName("TAG", Column.class);
    String tempTable = UUID.randomUUID().toString().replaceAll("-", "");
    CreateTableAsSelectStatement createTableAsSelectStatement = new CreateTableAsSelectStatement(catalogName, schemaName, tableName, tempTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "TAG", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(tableNameEscaped + "." + dateColumnNameEscaped + " NOT IN (SELECT MAX(" + tableNameEscaped + "." + dateColumnNameEscaped + ") " +
                    "FROM " + tableNameEscaped + ")");
    InsertAsSelectStatement insertAsSelectStatement = new InsertAsSelectStatement(catalogName, schemaName, tableName, tempTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "'" + statement.getTag() + "'", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(tableNameEscaped + "." + dateColumnNameEscaped + " IN (SELECT MAX(" + tableNameEscaped + "." + dateColumnNameEscaped + ") FROM " + tableNameEscaped + ") AND ("
                    + tableNameEscaped + "." + tagColumnNameEscaped + " IS NULL OR " + tableNameEscaped + "." + tagColumnNameEscaped + " != ?)").addWhereParameters(statement.getTag());

    return CustomSqlGenerator.generateSql(database,
            createTableAsSelectStatement,
            insertAsSelectStatement,
            new DropTableStatement(catalogName, schemaName, tableName, false),
            new RenameTableStatement(catalogName, schemaName, tempTable, tableName));
}
 
Example 3
Source File: ImpalaRemoveChangeSetRanStatusGenerator.java    From liquibase-impala with Apache License 2.0 6 votes vote down vote up
@Override
public Sql[] generateSql(RemoveChangeSetRanStatusStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ChangeSet changeSet = statement.getChangeSet();
    String tmpTable = UUID.randomUUID().toString().replaceAll("-", "");
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogTableName();
    CreateTableAsSelectStatement createTableAsSelectStatement = new CreateTableAsSelectStatement(catalogName, schemaName, tableName, tmpTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "TAG", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(" NOT (" + database.escapeObjectName("ID", Column.class) + " = ? " +
                    "AND " + database.escapeObjectName("FILENAME", Column.class) + " = ?)")
            .addWhereParameters(changeSet.getId(), changeSet.getFilePath());

    return CustomSqlGenerator.generateSql(database,
            UserSessionSettings.syncDdlStart(),
            createTableAsSelectStatement,
            new DropTableStatement(catalogName, schemaName, tableName, false),
            new RenameTableStatement(catalogName, schemaName, tmpTable, tableName),
            UserSessionSettings.syncDdlStop());
}
 
Example 4
Source File: ImpalaLockDatabaseChangeLogGenerator.java    From liquibase-impala with Apache License 2.0 6 votes vote down vote up
@Override
public Sql[] generateSql(LockDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    InsertStatement insertStatement = new InsertStatement(catalogName, schemaName, tableName)
            .addColumnValue("ID", 1)
            .addColumnValue("LOCKED", Boolean.TRUE)
            .addColumnValue("LOCKEDBY", hostname + " [" + hostaddress + "]")
            .addColumnValue("LOCKGRANTED", DateTimeUtils.getCurrentTS("yyyy-MM-dd HH:mm:ss"));

    return CustomSqlGenerator.generateSql(database,
            UserSessionSettings.syncDdlStart(),
            new TruncateTableStatement(catalogName, schemaName, tableName),
            insertStatement,
            UserSessionSettings.syncDdlStop());
}
 
Example 5
Source File: HiveLockDatabaseChangeLogGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(LockDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    HiveInsertStatement hiveInsertStatement = new HiveInsertStatement(catalogName, schemaName, tableName);
    hiveInsertStatement.addColumnValue(1);
    hiveInsertStatement.addColumnValue(Boolean.TRUE);
    hiveInsertStatement.addColumnValue(hostname + " (" + hostaddress + ")");
    hiveInsertStatement.addColumnValue(DateTimeUtils.getCurrentTS("yyyy-MM-dd HH:mm:ss"));

    return CustomSqlGenerator.generateSql(database,
            new TruncateTableStatement(catalogName, schemaName, tableName),
            hiveInsertStatement);
}
 
Example 6
Source File: HiveUnlockDatabaseChangeLogGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(UnlockDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    HiveInsertStatement hiveInsertStatement = new HiveInsertStatement(catalogName, schemaName, tableName)
            .addColumnValue(1)
            .addColumnValue(Boolean.FALSE)
            .addColumnValue("NULL")
            .addColumnValue("NULL");

    return CustomSqlGenerator.generateSql(database,
            new TruncateTableStatement(catalogName, schemaName, tableName),
            hiveInsertStatement);
}
 
Example 7
Source File: HiveInitializeDatabaseChangeLogLockTableGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(InitializeDatabaseChangeLogLockTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    HiveInsertStatement insertStatementHive = new HiveInsertStatement(catalogName, schemaName, tableName)
            .addColumnValue(1)
            .addColumnValue(Boolean.FALSE)
            .addColumnValue("NULL")
            .addColumnValue("NULL");

    return CustomSqlGenerator.generateSql(database,
            new TruncateTableStatement(catalogName, schemaName, tableName),
            insertStatementHive);
}
 
Example 8
Source File: HiveStandardChangeLogHistoryService.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public void clearAllCheckSums() throws LiquibaseException {
    Database database = getDatabase();
    UpdateStatement updateStatement = new UpdateStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName());
    updateStatement.addNewColumnValue("MD5SUM", null);
    ExecutorService.getInstance().getExecutor(database).execute(updateStatement);
    database.commit();
}
 
Example 9
Source File: ImpalaInitializeDatabaseChangeLogLockTableGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(InitializeDatabaseChangeLogLockTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    InsertStatement insertStatement = new InsertStatement(catalogName, schemaName, tableName)
            .addColumnValue("ID", 1)
            .addColumnValue("LOCKED", Boolean.FALSE);

    return CustomSqlGenerator.generateSql(database,
            UserSessionSettings.syncDdlStart(),
            new TruncateTableStatement(catalogName, schemaName, tableName),
            insertStatement,
            UserSessionSettings.syncDdlStop());
}
 
Example 10
Source File: ImpalaTagDatabaseGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(TagDatabaseStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogTableName();
    String tableNameEscaped = database.escapeTableName(catalogName, schemaName, tableName);
    String dateColumnNameEscaped = database.escapeObjectName("DATEEXECUTED", Column.class);
    String tagColumnNameEscaped = database.escapeObjectName("TAG", Column.class);
    String tmpTable = UUID.randomUUID().toString().replaceAll("-", "");
    CreateTableAsSelectStatement createTableAsSelectStatement = new CreateTableAsSelectStatement(catalogName, schemaName, tableName, tmpTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "TAG", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(dateColumnNameEscaped + " != (SELECT MAX(" + dateColumnNameEscaped + ") " +
                    "FROM " + tableNameEscaped + ")");
    InsertAsSelectStatement insertAsSelectStatement = new InsertAsSelectStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName(), tmpTable)
            .addColumnNames("ID", "AUTHOR", "FILENAME", "DATEEXECUTED", "ORDEREXECUTED", "EXECTYPE", "MD5SUM", "DESCRIPTION", "COMMENTS", "'" + statement.getTag() + "'", "LIQUIBASE", "CONTEXTS", "LABELS", "DEPLOYMENT_ID")
            .setWhereCondition(dateColumnNameEscaped + " = (SELECT MAX(" + dateColumnNameEscaped + ") FROM " + tableNameEscaped + ") AND ("
                    + tagColumnNameEscaped + " IS NULL OR " + tagColumnNameEscaped + " != ?)")
            .addWhereParameters(statement.getTag());

    return CustomSqlGenerator.generateSql(database,
            UserSessionSettings.syncDdlStart(),
            createTableAsSelectStatement,
            insertAsSelectStatement,
            new DropTableStatement(catalogName, schemaName, tableName, false),
            new RenameTableStatement(catalogName, schemaName, tmpTable, tableName),
            UserSessionSettings.syncDdlStop());
}
 
Example 11
Source File: ImpalaUnlockDatabaseChangeLogGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
@Override
public Sql[] generateSql(UnlockDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String catalogName = database.getLiquibaseCatalogName();
    String schemaName = database.getDefaultSchemaName();
    String tableName = database.getDatabaseChangeLogLockTableName();
    InsertStatement insertStatement = new InsertStatement(catalogName, schemaName, tableName)
            .addColumnValue("ID", 1)
            .addColumnValue("LOCKED", Boolean.FALSE);

    return CustomSqlGenerator.generateSql(database,
            UserSessionSettings.syncDdlStart(),
            new TruncateTableStatement(catalogName, schemaName, tableName),
            insertStatement,
            UserSessionSettings.syncDdlStop());
}
 
Example 12
Source File: CustomLockDatabaseChangeLogGenerator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private Sql generateSelectForUpdate(Database database, int id) {
    String catalog = database.getLiquibaseCatalogName();
    String schema = database.getLiquibaseSchemaName();
    String rawLockTableName = database.getDatabaseChangeLogLockTableName();

    String lockTableName = database.escapeTableName(catalog, schema, rawLockTableName);
    String idColumnName  = database.escapeColumnName(catalog, schema, rawLockTableName, "ID");

    String sqlBase = "SELECT " + idColumnName + " FROM " + lockTableName;
    String sqlWhere = " WHERE " + idColumnName + "=" + id;

    String sql;
    if (database instanceof MySQLDatabase || database instanceof PostgresDatabase || database instanceof H2Database ||
            database instanceof OracleDatabase) {
        sql = sqlBase + sqlWhere + " FOR UPDATE";
    } else if (database instanceof MSSQLDatabase) {
        sql = sqlBase + " WITH (UPDLOCK, ROWLOCK)" + sqlWhere;
    } else if (database instanceof DB2Database) {
        sql = sqlBase + sqlWhere +  " FOR READ ONLY WITH RS USE AND KEEP UPDATE LOCKS";
    } else {
        sql = sqlBase + sqlWhere;
        logger.warnf("No direct support for database %s . Database lock may not work correctly", database.getClass().getName());
    }

    logger.debugf("SQL command for pessimistic lock: %s", sql);
    
    return new UnparsedSql(sql);
}