Beispiel #1
0
 @edu.umd.cs.findbugs.annotations.SuppressWarnings(
     value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE",
     justification = "Dynamic based upon tables in the database")
 public void dropTables(long start, long end) {
   String cluster = System.getProperty("CLUSTER");
   if (cluster == null) {
     cluster = "unknown";
   }
   DatabaseWriter dbw = new DatabaseWriter(cluster);
   try {
     HashMap<String, String> dbNames = dbc.startWith("report.db.name.");
     for (Entry<String, String> entry : dbNames.entrySet()) {
       String tableName = entry.getValue();
       if (!RegexUtil.isRegex(tableName)) {
         log.warn(
             "Skipping tableName: '"
                 + tableName
                 + "' because there was an error parsing it as a regex: "
                 + RegexUtil.regexError(tableName));
         return;
       }
       String[] tableList = dbc.findTableName(tableName, start, end);
       for (String tl : tableList) {
         log.debug("table name: " + tableList[0]);
         try {
           String[] parts = tl.split("_");
           int partition = Integer.parseInt(parts[parts.length - 2]);
           StringBuilder table = new StringBuilder();
           for (int i = 0; i < parts.length - 2; i++) {
             if (i != 0) {
               table.append("_");
             }
             table.append(parts[i]);
           }
           partition = partition - 3;
           if (partition >= 0) {
             StringBuilder dropPartition = new StringBuilder();
             dropPartition.append("drop table if exists ");
             dropPartition.append(table);
             dropPartition.append("_");
             dropPartition.append(partition);
             dropPartition.append("_");
             dropPartition.append(parts[parts.length - 1]);
             final String query = dropPartition.toString();
             dbw.execute(query);
           }
         } catch (NumberFormatException e) {
           log.error("Error in parsing table partition number, skipping table:" + tableList[0]);
         } catch (ArrayIndexOutOfBoundsException e) {
           log.debug(
               "Skipping table:" + tableList[0] + ", because it has no partition configuration.");
         }
       }
     }
     dbw.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }