liquibase.database.DatabaseConnection Java Examples

The following examples show how to use liquibase.database.DatabaseConnection. 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-percona   Author: adangel   File: AbstractPerconaChangeTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() {
    System.setProperty(Configuration.LIQUIBASE_PASSWORD, "root");

    database = new MySQLDatabase();
    database.setLiquibaseSchemaName("testdb");
    DatabaseConnection conn = new MockDatabaseConnection("jdbc:mysql://[email protected]:3306/testdb",
            "[email protected]");
    database.setConnection(conn);
    JdbcExecutor executor = new JdbcExecutor();
    executor.setDatabase(database);
    ExecutorService.getInstance().setExecutor(database, executor);

    PTOnlineSchemaChangeStatement.available = true;
    PTOnlineSchemaChangeStatement.perconaToolkitVersion = null;
    System.setProperty(Configuration.FAIL_IF_NO_PT, "false");
    System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "false");
    System.setProperty(Configuration.SKIP_CHANGES, "");

    PerconaForeignKeyService.getInstance().disable();

    setupChange(change);
}
 
Example #2
Source Project: liquibase-spatial   Author: lonnyj   File: GeometryColumnsUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@DataProvider
public Object[][] geometryColumnsExistsTestData() throws SQLException {
   // Create an H2 database instance without geometry_columns table.
   final Database noGeometryColumnsDatabase = new H2Database();
   noGeometryColumnsDatabase.setConnection(new JdbcConnection(DriverManager
         .getConnection("jdbc:h2:mem:target/noGeometryColumns")));

   final Database geometryColumnsDatabase = new H2Database();
   Connection connection = DriverManager
         .getConnection("jdbc:h2:mem:target/geometryColumns");
   DatabaseConnection conn = new JdbcConnection(connection);
   geometryColumnsDatabase.setConnection(conn);

   Statement statement = connection.createStatement();
   statement
         .execute("CREATE TABLE geometry_columns (f_table_schema VARCHAR(128), "
               + "f_table_name VARCHAR(128), f_geometry_column VARCHAR(128), coord_dimension INT, "
               + "srid INT, type VARCHAR(30))");
   statement.close();
   return new Object[][] {
         new Object[] { noGeometryColumnsDatabase, false },
         new Object[] { geometryColumnsDatabase, true } };
}
 
Example #3
Source Project: activiti6-boot2   Author: dingziyang   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  try {
    FormEngine formEngine = FormEngines.getDefaultFormEngine();
    DataSource dataSource = formEngine.getFormEngineConfiguration().getDataSource();
    
    DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
    database.setDatabaseChangeLogTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName());
    database.setDatabaseChangeLogLockTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName());
    
    if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseSchema())) {
      database.setDefaultSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema());
      database.setLiquibaseSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema());
    }
    
    if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseCatalog())) {
      database.setDefaultCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog());
      database.setLiquibaseCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog());
    }

    Liquibase liquibase = new Liquibase("org/activiti/form/db/liquibase/activiti-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
    liquibase.dropAll();
    
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example #4
Source Project: activiti6-boot2   Author: dingziyang   File: FormEngineConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public void initDbSchema() {
  try {
    DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
    database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName());
    database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName());
    
    if (StringUtils.isNotEmpty(databaseSchema)) {
      database.setDefaultSchemaName(databaseSchema);
      database.setLiquibaseSchemaName(databaseSchema);
    }
    
    if (StringUtils.isNotEmpty(databaseCatalog)) {
      database.setDefaultCatalogName(databaseCatalog);
      database.setLiquibaseCatalogName(databaseCatalog);
    }

    Liquibase liquibase = new Liquibase("org/activiti/form/db/liquibase/activiti-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database);

    if (DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
      logger.debug("Dropping and creating schema FORM");
      liquibase.dropAll();
      liquibase.update("form");
    } else if (DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
      logger.debug("Updating schema FORM");
      liquibase.update("form");
    } else if (DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
      logger.debug("Validating schema FORM");
      liquibase.validate();
    }
  } catch (Exception e) {
    throw new ActivitiFormException("Error initialising form data schema", e);
  }
}
 
