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);
}
}
}
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);
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
Aggregations