コード例 #1
0
ファイル: ResultSetCache.java プロジェクト: NeosIT/liquibase
 public String createSchemaKey(Database database) {
   if (!database.supportsCatalogs() && !database.supportsSchemas()) {
     return "all";
   } else if (database.supportsCatalogs() && database.supportsSchemas()) {
     return (catalog + "." + schema).toLowerCase();
   } else {
     if (catalog == null && schema != null) {
       return schema.toLowerCase();
     } else {
       if (catalog == null) {
         return "all";
       }
       return catalog.toLowerCase();
     }
   }
 }
コード例 #2
0
  protected void dropSequenceIfExists(String schemaName, String sequenceName, Database database)
      throws SQLException {
    if (schemaName != null && !database.supportsSchemas()) {
      return;
    }

    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }

    try {
      new JdbcTemplate(database).execute(new DropSequenceStatement(schemaName, sequenceName));

      if (!database.getAutoCommitMode()) {
        database.getConnection().commit();
      }

    } catch (JDBCException e) {
      //            System.out.println("Error dropping sequence
      // "+database.escapeSequenceName(schemaName, sequenceName));
      //            e.printStackTrace();
      if (!database.getConnection().getAutoCommit()) {
        database.getConnection().rollback();
      }
    }
    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }
  }
コード例 #3
0
  protected void dropTableIfExists(String schemaName, String tableName, Database database)
      throws SQLException {
    if (schemaName != null && !database.supportsSchemas()) {
      return;
    }

    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }

    try {
      boolean cascade = false;
      if (database instanceof PostgresDatabase) {
        cascade = true;
      }
      new JdbcTemplate(database).execute(new DropTableStatement(schemaName, tableName, cascade));

      if (!database.getAutoCommitMode()) {
        database.getConnection().commit();
      }

    } catch (JDBCException e) {
      //            System.out.println("Error dropping table "+database.escapeTableName(schemaName,
      // tableName)+" on "+database);
      //            e.printStackTrace();
      if (!database.getConnection().getAutoCommit()) {
        database.getConnection().rollback();
      }
    }
  }
コード例 #4
0
  protected void dropViewIfExists(String schemaName, String viewName, Database database)
      throws SQLException {
    if (schemaName != null && !database.supportsSchemas()) {
      return;
    }

    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }

    String schema = "";
    if (schemaName != null) {
      schema = schemaName + ".";
    }

    try {
      new JdbcTemplate(database).execute(new RawSqlStatement("drop view " + schema + viewName));

      if (!database.getAutoCommitMode()) {
        database.getConnection().commit();
      }

    } catch (JDBCException e) {
      //            System.out.println("Cannot drop view "+database.escapeViewName(schemaName,
      // viewName)+" on "+database);
      //            e.printStackTrace();
      if (!database.getConnection().getAutoCommit()) {
        database.getConnection().rollback();
      }
    }

    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }
  }
コード例 #5
0
 @Before
 public void setupAvailableDatabases() throws Exception {
   for (Database database : TestContext.getInstance().getAvailableDatabases()) {
     if (generateTestStatement().supportsDatabase(database)) {
       if (database.supportsSchemas()) {
         database.dropDatabaseObjects(TestContext.ALT_SCHEMA);
       }
       database.dropDatabaseObjects(null);
       setupDatabase(database);
     }
   }
 }
コード例 #6
0
  protected void dropAndCreateSequence(CreateSequenceStatement statement, Database database)
      throws SQLException, JDBCException {
    if (statement.getSchemaName() != null && !database.supportsSchemas()) {
      return;
    }

    dropSequenceIfExists(statement.getSchemaName(), statement.getSequenceName(), database);

    new JdbcTemplate(database).execute(statement);

    if (!database.getAutoCommitMode()) {
      database.getConnection().commit();
    }
  }
コード例 #7
0
  @Override
  protected List<? extends SqlStatement> setupStatements(Database database) {
    ArrayList<CreateTableStatement> statements = new ArrayList<CreateTableStatement>();
    CreateTableStatement table = new CreateTableStatement(null, TABLE_NAME);
    table.addColumn(
        "id",
        TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false),
        null,
        new NotNullConstraint());
    statements.add(table);

    if (database.supportsSchemas()) {
      table = new CreateTableStatement(DatabaseTestContext.ALT_SCHEMA, TABLE_NAME);
      table.addColumn(
          "id",
          TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false),
          null,
          new NotNullConstraint());
      statements.add(table);
    }
    return statements;
  }