Example #5
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void dropSchema() throws Exception {
    System.out.println("Dropping schema");
    DatabaseConnection databaseConnection = createDbConnection();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection);

    Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog.xml", new ClassLoaderResourceAccessor(), database);
    liquibase.dropAll();

    closeDatabase(database, databaseConnection);
}
 
Example #6
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static DatabaseConnection createDbConnection() throws Exception {
    Properties properties = new Properties();
    properties.load(DbScriptUtil.class.getClassLoader().getResourceAsStream("META-INF/activiti-admin/TEST-db.properties"));
    Connection connection = DriverManager.getConnection(properties.getProperty("datasource.url"),
            properties.getProperty("datasource.username"), properties.getProperty("datasource.password"));
    DatabaseConnection databaseConnection = new JdbcConnection(connection);
    return databaseConnection;
}
 
Example #7
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static void closeDatabase(Database database, DatabaseConnection databaseConnection) {
    try {
        database.close();
        databaseConnection.close();
    } catch (Exception e) {
        System.out.println("Error closing db connection " + e.getMessage());
    }
}
 
Example #8
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void dropSchema() throws Exception {
    System.out.println("Dropping schema");
    DatabaseConnection databaseConnection = createDbConnection();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection);
    
    Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog-onpremise.xml", new ClassLoaderResourceAccessor(), database);
    liquibase.dropAll();
    
    closeDatabase(database, databaseConnection);
}
 
Example #9
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static DatabaseConnection createDbConnection() throws Exception {
    Properties properties = new Properties();
    properties.load(DbScriptUtil.class.getClassLoader().getResourceAsStream("META-INF/activiti-app-test/TEST-db.properties"));
    Connection connection = DriverManager.getConnection(properties.getProperty("datasource.url"), 
            properties.getProperty("datasource.username"), properties.getProperty("datasource.password"));
    DatabaseConnection databaseConnection = new JdbcConnection(connection);
    return databaseConnection;
}
 
Example #10
Source Project: activiti6-boot2   Author: dingziyang   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static void closeDatabase(Database database, DatabaseConnection databaseConnection) {
    try {
        database.close();
        databaseConnection.close();
    } catch (Exception e) {
        System.out.println("Error closing db connection " + e.getMessage());
    }
}
 
Example #11
Source Project: activiti6-boot2   Author: dingziyang   File: DmnEngineConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public void initDbSchema() {
  try {
    DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
    database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
    database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
    
    if (StringUtils.isNotEmpty(databaseSchema)) {
      database.setDefaultSchemaName(databaseSchema);
      database.setLiquibaseSchemaName(databaseSchema);
    }
    
    if (StringUtils.isNotEmpty(databaseCatalog)) {
      database.setDefaultCatalogName(databaseCatalog);
      database.setLiquibaseCatalogName(databaseCatalog);
    }

    Liquibase liquibase = new Liquibase("org/activiti/dmn/db/liquibase/activiti-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database);

    if (DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
      logger.debug("Dropping and creating schema DMN");
      liquibase.dropAll();
      liquibase.update("dmn");
    } else if (DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
      logger.debug("Updating schema DMN");
      liquibase.update("dmn");
    } else if (DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
      logger.debug("Validating schema DMN");
      liquibase.validate();
    }
  } catch (Exception e) {
    throw new ActivitiDmnException("Error initialising dmn data model");
  }
}
 
Example #12
Source Project: activiti6-boot2   Author: dingziyang   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  try {
    DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine();
    DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource();
    
    DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
    database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName());
    database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName());
    
    if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) {
      database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
      database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
    }
    
    if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) {
      database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
      database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
    }

    Liquibase liquibase = new Liquibase("org/activiti/dmn/db/liquibase/activiti-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
    liquibase.dropAll();
    
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example #13
Source Project: flowable-engine   Author: flowable   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine();
        DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource();

        DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
        database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

        if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) {
            database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
            database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema());
        }

        if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) {
            database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
            database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog());
        }

        Liquibase liquibase = new Liquibase("org/flowable/dmn/db/liquibase/flowable-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.dropAll();
        liquibase.getDatabase().close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #14
Source Project: flowable-engine   Author: flowable   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void dropSchema() throws Exception {
    System.out.println("Dropping schema");
    DatabaseConnection databaseConnection = createDbConnection();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection);

    Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog.xml", new ClassLoaderResourceAccessor(), database);
    liquibase.dropAll();

    closeDatabase(database, databaseConnection);
}
 
