Java Code Examples for liquibase.database.core.MSSQLDatabase

The following examples show how to use liquibase.database.core.MSSQLDatabase. These examples are extracted from open source projects. 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 Project: keycloak   Source File: JpaUpdateAuthz_3_4_0_CR1.java    License: Apache License 2.0 5 votes vote down vote up
private SqlStatement generateUpdateStatement(String resourceServerDetailTable) {
        String resourceServerTableName = database.correctObjectName(getTableName("RESOURCE_SERVER"), Table.class);
        String resourceServerDetailTableName = database.correctObjectName(getTableName(resourceServerDetailTable), Table.class);

        if (database instanceof MSSQLDatabase) {
//            UPDATE RESOURCE_SERVER_POLICY   SET RESOURCE_SERVER_CLIENT_ID = s.CLIENT_ID FROM (SELECT ID, CLIENT_ID FROM RESOURCE_SERVER) s WHERE s.ID = RESOURCE_SERVER_POLICY.RESOURCE_SERVER_ID;
//            UPDATE RESOURCE_SERVER_RESOURCE SET RESOURCE_SERVER_CLIENT_ID = s.CLIENT_ID FROM (SELECT ID, CLIENT_ID FROM RESOURCE_SERVER) s WHERE s.ID = RESOURCE_SERVER_RESOURCE.RESOURCE_SERVER_ID;
//            UPDATE RESOURCE_SERVER_SCOPE    SET RESOURCE_SERVER_CLIENT_ID = s.CLIENT_ID FROM (SELECT ID, CLIENT_ID FROM RESOURCE_SERVER) s WHERE s.ID = RESOURCE_SERVER_SCOPE.RESOURCE_SERVER_ID;
            return new RawSqlStatement(
              "UPDATE "
              + resourceServerDetailTableName
                + " SET RESOURCE_SERVER_CLIENT_ID = s.CLIENT_ID FROM "
                  + " (SELECT ID, CLIENT_ID FROM "
                  + resourceServerTableName
                  + ") s "
                + " WHERE s.ID = "
                + resourceServerDetailTableName
                + ".RESOURCE_SERVER_ID"
            );
        } else {
//          UPDATE RESOURCE_SERVER_POLICY p   SET RESOURCE_SERVER_CLIENT_ID = (SELECT CLIENT_ID FROM RESOURCE_SERVER s WHERE s.ID = p.RESOURCE_SERVER_ID);
//          UPDATE RESOURCE_SERVER_RESOURCE p SET RESOURCE_SERVER_CLIENT_ID = (SELECT CLIENT_ID FROM RESOURCE_SERVER s WHERE s.ID = p.RESOURCE_SERVER_ID);
//          UPDATE RESOURCE_SERVER_SCOPE p    SET RESOURCE_SERVER_CLIENT_ID = (SELECT CLIENT_ID FROM RESOURCE_SERVER s WHERE s.ID = p.RESOURCE_SERVER_ID);
            return new RawSqlStatement(
              "UPDATE "
              + resourceServerDetailTableName
              + " p SET RESOURCE_SERVER_CLIENT_ID = "
                + "(SELECT CLIENT_ID FROM "
                + resourceServerTableName
                + " s WHERE s.ID = p.RESOURCE_SERVER_ID)"
            );
        }

    }
 
Example 2
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);
}
 
Example 3
Source Project: liquibase-mssql   Source File: InsertGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public boolean supports(InsertStatement statement, Database database) {
    return database instanceof MSSQLDatabase;
}
 
Example 4
Source Project: liquibase-mssql   Source File: InsertSetGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public boolean supports(InsertSetStatement statement, Database database) {
    return database instanceof MSSQLDatabase;
}
 
Example 5
@Override
public boolean supports(DropStoredProcedureStatement statement, Database database)
{
    return database instanceof MSSQLDatabase;
}