use of org.apache.cayenne.commitlog.model.MutableObjectChange 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;
}
});
}
use of org.apache.cayenne.commitlog.model.MutableObjectChange in project cayenne by apache.
the class DiffProcessor method arcDeleted.
@Override
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
ObjectId id = (ObjectId) nodeId;
String relationshipName = arcId.toString();
ObjEntity entity = entityResolver.getObjEntity(id.getEntityName());
ObjRelationship relationship = entity.getRelationship(relationshipName);
MutableObjectChange c = changeSet.getOrCreate(id, ObjectChangeType.UPDATE);
ObjectId tid = (ObjectId) targetNodeId;
if (relationship.isToMany()) {
c.toManyRelationshipDisconnected(relationshipName, tid);
} else {
c.toOneRelationshipDisconnected(relationshipName, tid);
}
}
use of org.apache.cayenne.commitlog.model.MutableObjectChange in project cayenne by apache.
the class DiffProcessor method arcCreated.
@Override
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
ObjectId id = (ObjectId) nodeId;
String relationshipName = arcId.toString();
ObjEntity entity = entityResolver.getObjEntity(id.getEntityName());
ObjRelationship relationship = entity.getRelationship(relationshipName);
MutableObjectChange c = changeSet.getOrCreate(id, ObjectChangeType.UPDATE);
ObjectId tid = (ObjectId) targetNodeId;
if (relationship.isToMany()) {
c.toManyRelationshipConnected(relationshipName, tid);
} else {
c.toOneRelationshipConnected(relationshipName, tid);
}
}
Aggregations