AbstractDynamoDao extends AbstractDao<M,P,K,I> { public void ensureIndexes() { TableDescription desc = getTable().describe(); List<AttributeDefinition> actualAttribs = desc.getAttributeDefinitions(); List<GlobalSecondaryIndexDescription> actualIndexes = desc.getGlobalSecondaryIndexes(); List<AttributeDefinition> desiredAttribs = getAttributeDefinitions(); List<GlobalSecondaryIndex> desiredIndexes = getGlobalSecondaryIndexes(); for (GlobalSecondaryIndex index : desiredIndexes) { if (!checkIndex(actualIndexes, index)) { CreateGlobalSecondaryIndexAction create = new CreateGlobalSecondaryIndexAction() .withIndexName(index.getIndexName()) .withKeySchema(index.getKeySchema()) .withProvisionedThroughput(index.getProvisionedThroughput()) .withProjection(index.getProjection()); AttributeDefinition attrHash = getAttribute(desiredAttribs, index.getKeySchema(), KeyType.HASH); AttributeDefinition attrRange = getAttribute(desiredAttribs, index.getKeySchema(), KeyType.RANGE); Index created; if (attrRange == null) { created = getTable().createGSI(create, attrHash); } else { created = getTable().createGSI(create, attrHash, attrRange); } try { created.waitForActive(); } catch (InterruptedException e) { LOGGER.warn("InterruptedException while waiting for index creation: " + created, e); } } } } AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName);  AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName, ItemMapper<M> modelMapper, ItemMapper<P> partialMapper); String getTableName(); Table getTable(); Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); Results<M,K> scanAll(); @Override M create(P partial, Instant createAt, I creatorId); void update(K id, Update<P> update, Instant updateAt, I updaterId); M updateAndReturn(K id, Update<P> update, Instant updateAt, I updaterId); Update<P> updateOf(P partial); Update<P> updateOf(P partial, Iterable<String> removeFields); @Override void delete(K id); abstract List<KeySchemaElement> getKeySchema(); abstract List<AttributeDefinition> getAttributeDefinitions(); List<GlobalSecondaryIndex> getGlobalSecondaryIndexes(); void initTable(); void dropTable(); void copyTable(AmazonDynamoDB sourceDb, String sourceTable); void ensureIndexes();  }
@Test public void testEnsureIndexes() throws Exception { dao.ensureIndexes(); Index index = dao.getTable().getIndex("orgId_createAt"); assertNotNull(index); }