Example #1
0
  protected void discoverBeanMethods() {
    // break this off?
    Class<?> ft = field.getType();
    if (String.class.equals(ft)) {
      type = DataType.text();
    } else if (int.class.equals(ft)) {
      type = DataType.cint();
    } else if (Integer.class.equals(ft)) {
      type = DataType.cint();
    } else if (int.class.equals(ft)) {
      type = DataType.cint();
    } else if (Long.class.equals(ft)) {
      type = DataType.bigint();
    } else if (long.class.equals(ft)) {
      type = DataType.bigint();
    } else if (Date.class.equals(ft)) {
      type = DataType.timestamp();
    } else if (ByteBuffer.class.equals(ft)) {
      type = DataType.blob();
    } else if (Double.class.equals(ft)) {
      type = DataType.cdouble();
    } else if (double.class.equals(ft)) {
      type = DataType.cdouble();
    } else if (Float.class.equals(ft)) {
      type = DataType.cfloat();
    } else if (float.class.equals(ft)) {
      type = DataType.cfloat();
    } else if (Boolean.class.equals(ft)) {
      type = DataType.cboolean();
    }
    // how to differentiate type tuuid and uuid
    else if (UUID.class.equals(ft)) {
      type = DataType.uuid();
    }
    // java.sql.timestamp is not directly supported
    // remove it for now
    /*else if (Timestamp.class.equals(ft)) {
    	type = DataType.timestamp();
    }*/ else if (Map.class.isAssignableFrom(ft)) {
      type = DataType.map(DataType.text(), DataType.text());
    }

    // getter and setter find
    try {
      String getMeth =
          "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
      String setMeth =
          "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
      getter = field.getDeclaringClass().getDeclaredMethod(getMeth);
      setter = field.getDeclaringClass().getDeclaredMethod(setMeth, field.getType());
    } catch (Exception e) {
      // TODO some useful stuff: warning of non-conformance to java bean conventions
    }
  }
Example #2
0
  private Object getValue(Row row, ColumnMapping mapping, Definition def) {
    Object value = null;

    if (DataType.text().equals(mapping.type)) {
      value = row.getString(def.getName());

    } else if (DataType.blob().equals(mapping.type)) {
      value = row.getBytes(def.getName());

    } else if (DataType.map(DataType.text(), DataType.text()).equals(mapping.type)) {
      value = row.getMap(def.getName(), String.class, String.class);

    } else if (DataType.cint().equals(mapping.type)) {
      value = row.getInt(def.getName());
    } else if (DataType.bigint().equals(mapping.type)) {
      value = row.getLong(def.getName());
    } else if (DataType.timestamp().equals(mapping.type)) {
      value = row.getDate(def.getName());
    } else if (DataType.blob().equals(mapping.type)) {
      value = row.getBytes(def.getName());
    } else if (DataType.cdouble().equals(mapping.type)) {
      value = row.getBytes(def.getName());
    } else if (DataType.cfloat().equals(mapping.type)) {
      value = row.getFloat(def.getName());
    } else if (DataType.inet().equals(mapping.type)) {
      value = row.getInet(def.getName());
    } else if (DataType.cboolean().equals(mapping.type)) {
      value = row.getBool(def.getName());
    } else if (DataType.uuid().equals(mapping.type)) {
      value = row.getUUID(def.getName());
    }
    // what if value is null? primitives won't like this
    return value;
  }