use of org.apache.cayenne.Persistent in project cayenne by apache.
the class DataDomainFlushAction method preprocess.
private void preprocess(DataContext context, GraphDiff changes) {
// categorize dirty objects by state
ObjectStore objectStore = context.getObjectStore();
for (Object o : changesByObjectId.keySet()) {
ObjectId id = (ObjectId) o;
Persistent object = (Persistent) objectStore.getNode(id);
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(id.getEntityName());
switch(object.getPersistenceState()) {
case PersistenceState.NEW:
insertBucket.addDirtyObject(object, descriptor);
break;
case PersistenceState.MODIFIED:
updateBucket.addDirtyObject(object, descriptor);
break;
case PersistenceState.DELETED:
deleteBucket.addDirtyObject(object, descriptor);
break;
}
}
new DataDomainIndirectDiffBuilder(this).processIndirectChanges(changes);
insertBucket.appendQueries(queries);
// TODO: the following line depends on the "queries" collection filled by insertBucket.. Moreover it may
// potentially remove values from the passed collection. Replace with something with fewer unobvious
// side-effects...
flattenedBucket.appendInserts(queries);
updateBucket.appendQueries(queries);
flattenedBucket.appendDeletes(queries);
deleteBucket.appendQueries(queries);
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ChildDiffLoader method arcDeleted.
public void arcDeleted(Object nodeId, final Object targetNodeId, Object arcId) {
final Persistent source = findObject(nodeId);
// changing their relationships
if (source == null) {
return;
}
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(((ObjectId) nodeId).getEntityName());
PropertyDescriptor property = descriptor.getProperty(arcId.toString());
setExternalChange(Boolean.TRUE);
try {
property.visit(new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
return false;
}
public boolean visitToMany(ToManyProperty property) {
// connect reverse arc if the relationship is marked as
// "runtime"
ArcProperty reverseArc = property.getComplimentaryReverseArc();
boolean autoConnectReverse = reverseArc != null && reverseArc.getRelationship().isRuntime();
Persistent target = findObject(targetNodeId);
if (target == null) {
// this is usually the case when a NEW object was
// deleted and then
// its
// relationships were manipulated; so try to locate the
// object in
// the
// collection ...
// the performance of this is rather dubious of
// course...
target = findObjectInCollection(targetNodeId, property.readProperty(source));
}
if (target == null) {
// ignore?
} else {
property.removeTarget(source, target, autoConnectReverse);
}
return false;
}
public boolean visitToOne(ToOneProperty property) {
property.setTarget(source, null, false);
return false;
}
});
} finally {
setExternalChange(Boolean.FALSE);
}
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ChildDiffLoader method arcCreated.
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
final Persistent source = findObject(nodeId);
final Persistent target = findObject(targetNodeId);
// can result in NULL target here.
if (target == null) {
return;
}
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(((ObjectId) nodeId).getEntityName());
ArcProperty property = (ArcProperty) descriptor.getProperty(arcId.toString());
setExternalChange(Boolean.TRUE);
try {
property.visit(new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
return false;
}
public boolean visitToMany(ToManyProperty property) {
// connect reverse arc if the relationship is marked as
// "runtime"
ArcProperty reverseArc = property.getComplimentaryReverseArc();
boolean autoConnectReverse = reverseArc != null && reverseArc.getRelationship().isRuntime();
property.addTarget(source, target, autoConnectReverse);
return false;
}
public boolean visitToOne(ToOneProperty property) {
property.setTarget(source, target, false);
return false;
}
});
} finally {
setExternalChange(Boolean.FALSE);
}
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class DefaultDataDomainFlushActionTest method mockObject.
private Persistent mockObject(ObjectId id) {
Persistent persistent = mock(Persistent.class);
when(persistent.getObjectId()).thenReturn(id);
when(persistent.getPersistenceState()).thenReturn(PersistenceState.MODIFIED);
return persistent;
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class DefaultDbRowOpSorterTest method mockObject.
private Persistent mockObject(ObjectId id) {
Persistent persistent = mock(Persistent.class);
when(persistent.getObjectId()).thenReturn(id);
when(persistent.getPersistenceState()).thenReturn(PersistenceState.MODIFIED);
return persistent;
}
Aggregations