Пример #1
0
  public PreparedStatement prepareStatement(SqlDao dao, String query) throws SQLException {
    StringBuffer ret = new StringBuffer();
    Matcher m = TABLE_PATTERN.matcher(query);
    while (m.find()) {
      m.appendReplacement(ret, dao.getDataStore().getTableName(m.group(1), true));
    }
    m.appendTail(ret);

    return dao.prepareStatement(ret.toString());
  }
Пример #2
0
 public void renameTable(SqlDao dao, String oldName, String newName) throws SQLException {
   final String expandedOld = dao.getDataStore().getTableName(oldName, true);
   final String expandedNew = dao.getDataStore().getTableName(newName, false);
   try (PreparedStatement stmt =
       prepareStatement(dao, "ALTER TABLE `" + expandedOld + "` RENAME `" + expandedNew + "`")) {
     /*try (PreparedStatement stmt = prepareStatement(dao, dao.getRenameTableQuery())) {
     stmt.setString(1, expandedOld);
     stmt.setString(2, expandedNew);*/
     stmt.executeUpdate();
   }
 }
Пример #3
0
  public String getOption(
      SqlDao dao, String name, LegacyMigration.Type type, String world, String option)
      throws SQLException {
    try (PreparedStatement stmt = dao.prepareStatement(getSelectOptionQuery())) {
      stmt.setString(1, name);
      stmt.setInt(2, type.ordinal());
      stmt.setString(3, option);
      if (world == null) {
        stmt.setNull(4, Types.VARCHAR);
      } else {
        stmt.setString(4, world);
      }

      ResultSet rs = stmt.executeQuery();
      if (rs.next()) {
        return rs.getString(1);
      } else {
        return null;
      }
    }
  }
Пример #4
0
 public boolean hasTable(SqlDao dao, String table) throws SQLException {
   return dao.getConnection()
       .getMetaData()
       .getTables(null, null, dao.getDataStore().getTableName(table, true).toUpperCase(), null)
       .next(); // Upper-case for H2
 }