private final Beans<T> getBeans(Class<T> clazz) { if (!cache.containsKey(clazz)) { final TableMap<T> annotations = StandardAnnotationMaps.<T>of(clazz); final BeanMap<T,Object> map = new BeanMap<T,Object>(clazz, false); cache.putIfAbsent(clazz, new Beans<T>(annotations, map)); } return cache.get(clazz); } }
private void flatten(Class<T> targetType, Map<String,String> attributes, Reflect<T,T> declaring) { for (final Method method : targetType.getMethods()) { if (canMap(method, true)) { String name = fieldNameOf(method); if ((name = attributes.remove(name)) == null) { continue; } final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, name); if (!annotations.ignored()) { final Reflect<T,V> reflect = new DeclaringReflect<T,V>(method, declaring, targetType); putOrFlatten(annotations, reflect, method); } } } if (!attributes.isEmpty()) { //<- this should be empty by now throw new DynamoDBMappingException("contains unknown flattened attribute(s): " + attributes); } }
@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 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(); }
private void flatten(Class<T> targetType, Map<String,String> attributes, Reflect<T,T> declaring) { for (final Method method : targetType.getMethods()) { if (canMap(method, true)) { String name = fieldNameOf(method); if ((name = attributes.remove(name)) == null) { continue; } final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, name); if (!annotations.ignored()) { final Reflect<T,V> reflect = new DeclaringReflect<T,V>(method, declaring, targetType); putOrFlatten(annotations, reflect, method); } } } if (!attributes.isEmpty()) { //<- this should be empty by now throw new DynamoDBMappingException("contains unknown flattened attribute(s): " + attributes); } }
public Converter(Class<T> targetType, DynamoDBDelimited annotation) { final BeanMap<T,Object> beans = new BeanMap<T,Object>(targetType, true); final String[] names = annotation.attributeNames(); if (names.length <= 1) { throw new DynamoDBMappingException(targetType + " missing attributeNames in @DynamoDBDelimited; must specify two or more attribute names"); } this.delimiter = String.valueOf(annotation.delimiter()); this.fields = new Field[names.length]; this.targetType = targetType; for (int i = 0; i < fields.length; i ++) { if (beans.containsKey(names[i]) == false) { throw new DynamoDBMappingException(targetType + " does not map %s on model " + names[i]); } this.fields[i] = new Field<T,Object>(targetType, beans.get(names[i])); } }
BeanMap(Class<T> clazz, boolean inherited) { this.clazz = clazz; putAll(clazz, inherited); }
private final Beans<T> getBeans(Class<T> clazz) { if (!cache.containsKey(clazz)) { final TableMap<T> annotations = StandardAnnotationMaps.<T>of(clazz); final BeanMap<T,Object> map = new BeanMap<T,Object>(clazz, false); cache.putIfAbsent(clazz, new Beans<T>(annotations, map)); } return cache.get(clazz); } }
private void putAll(Class<T> clazz, boolean inherited) { for (final Method method : clazz.getMethods()) { if (canMap(method, inherited)) { final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, null); if (!annotations.ignored()) { final Reflect<T,V> reflect = new MethodReflect<T,V>(method); putOrFlatten(annotations, reflect, method); } } } }
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()); } } }
public Converter(Class<T> targetType, DynamoDBDelimited annotation) { final BeanMap<T,Object> beans = new BeanMap<T,Object>(targetType, true); final String[] names = annotation.attributeNames(); if (names.length <= 1) { throw new DynamoDBMappingException(targetType + " missing attributeNames in @DynamoDBDelimited; must specify two or more attribute names"); } this.delimiter = String.valueOf(annotation.delimiter()); this.fields = new Field[names.length]; this.targetType = targetType; for (int i = 0; i < fields.length; i ++) { if (beans.containsKey(names[i]) == false) { throw new DynamoDBMappingException(targetType + " does not map %s on model " + names[i]); } this.fields[i] = new Field<T,Object>(targetType, beans.get(names[i])); } }
BeanMap(Class<T> clazz, boolean inherited) { this.clazz = clazz; putAll(clazz, inherited); }
private void putAll(Class<T> clazz, boolean inherited) { for (final Method method : clazz.getMethods()) { if (canMap(method, inherited)) { final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, null); if (!annotations.ignored()) { final Reflect<T,V> reflect = new MethodReflect<T,V>(method); putOrFlatten(annotations, reflect, method); } } } }
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()); } } }