@Override public final String convert(final T object) { final StringBuilder string = new StringBuilder(); for (int i = 0; i < fields.length; i++) { if (i > 0) { string.append(delimiter); } final String value = fields[i].get(object); if (value != null) { if (value.contains(delimiter)) { throw new DynamoDBMappingException(String.format( "%s[%s] field value \"%s\" must not contain delimiter %s", targetType, fields[i].bean.properties().attributeName(), value, delimiter )); } string.append(value); } } return string.length() < fields.length ? null : string.toString(); }
@Override public Map<String, AttributeValue> convert(Object object) { if (object == null) { return null; } Class<Object> clazz = (Class<Object>)object.getClass(); Map<String, AttributeValue> result = new HashMap<String, AttributeValue>(); for (final Bean<Object,Object> bean : StandardBeanProperties.of(clazz).map().values()) { Object getterResult = bean.reflect().get(object); if (getterResult != null) { AttributeValue value = convert(bean.type().getter(), getterResult); if (value != null) { result.put(bean.properties().attributeName(), value); } } } return result; }
private TableBuilder(Class<T> clazz, Beans<T> beans, RuleFactory<Object> rules) { super(clazz, beans.properties()); for (final Bean<T,Object> bean : beans.map().values()) { try { with(new FieldBuilder<T,Object>(clazz, bean, rules.getRule(bean.type())).build()); } catch (final RuntimeException e) { throw new DynamoDBMappingException(String.format( "%s[%s] could not be mapped for type %s", clazz.getSimpleName(), bean.properties().attributeName(), bean.type() ), e); } } }
@Override public Map<String, AttributeValue> convert(Object object) { if (object == null) { return null; } Class<Object> clazz = (Class<Object>)object.getClass(); Map<String, AttributeValue> result = new HashMap<String, AttributeValue>(); for (final Bean<Object,Object> bean : StandardBeanProperties.of(clazz).map().values()) { Object getterResult = bean.reflect().get(object); if (getterResult != null) { AttributeValue value = convert(bean.type().getter(), getterResult); if (value != null) { result.put(bean.properties().attributeName(), value); } } } return result; }
@Override public final String convert(final T object) { final StringBuilder string = new StringBuilder(); for (int i = 0; i < fields.length; i++) { if (i > 0) { string.append(delimiter); } final String value = fields[i].get(object); if (value != null) { if (value.contains(delimiter)) { throw new DynamoDBMappingException(String.format( "%s[%s] field value \"%s\" must not contain delimiter %s", targetType, fields[i].bean.properties().attributeName(), value, delimiter )); } string.append(value); } } return string.length() < fields.length ? null : string.toString(); }
@Override public <T> T unconvert( Class<T> clazz, Map<String, AttributeValue> value) { T result = createObject(clazz); if (value == null || value.isEmpty()) { return result; } for (final Bean<T,Object> bean : StandardBeanProperties.of(clazz).map().values()) { AttributeValue av = value.get(bean.properties().attributeName()); if (av != null) { ArgumentUnmarshaller unmarshaller = getUnmarshaller(bean.type().getter(), bean.type().setter()); Object unmarshalled = unmarshall(unmarshaller, bean.type().setter(), av); bean.reflect().set(result, unmarshalled); } } return result; }
final boolean isVersion() { return bean.properties().versioned(); } final String getAttributeName() {
final boolean isPrimaryKey() { return bean.properties().keyType() != null; } final boolean isVersion() {
private TableBuilder(Class<T> clazz, Beans<T> beans, RuleFactory<Object> rules) { super(clazz, beans.properties()); for (final Bean<T,Object> bean : beans.map().values()) { try { with(new FieldBuilder<T,Object>(clazz, bean, rules.getRule(bean.type())).build()); } catch (final RuntimeException e) { throw new DynamoDBMappingException(String.format( "%s[%s] could not be mapped for type %s", clazz.getSimpleName(), bean.properties().attributeName(), bean.type() ), e); } } }
final String getAttributeName() { return bean.properties().attributeName(); } }
private void putOrFlatten(FieldMap<V> annotations, Reflect<T,V> reflect, Method getter) { if (annotations.flattened()) { flatten((Class<T>)annotations.targetType(), annotations.attributes(), (Reflect<T,T>)reflect); } else { final Bean<T,V> bean = new Bean<T,V>(annotations, reflect, getter); if (put(bean.properties().attributeName(), bean) != null) { throw new DynamoDBMappingException("duplicate attribute name " + bean.properties().attributeName()); } } }
private FieldBuilder(Class<T> clazz, Bean<T,V> bean, Rule<V> rule) { super(clazz, bean.properties()); if (bean.type().attributeType() != null) { with(bean.type().attributeType()); } else { with(rule.getAttributeType()); } with(rule.newConverter(bean.type())); with(bean.reflect()); } }
@Override public <T> T unconvert( Class<T> clazz, Map<String, AttributeValue> value) { T result = createObject(clazz); if (value == null || value.isEmpty()) { return result; } for (final Bean<T,Object> bean : StandardBeanProperties.of(clazz).map().values()) { AttributeValue av = value.get(bean.properties().attributeName()); if (av != null) { ArgumentUnmarshaller unmarshaller = getUnmarshaller(bean.type().getter(), bean.type().setter()); Object unmarshalled = unmarshall(unmarshaller, bean.type().setter(), av); bean.reflect().set(result, unmarshalled); } } return result; }
final boolean isVersion() { return bean.properties().versioned(); } final String getAttributeName() {
private void putOrFlatten(FieldMap<V> annotations, Reflect<T,V> reflect, Method getter) { if (annotations.flattened()) { flatten((Class<T>)annotations.targetType(), annotations.attributes(), (Reflect<T,T>)reflect); } else { final Bean<T,V> bean = new Bean<T,V>(annotations, reflect, getter); if (put(bean.properties().attributeName(), bean) != null) { throw new DynamoDBMappingException("duplicate attribute name " + bean.properties().attributeName()); } } }
private FieldBuilder(Class<T> clazz, Bean<T,V> bean, Rule<V> rule) { super(clazz, bean.properties()); if (bean.type().attributeType() != null) { with(bean.type().attributeType()); } else { with(rule.getAttributeType()); } with(rule.newConverter(bean.type())); with(bean.reflect()); } }
final String getAttributeName() { return bean.properties().attributeName(); } }
final boolean isPrimaryKey() { return bean.properties().keyType() != null; } final boolean isVersion() {