コード例 #1
0
ファイル: QueryGenerator.java プロジェクト: bunnyg/openpais
  public boolean addBatchFlatCalculationQuery(
      PreparedStatement pstmt, HashMap<String, String> valueMap) {

    String[][] table = loadingConfig.getTableMatrix("flatCalculationTable");
    String nameKey = "Calculation/@name";
    String valueKey = "CalculationResult/@value";
    String nameStr = valueMap.get(nameKey);
    if (nameStr == null) return true;

    String valueStr = valueMap.get(valueKey);
    String[] names = nameStr.split(DELIM);
    String[] values = valueStr.split(DELIM);
    if (names.length != values.length) return false;

    for (int i = 0; i < table.length; i++) {
      String[] map = table[i];
      String key = map[0];
      if (key.contains("partitionKey")) {
        String tileName = valueMap.get("Region/@name");
        try {
          pstmt.setInt(i + 1, partitioningKeyGenerator.getPartitionKeyByTilename(tileName));
        } catch (SQLException e) {
          e.printStackTrace();
          return false;
        }
      } else {
        String value = valueMap.get(key);
        try {
          pstmt.setString(i + 1, value);
        } catch (SQLException e) {
          e.printStackTrace();
          return false;
        }
      }
    }
    for (int i = 0; i < values.length; i++)
      try {
        String value = values[i];
        if (value.equals("NaN")) value = "0";
        pstmt.setString(i + table.length + 1, value);
      } catch (SQLException e) {
        e.printStackTrace();
      }

    try {
      pstmt.addBatch();
    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
コード例 #2
0
ファイル: QueryGenerator.java プロジェクト: bunnyg/openpais
 public void createPartitonKeyGenerator(PAISDBHelper db, int numOfPartitions) {
   this.partitioningKeyGenerator =
       PartitioningKeyGenerator.getInstance(Partitioner.TILE_BASED, db, numOfPartitions);
 }
コード例 #3
0
ファイル: QueryGenerator.java プロジェクト: bunnyg/openpais
  public boolean addBatchObservationQueries(
      PreparedStatement opstmt, PreparedStatement npstmt, HashMap<String, String> annMap) {
    PreparedStatement pstmt = null;
    String quantificationTypeStr = annMap.get("Quantification/@xsitype");
    if (quantificationTypeStr == null) return false;

    String[] quantificationTypes = quantificationTypeStr.split(DELIM);
    String[] singleValues =
        new String[loadingConfig.getTableMatrix("observationSingleTable").length];
    String[][] multiOrdinalValues =
        new String[loadingConfig.getTableMatrix("observationOrdinalMultiTable").length]
            [quantificationTypes.length];
    String[][] multiNominalValues =
        new String[loadingConfig.getTableMatrix("observationNominalMultiTable").length]
            [quantificationTypes.length];
    String[][] multiValues = null;

    for (int i = 0; i < loadingConfig.getTableMatrix("observationSingleTable").length; i++) {
      String key = loadingConfig.getTableMatrix("observationSingleTable")[i][0];
      singleValues[i] = annMap.get(key);
    }

    for (int i = 0; i < loadingConfig.getTableMatrix("observationOrdinalMultiTable").length; i++) {
      String[] table = loadingConfig.getTableMatrix("observationOrdinalMultiTable")[i];
      String key = table[0];
      String valueStr = annMap.get(key);
      if (valueStr == null) multiOrdinalValues[i] = null;
      else multiOrdinalValues[i] = valueStr.split(DELIM);
    }

    for (int i = 0; i < loadingConfig.getTableMatrix("observationNominalMultiTable").length; i++) {
      String[] table = loadingConfig.getTableMatrix("observationNominalMultiTable")[i];
      String key = table[0];
      String valueStr = annMap.get(key);
      if (valueStr == null) multiNominalValues[i] = null;
      else multiNominalValues[i] = valueStr.split(DELIM);
    }

    for (int count = 0;
        count < quantificationTypes.length;
        count++) { // For each observation instance <Observation>, generate a new query
      String quantificationType = quantificationTypes[count];
      String[][] table = loadingConfig.getTableMatrix("observationOrdinalMultiTable");
      multiValues = multiOrdinalValues;

      if ("Nominal".equals(quantificationType)) {
        pstmt = npstmt;
        table = loadingConfig.getTableMatrix("observationNominalMultiTable");
        multiValues = multiNominalValues;
      } else pstmt = opstmt;

      // Add single value attributes
      for (int i = 0; i < loadingConfig.getTableMatrix("observationSingleTable").length; i++) {
        String[] map = loadingConfig.getTableMatrix("observationSingleTable")[i];
        String key = map[0];
        String value = annMap.get(key);
        try {
          pstmt.setString(i + 1, value);
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }

      // Add multi-value attributes
      for (int i = 0; i < table.length; i++) {
        if (table[i][0].contains("partitionKey")) {
          String tileName = annMap.get("Region/@name");
          try {
            pstmt.setInt(
                i + 1 + loadingConfig.getTableMatrix("observationSingleTable").length,
                partitioningKeyGenerator.getPartitionKeyByTilename(tileName));
          } catch (SQLException e) {
            e.printStackTrace();
            return false;
          }
        } else {
          String value = null;
          if (multiValues[i] != null) value = multiValues[i][count];
          try {
            pstmt.setString(
                i + 1 + loadingConfig.getTableMatrix("observationSingleTable").length, value);
          } catch (SQLException e) {
            e.printStackTrace();
          }
        }
      }
      try {
        pstmt.addBatch();
      } catch (SQLException e) {
        e.printStackTrace();
        return false;
      }
    }
    return true;
  }
コード例 #4
0
ファイル: QueryGenerator.java プロジェクト: bunnyg/openpais
  public boolean setQueryParams(
      PreparedStatement pstmt,
      String tableName,
      HashMap<String, String> valueMap,
      String[][] table) {
    String polygonKey = "GeometricShape/@points";
    String tokens[];
    String demi = "[(), ]+";
    int j;
    int i;
    ArrayList<Double> cent = new ArrayList<Double>();

    for (i = 0; i < table.length; i++) {
      String[] map = table[i];
      String key = map[0];
      String value = valueMap.get(key);

      try {
        if (tableName.equals(markupPolygonTableName) && key.equals(polygonKey)) {

          String polygonValue = GISHelper.convert(value);

          /*Code block to calculate the centroid of a polygon */
          if (this.CentFlag == 1) {
            // The first element is not a polygon point -- "POLYGON"
            // The LAST pair of (x,y) is the same as the first pair, showing that it's a closed
            // polygon.
            tokens = polygonValue.split(demi);

            /* output the original array of polygon points
             *
            System.out.println("INSERT POLYGON:  ");
            System.out.println(polygonValue);

            for (j=0;j<tokens.length;j++)
            {
            	System.out.print(tokens[j] + " ");
            	if (j%2 == 0)
            		System.out.print(", ");
            }
            System.out.println("");
             */

            if ((cent = CentOfPoly(tokens, (tokens.length - 3) / 2)) == null) {
              System.out.println("CENTROID is bad!");
            }
          }

          pstmt.setString(i + 1, polygonValue);
        } else if (key.contains("partitionKey")) {
          String tileName = valueMap.get("Region/@name");
          pstmt.setInt(i + 1, partitioningKeyGenerator.getPartitionKeyByTilename(tileName));
        } else pstmt.setString(i + 1, value);
      } catch (SQLException e) {
        e.printStackTrace();
        return false;
      }
    }

    try {
      if (tableName.equals(markupPolygonTableName) && CentFlag == 1) {
        pstmt.setDouble(i + 1, cent.get(0));
        pstmt.setDouble(i + 2, cent.get(1));
      }
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    try {
      pstmt.addBatch();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return true;
  }