Search in sources :

Example 1 with Getter

use of org.apache.apex.malhar.lib.util.PojoUtils.Getter in project apex-malhar by apache.

the class RedisPOJOOutputOperator method convertObjectToMap.

private Map<String, String> convertObjectToMap(Object tuple) {
    Map<String, String> mappedObject = new HashMap<String, String>();
    for (int i = 0; i < dataColumns.size(); i++) {
        final SupportType type = dataColumns.get(i).getType();
        final String columnName = dataColumns.get(i).getColumnName();
        if (i < getters.size()) {
            Getter<Object, Object> obj = (Getter<Object, Object>) (getters.get(i));
            Object value = obj.get(tuple);
            mappedObject.put(columnName, value.toString());
        }
    }
    return mappedObject;
}
Also used : HashMap(java.util.HashMap) Getter(org.apache.apex.malhar.lib.util.PojoUtils.Getter) SupportType(org.apache.apex.malhar.lib.util.FieldInfo.SupportType)

Example 2 with Getter

use of org.apache.apex.malhar.lib.util.PojoUtils.Getter in project apex-malhar by apache.

the class CassandraPOJOOutputOperator method setStatementParameters.

@Override
@SuppressWarnings("unchecked")
protected Statement setStatementParameters(PreparedStatement updateCommand, Object tuple) throws DriverException {
    final BoundStatement boundStmnt = new BoundStatement(updateCommand);
    final int size = columnDataTypes.size();
    for (int i = 0; i < size; i++) {
        final DataType type = columnDataTypes.get(i);
        switch(type.getName()) {
            case UUID:
                final UUID id = ((Getter<Object, UUID>) getters.get(i)).get(tuple);
                boundStmnt.setUUID(i, id);
                break;
            case ASCII:
            case VARCHAR:
            case TEXT:
                final String ascii = ((Getter<Object, String>) getters.get(i)).get(tuple);
                boundStmnt.setString(i, ascii);
                break;
            case BOOLEAN:
                final boolean bool = ((GetterBoolean<Object>) getters.get(i)).get(tuple);
                boundStmnt.setBool(i, bool);
                break;
            case INT:
                final int intValue = ((GetterInt<Object>) getters.get(i)).get(tuple);
                boundStmnt.setInt(i, intValue);
                break;
            case BIGINT:
            case COUNTER:
                final long longValue = ((GetterLong<Object>) getters.get(i)).get(tuple);
                boundStmnt.setLong(i, longValue);
                break;
            case FLOAT:
                final float floatValue = ((GetterFloat<Object>) getters.get(i)).get(tuple);
                boundStmnt.setFloat(i, floatValue);
                break;
            case DOUBLE:
                final double doubleValue = ((GetterDouble<Object>) getters.get(i)).get(tuple);
                boundStmnt.setDouble(i, doubleValue);
                break;
            case DECIMAL:
                final BigDecimal decimal = ((Getter<Object, BigDecimal>) getters.get(i)).get(tuple);
                boundStmnt.setDecimal(i, decimal);
                break;
            case SET:
                Set<?> set = ((Getter<Object, Set<?>>) getters.get(i)).get(tuple);
                boundStmnt.setSet(i, set);
                break;
            case MAP:
                final Map<?, ?> map = ((Getter<Object, Map<?, ?>>) getters.get(i)).get(tuple);
                boundStmnt.setMap(i, map);
                break;
            case LIST:
                final List<?> list = ((Getter<Object, List<?>>) getters.get(i)).get(tuple);
                boundStmnt.setList(i, list);
                break;
            case TIMESTAMP:
                final Date date = ((Getter<Object, Date>) getters.get(i)).get(tuple);
                boundStmnt.setDate(i, LocalDate.fromMillisSinceEpoch(date.getTime()));
                break;
            default:
                throw new RuntimeException("unsupported data type " + type.getName());
        }
    }
    return boundStmnt;
}
Also used : Getter(org.apache.apex.malhar.lib.util.PojoUtils.Getter) GetterFloat(org.apache.apex.malhar.lib.util.PojoUtils.GetterFloat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LocalDate(com.datastax.driver.core.LocalDate) GetterBoolean(org.apache.apex.malhar.lib.util.PojoUtils.GetterBoolean) DataType(com.datastax.driver.core.DataType) GetterLong(org.apache.apex.malhar.lib.util.PojoUtils.GetterLong) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) GetterInt(org.apache.apex.malhar.lib.util.PojoUtils.GetterInt) GetterDouble(org.apache.apex.malhar.lib.util.PojoUtils.GetterDouble)

Aggregations

Getter (org.apache.apex.malhar.lib.util.PojoUtils.Getter)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 DataType (com.datastax.driver.core.DataType)1 LocalDate (com.datastax.driver.core.LocalDate)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 SupportType (org.apache.apex.malhar.lib.util.FieldInfo.SupportType)1 GetterBoolean (org.apache.apex.malhar.lib.util.PojoUtils.GetterBoolean)1 GetterDouble (org.apache.apex.malhar.lib.util.PojoUtils.GetterDouble)1 GetterFloat (org.apache.apex.malhar.lib.util.PojoUtils.GetterFloat)1 GetterInt (org.apache.apex.malhar.lib.util.PojoUtils.GetterInt)1 GetterLong (org.apache.apex.malhar.lib.util.PojoUtils.GetterLong)1