예제 #1
0
  @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));
  }
예제 #2
0
 @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));
   }
 }
예제 #3
0
  @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;
  }