List of usage examples for com.amazonaws.services.simpledb.util SimpleDBUtils encodeDate
public static String encodeDate(Date date)
From source file:com.shelfmap.simplequery.domain.impl.DateAttributeConverter.java
License:Apache License
@Override public String convertValue(Date targetValue) { if (targetValue == null) return null; return SimpleDBUtils.encodeDate(targetValue); }
From source file:wwutil.jsoda.DataUtil.java
License:Mozilla Public License
/** Caller should handle custom valueType first before calling this. * E.g. DynamoDB's Set<String> and Set<long> fields are encoded as Multi-Value AttributeValue. *//*from ww w . j av a2s . com*/ @SuppressWarnings("unchecked") static String encodeValueToAttrStr(Object value, Class valueType) { if (value == null) return null; // Caller needs to handle null correctly, e.g. skip storing AttributeValue. if (valueType == String.class) return value.toString(); // NOTE: Don't change encoding and padding once data have been created. Different encoding will mess up sorting. // Stringify basic type and encode them for sorting. if (valueType == Byte.class || valueType == byte.class) { Byte casted = (Byte) ConvertUtils.convert(value, Byte.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 3); // 0-Padded for sorting } else if (valueType == Short.class || valueType == short.class) { Short casted = (Short) ConvertUtils.convert(value, Short.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 5); // 0-Padded for sorting } else if (valueType == Integer.class || valueType == int.class) { Integer casted = (Integer) ConvertUtils.convert(value, Integer.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 10); // 0-Padded for sorting } else if (valueType == Long.class || valueType == long.class) { Long casted = (Long) ConvertUtils.convert(value, Long.class); return SimpleDBUtils.encodeZeroPadding(casted.longValue(), 19); // 0-Padded for sorting } else if (valueType == Float.class || valueType == float.class) { Float casted = (Float) ConvertUtils.convert(value, Float.class); return SimpleDBUtils.encodeZeroPadding(casted.floatValue(), 16); // 0-Padded for sorting } else if (valueType == Double.class || valueType == double.class) { // SimpleDBUtils has no padding for double. Just convert it to String. return value.toString(); } else if (valueType == Boolean.class || valueType == boolean.class) { return value.toString(); } else if (valueType == Character.class || valueType == char.class) { return value.toString(); } else if (valueType == Date.class) { return SimpleDBUtils.encodeDate((Date) value); } else if (valueType.isEnum()) { return ((Enum) value).name(); } // JSONify the rest. return toJson(value); }