Search in sources :

Example 1 with CommitLogEntity

use of org.apache.cayenne.commitlog.meta.CommitLogEntity in project cayenne by apache.

the class DeletedDiffProcessor method nodeRemoved.

@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 CommitLogEntity 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;
        }
    });
}
Also used : MutableObjectChange(org.apache.cayenne.commitlog.model.MutableObjectChange) CommitLogEntity(org.apache.cayenne.commitlog.meta.CommitLogEntity) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ObjectId(org.apache.cayenne.ObjectId) AttributeProperty(org.apache.cayenne.reflect.AttributeProperty) DataRow(org.apache.cayenne.DataRow) ToOneProperty(org.apache.cayenne.reflect.ToOneProperty) ToManyProperty(org.apache.cayenne.reflect.ToManyProperty) QueryResponse(org.apache.cayenne.QueryResponse) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) PropertyVisitor(org.apache.cayenne.reflect.PropertyVisitor)

Example 2 with CommitLogEntity

use of org.apache.cayenne.commitlog.meta.CommitLogEntity in project cayenne by apache.

the class DiffFilter method nodePropertyChanged.

@Override
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
    CommitLogEntity entity = entityFactory.getEntity((ObjectId) nodeId);
    if (entity.isIncluded(property)) {
        if (entity.isConfidential(property)) {
            oldValue = Confidential.getInstance();
            newValue = Confidential.getInstance();
        }
        delegate.nodePropertyChanged(nodeId, property, oldValue, newValue);
    }
}
Also used : CommitLogEntity(org.apache.cayenne.commitlog.meta.CommitLogEntity)

Aggregations

CommitLogEntity (org.apache.cayenne.commitlog.meta.CommitLogEntity)2 DataRow (org.apache.cayenne.DataRow)1 ObjectId (org.apache.cayenne.ObjectId)1 QueryResponse (org.apache.cayenne.QueryResponse)1 MutableObjectChange (org.apache.cayenne.commitlog.model.MutableObjectChange)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)1 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)1 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)1 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)1 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)1