@Override public void updateAssociation( Association association, AssociationKey associationKey, AssociationContext associationContext) { List<Map<String, Object>> rows = getAssociationRows(association, associationKey); CouchDBAssociation couchDBAssociation = ((CouchDBAssociationSnapshot) association.getSnapshot()).getCouchDbAssociation(); couchDBAssociation.setRows(rows); getDataStore().saveDocument(couchDBAssociation.getOwningDocument()); }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { CouchDBAssociation couchDBAssociation = null; if (isStoredInEntityStructure(key, associationContext)) { EntityDocument owningEntity = getDataStore().getEntity(Identifier.createEntityId(key.getEntityKey())); if (owningEntity == null) { owningEntity = (EntityDocument) getDataStore().saveDocument(new EntityDocument(key.getEntityKey())); } couchDBAssociation = CouchDBAssociation.fromEmbeddedAssociation(owningEntity, key.getCollectionRole()); } else { AssociationDocument association = new AssociationDocument(Identifier.createAssociationId(key)); couchDBAssociation = CouchDBAssociation.fromAssociationDocument(association); } return new Association(new CouchDBAssociationSnapshot(couchDBAssociation, key)); }
@Override public Association getAssociation(AssociationKey key, AssociationContext associationContext) { CouchDBAssociation couchDBAssociation = null; if (isStoredInEntityStructure(key, associationContext)) { EntityDocument owningEntity = getDataStore().getEntity(Identifier.createEntityId(key.getEntityKey())); if (owningEntity != null && owningEntity.getProperties().containsKey(key.getCollectionRole())) { couchDBAssociation = CouchDBAssociation.fromEmbeddedAssociation(owningEntity, key.getCollectionRole()); } } else { AssociationDocument association = getDataStore().getAssociation(Identifier.createAssociationId(key)); if (association != null) { couchDBAssociation = CouchDBAssociation.fromAssociationDocument(association); } } return couchDBAssociation != null ? new Association(new CouchDBAssociationSnapshot(couchDBAssociation, key)) : null; }