Ejemplo n.º 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));
  }
Ejemplo n.º 2
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;
  }