Example #15
Source Project: flowable-engine   Author: flowable   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static DatabaseConnection createDbConnection() throws Exception {
    Properties properties = new Properties();
    properties.load(DbScriptUtil.class.getClassLoader().getResourceAsStream("META-INF/flowable-admin/TEST-db.properties"));
    Connection connection = DriverManager.getConnection(properties.getProperty("spring.datasource.url"),
            properties.getProperty("spring.datasource.username"), properties.getProperty("spring.datasource.password"));
    DatabaseConnection databaseConnection = new JdbcConnection(connection);
    return databaseConnection;
}
 
Example #16
Source Project: flowable-engine   Author: flowable   File: DbScriptUtil.java    License: Apache License 2.0 5 votes vote down vote up
protected static void closeDatabase(Database database, DatabaseConnection databaseConnection) {
    try {
        database.close();
        databaseConnection.close();
    } catch (Exception e) {
        System.out.println("Error closing db connection " + e.getMessage());
    }
}
 
Example #17
Source Project: flowable-engine   Author: flowable   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        FormEngine formEngine = FormEngines.getDefaultFormEngine();
        DataSource dataSource = formEngine.getFormEngineConfiguration().getDataSource();

        DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDatabaseChangeLogTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
        database.setDatabaseChangeLogLockTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

        if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseSchema())) {
            database.setDefaultSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema());
            database.setLiquibaseSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema());
        }

        if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseCatalog())) {
            database.setDefaultCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog());
            database.setLiquibaseCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog());
        }

        Liquibase liquibase = new Liquibase("org/flowable/form/db/liquibase/flowable-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.dropAll();
        liquibase.getDatabase().close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #18
Source Project: flowable-engine   Author: flowable   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        ContentEngine contentEngine = ContentEngines.getDefaultContentEngine();
        DataSource dataSource = contentEngine.getContentEngineConfiguration().getDataSource();

        DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDatabaseChangeLogTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
        database.setDatabaseChangeLogLockTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

        if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseSchema())) {
            database.setDefaultSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
            database.setLiquibaseSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema());
        }

        if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseCatalog())) {
            database.setDefaultCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
            database.setLiquibaseCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog());
        }

        Liquibase liquibase = new Liquibase("org/flowable/content/db/liquibase/flowable-content-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.dropAll();
        liquibase.getDatabase().close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #19
Source Project: flowable-engine   Author: flowable   File: DbSchemaDrop.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        EventRegistryEngine eventRegistryEngine = EventRegistryEngines.getDefaultEventRegistryEngine();
        EventRegistryEngineConfiguration eventRegistryEngineConfiguration = eventRegistryEngine.getEventRegistryEngineConfiguration();
        DataSource dataSource = eventRegistryEngineConfiguration.getDataSource();

        DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDatabaseChangeLogTableName(EventRegistryEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
        database.setDatabaseChangeLogLockTableName(EventRegistryEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());

        if (StringUtils.isNotEmpty(eventRegistryEngineConfiguration.getDatabaseSchema())) {
            database.setDefaultSchemaName(eventRegistryEngineConfiguration.getDatabaseSchema());
            database.setLiquibaseSchemaName(eventRegistryEngineConfiguration.getDatabaseSchema());
        }

        if (StringUtils.isNotEmpty(eventRegistryEngineConfiguration.getDatabaseCatalog())) {
            database.setDefaultCatalogName(eventRegistryEngineConfiguration.getDatabaseCatalog());
            database.setLiquibaseCatalogName(eventRegistryEngineConfiguration.getDatabaseCatalog());
        }

        Liquibase liquibase = new Liquibase("org/flowable/eventregistry/db/liquibase/flowable-eventregistry-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.dropAll();
        liquibase.getDatabase().close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #20
Source Project: attic-polygene-java   Author: apache   File: LiquibaseService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException
{
    config.refresh();
    DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() );
    return new Liquibase( config.get().changeLog().get(),
                          new ClassLoaderResourceAccessor(),
                          dbConnection );
}
 
Example #21
Source Project: liquibase-percona   Author: adangel   File: PTOnlineSchemaChangeStatementTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
    System.setProperty(Configuration.LIQUIBASE_PASSWORD, "root");

    database = new MySQLDatabase();
    database.setLiquibaseSchemaName("testdb");
    DatabaseConnection conn = new MockDatabaseConnection("jdbc:mysql://[email protected]:3306/testdb",
            "[email protected]");
    database.setConnection(conn);
}
 
Example #22
Source Project: liquibase-spatial   Author: lonnyj   File: GeometryColumnsUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the given table is in <code>GEOMETRY_COLUMNS</code> and,
 * therefore, has a geometry column.
 * 
 * @param database
 *           the database to query.
 * @param schemaName
 *           the schema name.
 * @param tableName
 *           the table name to check.
 * @return <code>true</code> if the table has a geometry column.
 */
public static boolean hasGeometryColumn(final Database database,
      final String schemaName, final String tableName) {
   boolean isSpatialColumn = false;
   Statement jdbcStatement = null;
   try {
      if (geometryColumnsExists(database)) {
         final String query = "SELECT * FROM geometry_columns WHERE f_table_schema = '"
               + (schemaName == null ? database.getDefaultSchemaName()
                     : schemaName)
               + "' AND f_table_name = '"
               + tableName
               + "'";
         final DatabaseConnection databaseConnection = database
               .getConnection();
         final JdbcConnection jdbcConnection = (JdbcConnection) databaseConnection;
         jdbcStatement = jdbcConnection.getUnderlyingConnection()
               .createStatement();
         final ResultSet rs = jdbcStatement.executeQuery(query);
         isSpatialColumn = rs.next();
      }
   } catch (final SQLException e) {
      throw new UnexpectedLiquibaseException(
            "Failed to determine if the table has a geometry column", e);
   } finally {
      if (jdbcStatement != null) {
         try {
            jdbcStatement.close();
         } catch (final SQLException ignore) {
         }
      }
   }
   return isSpatialColumn;
}
 
Example #23
Source Project: liquibase-spatial   Author: lonnyj   File: GeometryColumnsUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the given column is in <code>GEOMETRY_COLUMNS</code>.
 * 
 * @param database
 *           the database to query.
 * @param schemaName
 *           the schema name.
 * @param tableName
 *           the table name.
 * @param columnName
 *           the column name.
 * @return <code>true</code> if the column is a geometry column.
 */
public static boolean isGeometryColumn(final Database database,
      final String schemaName, final String tableName,
      final String columnName) {
   boolean isSpatialColumn = false;
   Statement jdbcStatement = null;
   try {
      if (geometryColumnsExists(database)) {
         final String query = "SELECT * FROM geometry_columns WHERE f_table_schema = '"
               + (schemaName == null ? database.getDefaultSchemaName()
                     : schemaName)
               + "' AND f_table_name = '"
               + tableName
               + "' AND upper(f_geometry_column) = '"
               + columnName.toUpperCase() + "'";
         final DatabaseConnection databaseConnection = database
               .getConnection();
         final JdbcConnection jdbcConnection = (JdbcConnection) databaseConnection;
         jdbcStatement = jdbcConnection.getUnderlyingConnection()
               .createStatement();
         final ResultSet rs = jdbcStatement.executeQuery(query);
         isSpatialColumn = rs.next();
      }
   } catch (final SQLException e) {
      throw new UnexpectedLiquibaseException(
            "Failed to determine if the column to be dropped is a geometry column",
            e);
   } finally {
      if (jdbcStatement != null) {
         try {
            jdbcStatement.close();
         } catch (final SQLException ignore) {
         }
      }
   }
   return isSpatialColumn;
}
 
Example #24
Source Project: liquibase-spatial   Author: lonnyj   File: LiquibasePostgreSQLIT.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see liquibase.ext.spatial.LiquibaseIT#createLiquibase(java.lang.String,
 *      liquibase.resource.ResourceAccessor, liquibase.database.DatabaseConnection)
 */
