Пример #1
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");
 }
Пример #2
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);
     }
   }
 }