AbstractDynamoDao extends AbstractDao<M,P,K,I> { @Override public M create(P partial, Instant createAt, I creatorId) { Item item = toCreateItem(partial, createAt, creatorId); PutItemSpec spec = new PutItemSpec() .withItem(item); if (getFieldData().getId() != null) { spec = spec.withConditionExpression("attribute_not_exists(#id)") .withNameMap(new NameMap() .with("#id", getFieldData().getId().getStorageName()) ); } M model = modelMapper.toObject(item); getTable().putItem(spec); return model; } 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 testNoIdField() throws Exception { NoIdModel model = new NoIdModel(); model.name = "Test"; NoIdDao noIdDao = new NoIdDao(NoIdModel.class, dynamodb, "noid"); noIdDao.dropAndInitTable(); NoIdModel created = noIdDao.create(model); assertEquals(model.name, created.name); }
@Test public void testCreateLoad() throws Exception { UUID creatorId = UUID.randomUUID(); TestModel created = dao.create(TestModel.builder() .name("Ian White") .birthday(LocalDate.of(1980, 5, 12)) .build(), creatorId); TestModel loaded = dao.load(created.getId()); assertEquals(created, loaded); assertNotNull(created.getCreateAt()); assertEquals(creatorId, created.getCreateId()); }