@Override
protected Liquibase createLiquibase(final String changeLogFile,
      final ResourceAccessor resourceAccessor, final DatabaseConnection databaseConnection)
      throws LiquibaseException {
   final Liquibase liquibase = super.createLiquibase(changeLogFile, resourceAccessor,
         databaseConnection);
   liquibase.getDatabase().setDefaultSchemaName(getUserName());
   return liquibase;
}
 
Example #25
Source Project: liquibase-spatial   Author: lonnyj   File: LiquibaseH2AsSAIT.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see liquibase.ext.spatial.LiquibaseIT#createLiquibase(java.lang.String,
 *      liquibase.resource.ResourceAccessor, liquibase.database.DatabaseConnection)
 */
@Override
protected Liquibase createLiquibase(final String changeLogFile,
      final ResourceAccessor resourceAccessor, final DatabaseConnection databaseConnection)
      throws LiquibaseException {
   final Liquibase liquibase = super.createLiquibase(changeLogFile, resourceAccessor,
         databaseConnection);
   liquibase.getDatabase().setDefaultSchemaName(getUserName());
   return liquibase;
}
 
Example #26
Source Project: liquibase-impala   Author: eselyavka   File: HiveMetastoreDatabase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCorrectDatabaseImplementation(DatabaseConnection databaseConnection) throws DatabaseException {
    return databaseProductName.equalsIgnoreCase(databaseConnection.getDatabaseProductName());
}
 
