use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class AvroToPojo method initializeActiveFieldSetters.
/**
* Initialize the setters for generating the POJO
*/
private void initializeActiveFieldSetters() {
for (int i = 0; i < columnFieldSetters.size(); i++) {
ActiveFieldInfo activeFieldInfo = columnFieldSetters.get(i);
SupportType st = activeFieldInfo.fieldInfo.getType();
switch(st) {
case BOOLEAN:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterBoolean(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case DOUBLE:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterDouble(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case FLOAT:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterFloat(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case INTEGER:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterInt(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case STRING:
activeFieldInfo.setterOrGetter = PojoUtils.createSetter(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression(), activeFieldInfo.fieldInfo.getType().getJavaType());
break;
case LONG:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterLong(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
default:
activeFieldInfo.setterOrGetter = PojoUtils.createSetter(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression(), Byte.class);
break;
}
columnFieldSetters.get(i).setterOrGetter = activeFieldInfo.setterOrGetter;
}
}
use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class StreamingJsonParser method initializeActiveFieldSetters.
/**
* Initialize the setters for generating the POJO
*/
private void initializeActiveFieldSetters() {
for (int i = 0; i < columnFieldSetters.size(); i++) {
ActiveFieldInfo activeFieldInfo = columnFieldSetters.get(i);
SupportType st = activeFieldInfo.fieldInfo.getType();
switch(st) {
case BOOLEAN:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterBoolean(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case DOUBLE:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterDouble(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case FLOAT:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterFloat(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case INTEGER:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterInt(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
case STRING:
activeFieldInfo.setterOrGetter = PojoUtils.createSetter(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression(), activeFieldInfo.fieldInfo.getType().getJavaType());
break;
case LONG:
activeFieldInfo.setterOrGetter = PojoUtils.createSetterLong(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression());
break;
default:
activeFieldInfo.setterOrGetter = PojoUtils.createSetter(getPojoClass(), activeFieldInfo.fieldInfo.getPojoFieldExpression(), Byte.class);
break;
}
columnFieldSetters.get(i).setterOrGetter = activeFieldInfo.setterOrGetter;
}
}
use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType in project apex-malhar by apache.
the class StreamingJsonParser method setPojoFields.
/**
* Returns a POJO from a Generic Record Null is set as the default value if a
* key is not found in the parsed JSON
*
* @return Object
*/
@SuppressWarnings("unchecked")
private Object setPojoFields(HashMap<Object, Object> tuple) throws InstantiationException, IllegalAccessException {
Object newObj = getPojoClass().newInstance();
try {
for (int i = 0; i < columnFieldSetters.size(); i++) {
StreamingJsonParser.ActiveFieldInfo afi = columnFieldSetters.get(i);
SupportType st = afi.fieldInfo.getType();
Object val = null;
try {
val = tuple.get(afi.fieldInfo.getColumnName());
} catch (Exception e) {
LOG.error("Could not find field -" + afi.fieldInfo.getColumnName() + "- in the generic record", e);
val = null;
}
// Nothing to set if a value is null
if (val == null) {
continue;
}
try {
switch(st) {
case BOOLEAN:
((PojoUtils.SetterBoolean<Object>) afi.setterOrGetter).set(newObj, (boolean) tuple.get(afi.fieldInfo.getColumnName()));
break;
case DOUBLE:
((PojoUtils.SetterDouble<Object>) afi.setterOrGetter).set(newObj, (double) tuple.get(afi.fieldInfo.getColumnName()));
break;
case INTEGER:
int intVal = Ints.checkedCast((long) tuple.get(afi.fieldInfo.getColumnName()));
((PojoUtils.SetterInt<Object>) afi.setterOrGetter).set(newObj, intVal);
break;
case STRING:
((PojoUtils.Setter<Object, String>) afi.setterOrGetter).set(newObj, new String(tuple.get(afi.fieldInfo.getColumnName()).toString()));
break;
case LONG:
((PojoUtils.SetterLong<Object>) afi.setterOrGetter).set(newObj, (long) tuple.get(afi.fieldInfo.getColumnName()));
break;
default:
throw new RuntimeException("Invalid Support Type");
}
} catch (Exception e) {
LOG.error("Exception in setting value", e);
throw new RuntimeException(e);
}
}
} catch (Exception ex) {
LOG.error("Generic Exception in setting value" + ex.getMessage());
newObj = null;
}
return newObj;
}
use of org.apache.apex.malhar.lib.util.FieldInfo.SupportType 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.FieldInfo.SupportType in project apex-malhar by apache.
the class RedisPOJOOutputOperator method processFirstTuple.
public void processFirstTuple(KeyValPair<String, Object> tuple) {
// Create getters using first value entry in map
// Entry<String, Object> entry= tuple.entrySet().iterator().next();
Object value = tuple.getValue();
final Class<?> fqcn = value.getClass();
final int size = dataColumns.size();
for (int i = 0; i < size; i++) {
final SupportType type = dataColumns.get(i).getType();
final String getterExpression = dataColumns.get(i).getPojoFieldExpression();
final Object getter;
switch(type) {
case STRING:
getter = PojoUtils.createGetter(fqcn, getterExpression, String.class);
break;
case BOOLEAN:
getter = PojoUtils.createGetterBoolean(fqcn, getterExpression);
break;
case SHORT:
getter = PojoUtils.createGetterShort(fqcn, getterExpression);
break;
case INTEGER:
getter = PojoUtils.createGetter(fqcn, getterExpression, type.getJavaType());
break;
case LONG:
getter = PojoUtils.createGetterLong(fqcn, getterExpression);
break;
case FLOAT:
getter = PojoUtils.createGetterFloat(fqcn, getterExpression);
break;
case DOUBLE:
getter = PojoUtils.createGetterDouble(fqcn, getterExpression);
break;
default:
getter = PojoUtils.createGetter(fqcn, getterExpression, Object.class);
break;
}
getters.add(getter);
}
}
Aggregations