예제 #1
0
  private void processDelayedUpdates(
      final List<EntityLinkDesc> delayedUpdates,
      int pos,
      final TransactionItems items,
      final ODataChangeset changeset) {

    for (EntityLinkDesc delayedUpdate : delayedUpdates) {
      pos++;
      items.put(delayedUpdate.getSource(), pos);

      final ODataEntity changes =
          ODataFactory.newEntity(delayedUpdate.getSource().getEntity().getName());

      AttachedEntityStatus status =
          EntityContainerFactory.getContext().entityContext().getStatus(delayedUpdate.getSource());

      final URI sourceURI;
      if (status == AttachedEntityStatus.CHANGED) {
        sourceURI =
            URIUtils.getURI(
                factory.getServiceRoot(),
                delayedUpdate.getSource().getEntity().getEditLink().toASCIIString());
      } else {
        int sourcePos = items.get(delayedUpdate.getSource());
        sourceURI = URI.create("$" + sourcePos);
      }

      for (EntityTypeInvocationHandler target : delayedUpdate.getTargets()) {
        status = EntityContainerFactory.getContext().entityContext().getStatus(target);

        final URI targetURI;
        if (status == AttachedEntityStatus.CHANGED) {
          targetURI =
              URIUtils.getURI(
                  factory.getServiceRoot(), target.getEntity().getEditLink().toASCIIString());
        } else {
          int targetPos = items.get(target);
          targetURI = URI.create("$" + targetPos);
        }

        changes.addLink(
            delayedUpdate.getType() == ODataLinkType.ENTITY_NAVIGATION
                ? ODataFactory.newEntityNavigationLink(delayedUpdate.getSourceName(), targetURI)
                : ODataFactory.newFeedNavigationLink(delayedUpdate.getSourceName(), targetURI));

        LOG.debug(
            "'{}' from {} to {}",
            new Object[] {delayedUpdate.getType().name(), sourceURI, targetURI});
      }

      batchUpdate(delayedUpdate.getSource(), sourceURI, changes, changeset);
    }
  }
예제 #2
0
  private ODataLink buildNavigationLink(
      final String name, final URI uri, final ODataLinkType type) {
    switch (type) {
      case ENTITY_NAVIGATION:
        return ODataFactory.newEntityNavigationLink(name, uri);

      case ENTITY_SET_NAVIGATION:
        return ODataFactory.newFeedNavigationLink(name, uri);

      default:
        throw new IllegalArgumentException("Invalid link type " + type.name());
    }
  }