Package liquibase.database

Examples of liquibase.database.DatabaseConnection


        } catch (DatabaseException e) {
            //ok
        }
        database.commit();

        DatabaseConnection connection = DatabaseTestContext.getInstance().getConnection(url);
        database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDefaultSchemaName("lbcat2");
        liquibase = createLiquibase(tempFile.getName());
        try {
            liquibase.update(this.contexts);
View Full Code Here


    @Test
    public void generateStatements_willCallNativeSqlIfPossible() throws DatabaseException {
        ExampleAbstractSQLChange change = new ExampleAbstractSQLChange("SOME SQL");

        Database database = mock(Database.class);
        DatabaseConnection connection = mock(DatabaseConnection.class);
        when(database.getConnection()).thenReturn(connection);
        when(connection.nativeSQL("SOME SQL")).thenReturn("SOME NATIVE SQL");

        SqlStatement[] statements = change.generateStatements(database);
        assertEquals(1, statements.length);
        assertEquals("SOME NATIVE SQL", ((RawSqlStatement) statements[0]).getSql());

        //If there is an error, it falls back to passed SQL
        when(connection.nativeSQL("SOME SQL")).thenThrow(new DatabaseException("Testing exception"));
        statements = change.generateStatements(database);
        assertEquals(1, statements.length);
        assertEquals("SOME SQL", ((RawSqlStatement) statements[0]).getSql());
    }
View Full Code Here

        assertEquals("\"Test\"", databaseWithAllQuoting.escapeObjectName("Test", Table.class));
    }
   
    public void testUsingOracleSyntax()  {
        HsqlDatabase database = new HsqlDatabase();
        DatabaseConnection conn = mock(DatabaseConnection.class);
        when(conn.getURL()).thenReturn("jdbc:hsqldb:mem:testdb;sql.syntax_ora=true;sql.enforce_names=true");
        database.setConnection(conn );
        assertTrue("Using oracle syntax", database.isUsingOracleSyntax());
    }
View Full Code Here

        assertTrue("Using oracle syntax", database.isUsingOracleSyntax());
    }

    public void testNotUsingOracleSyntax()  {
        HsqlDatabase database = new HsqlDatabase();
        DatabaseConnection conn = mock(DatabaseConnection.class);
        when(conn.getURL()).thenReturn("jdbc:hsqldb:mem:testdb");
        database.setConnection(conn );
        assertFalse("Using oracle syntax", database.isUsingOracleSyntax());
    }
View Full Code Here

        assertEquals("/absolute/path/remains.xml", liquibase.getChangeLogFile());
    }

    @Test
    public void constructor_createDatabaseInstanceFromConnection() throws LiquibaseException {
        DatabaseConnection databaseConnection = mock(DatabaseConnection.class);
        Database database = mockDatabase;

        try {
            DatabaseFactory.setInstance(mock(DatabaseFactory.class));
            when(DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection)).thenReturn(database);
View Full Code Here

        return convertedSql;
    }

    public void resetAvailableDatabases() throws Exception {
        for (Database database : DatabaseTestContext.getInstance().getAvailableDatabases()) {
            DatabaseConnection connection = database.getConnection();
            Statement connectionStatement = ((JdbcConnection) connection).getUnderlyingConnection().createStatement();

            try {
                database.dropDatabaseObjects(CatalogAndSchema.DEFAULT);
            } catch (Throwable e) {
                throw new UnexpectedLiquibaseException("Error dropping objects for database "+database.getShortName(), e);
            }
            try {
                connectionStatement.executeUpdate("drop table " + database.escapeTableName(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName()));
            } catch (SQLException e) {
                ;
            }
            connection.commit();
            try {
                connectionStatement.executeUpdate("drop table " + database.escapeTableName(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()));
            } catch (SQLException e) {
                ;
            }
            connection.commit();

            if (database.supportsSchemas()) {
                database.dropDatabaseObjects(new CatalogAndSchema(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA));
                connection.commit();

                try {
                    connectionStatement.executeUpdate("drop table " + database.escapeTableName(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA, database.getDatabaseChangeLogLockTableName()));
                } catch (SQLException e) {
                    //ok
                }
                connection.commit();
                try {
                    connectionStatement.executeUpdate("drop table " + database.escapeTableName(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA, database.getDatabaseChangeLogTableName()));
                } catch (SQLException e) {
                    //ok
                }
                connection.commit();
            }

            List<? extends SqlStatement> setupStatements = setupStatements(database);
            if (setupStatements != null) {
                for (SqlStatement statement : setupStatements) {
View Full Code Here

TOP

Related Classes of liquibase.database.DatabaseConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.