public void createTable(Class<? extends IDomain> domain){ CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(domain); tableRequest = tableRequest.withProvisionedThroughput(new ProvisionedThroughput(5L,5L)); //check whether or not we need to add a provisioning throughput value for GSI for (Method method : domain.getMethods()) { if(method.isAnnotationPresent(DynamoDBIndexHashKey.class)){ String tempGSI = method.getAnnotation(DynamoDBIndexHashKey.class).globalSecondaryIndexName(); for (GlobalSecondaryIndex globalSecondaryIndex : tableRequest.getGlobalSecondaryIndexes()) { if(globalSecondaryIndex.getIndexName().equals(tempGSI)){ globalSecondaryIndex.setProvisionedThroughput(new ProvisionedThroughput(5L,5L)); } } } } amazonDynamoDBClient.createTable(tableRequest); }
/*** * 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; }
@DynamoDBHashKey @DynamoDBIndexHashKey ( globalSecondaryIndexNames = { "GSI-primary-hash-index-range-1", "GSI-primary-hash-index-range-2"} ) public String getPrimaryHashKey() { return primaryHashKey; }
@DynamoDBIndexHashKey ( globalSecondaryIndexNames = { "GSI-index-hash-primary-range", "GSI-index-hash-index-range-1", "GSI-index-hash-index-range-2"} ) public String getIndexHashKey() { return indexHashKey; }
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 @DynamoDBIndexHashKey(globalSecondaryIndexName = "accountToken-index") public String getAccountToken() { return accountToken; }
@DynamoDBIndexHashKey public String getFolio() { return folio; }
@DynamoDBIndexHashKey public String getIdDenuncia() { return idDenuncia; }
@DynamoDBAttribute(attributeName="by") @DynamoDBIndexHashKey(attributeName="by", globalSecondaryIndexName="by-time-index") public String getBy() {return by; }
@DynamoDBIndexHashKey(attributeName="isbn", globalSecondaryIndexName="isbn-index") public String getIsbn() { return isbn; }
@DynamoDBIndexHashKey(attributeName="libraryId", globalSecondaryIndexName=GLOBAL_INDEX_LIBRARY_ISBN) public String getLibraryId() { return libraryId; }
@DynamoDBIndexHashKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_ISBN}) @DynamoDBIndexRangeKey(attributeName="isbn", globalSecondaryIndexName=GLOBAL_INDEX_LIBRARY_ISBN) public String getIsbn() { return isbn; }
@DynamoDBIndexHashKey(attributeName="checkedOutBy", globalSecondaryIndexName=GLOBAL_INDEX_CHECKED_OUT_BY) public String getCheckedOutBy() { return checkedOutBy; }
@DynamoDBIndexHashKey(attributeName="libraryId", globalSecondaryIndexNames={GLOBAL_INDEX_LIBRARY_ID, GLOBAL_INDEX_LIBRARY_ISBN}) public String getLibraryId() { return libraryId; }
@DynamoDBIndexHashKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_ISBN, GLOBAL_INDEX_ISBN_STATUS}) @DynamoDBIndexRangeKey(attributeName="isbn", globalSecondaryIndexNames={GLOBAL_INDEX_LIBRARY_ISBN}) public String getIsbn() { return isbn; }
/*** * Get data required to build out global secondary indexes * * @param hashKeyIndexFields * @param rangeKeyIndexFields * @param clazz * * @return globalIndexMap */ private Map<String, GlobalIndex> createGlobalIndexes(final Set<Method> hashKeyIndexFields, final Set<Method> rangeKeyIndexFields, Class<?> clazz) { final Map<String, GlobalIndex> globalIndexes = Maps.newHashMap(); for(Method m : hashKeyIndexFields){ final Set<String> globalIndexNames = Sets.newHashSet(); final DynamoDBIndexHashKey indexHashKeyAnno = m.getAnnotation(DynamoDBIndexHashKey.class); String[] indexNames = this.getAnnotationValue(indexHashKeyAnno, "globalSecondaryIndexNames", String[].class); if(indexNames==null || indexNames.length==0){ String indexName = this.getAnnotationValue(indexHashKeyAnno, "globalSecondaryIndexName", String.class); Preconditions.checkArgument(!Strings.isNullOrEmpty(indexName), String.format("Index Name is required for DynamoDBIndexHashKey attribute for class %s field %s", clazz.getName(), m.getName())); globalIndexNames.add(indexName); }else{ globalIndexNames.addAll(Sets.newHashSet(indexNames)); } String attributeName = this.getAnnotationValue(indexHashKeyAnno, "attributeName", String.class); String dataType = this.getKeyType(m); final Map<String, RangeKeyIndexField> globalIndexRangeKeys = this.getGlobalIndexRangeKeys(rangeKeyIndexFields); /** Process Global Indexes **/ for(String name : globalIndexNames){ final GlobalIndex global = new GlobalIndex(); global.setName(name); global.setHashKey(attributeName); global.setHashKeyType(dataType); /** Range key is optional for a global secondary index **/ final RangeKeyIndexField rangeKey = globalIndexRangeKeys.get(name); if(rangeKey!=null){ global.setRangeKeyField(rangeKey); } globalIndexes.put(name, global); } } return globalIndexes; }
@DynamoDBIndexHashKey(globalSecondaryIndexName="CraftId-PostTimestamp-index", attributeName="CraftId") public String getCraftId() { return craftId; }
@DynamoDBIndexHashKey(globalSecondaryIndexName="FandomId-PostTimestamp-index",attributeName="FandomId") public String getFandomId() { return fandomId; }
@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; }