use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class ObjectResolver method objectFromDataRow.
Persistent objectFromDataRow(DataRow row) {
// determine entity to use
ClassDescriptor classDescriptor = descriptorResolutionStrategy.descriptorForRow(row);
// not using DataRow.createObjectId for performance reasons -
// ObjectResolver has all needed metadata already cached.
ObjectId anId = createObjectId(row, classDescriptor.getEntity(), null);
return objectFromDataRow(row, anId, classDescriptor);
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class ObjectStore method processIndirectlyModifiedIDs.
/**
* Requires external synchronization.
*
* @since 1.1
*/
void processIndirectlyModifiedIDs(Collection<ObjectId> indirectlyModifiedIDs) {
for (ObjectId oid : indirectlyModifiedIDs) {
// access object map directly - the method should be called in a synchronized context...
final DataObject object = (DataObject) objectMap.get(oid);
if (object == null || object.getPersistenceState() != PersistenceState.COMMITTED) {
continue;
}
// for now break all "independent" object relationships...
// in the future we may want to be more precise and go after modified
// relationships only, or even process updated lists without invalidating...
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(object, null)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(oid.getEntityName());
descriptor.visitProperties(new PropertyVisitor() {
@Override
public boolean visitToMany(ToManyProperty property) {
property.invalidate(object);
return true;
}
@Override
public boolean visitToOne(ToOneProperty property) {
if (property.getRelationship().isSourceIndependentFromTargetChange()) {
property.invalidate(object);
}
return true;
}
@Override
public boolean visitAttribute(AttributeProperty property) {
return true;
}
});
delegate.finishedProcessDelete(object);
}
}
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class ObjectStore method processUpdatedSnapshot.
/**
* Requires external synchronization.
*
* @since 1.1
*/
void processUpdatedSnapshot(ObjectId nodeId, DataRow diff) {
// access object map directly - the method should be called in a synchronized context...
DataObject object = (DataObject) objectMap.get(nodeId);
// no object, or HOLLOW object require no processing
if (object != null) {
int state = object.getPersistenceState();
if (state != PersistenceState.HOLLOW) {
// perform same steps as resolveHollow()
if (state == PersistenceState.COMMITTED) {
// consult delegate if it exists
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(object, diff)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(nodeId.getEntityName());
// TODO: andrus, 5/26/2006 - call to 'getSnapshot' is expensive,
// however my attempts to merge the 'diff' instead of snapshot
// via 'refreshObjectWithSnapshot' resulted in even worse performance.
// This sounds counterintuitive (Not sure if this is some HotSpot related glitch)...
// still keeping the old algorithm here until we switch from snapshot events
// to GraphEvents and all this code becomes obsolete.
DataRow snapshot = getSnapshot(object.getObjectId());
DataRowUtils.refreshObjectWithSnapshot(descriptor, object, snapshot, true);
delegate.finishedMergeChanges(object);
}
} else // merge modified and deleted
if (state == PersistenceState.DELETED || state == PersistenceState.MODIFIED) {
// consult delegate if it exists
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(object, diff)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(nodeId.getEntityName());
DataRowUtils.forceMergeWithSnapshot(context, descriptor, object, diff);
delegate.finishedMergeChanges(object);
}
}
}
}
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class ObjectStore method registerDiff.
/**
* Registers object change.
*
* @since 1.2
*/
synchronized ObjectDiff registerDiff(Object nodeId, NodeDiff diff) {
if (diff != null) {
diff.setDiffId(++currentDiffId);
}
ObjectDiff objectDiff = changes.get(nodeId);
if (objectDiff == null) {
Persistent object = objectMap.get(nodeId);
if (object == null) {
throw new CayenneRuntimeException("No object is registered in context with Id %s", nodeId);
}
if (object.getPersistenceState() == PersistenceState.COMMITTED) {
object.setPersistenceState(PersistenceState.MODIFIED);
// replacement yet, so we still need to handle them...
if (object instanceof DataObject) {
DataObject dataObject = (DataObject) object;
DataRow snapshot = getCachedSnapshot((ObjectId) nodeId);
if (snapshot != null && snapshot.getVersion() != dataObject.getSnapshotVersion()) {
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(dataObject, snapshot)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(((ObjectId) nodeId).getEntityName());
DataRowUtils.forceMergeWithSnapshot(context, descriptor, dataObject, snapshot);
dataObject.setSnapshotVersion(snapshot.getVersion());
delegate.finishedMergeChanges(dataObject);
}
}
}
}
objectDiff = new ObjectDiff(object);
objectDiff.setDiffId(++currentDiffId);
changes.put(nodeId, objectDiff);
}
if (diff != null) {
objectDiff.addDiff(diff, this);
}
return objectDiff;
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class CayenneContext method createFault.
Persistent createFault(ObjectId id) {
ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName());
Persistent object = (Persistent) descriptor.createObject();
object.setPersistenceState(PersistenceState.HOLLOW);
object.setObjectContext(this);
object.setObjectId(id);
graphManager.registerNode(id, object);
return object;
}
Aggregations