@Override
  public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    EntityDocument entity = getDataStore().getEntity(Identifier.createEntityId(key));
    if (entity != null) {
      return new Tuple(new CouchDBTupleSnapshot(entity.getProperties()));
    }

    return null;
  }
 @Override
 public void removeAssociation(AssociationKey key, AssociationContext associationContext) {
   if (isStoredInEntityStructure(key, associationContext)) {
     EntityDocument owningEntity =
         getDataStore().getEntity(Identifier.createEntityId(key.getEntityKey()));
     if (owningEntity != null) {
       owningEntity.removeAssociation(key.getCollectionRole());
       getDataStore().saveDocument(owningEntity);
     }
   } else {
     removeDocumentIfPresent(Identifier.createAssociationId(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;
  }