コード例 #1
0
  private int writeTablePopulationFile(
      int primaryKey,
      String folderPathAndName,
      int overlapPercentage,
      int ratio,
      int tableNumber,
      int distinctValues,
      String comment)
      throws IOException {

    boolean bottom = BOTTOM.equals(comment) || BOTTOM2.equals(comment);
    boolean scattered = !bottom;

    System.out.println(MyUtils.TAB_SEPARATOR + tableNumber);
    String filePathAndName =
        folderPathAndName + SCRIPT_FILE_NAME_PREFIX + tableNumber + SCRIPT_EXTENSION;
    FileWriter fileWriter = new FileWriter(new File(filePathAndName));
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

    int rowNumber = 0;
    for (int distinctValue = 0;
        distinctValue < distinctValues;
        distinctValue++) { // doesn't handle 1 table only well
      for (int i = 0; i < Math.pow(ratio, tableNumber); i++) {
        rowNumber++;
      }
    }
    int totalRows = rowNumber;

    rowNumber = 0;
    int overlap = getOverlap(overlapPercentage);
    int totalMismatch = totalRows - ((int) (totalRows * (overlapPercentage / 100.0)));
    for (int distinctValue = 0;
        distinctValue < distinctValues;
        distinctValue++) { // doesn't handle 1 table only well
      Boolean match = null;
      if (scattered) {
        match = (tableNumber == 0 ? true : (overlap != -1 ? distinctValue % overlap == 0 : false));
      } else {
        match = (tableNumber == 0 ? true : rowNumber >= totalMismatch);
      }
      for (int i = 0; i < Math.pow(ratio, tableNumber); i++) {
        String leftValue = generateLeftValue(tableNumber, distinctValue, match);
        String rightValue = generateRightValue(tableNumber, distinctValue);
        String line = null;
        if (rdbs.isMySql()) {
          line =
              leftValue + MyUtils.TAB_SEPARATOR + primaryKey + MyUtils.TAB_SEPARATOR + rightValue;
        } else {
          line =
              "insert into "
                  + generateTableName(tableNumber)
                  + " values ("
                  + "'"
                  + leftValue
                  + "'"
                  + ","
                  + "'"
                  + primaryKey
                  + "'"
                  + ","
                  + "'"
                  + rightValue
                  + "'"
                  + ");";
        }
        bufferedWriter.write(line + MyUtils.LINE_SEPARATOR);
        primaryKey++;
        rowNumber++;
      }
    }

    bufferedWriter.close();
    fileWriter.close();

    return primaryKey;
  }
コード例 #2
0
 private void changeRdbs(Rdbs rdbs) {
   this.rdbs = rdbs;
   this.stringDeclaration =
       rdbs.isMySql() ? "varchar(16)" : (rdbs.isPostgreSql() ? "text" : "varchar2(16)");
   this.intDeclaration = rdbs.isMySql() ? "int(1)" : (rdbs.isPostgreSql() ? "bigint" : "number");
 }
コード例 #3
0
 private void writeScript(
     String folderPathAndName,
     int overlapPercentage,
     int ratio,
     int distinctValues,
     String comment) {
   this.databaseName =
       "ac_query_runner_" + overlapPercentage + "_" + ratio + "_" + distinctValues + "_" + comment;
   this.databaseShortName =
       "ac_" + "qr_" + overlapPercentage + "_" + ratio + "_" + distinctValues + "_" + comment;
   stringBuffer.append(
       (this.rdbs.isOracle() ? "REMARK " : "/* ")
           + this.rdbs
           + (this.rdbs.isOracle() ? "" : " */")
           + MyUtils.LINE_SEPARATOR);
   if (!rdbs.isOracle()) {
     if (rdbs.isMySql()) {
       stringBuffer.append(
           "drop database if exists " + databaseName + ";" + MyUtils.LINE_SEPARATOR);
     } else if (rdbs.isPostgreSql()) {
       stringBuffer.append("drop database " + databaseName + ";" + MyUtils.LINE_SEPARATOR);
     }
     stringBuffer.append("create database " + databaseName + ";" + MyUtils.LINE_SEPARATOR);
     if (rdbs.isMySql()) {
       stringBuffer.append("use " + databaseName + ";" + MyUtils.LINE_SEPARATOR);
     } else if (rdbs.isPostgreSql()) {
       stringBuffer.append("\\c " + databaseName + ";" + MyUtils.LINE_SEPARATOR);
     }
   }
   if (!rdbs.isMySql()) {
     for (int tableNumber = 0; tableNumber < DataScriptGenerator.TOTAL_TABLES; tableNumber++) {
       String tableName = generateTableName(tableNumber);
       stringBuffer.append("drop table " + tableName + ";" + MyUtils.LINE_SEPARATOR);
     }
   }
   for (int tableNumber = 0; tableNumber < DataScriptGenerator.TOTAL_TABLES; tableNumber++) {
     String tableName = generateTableName(tableNumber);
     stringBuffer.append(
         "create table "
             + tableName
             + "(l"
             + tableNumber
             + " "
             + stringDeclaration
             + ", "
             + "pk"
             + tableNumber
             + " "
             + intDeclaration
             + ", r"
             + tableNumber
             + " "
             + stringDeclaration
             + ");"
             + MyUtils.LINE_SEPARATOR);
   }
   for (int tableNumber = 0; tableNumber < DataScriptGenerator.TOTAL_TABLES; tableNumber++) {
     String line = null;
     String scriptFileName = SCRIPT_FILE_NAME_PREFIX + tableNumber;
     String scriptFilePathAndName = folderPathAndName + scriptFileName + SCRIPT_EXTENSION;
     if (rdbs.isMySql()) {
       line =
           "load data local infile '"
               + scriptFilePathAndName
               + "' "
               + "into table "
               + scriptFileName
               + ";";
     } else if (rdbs.isPostgreSql()) {
       line = "\\i " + scriptFilePathAndName;
     } else if (rdbs.isOracle()) {
       line = "@" + scriptFilePathAndName;
     }
     stringBuffer.append(line + MyUtils.LINE_SEPARATOR);
     if (rdbs.isOracle()) {
       stringBuffer.append("commit;" + MyUtils.LINE_SEPARATOR);
     }
   }
   for (int tableNumber = 0; tableNumber < DataScriptGenerator.TOTAL_TABLES; tableNumber++) {
     String tableName = generateTableName(tableNumber);
     String leftIndexName = "li_" + tableName;
     String rightIndexName = "ri_" + tableName;
     stringBuffer.append(
         "create unique index "
             + leftIndexName
             + " "
             + "on "
             + tableName
             + "(l"
             + tableNumber
             + ");"
             + MyUtils.LINE_SEPARATOR);
     if (rdbs.isOracle()) {
       stringBuffer.append("commit;" + MyUtils.LINE_SEPARATOR);
     }
     stringBuffer.append(
         "create unique index "
             + rightIndexName
             + " "
             + "on "
             + tableName
             + "(r"
             + tableNumber
             + ");"
             + MyUtils.LINE_SEPARATOR);
     if (rdbs.isOracle()) {
       stringBuffer.append("commit;" + MyUtils.LINE_SEPARATOR);
     }
   }
 }