Search in sources :

Example 36 with OracleDatabase

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

the class ViewSnapshotGenerator method addTo.

@Override
protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException {
    if (!snapshot.getSnapshotControl().shouldInclude(View.class)) {
        return;
    }
    if (foundObject instanceof Schema) {
        Schema schema = (Schema) foundObject;
        Database database = snapshot.getDatabase();
        List<CachedRow> viewsMetadataRs = null;
        try {
            viewsMetadataRs = ((JdbcDatabaseSnapshot) snapshot).getMetaDataFromCache().getViews(((AbstractJdbcDatabase) database).getJdbcCatalogName(schema), ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema), null);
            for (CachedRow row : viewsMetadataRs) {
                CatalogAndSchema catalogAndSchema = ((AbstractJdbcDatabase) database).getSchemaFromJdbcInfo(row.getString("TABLE_CAT"), row.getString("TABLE_SCHEM"));
                View view = new View();
                view.setName(row.getString("TABLE_NAME"));
                view.setSchema(new Schema(catalogAndSchema.getCatalogName(), catalogAndSchema.getSchemaName()));
                view.setRemarks(row.getString("REMARKS"));
                String definition = StringUtil.standardizeLineEndings(row.getString("OBJECT_BODY"));
                view.setDefinition(definition);
                if (database instanceof OracleDatabase) {
                    view.setAttribute("editioning", "Y".equals(row.getString("EDITIONING_VIEW")));
                }
                schema.addDatabaseObject(view);
            }
        } catch (SQLException e) {
            throw new DatabaseException(e);
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CachedRow(liquibase.snapshot.CachedRow) SQLException(java.sql.SQLException) Schema(liquibase.structure.core.Schema) CatalogAndSchema(liquibase.CatalogAndSchema) OracleDatabase(liquibase.database.core.OracleDatabase) InformixDatabase(liquibase.database.core.InformixDatabase) Database(liquibase.database.Database) MariaDBDatabase(liquibase.database.core.MariaDBDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) AbstractJdbcDatabase(liquibase.database.AbstractJdbcDatabase) JdbcDatabaseSnapshot(liquibase.snapshot.JdbcDatabaseSnapshot) CatalogAndSchema(liquibase.CatalogAndSchema) View(liquibase.structure.core.View) AbstractJdbcDatabase(liquibase.database.AbstractJdbcDatabase) DatabaseException(liquibase.exception.DatabaseException)

Example 37 with OracleDatabase

use of liquibase.database.core.OracleDatabase 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);
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) DatabaseFactory(liquibase.database.DatabaseFactory) OracleDatabase(liquibase.database.core.OracleDatabase) Database(liquibase.database.Database) MockDatabase(liquibase.database.core.MockDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) Test(org.junit.Test)

Example 38 with OracleDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithOracleDatabase.

@Test
public void testAutoIncrementStartWithOracleDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            MockDatabaseConnection conn = new MockDatabaseConnection();
            database.setConnection(conn);
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, null));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT AS IDENTITY (START WITH 0))", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) 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) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 39 with OracleDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementOracleDatabase.

@Test
public void testAutoIncrementOracleDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            MockDatabaseConnection conn = new MockDatabaseConnection();
            database.setConnection(conn);
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) 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) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 40 with OracleDatabase

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

the class AlterSequenceGeneratorTest method testAlterSequenceDatabase.

// @Before
// public void setUpMocks() throws DatabaseException {
// 
// mockedUnsupportedMinMaxSequenceConnection = mock(DatabaseConnection.class);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseMajorVersion()).thenReturn(1);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseMinorVersion()).thenReturn(3);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseProductVersion()).thenReturn("1.3.174 (2013-10-19)");
// 
// mockedSupportedMinMaxSequenceConnection = mock(DatabaseConnection.class);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseMajorVersion()).thenReturn(1);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseMinorVersion()).thenReturn(3);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseProductVersion()).thenReturn("1.3.175 (2014-01-18)");
// }
@Test
public void testAlterSequenceDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            AlterSequenceStatement statement = createSampleSqlStatement();
            statement.setCacheSize(BigInteger.valueOf(3000L));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("ALTER SEQUENCE CATALOG_NAME.SEQUENCE_NAME CACHE 3000", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) Database(liquibase.database.Database) CockroachDatabase(liquibase.database.core.CockroachDatabase) AlterSequenceStatement(liquibase.statement.core.AlterSequenceStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Aggregations

OracleDatabase (liquibase.database.core.OracleDatabase)40 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)17 Test (org.junit.Test)17 Sql (liquibase.sql.Sql)16 MySQLDatabase (liquibase.database.core.MySQLDatabase)15 Database (liquibase.database.Database)11 PostgresDatabase (liquibase.database.core.PostgresDatabase)11 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)10 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)10 H2Database (liquibase.database.core.H2Database)9 SybaseDatabase (liquibase.database.core.SybaseDatabase)8 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)8 ArrayList (java.util.ArrayList)7 HsqlDatabase (liquibase.database.core.HsqlDatabase)7 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)7 CreateTableStatement (liquibase.statement.core.CreateTableStatement)7 DerbyDatabase (liquibase.database.core.DerbyDatabase)6 Change (liquibase.change.Change)5 MockDatabaseConnection (liquibase.database.MockDatabaseConnection)5 ColumnConfig (liquibase.change.ColumnConfig)4