Search in sources :

Example 11 with OracleDatabase

use of liquibase.database.core.OracleDatabase in project liquibase by liquibase.

the class ChangeMetaDataTest method getRequiredParameters.

@Test
public void getRequiredParameters() {
    HashSet<ChangeParameterMetaData> parameters = new HashSet<ChangeParameterMetaData>();
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "noneRequired", "x", null, null, null, Integer.class, new String[] { "none" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "allRequired", "x", null, null, null, Integer.class, new String[] { "all" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "h2Required", "x", null, null, null, Integer.class, new String[] { "h2" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "oracleRequired", "x", null, null, null, Integer.class, new String[] { "oracle" }, null, null, null));
    ChangeMetaData changeMetaData = new ChangeMetaData("x", "y", 1, null, null, parameters);
    assertSetsEqual(new String[] { "allRequired", "h2Required" }, changeMetaData.getRequiredParameters(new H2Database()).keySet());
    assertSetsEqual(new String[] { "allRequired", "oracleRequired" }, changeMetaData.getRequiredParameters(new OracleDatabase()).keySet());
    assertSetsEqual(new String[] { "allRequired" }, changeMetaData.getRequiredParameters(new MySQLDatabase()).keySet());
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) H2Database(liquibase.database.core.H2Database) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with OracleDatabase

use of liquibase.database.core.OracleDatabase in project liquibase by liquibase.

the class ChangeMetaDataTest method getOptionalParameters.

@Test
public void getOptionalParameters() {
    HashSet<ChangeParameterMetaData> parameters = new HashSet<ChangeParameterMetaData>();
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "noneRequired", "x", null, null, null, Integer.class, new String[] { "none" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "allRequired", "x", null, null, null, Integer.class, new String[] { "all" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "h2Required", "x", null, null, null, Integer.class, new String[] { "h2" }, null, null, null));
    parameters.add(new ChangeParameterMetaData(new ExampleAbstractChange(), "oracleRequired", "x", null, null, null, Integer.class, new String[] { "oracle" }, null, null, null));
    ChangeMetaData changeMetaData = new ChangeMetaData("x", "y", 1, null, null, parameters);
    assertSetsEqual(new String[] { "noneRequired", "oracleRequired" }, changeMetaData.getOptionalParameters(new H2Database()).keySet());
    assertSetsEqual(new String[] { "noneRequired", "h2Required" }, changeMetaData.getOptionalParameters(new OracleDatabase()).keySet());
    assertSetsEqual(new String[] { "noneRequired", "h2Required", "oracleRequired" }, changeMetaData.getOptionalParameters(new MySQLDatabase()).keySet());
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) H2Database(liquibase.database.core.H2Database) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with OracleDatabase

use of liquibase.database.core.OracleDatabase in project liquibase by liquibase.

the class ValidatingVisitorPreConditionsTest method testPreconditionForOracleOnOracleWithChangeLog.

/**
     * Test against oracle, but I don't know for sure if the precondition is really
     * validated because oracle supports creating sequences.
     */
@Test
public void testPreconditionForOracleOnOracleWithChangeLog() {
    // create the pre condition
    PreconditionContainer preCondition = new PreconditionContainer();
    preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
    DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
    dbmsPrecondition.setType("oracle");
    preCondition.addNestedPrecondition(dbmsPrecondition);
    changeSet1.setPreconditions(preCondition);
    OracleDatabase oracleDb = new OracleDatabase() {

        @Override
        public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
            return new ArrayList<RanChangeSet>();
        }

        @Override
        public void rollback() throws DatabaseException {
        //super.rollback();
        }
    };
    String[] empty = {};
    boolean exceptionThrown = false;
    try {
        changeLog.validate(oracleDb, empty);
    } catch (LiquibaseException ex) {
        exceptionThrown = true;
    }
    assertFalse(exceptionThrown);
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) PreconditionContainer(liquibase.precondition.core.PreconditionContainer) DBMSPrecondition(liquibase.precondition.core.DBMSPrecondition) ArrayList(java.util.ArrayList) LiquibaseException(liquibase.exception.LiquibaseException) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 14 with OracleDatabase

use of liquibase.database.core.OracleDatabase in project liquibase by liquibase.

