コード例 #1
0
ファイル: Probe.java プロジェクト: jadahl/jgroups-android
  public static void main(String[] args) {
    InetAddress addr = null, bind_addr = null;
    int port = 0;
    int ttl = 32;
    long timeout = 2000;
    final String DEFAULT_DIAG_ADDR = "224.0.75.75";
    final int DEFAULT_DIAG_PORT = 7500;
    List<String> query = new ArrayList<String>();
    String match = null;
    boolean weed_out_duplicates = false;

    try {
      for (int i = 0; i < args.length; i++) {
        if ("-addr".equals(args[i])) {
          addr = InetAddress.getByName(args[++i]);
          continue;
        }
        if ("-bind_addr".equals(args[i])) {
          bind_addr = InetAddress.getByName(args[++i]);
          continue;
        }
        if ("-port".equals(args[i])) {
          port = Integer.parseInt(args[++i]);
          continue;
        }
        if ("-ttl".equals(args[i])) {
          ttl = Integer.parseInt(args[++i]);
          continue;
        }
        if ("-timeout".equals(args[i])) {
          timeout = Long.parseLong(args[++i]);
          continue;
        }
        if ("-match".equals(args[i])) {
          match = args[++i];
          continue;
        }
        if ("-weed_out_duplicates".equals(args[i])) {
          weed_out_duplicates = true;
          continue;
        }
        if ("-help".equals(args[i]) || "-h".equals(args[i])) {
          help();
          return;
        }
        query.add(args[i]);
      }
      Probe p = new Probe();
      if (addr == null) addr = InetAddress.getByName(DEFAULT_DIAG_ADDR);
      if (port == 0) port = DEFAULT_DIAG_PORT;
      p.start(addr, bind_addr, port, ttl, timeout, query, match, weed_out_duplicates);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
コード例 #2
0
  private void initializeBeanResults(ResultSet rs) {
    try {
      ClassInfo classInfo = ClassInfo.getInstance(getResultClass());
      String[] propertyNames = classInfo.getWriteablePropertyNames();

      Map propertyMap = new HashMap();
      for (int i = 0; i < propertyNames.length; i++) {
        propertyMap.put(propertyNames[i].toUpperCase(java.util.Locale.ENGLISH), propertyNames[i]);
      }

      List resultMappingList = new ArrayList();
      ResultSetMetaData rsmd = rs.getMetaData();
      for (int i = 0, n = rsmd.getColumnCount(); i < n; i++) {
        String columnName = getColumnIdentifier(rsmd, i + 1);
        String upperColumnName = columnName.toUpperCase(java.util.Locale.ENGLISH);
        String matchedProp = (String) propertyMap.get(upperColumnName);
        Class type = null;
        if (matchedProp == null) {
          Probe p = ProbeFactory.getProbe(this.getResultClass());
          try {
            type = p.getPropertyTypeForSetter(this.getResultClass(), columnName);
          } catch (Exception e) {
            // TODO - add logging to this class?
          }
        } else {
          type = classInfo.getSetterType(matchedProp);
        }
        if (type != null || matchedProp != null) {
          ResultMapping resultMapping = new ResultMapping();
          resultMapping.setPropertyName((matchedProp != null ? matchedProp : columnName));
          resultMapping.setColumnName(columnName);
          resultMapping.setColumnIndex(i + 1);
          resultMapping.setTypeHandler(
              getDelegate().getTypeHandlerFactory().getTypeHandler(type)); // map SQL to JDBC type
          resultMappingList.add(resultMapping);
        }
      }
      setResultMappingList(resultMappingList);

    } catch (SQLException e) {
      throw new RuntimeException("Error automapping columns. Cause: " + e);
    }
  }