use of org.apache.apex.malhar.lib.util.PojoUtils.SetterLong in project apex-malhar by apache.
the class CouchDBPOJOInputOperator method getTuple.
@Override
@SuppressWarnings("unchecked")
public Object getTuple(Row value) throws IOException {
Object obj;
try {
obj = objectClass.newInstance();
} catch (InstantiationException ex) {
throw new RuntimeException(ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
}
if (setterDocId != null) {
setterDocId.set(obj, value.getId());
}
JsonNode val = value.getValueAsNode();
for (int i = 0; i < setterDoc.size(); i++) {
Class<?> type = fieldType.get(i);
if (type.isPrimitive()) {
if (type == int.class) {
((SetterInt) setterDoc.get(i)).set(obj, val.get(columns.get(i)).getIntValue());
} else if (type == boolean.class) {
((SetterBoolean) setterDoc.get(i)).set(obj, val.get(columns.get(i)).getBooleanValue());
} else if (type == long.class) {
((SetterLong) setterDoc.get(i)).set(obj, val.get(columns.get(i)).getLongValue());
} else if (type == double.class) {
((SetterDouble) setterDoc.get(i)).set(obj, val.get(columns.get(i)).getDoubleValue());
} else {
throw new RuntimeException("Type is not supported");
}
} else {
((Setter<Object, Object>) setterDoc.get(i)).set(obj, mapper.readValue(val.get(columns.get(i)), type));
}
}
return obj;
}
use of org.apache.apex.malhar.lib.util.PojoUtils.SetterLong in project apex-malhar by apache.
the class RedisPOJOInputOperator method convertMapToObject.
@SuppressWarnings("unchecked")
private Object convertMapToObject(Map<String, String> tuple) {
try {
Object mappedObject = objectClass.newInstance();
for (int i = 0; i < dataColumns.size(); i++) {
final SupportType type = dataColumns.get(i).getType();
final String columnName = dataColumns.get(i).getColumnName();
if (i < setters.size()) {
String value = tuple.get(columnName);
switch(type) {
case STRING:
((Setter<Object, String>) setters.get(i)).set(mappedObject, value);
break;
case BOOLEAN:
((SetterBoolean) setters.get(i)).set(mappedObject, Boolean.parseBoolean(value));
break;
case SHORT:
((SetterShort) setters.get(i)).set(mappedObject, Short.parseShort(value));
break;
case INTEGER:
((SetterInt) setters.get(i)).set(mappedObject, Integer.parseInt(value));
break;
case LONG:
((SetterLong) setters.get(i)).set(mappedObject, Long.parseLong(value));
break;
case FLOAT:
((SetterFloat) setters.get(i)).set(mappedObject, Float.parseFloat(value));
break;
case DOUBLE:
((SetterDouble) setters.get(i)).set(mappedObject, Double.parseDouble(value));
break;
default:
break;
}
}
}
return mappedObject;
} catch (Exception e) {
DTThrowable.wrapIfChecked(e);
}
return null;
}
use of org.apache.apex.malhar.lib.util.PojoUtils.SetterLong in project apex-malhar by apache.
the class CassandraPOJOInputOperator method getTuple.
@Override
@SuppressWarnings("unchecked")
public Object getTuple(Row row) {
Object obj;
try {
// This code will be replaced after integration of creating POJOs on the fly utility.
obj = pojoClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
throw new RuntimeException(ex);
}
for (int i = 0; i < columnDataTypes.size(); i++) {
DataType type = columnDataTypes.get(i);
String columnName = fieldInfos.get(i).getColumnName();
switch(type.getName()) {
case UUID:
final UUID id = row.getUUID(columnName);
((Setter<Object, UUID>) setters.get(i)).set(obj, id);
break;
case ASCII:
case VARCHAR:
case TEXT:
final String ascii = row.getString(columnName);
((Setter<Object, String>) setters.get(i)).set(obj, ascii);
break;
case BOOLEAN:
final boolean bool = row.getBool(columnName);
((SetterBoolean) setters.get(i)).set(obj, bool);
break;
case INT:
final int intValue = row.getInt(columnName);
((SetterInt) setters.get(i)).set(obj, intValue);
break;
case BIGINT:
case COUNTER:
final long longValue = row.getLong(columnName);
((SetterLong) setters.get(i)).set(obj, longValue);
break;
case FLOAT:
final float floatValue = row.getFloat(columnName);
((SetterFloat) setters.get(i)).set(obj, floatValue);
break;
case DOUBLE:
final double doubleValue = row.getDouble(columnName);
((SetterDouble) setters.get(i)).set(obj, doubleValue);
break;
case DECIMAL:
final BigDecimal decimal = row.getDecimal(columnName);
((Setter<Object, BigDecimal>) setters.get(i)).set(obj, decimal);
break;
case SET:
Set<?> set = row.getSet(columnName, Object.class);
((Setter<Object, Set<?>>) setters.get(i)).set(obj, set);
break;
case MAP:
final Map<?, ?> map = row.getMap(columnName, Object.class, Object.class);
((Setter<Object, Map<?, ?>>) setters.get(i)).set(obj, map);
break;
case LIST:
final List<?> list = row.getList(columnName, Object.class);
((Setter<Object, List<?>>) setters.get(i)).set(obj, list);
break;
case TIMESTAMP:
final Date date = new Date(row.getDate(columnName).getMillisSinceEpoch());
((Setter<Object, Date>) setters.get(i)).set(obj, date);
break;
default:
throw new RuntimeException("unsupported data type " + type.getName());
}
}
return obj;
}
Aggregations