Example #27
Source Project: liquibase-impala   Author: eselyavka   File: HiveMetastoreDatabase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setConnection(DatabaseConnection conn) {
    setReservedWords();
    super.setConnection(conn);
}
 
Example #28
Source Project: flowable-engine   Author: flowable   File: LiquibaseBasedSchemaManager.java    License: Apache License 2.0 4 votes vote down vote up
protected Liquibase createLiquibaseInstance(LiquibaseDatabaseConfiguration databaseConfiguration) throws SQLException {
    Connection jdbcConnection = null;
    boolean closeConnection = false;
    try {
        CommandContext commandContext = Context.getCommandContext();
        if (commandContext == null) {
            jdbcConnection = databaseConfiguration.getDataSource().getConnection();
            closeConnection = true;
        } else {
            jdbcConnection = commandContext.getSession(DbSqlSession.class).getSqlSession().getConnection();
        }

        // A commit is needed here, because one of the things that Liquibase does when acquiring its lock
        // is doing a rollback, which removes all changes done so far.
        // For most databases, this is not a problem as DDL statements are not transactional.
        // However for some (e.g. sql server), this would remove all previous statements, which is not wanted,
        // hence the extra commit here.
        if (!jdbcConnection.getAutoCommit()) {
            jdbcConnection.commit();
        }

        DatabaseConnection connection = new JdbcConnection(jdbcConnection);
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        database.setDatabaseChangeLogTableName(changeLogPrefix + database.getDatabaseChangeLogTableName());
        database.setDatabaseChangeLogLockTableName(changeLogPrefix + database.getDatabaseChangeLogLockTableName());

        String databaseSchema = databaseConfiguration.getDatabaseSchema();
        if (StringUtils.isNotEmpty(databaseSchema)) {
            database.setDefaultSchemaName(databaseSchema);
            database.setLiquibaseSchemaName(databaseSchema);
        }

        String databaseCatalog = databaseConfiguration.getDatabaseCatalog();
        if (StringUtils.isNotEmpty(databaseCatalog)) {
            database.setDefaultCatalogName(databaseCatalog);
            database.setLiquibaseCatalogName(databaseCatalog);
        }

        return new Liquibase(changeLogFile, new ClassLoaderResourceAccessor(), database);

    } catch (Exception e) {
        // We only close the connection if an exception occurred, otherwise the Liquibase instance cannot be used
        if (jdbcConnection != null && closeConnection) {
            jdbcConnection.close();
        }
        throw new FlowableException("Error creating " + context + " liquibase instance", e);
    }
}
 
Example #29
Source Project: liquibase-percona   Author: adangel   File: DatabaseConnectionUtil.java    License: Apache License 2.0 4 votes vote down vote up
public DatabaseConnectionUtil(DatabaseConnection connection) {
    this.connection = connection;
}
 
Example #30
Source Project: keycloak   Author: keycloak   File: PostgresPlusDatabase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
    return POSTGRESPLUS_PRODUCT_NAME.equalsIgnoreCase(conn.getDatabaseProductName());
}