예제 #1
0
  @Override
  public void nodeRemoved(Object nodeId) {
    ObjectId id = (ObjectId) nodeId;

    final MutableObjectChange objectChangeSet = changeSet.getOrCreate(id, ObjectChangeType.DELETE);

    // TODO: rewrite with SelectById query after Cayenne upgrade
    ObjectIdQuery query = new ObjectIdQuery(id, true, ObjectIdQuery.CACHE);
    QueryResponse result = channel.onQuery(null, query);

    @SuppressWarnings("unchecked")
    List<DataRow> rows = result.firstList();

    if (rows.isEmpty()) {
      LOGGER.warn(
          "No DB snapshot for object to be deleted, no changes will be recorded. ID: " + id);
      return;
    }

    final DataRow row = rows.get(0);

    ClassDescriptor descriptor = channel.getEntityResolver().getClassDescriptor(id.getEntityName());
    final PostCommitEntity entity = entityFactory.getEntity(id);

    descriptor.visitProperties(
        new PropertyVisitor() {

          @Override
          public boolean visitAttribute(AttributeProperty property) {

            if (!entity.isIncluded(property.getName())) {
              return true;
            }

            Object value;
            if (entity.isConfidential(property.getName())) {
              value = Confidential.getInstance();
            } else {
              String key = property.getAttribute().getDbAttributeName();
              value = row.get(key);
            }

            if (value != null) {
              objectChangeSet.attributeChanged(property.getName(), value, null);
            }
            return true;
          }

          @Override
          public boolean visitToOne(ToOneProperty property) {
            // TODO record FK changes?
            return true;
          }

          @Override
          public boolean visitToMany(ToManyProperty property) {
            return true;
          }
        });
  }
예제 #2
0
  /** @since 3.1 */
  @Override
  protected void attachToChannel(DataChannel channel) {

    super.attachToChannel(channel);

    if (mergeHandler != null) {
      mergeHandler.setActive(false);
      mergeHandler = null;
    }

    EventManager eventManager = channel.getEventManager();

    if (eventManager != null) {
      mergeHandler = new DataContextMergeHandler(this);

      // listen to our channel events...
      // note that we must reset listener on channel switch, as there is
      // no
      // guarantee that a new channel uses the same EventManager.
      EventUtil.listenForChannelEvents(channel, mergeHandler);
    }

    if (!usingSharedSnaphsotCache && getObjectStore() != null) {
      DataRowStore cache = getObjectStore().getDataRowCache();

      if (cache != null) {
        cache.setEventManager(eventManager);
      }
    }
  }