liquibase.database.core.OracleDatabase Java Examples

The following examples show how to use liquibase.database.core.OracleDatabase. 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: liquibase-spatial   Author: lonnyj   File: DropSpatialTableGeneratorOracleTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests
 * {@link DropSpatialTableGeneratorOracle#generateSql(DropTableStatement, Database, SqlGeneratorChain)}
 */
@Test
public void testGenerateSql() {
   final DropSpatialTableGeneratorOracle generator = new DropSpatialTableGeneratorOracle();
   final Database database = new OracleDatabase();
   final SqlGeneratorChain sqlGeneratorChain = mock(SqlGeneratorChain.class);
   final DropTableStatement statement = new DropTableStatement("catalog_name", "schema_name",
         "table_name", true);
   final Sql comment = new SingleLineComment("No-op", "--");
   when(sqlGeneratorChain.generateSql(statement, database)).thenReturn(new Sql[] { comment });
   final Sql[] result = generator.generateSql(statement, database, sqlGeneratorChain);
   assertNotNull(result);
   assertEquals(result.length, 2);
   assertEquals(result[1], comment);

   // Verify the DELETE statement.
   final String deleteSql = result[0].toSql();
   String deletePattern = "(?i)DELETE FROM user_sdo_geom_metadata ";
   deletePattern += "WHERE table_name = '" + statement.getTableName().toUpperCase();
   deletePattern += "'";
   assertTrue(deleteSql.matches(deletePattern), "'" + deleteSql
         + "' does not match the pattern '" + deletePattern + "'");
   assertNotNull(result[0].getAffectedDatabaseObjects());
   assertTrue(result[0].getAffectedDatabaseObjects().size() >= 1, result[0]
         .getAffectedDatabaseObjects().toString());
}
 
Example #2
Source Project: liquibase-spatial   Author: lonnyj   File: SpatialSupportedPrecondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Warnings warn(final Database database) {
   final Warnings warnings = new Warnings();
   if (!(database instanceof DerbyDatabase || database instanceof H2Database
         || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) {
      warnings.addWarning(database.getDatabaseProductName()
            + " is not supported by this extension");
   }
   return warnings;
}
 
Example #3
Source Project: liquibase-spatial   Author: lonnyj   File: SpatialSupportedPrecondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ValidationErrors validate(final Database database) {
   final ValidationErrors errors = new ValidationErrors();
   if (!(database instanceof DerbyDatabase || database instanceof H2Database
         || database instanceof MySQLDatabase || database instanceof OracleDatabase || database instanceof PostgresDatabase)) {
      errors.addError(database.getDatabaseProductName() + " is not supported by this extension");
   }
   return errors;
}
 
Example #4
Source Project: liquibase-spatial   Author: lonnyj   File: DropSpatialTableGeneratorOracleTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link DropSpatialTableGeneratorOracle#supports(CreateSpatialIndexStatement, Database)}
 */
@Test
public void testSupports() {
   final DropSpatialTableGeneratorOracle generator = new DropSpatialTableGeneratorOracle();
   final DropTableStatement statement = mock(DropTableStatement.class);
   assertTrue(generator.supports(statement, new OracleDatabase()));
   assertFalse(generator.supports(statement, new H2Database()));
}
 
Example #5
Source Project: liquibase-spatial   Author: lonnyj   File: CreateSpatialIndexGeneratorOracleTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests
 * {@link CreateSpatialIndexGeneratorOracle#supports(CreateSpatialIndexStatement, Database)}
 */
@Test
public void testSupports() {
   final CreateSpatialIndexGeneratorOracle generator = new CreateSpatialIndexGeneratorOracle();
   final CreateSpatialIndexStatement statement = mock(CreateSpatialIndexStatement.class);
   assertTrue(generator.supports(statement, new OracleDatabase()));
   assertFalse(generator.supports(statement, new H2Database()));
}
 
Example #6
Source Project: liquibase-spatial   Author: lonnyj   File: AddGeometryColumnGeneratorGeoDBTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Provides test data to {@link #testSupports(AddColumnStatement, Database, boolean)}.
 *
 * @return the test data.
 */
@DataProvider
public Object[][] supportsTestData() {
   final AddColumnStatement statement = new AddColumnStatement((String) null, null, null, null,
         null, null);
   return new Object[][] { new Object[] { statement, new DerbyDatabase(), true },
         new Object[] { statement, new H2Database(), true },
         new Object[] { statement, new OracleDatabase(), false }, };
}
 
Example #7
Source Project: liquibase-spatial   Author: lonnyj   File: DropGeometryColumnGeneratorGeoDBTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Provides test data to {@link #testSupports(DropColumnStatement, Database, boolean)}.
 * 
 * @return the test data.
 */
@DataProvider
public Object[][] supportsTestData() {
   final DropColumnStatement statement = new DropColumnStatement(null, null, null, null);
   return new Object[][] { new Object[] { statement, new DerbyDatabase(), true },
         new Object[] { statement, new H2Database(), true },
         new Object[] { statement, new OracleDatabase(), false }, };
}
 
Example #8
Source Project: keycloak   Author: keycloak   File: CustomLockDatabaseChangeLogGenerator.java    License: 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);
}
 
Example #9
Source Project: jweb-cms   Author: chifei   File: AbstractJdbcDatabase.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean supportsDropTableCascadeConstraints() {
    return ((this instanceof SQLiteDatabase) || (this instanceof SybaseDatabase) || (this instanceof
        SybaseASADatabase) || (this instanceof PostgresDatabase) || (this instanceof OracleDatabase));
}
 
Example #10
Source Project: liquibase-spatial   Author: lonnyj   File: DropSpatialIndexGeneratorOracle.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(final DropSpatialIndexStatement statement, final Database database) {
   return database instanceof OracleDatabase;
}
 
Example #11
Source Project: liquibase-spatial   Author: lonnyj   File: SpatialInsertGeneratorOracle.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that the <code>InsertStatement</code> has WKT or EWKT.
 */
@Override
public boolean supports(final InsertStatement statement, final Database database) {
   return database instanceof OracleDatabase;
}
 
Example #12
Source Project: liquibase-spatial   Author: lonnyj   File: CreateSpatialIndexGeneratorOracle.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(final CreateSpatialIndexStatement statement, final Database database) {
   return database instanceof OracleDatabase;
}
 
Example #13
Source Project: liquibase-spatial   Author: lonnyj   File: SpatialUpdateGeneratorOracle.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that the <code>UpdateStatement</code> has WKT or EWKT.
 */
@Override
public boolean supports(final UpdateStatement statement, final Database database) {
   return database instanceof OracleDatabase;
}
 
Example #14
Source Project: liquibase-spatial   Author: lonnyj   File: DropSpatialTableGeneratorOracle.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(final DropTableStatement statement, final Database database) {
   return database instanceof OracleDatabase;
}
 
Example #15
Source Project: liquibase-spatial   Author: lonnyj   File: CreateSpatialIndexGeneratorOracleTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Tests
 * {@link CreateSpatialIndexGeneratorOracle#generateSql(CreateSpatialIndexStatement, Database, SqlGeneratorChain)}
 * with a variety of inputs.
 * 
 * @param statement
 */
@Test(dataProvider = "generateSqlTestData")
public void testGenerateSql(final CreateSpatialIndexStatement statement) {
   final CreateSpatialIndexGeneratorOracle generator = new CreateSpatialIndexGeneratorOracle();
   final Database database = new OracleDatabase();
   final SqlGeneratorChain sqlGeneratorChain = mock(SqlGeneratorChain.class);
   final Sql[] result = generator.generateSql(statement, database, sqlGeneratorChain);
   assertNotNull(result);
   assertEquals(result.length, 3);

   // Verify the DELETE statement.
   final String deleteSql = result[0].toSql();
   String deletePattern = "(?i)DELETE FROM user_sdo_geom_metadata ";
   deletePattern += "WHERE table_name = '" + statement.getTableName().toUpperCase();
   deletePattern += "' AND column_name = '" + statement.getColumns()[0].toUpperCase();
   deletePattern += "'";
   assertTrue(deleteSql.matches(deletePattern), "'" + deleteSql
         + "' does not match the pattern '" + deletePattern + "'");
   assertNotNull(result[0].getAffectedDatabaseObjects());
   assertTrue(result[0].getAffectedDatabaseObjects().size() >= 1, result[0]
         .getAffectedDatabaseObjects().toString());

   // Verify the INSERT statement.
   final String insertSql = result[1].toSql();
   final String insertPattern = "(?i)INSERT INTO user_sdo_geom_metadata \\(.*\\) VALUES \\(.*\\)";
   assertTrue(insertSql.matches(insertPattern), "'" + insertSql
         + "' does not match the pattern '" + insertPattern + "'");
   assertNotNull(result[1].getAffectedDatabaseObjects());
   assertTrue(result[1].getAffectedDatabaseObjects().size() >= 1, result[0]
         .getAffectedDatabaseObjects().toString());

   // Verify the CREATE INDEX statement.
   final String createSql = result[2].toSql();
   String createPattern = "(?i)CREATE INDEX ";
   if (statement.getTableCatalogName() != null) {
      createPattern += statement.getTableCatalogName() + '.';
   } else if (statement.getTableSchemaName() != null) {
      createPattern += statement.getTableSchemaName() + '.';
   }
   createPattern += statement.getIndexName() + " ON ";
   if (statement.getTableCatalogName() != null) {
      createPattern += statement.getTableCatalogName() + '.';
   } else if (statement.getTableSchemaName() != null) {
      createPattern += statement.getTableSchemaName() + '.';
   }
   createPattern += statement.getTableName() + " \\(" + statement.getColumns()[0] + "\\)";
   createPattern += " INDEXTYPE IS mdsys.spatial_index";
   if (statement.getGeometryType() != null || statement.getTablespace() != null) {
      createPattern += " PARAMETERS \\('";
      if (statement.getGeometryType() != null) {
         createPattern += " ?layer_gtype=[a-zA-Z]+";
      }
      if (statement.getTablespace() != null) {
         createPattern += " ?tablespace=" + statement.getTablespace();
      }
      createPattern += "'\\)";
   }
   assertTrue(createSql.matches(createPattern), "'" + createSql
         + "' does not match the pattern '" + createPattern + "'");
   assertNotNull(result[2].getAffectedDatabaseObjects());
   assertTrue(result[2].getAffectedDatabaseObjects().size() > 1, result[0]
         .getAffectedDatabaseObjects().toString());
}