the class CreateTableGeneratorTest method testWithColumnWithDefaultValue.

@Test
public void testWithColumnWithDefaultValue() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("java.sql.Types.TIMESTAMP", database), new ColumnConfig().setDefaultValue("null").getDefaultValueObject());
            if (shouldBeImplementation(database)) {
                assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME TIMESTAMP DEFAULT null)", this.generatorUnderTest.generateSql(statement, database, null)[0].toSql());
            }
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) ColumnConfig(liquibase.change.ColumnConfig) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 15 with OracleDatabase

use of liquibase.database.core.OracleDatabase in project liquibase by liquibase.

the class InsertOrUpdateGeneratorOracleTest method ContainsInsertStatement.

@Test
public void ContainsInsertStatement() {
    OracleDatabase database = new OracleDatabase();
    InsertOrUpdateGeneratorOracle generator = new InsertOrUpdateGeneratorOracle();
    InsertOrUpdateStatement statement = new InsertOrUpdateStatement("mycatalog", "myschema", "mytable", "pk_col1");
    statement.addColumnValue("pk_col1", "value1");
    statement.addColumnValue("col2", "value2");
    Sql[] sql = generator.generateSql(statement, database, null);
    String theSql = sql[0].toSql();
    assertTrue(theSql.contains("INSERT INTO mycatalog.mytable (pk_col1, col2) VALUES ('value1', 'value2');"));
    assertTrue(theSql.contains("UPDATE mycatalog.mytable"));
    String[] sqlLines = theSql.split("\n");
    int lineToCheck = 0;
    assertEquals("DECLARE", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("v_reccount NUMBER := 0;", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("BEGIN", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("SELECT COUNT(*) INTO v_reccount FROM mycatalog.mytable WHERE pk_col1 = 'value1';", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("IF v_reccount = 0 THEN", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("INSERT INTO mycatalog.mytable (pk_col1, col2) VALUES ('value1', 'value2');", sqlLines[lineToCheck]);
    lineToCheck++;
    assertEquals("ELSIF v_reccount = 1 THEN", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("UPDATE mycatalog.mytable SET col2 = 'value2' WHERE pk_col1 = 'value1';", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("END IF;", sqlLines[lineToCheck].trim());
    lineToCheck++;
    assertEquals("END;", sqlLines[lineToCheck].trim());
/*
DECLARE
  v_prodcount NUMBER := 0;
BEGIN
  -- Check if product with this name already exists
  SELECT COUNT (*)
  INTO   v_prodcount
   FROM books WHERE isbn = 12345678;
  -- Product does not exist
  IF v_prodcount = 0 THEN
   -- Insert row into PRODUCT based on arguments passed
   INSERT INTO books
   VALUES
         ( 12345678,
           98765432,
           'Working with Liquibase');
  -- Product with this name already exists
  ELSIF v_prodcount = 1 THEN
    -- Update the existing product with values
    -- passed as arguments
    UPDATE books
    SET    author_id = 98765432,
           title = 'Working with liquibase'
    WHERE  isbn = 12345678;
  END IF;
END;*/
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Aggregations

OracleDatabase (liquibase.database.core.OracleDatabase)31 Test (org.junit.Test)11 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)9 DB2Database (liquibase.database.core.DB2Database)8 MySQLDatabase (liquibase.database.core.MySQLDatabase)7 Change (liquibase.change.Change)6 ArrayList (java.util.ArrayList)5 Database (liquibase.database.Database)5 H2Database (liquibase.database.core.H2Database)4 Sql (liquibase.sql.Sql)4 HashSet (java.util.HashSet)3 PostgresDatabase (liquibase.database.core.PostgresDatabase)3 DatabaseException (liquibase.exception.DatabaseException)3 LiquibaseException (liquibase.exception.LiquibaseException)3 IOException (java.io.IOException)2 CatalogAndSchema (liquibase.CatalogAndSchema)2 ColumnConfig (liquibase.change.ColumnConfig)2 AddPrimaryKeyChange (liquibase.change.core.AddPrimaryKeyChange)2 AddUniqueConstraintChange (liquibase.change.core.AddUniqueConstraintChange)2 CreateViewChange (liquibase.change.core.CreateViewChange)2