Пример #1
0
  /**
   * @param columnIdx
   * @return Object
   * @roseuid 3E5D894200B1
   */
  public Object getObject(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    return value;
  }
  public void testStackContainerPolicy() {
    DataReadQuery query = this.buildNewQuery();
    query.useCollectionClass(Stack.class);

    stack = (Stack) getSession().executeQuery(query);
    // if we get here, we must not have generated a ClassCastException
    Record row = (Record) stack.peek();
    if (row.get("CUSTNAME") == null) {
      throw new TestErrorException("missing data");
    }
  }
Пример #3
0
  public String getTimeString(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return null;

    return value.toString().trim().split("\\.")[0];
  }
Пример #4
0
  /**
   * 只有String和Boolean类型进行转换,其他类型均返回false
   *
   * @param columnIdx
   * @return boolean
   * @roseuid 3E5D883200BA
   */
  public boolean getBoolean(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return false;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);

    if (rmd.getType() == MetaDataTypes.STRING_TP) {
      Record record = (Record) records.get(currentNo);
      String value = (String) record.get(columnIdx);
      if (value == null || value.equals("0")) return false;
      return true;
    }
    if (rmd.getType() == MetaDataTypes.BOOLEAN_TP) {
      Record record = (Record) records.get(currentNo);
      Boolean value = (Boolean) record.get(columnIdx);
      return value.booleanValue();
    } else {
      return false;
    }
  }
Пример #5
0
  /**
   * @param columnIdx
   * @return String
   * @roseuid 3E5D88F000F9
   */
  public String getString(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return "";

    if ((rmd.getType() == MetaDataTypes.CALENDAR_TP)
        || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) {
      String[] DateStr = value.toString().trim().split("\\.");
      return DateStr[0];
    }
    return value.toString().trim();
  }
Пример #6
0
  /**
   * @param columnIdx
   * @return double
   * @roseuid 3E5D88C701AE
   */
  public double getDouble(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return 0;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return 0;

    switch (rmd.getType()) {
      case MetaDataTypes.BIGDECIMAL_TP:
        return ((BigDecimal) value).doubleValue();
      case MetaDataTypes.BIGINTEGER_TP:
        return ((BigInteger) value).doubleValue();
      case MetaDataTypes.BOOLEAN_TP:
        Boolean b = (Boolean) value;
        if (b.booleanValue()) return 1;
        else return 0;
      case MetaDataTypes.DOUBLE_TP:
        return ((Double) value).doubleValue();
      case MetaDataTypes.FLOAT_TP:
        return ((Float) value).doubleValue();
      case MetaDataTypes.INTEGER_TP:
        return ((Integer) value).doubleValue();
      case MetaDataTypes.LONG_TP:
        return ((Long) value).doubleValue();
      case MetaDataTypes.SHORT_TP:
        return ((Short) value).doubleValue();
      case MetaDataTypes.STRING_TP:
        try {
          return Double.parseDouble((String) value);
        } catch (Exception e) {
          return 0;
        }
      default:
        return 0;
    } // switch
  }
  /** assume the stack has already been populated by the previous test */
  public void testCursoredStreamPolicy() {
    ValueReadQuery sizeQuery = new ValueReadQuery("select count(*) from ORD");

    DataReadQuery query = this.buildNewQuery();
    query.useCursoredStream(5, 5, sizeQuery);

    CursoredStream stream = (CursoredStream) getSession().executeQuery(query);

    // if we get here, we must not have generated a ClassCastException
    int count = 0;
    while (stream.hasMoreElements()) {
      count++;
      Record row = (Record) stream.nextElement();
      if (row.get("CUSTNAME") == null) {
        throw new TestErrorException("missing data");
      }
    }
    if (count != stack.size()) {
      throw new TestErrorException(
          "stream does not match stack - " + "expected: " + stack.size() + " actual: " + count);
    }
  }
Пример #8
0
  /**
   * @param columnIdx
   * @return java.util.Calendar
   * @roseuid 3E5D8903036D
   */
  public java.util.Date getCalendar(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) {
      return null;
    } else {
    }

    if ((rmd.getType() == MetaDataTypes.CALENDAR_TP)
        || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) {
      java.util.Date d = (java.util.Date) value;

      // Calendar c=Calendar.getInstance();
      // c.set(1900+d.getYear(),d.getMonth(),d.getDate());
      return d;
    } else {
      return null;
    }
  }
