use of org.apache.apex.malhar.lib.util.FieldInfo in project apex-malhar by apache.
the class JdbcHDFSApp method addFieldInfos.
/**
* This method can be modified to have field mappings based on user defined
* class
*/
private List<FieldInfo> addFieldInfos() {
List<FieldInfo> fieldInfos = Lists.newArrayList();
fieldInfos.add(new FieldInfo("ACCOUNT_NO", "accountNumber", SupportType.INTEGER));
fieldInfos.add(new FieldInfo("NAME", "name", SupportType.STRING));
fieldInfos.add(new FieldInfo("AMOUNT", "amount", SupportType.INTEGER));
return fieldInfos;
}
use of org.apache.apex.malhar.lib.util.FieldInfo in project apex-malhar by apache.
the class JdbcToJdbcApp method addFieldInfos.
/**
* This method can be modified to have field mappings based on used defined
* class
*/
private List<FieldInfo> addFieldInfos() {
List<FieldInfo> fieldInfos = Lists.newArrayList();
fieldInfos.add(new FieldInfo("ACCOUNT_NO", "accountNumber", SupportType.INTEGER));
fieldInfos.add(new FieldInfo("NAME", "name", SupportType.STRING));
fieldInfos.add(new FieldInfo("AMOUNT", "amount", SupportType.INTEGER));
return fieldInfos;
}
use of org.apache.apex.malhar.lib.util.FieldInfo in project apex-malhar by apache.
the class JdbcPOJOInsertOutputOperator method activate.
@Override
public void activate(OperatorContext context) {
if (getFieldInfos() == null || getFieldInfos().size() == 0) {
Field[] fields = pojoClass.getDeclaredFields();
// Create fieldInfos in case of direct mapping
List<JdbcFieldInfo> fieldInfos = Lists.newArrayList();
for (int i = 0; i < columnNames.size(); i++) {
String columnName = columnNames.get(i);
String pojoField = getMatchingField(fields, columnName);
if (columnNullabilities.get(i) == DatabaseMetaData.columnNoNulls && (pojoField == null || pojoField.length() == 0)) {
throw new RuntimeException("Data for a non-nullable field: " + columnName + " not found in POJO");
} else {
if (pojoField != null && pojoField.length() != 0) {
JdbcFieldInfo fi = new JdbcFieldInfo(columnName, pojoField, null, Types.NULL);
fieldInfos.add(fi);
} else {
columnDataTypes.remove(i);
columnNames.remove(i);
columnNullabilities.remove(i);
i--;
}
}
}
setFieldInfos(fieldInfos);
}
for (FieldInfo fi : getFieldInfos()) {
columnFieldGetters.add(new ActiveFieldInfo(fi));
}
StringBuilder columns = new StringBuilder();
StringBuilder values = new StringBuilder();
for (int i = 0; i < columnNames.size(); i++) {
columns.append(columnNames.get(i));
values.append("?");
if (i < columnNames.size() - 1) {
columns.append(",");
values.append(",");
}
}
insertStatement = "INSERT INTO " + getTablename() + " (" + columns.toString() + ")" + " VALUES (" + values.toString() + ")";
LOG.debug("insert statement is {}", insertStatement);
super.activate(context);
}
use of org.apache.apex.malhar.lib.util.FieldInfo in project apex-malhar by apache.
the class JdbcPOJOPollInputOperator method setup.
@Override
public void setup(OperatorContext context) {
super.setup(context);
try {
if (getColumnsExpression() == null) {
StringBuilder columns = new StringBuilder();
for (int i = 0; i < fieldInfos.size(); i++) {
columns.append(fieldInfos.get(i).getColumnName());
if (i < fieldInfos.size() - 1) {
columns.append(",");
}
}
setColumnsExpression(columns.toString());
LOG.debug("select expr {}", columns.toString());
}
if (columnDataTypes == null) {
populateColumnDataTypes();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
for (FieldInfo fi : fieldInfos) {
columnFieldSetters.add(new ActiveFieldInfo(fi));
}
}
use of org.apache.apex.malhar.lib.util.FieldInfo in project apex-malhar by apache.
the class JdbcPOJOInputOperator method setFieldInfosItem.
/**
* Function to initialize the list of {@link FieldInfo} externally from configuration/properties file.
* Example entry in the properties/configuration file:
* <property>
* <name>dt.operator.JdbcPOJOInput.fieldInfosItem[0]</name>
* <value>
* {
* "columnName":"ID",
* "pojoFieldExpression": "id",
* "type":"INTEGER"
* }
* </value>
* </property>
* @param index is the index in the list which is to be initialized.
* @param value is the JSON String with appropriate mappings for {@link FieldInfo}.
*/
public void setFieldInfosItem(int index, String value) {
try {
JSONObject jo = new JSONObject(value);
FieldInfo fieldInfo = new FieldInfo(jo.getString("columnName"), jo.getString("pojoFieldExpression"), FieldInfo.SupportType.valueOf(jo.getString("type")));
final int need = index - fieldInfos.size() + 1;
for (int i = 0; i < need; i++) {
fieldInfos.add(null);
}
fieldInfos.set(index, fieldInfo);
} catch (Exception e) {
throw new RuntimeException("Exception in setting FieldInfo " + value + " " + e.getMessage());
}
}
Aggregations