private <K> void copyValueIntoRecord(T outputRecord, Record inputRecord, Field<K> field, int idx) { outputRecord.setValue(field, inputRecord.getValue(idx, field.getConverter())); }
private boolean hasSqlTypeComment(Field<?> field, Configuration conf) { if (field.getConverter() != null) { Class<?> fieldType = field.getDataType().getType(); if (fieldType.equals(ScalarArray.class)) { return true; } if (fieldType.equals(ScalarMongoObjectId.class)) { return true; } if (fieldType.equals(ScalarMongoTimestamp.class)) { return true; } } return false; }
/** * The <code>AsyncSQLClient</code> does not know anything about converters you may have set for your entities, * so we have to convert them manually on each return. * @param table * @return a <code>UnaryOperator</code> to map custom values (e.g. nested JsonObjects). */ @SuppressWarnings("unchecked") protected UnaryOperator<JsonObject> convertFromSQL(Table<?> table){ Map<String, Converter<Object, Object>> pojoConverters = table .fieldStream() .filter(f -> f.getConverter() != null) .collect(Collectors.toMap(Field::getName, v -> ((Converter<Object, Object>) v.getConverter()))); return json -> { JsonObject theCopy = new JsonObject(); for (Map.Entry<String, Object> jsonMap : json.getMap().entrySet()) { Converter<Object, Object> converter = pojoConverters.get(jsonMap.getKey()); if(converter!=null){ theCopy.put(jsonMap.getKey(), converter.from(jsonMap.getValue())); }else{ theCopy.put(jsonMap.getKey(), jsonMap.getValue()); } } return theCopy; }; }
/** * The <code>AsyncSQLClient</code> does not know anything about converters you may have set for your entities, * so we have to convert them manually on each return. * @param table * @return a <code>UnaryOperator</code> to map custom values (e.g. nested JsonObjects). */ @SuppressWarnings("unchecked") protected UnaryOperator<JsonObject> convertFromSQL(Table<?> table){ Map<String, Converter<Object, Object>> pojoConverters = table .fieldStream() .filter(f -> f.getConverter() != null) .collect(Collectors.toMap(Field::getName, v -> ((Converter<Object, Object>) v.getConverter()))); return json -> { JsonObject theCopy = new JsonObject(); for (Map.Entry<String, Object> jsonMap : json.getMap().entrySet()) { Converter<Object, Object> converter = pojoConverters.get(jsonMap.getKey()); if(converter!=null){ theCopy.put(jsonMap.getKey(), converter.from(jsonMap.getValue())); }else{ theCopy.put(jsonMap.getKey(), jsonMap.getValue()); } } return theCopy; }; }
private <K> void copyValueIntoRecord(T outputRecord, Record inputRecord, Field<K> field, int idx) { outputRecord.setValue(field, inputRecord.getValue(idx, field.getConverter())); }
private static final <T> void pgSetValue(Record record, Field<T> field, String value) { record.set(field, pgFromString(field.getConverter(), value)); }
private String getSqlType(Field<?> field, Configuration conf) { if (field.getConverter() != null) { Class<?> fieldType = field.getDataType().getType(); if (fieldType.equals(ScalarArray.class)) { return PostgreSQLScalarTypeToSqlType.ARRAY_TYPE; } if (fieldType.equals(ScalarMongoObjectId.class)) { return PostgreSQLScalarTypeToSqlType.FULL_MONGO_OBJECT_ID_TYPE; } if (fieldType.equals(ScalarMongoTimestamp.class)) { return PostgreSQLScalarTypeToSqlType.FULL_MONGO_TIMESTAMP_TYPE; } } return field.getDataType().getTypeName(conf); }
private String getSqlType(Field<?> field, Configuration conf) { if (field.getConverter() != null) { Class<?> fieldType = field.getDataType().getType(); if (fieldType.equals(ScalarArray.class)) { return GreenplumScalarTypeToSqlType.ARRAY_TYPE; } if (fieldType.equals(ScalarMongoObjectId.class)) { return GreenplumScalarTypeToSqlType.FULL_MONGO_OBJECT_ID_TYPE; } if (fieldType.equals(ScalarMongoTimestamp.class)) { return GreenplumScalarTypeToSqlType.FULL_MONGO_TIMESTAMP_TYPE; } } return field.getDataType().getTypeName(conf); }
private String getSqlTypeComment(Field<?> field, Configuration conf) { if (field.getConverter() != null) { Class<?> fieldType = field.getDataType().getType(); if (fieldType.equals(ScalarArray.class)) { return MySQLScalarTypeToSqlType.ARRAY_SIGNATURE; } if (fieldType.equals(ScalarMongoObjectId.class)) { return MySQLScalarTypeToSqlType.MONGO_OBJECT_ID_SIGNATURE; } if (fieldType.equals(ScalarMongoTimestamp.class)) { return MySQLScalarTypeToSqlType.MONGO_TIMESTAMP_SIGNATURE; } } return field.getDataType().getTypeName(conf); }
private String getSqlType(Field<?> field, Configuration conf) { if (field.getConverter() != null) { Class<?> fieldType = field.getDataType().getType(); if (fieldType.equals(ScalarArray.class)) { return MySQLScalarTypeToSqlType.ARRAY_TYPE; } if (fieldType.equals(ScalarMongoObjectId.class)) { return MySQLScalarTypeToSqlType.MONGO_OBJECT_ID_TYPE; } if (fieldType.equals(ScalarMongoTimestamp.class)) { return MySQLScalarTypeToSqlType.MONGO_TIMESTAMP_TYPE; } } return field.getDataType().getTypeName(conf); }
@Override public <T> T get(Field<T> field) { return Convert.convert(current.getValue(field.getName()), field.getConverter()); }
/** * Create a PostgreSQL string representation of a record. */ public static String toPGString(Record r) { StringBuilder sb = new StringBuilder(); sb.append("("); String separator = ""; for (int i = 0; i < r.size(); i++) { @SuppressWarnings({ "unchecked", "rawtypes" }) Object a = ((Converter) r.field(i).getConverter()).to(r.get(i)); sb.append(separator); // [#753] null must not be set as a literal if (a != null) { if (a instanceof byte[]) sb.append(toPGString((byte[]) a)); else sb.append("\"") .append(StringUtils.replace(StringUtils.replace(toPGString(a), "\\", "\\\\"), "\"", "\\\"")) .append("\""); } separator = ","; } sb.append(")"); return sb.toString(); }
@Override public <T> T get(Field<T> field) { return Convert.convert(getCurrent().getValue(field.getName()),field.getConverter()); }
@Override public <T> T get(Field<T> field) { return Convert.convert(getCurrent().getValue(field.getName()),field.getConverter()); }
private <T> T get(String columnLabel, Class<T> type) throws SQLException { checkInRange(); Converter<?, ?> converter = Converters.inverse(field(columnLabel).getConverter()); T value = Convert.convert(result.get(index - 1).get(columnLabel, converter), type); wasNull = (value == null); return value; }
private <T> T get(int columnIndex, Class<T> type) throws SQLException { checkInRange(); Converter<?, ?> converter = Converters.inverse(field(columnIndex).getConverter()); T value = Convert.convert(result.get(index - 1).get(columnIndex - 1, converter), type); wasNull = (value == null); return value; }