Пример #9
0
  /**
   * {@link LanguageSubtagRegistryData}
   *
   * @param langSubtagReg the language subtag registry file
   * @throws IOException if an I/O error occurs
   */
  static void languageSubtagRegistry(Path langSubtagReg) throws IOException {
    List<String> lines = Files.readAllLines(langSubtagReg, StandardCharsets.UTF_8);
    ArrayDeque<String> stack = new ArrayDeque<>(lines);

    ArrayList<Record> language = new ArrayList<>();
    ArrayList<Record> region = new ArrayList<>();
    ArrayList<Record> grandfathered = new ArrayList<>();
    ArrayList<Record> redundant = new ArrayList<>();

    ArrayList<Record> extlang = new ArrayList<>();
    ArrayList<Record> script = new ArrayList<>();
    ArrayList<Record> variant = new ArrayList<>();

    // skip first two lines (file date + %% separator)
    stack.pop();
    stack.pop();
    while (!stack.isEmpty()) {
      Record rec = readRecord(stack);
      String type = rec.get(Field.Type);
      assert type != null;
      if ("language".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          language.add(rec);
        }
      }
      if ("region".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          region.add(rec);
        }
      }
      if ("grandfathered".equals(type)) {
        grandfathered.add(rec);
      }
      if ("redundant".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          redundant.add(rec);
        }
      }
      if ("extlang".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          extlang.add(rec);
        }
      }
      if ("script".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          script.add(rec);
        }
      }
      if ("variant".equals(type)) {
        if (rec.has(Field.PreferredValue)) {
          variant.add(rec);
        }
      }
    }

    /* Generate LanguageSubtagRegistryData#scriptData entries */
    System.out.println("--- [LanguageSubtagRegistryData#scriptData] ---");
    for (Record record : script) {
      assert record.has(Field.Prefix);
      System.out.printf(
          "%s -> %s [%s]%n",
          record.get(Field.Subtag), record.get(Field.PreferredValue), record.get(Field.Prefix));
    }
    System.out.println();
    assert script.isEmpty() : "no preferred values for 'script' expected";

    /* Generate LanguageSubtagRegistryData#extlangData entries */
    System.out.println("--- [LanguageSubtagRegistryData#extlangData] ---");
    for (Record record : extlang) {
      assert record.has(Field.Prefix);
      assert record.get(Field.Subtag).equals(record.get(Field.PreferredValue))
          : record.get(Field.Subtag);
      System.out.printf(
          "map.put(\"%s\", \"%s\");%n", record.get(Field.Subtag), record.get(Field.Prefix));
    }
    System.out.println();

    /* Generate LanguageSubtagRegistryData#variantData entries */
    System.out.println("--- [LanguageSubtagRegistryData#variantData] ---");
    for (Record record : variant) {
      assert record.has(Field.Prefix);
      System.out.printf(
          "%s -> %s [%s]%n",
          record.get(Field.Subtag), record.get(Field.PreferredValue), record.get(Field.Prefix));
      System.out.printf(
          "map.put(\"%s\", \"%s\");%n", record.get(Field.Subtag), record.get(Field.PreferredValue));
    }
    System.out.println();
    assert variant.size() == 1 : "Only one variant entry expected";
    assert variant.get(0).get(Field.Subtag).equals("heploc");
    assert variant.get(0).get(Field.PreferredValue).equals("alalc97");

    /* Generate LanguageSubtagRegistryData#regionData entries */
    System.out.println("--- [LanguageSubtagRegistryData#regionData] ---");
    for (Record record : region) {
      assert !record.has(Field.Prefix);
      System.out.printf(
          "map.put(\"%s\", \"%s\");%n",
          record.get(Field.Subtag).toLowerCase(Locale.ROOT), record.get(Field.PreferredValue));
    }
    System.out.println();

    /* Generate LanguageSubtagRegistryData#languageData entries */
    System.out.println("--- [LanguageSubtagRegistryData#languageData] ---");
    for (Record record : language) {
      assert !record.has(Field.Prefix);
      System.out.printf(
          "map.put(\"%s\", \"%s\");%n", record.get(Field.Subtag), record.get(Field.PreferredValue));
    }
    System.out.println();

    /* Generate LanguageSubtagRegistryData#grandfatheredData entries */
    System.out.println("--- [LanguageSubtagRegistryData#grandfatheredData] ---");
    for (Record record : grandfathered) {
      assert !record.has(Field.Prefix);
      if (record.has(Field.PreferredValue)) {
        System.out.printf(
            "map.put(\"%s\", \"%s\");%n",
            record.get(Field.Tag).toLowerCase(Locale.ROOT), record.get(Field.PreferredValue));
      } else {
        System.out.printf(
            "map.put(\"%s\", \"%s\");%n",
            record.get(Field.Tag).toLowerCase(Locale.ROOT), record.get(Field.Tag));
      }
    }
    System.out.println();

    /* Generate LanguageSubtagRegistryData#redundantData entries */
    System.out.println("--- [LanguageSubtagRegistryData#redundantData] ---");
    for (Record record : redundant) {
      assert !record.has(Field.Prefix);
      System.out.printf(
          "map.put(\"%s\", \"%s\");%n",
          record.get(Field.Tag).toLowerCase(Locale.ROOT), record.get(Field.PreferredValue));
    }
    System.out.println();
  }