/*** * Create the table and the associated indexes if it does not already exist * @param reflections * @param clazz */ private CreateTableResult createTable(Class<?> clazz) { final String tableName = this.getClassAnnotationValue(clazz, DynamoDBTable.class, String.class, "tableName"); final Method hashKeyMember = this.getMethodForAnnotation(clazz, DynamoDBHashKey.class); final DynamoDBHashKey hashKeyAnno = hashKeyMember.getAnnotation(DynamoDBHashKey.class); final String hashKeyName = this.getAnnotationValue(hashKeyAnno, "attributeName", String.class); String rangeKeyName = null; final Method rangeKeyMember = this.getMethodForAnnotation(clazz, DynamoDBRangeKey.class); if(rangeKeyMember!=null){ DynamoDBRangeKey rangeKeyAnno = rangeKeyMember.getAnnotation(DynamoDBRangeKey.class); rangeKeyName = this.getAnnotationValue(rangeKeyAnno, "attributeName", String.class); } final Set<Method> hashKeyIndexFields = this.getMethodsAnnotatedWith(DynamoDBIndexHashKey.class, clazz); final Set<Method> rangeKeyIndexFields = this.getMethodsAnnotatedWith(DynamoDBIndexRangeKey.class, clazz); final Map<String, GlobalIndex> globalIndexes = this.createGlobalIndexes(hashKeyIndexFields, rangeKeyIndexFields, clazz); final Map<String, RangeKeyIndexField> localIndexes = this.createLocalIndexMap(rangeKeyIndexFields); final CreateTableRequest tableRequest = this.createCreateTableRequest(tableName, hashKeyName, rangeKeyName, globalIndexes, localIndexes); final CreateTableResult result = this.client.createTable(tableRequest); return result; }
@DoNotEncrypt @DynamoDBIndexRangeKey ( localSecondaryIndexName = "index_foo", attributeName = "indexFooRangeKey" ) public Double getIndexFooRangeKeyWithFakeName() { return indexFooRangeKey; }
@DoNotEncrypt @DynamoDBIndexRangeKey ( localSecondaryIndexName = "index_bar" ) public Double getIndexBarRangeKey() { return indexBarRangeKey; }
@DoNotEncrypt @DynamoDBIndexRangeKey ( localSecondaryIndexNames = {"index_foo_copy", "index_bar_copy"} ) public Double getMultipleIndexRangeKey() { return multipleIndexRangeKey; }
@DynamoDBRangeKey @DynamoDBIndexRangeKey ( globalSecondaryIndexNames = {"GSI-index-hash-primary-range"}, localSecondaryIndexName = "LSI-primary-range" ) public String getPrimaryRangeKey() { return primaryRangeKey; }
@DynamoDBIndexRangeKey ( globalSecondaryIndexNames = { "GSI-primary-hash-index-range-1", "GSI-index-hash-index-range-1", "GSI-index-hash-index-range-2"}, localSecondaryIndexNames = {"LSI-index-range-1", "LSI-index-range-2"} ) public String getIndexRangeKey() { return indexRangeKey; }
@DynamoDBIndexRangeKey ( localSecondaryIndexName = "LSI-index-range-3", globalSecondaryIndexName = "GSI-primary-hash-index-range-2" ) public String getAnotherIndexRangeKey() { return anotherIndexRangeKey; }
@Override public Set<String> getIndexRangeKeyPropertyNames() { final Set<String> propertyNames = new HashSet<String>(); ReflectionUtils.doWithMethods(getJavaType(), new MethodCallback() { public void doWith(Method method) { if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null) { if ((method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && method .getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0) || (method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && method .getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) { propertyNames.add(getPropertyNameForAccessorMethod(method)); } } } }); ReflectionUtils.doWithFields(getJavaType(), new FieldCallback() { public void doWith(Field field) { if (field.getAnnotation(DynamoDBIndexRangeKey.class) != null) { if ((field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && field .getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0) || (field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && field .getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) { propertyNames.add(getPropertyNameForField(field)); } } } }); return propertyNames; }
public String getOverriddenAttributeName(Method method) { if (method != null) { if (method.getAnnotation(DynamoDBAttribute.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBAttribute.class).attributeName())) { return method.getAnnotation(DynamoDBAttribute.class).attributeName(); } if (method.getAnnotation(DynamoDBHashKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBHashKey.class).attributeName())) { return method.getAnnotation(DynamoDBHashKey.class).attributeName(); } if (method.getAnnotation(DynamoDBRangeKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBRangeKey.class).attributeName())) { return method.getAnnotation(DynamoDBRangeKey.class).attributeName(); } if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBIndexRangeKey.class).attributeName())) { return method.getAnnotation(DynamoDBIndexRangeKey.class).attributeName(); } if (method.getAnnotation(DynamoDBIndexHashKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBIndexHashKey.class).attributeName())) { return method.getAnnotation(DynamoDBIndexHashKey.class).attributeName(); } if (method.getAnnotation(DynamoDBVersionAttribute.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBVersionAttribute.class).attributeName())) { return method.getAnnotation(DynamoDBVersionAttribute.class).attributeName(); } } return null; }
@DynamoDBAttribute(attributeName="time") @DynamoDBIndexRangeKey(attributeName="time", globalSecondaryIndexName="by-time-index") public long getTime() {return time; }
@DynamoDBIndexRangeKey(localSecondaryIndexName = "LSI") public String getLsiRangeKey() { return lsiRangeKey; }
@DynamoDBIndexHashKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_ISBN}) @DynamoDBIndexRangeKey(attributeName="isbn", globalSecondaryIndexName=GLOBAL_INDEX_LIBRARY_ISBN) public String getIsbn() { return isbn; }
@DynamoDBIndexHashKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_ISBN, GLOBAL_INDEX_ISBN_STATUS}) @DynamoDBIndexRangeKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_LIBRARY_ISBN}) public String getIsbn() { return isbn; }
@DynamoDBIndexRangeKey(attributeName="status", globalSecondaryIndexName=GLOBAL_INDEX_ISBN_STATUS) public String getStatus() { return status; }
@DynamoDBRangeKey(attributeName="PostTimestamp") @DynamoDBIndexRangeKey(globalSecondaryIndexNames={"CraftId-PostTimestamp-index","FandomId-PostTimestamp-index"}, attributeName="PostTimestamp") public String getPosttimestamp() { return posttimestamp; }
@DynamoDBIndexRangeKey(attributeName = "Message") public String getMessage() { return message; }
@Override public String getOverriddenAttributeName(final String propertyName) { Method method = findMethod(propertyName); if (method != null) { if (method.getAnnotation(DynamoDBAttribute.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBAttribute.class).attributeName())) { return method.getAnnotation(DynamoDBAttribute.class).attributeName(); } if (method.getAnnotation(DynamoDBHashKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBHashKey.class).attributeName())) { return method.getAnnotation(DynamoDBHashKey.class).attributeName(); } if (method.getAnnotation(DynamoDBRangeKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBRangeKey.class).attributeName())) { return method.getAnnotation(DynamoDBRangeKey.class).attributeName(); } if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBIndexRangeKey.class).attributeName())) { return method.getAnnotation(DynamoDBIndexRangeKey.class).attributeName(); } if (method.getAnnotation(DynamoDBIndexHashKey.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBIndexHashKey.class).attributeName())) { return method.getAnnotation(DynamoDBIndexHashKey.class).attributeName(); } if (method.getAnnotation(DynamoDBVersionAttribute.class) != null && StringUtils.isNotEmpty(method.getAnnotation(DynamoDBVersionAttribute.class).attributeName())) { return method.getAnnotation(DynamoDBVersionAttribute.class).attributeName(); } } Field field = findField(propertyName); if (field != null) { if (field.getAnnotation(DynamoDBAttribute.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBAttribute.class).attributeName())) { return field.getAnnotation(DynamoDBAttribute.class).attributeName(); } if (field.getAnnotation(DynamoDBHashKey.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBHashKey.class).attributeName())) { return field.getAnnotation(DynamoDBHashKey.class).attributeName(); } if (field.getAnnotation(DynamoDBRangeKey.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBRangeKey.class).attributeName())) { return field.getAnnotation(DynamoDBRangeKey.class).attributeName(); } if (field.getAnnotation(DynamoDBIndexRangeKey.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBIndexRangeKey.class).attributeName())) { return field.getAnnotation(DynamoDBIndexRangeKey.class).attributeName(); } if (field.getAnnotation(DynamoDBIndexHashKey.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBIndexHashKey.class).attributeName())) { return field.getAnnotation(DynamoDBIndexHashKey.class).attributeName(); } if (field.getAnnotation(DynamoDBVersionAttribute.class) != null && StringUtils.isNotEmpty(field.getAnnotation(DynamoDBVersionAttribute.class).attributeName())) { return field.getAnnotation(DynamoDBVersionAttribute.class).attributeName(); } } return null; }