use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectResolver method objectsFromDataRows.
/**
* Converts rows to objects.
* <p>
* Synchronization note. This method requires EXTERNAL synchronization on
* ObjectStore and DataRowStore.
* </p>
*/
List<Persistent> objectsFromDataRows(List<? extends DataRow> rows) {
if (rows == null || rows.size() == 0) {
return new ArrayList<>(1);
}
List<Persistent> results = new ArrayList<>(rows.size());
for (DataRow row : rows) {
// nulls are possible here since 3.0 for some varieties of EJBQL,
// simple example of this: "select p.toGallery+ from Painting p" where toGallery is null.
results.add(objectFromDataRow(row));
}
// now deal with snapshots
cache.snapshotsUpdatedForObjects(results, rows, refreshObjects);
return results;
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectStore method processDeletedID.
/**
* Requires external synchronization.
*
* @since 1.2
*/
void processDeletedID(ObjectId nodeId) {
// access object map directly - the method should be called in a synchronized context...
Persistent object = objectMap.get(nodeId);
if (object != null) {
DataObject dataObject = (object instanceof DataObject) ? (DataObject) object : null;
DataContextDelegate delegate;
switch(object.getPersistenceState()) {
case PersistenceState.COMMITTED:
case PersistenceState.HOLLOW:
case PersistenceState.DELETED:
// consult delegate
delegate = context.nonNullDelegate();
if (dataObject == null || delegate.shouldProcessDelete(dataObject)) {
objectMap.remove(nodeId);
changes.remove(nodeId);
// setting DataContext to null will also set
// state to transient
object.setObjectContext(null);
if (dataObject != null) {
delegate.finishedProcessDelete(dataObject);
}
}
break;
case PersistenceState.MODIFIED:
// consult delegate
delegate = context.nonNullDelegate();
if (dataObject != null && delegate.shouldProcessDelete(dataObject)) {
object.setPersistenceState(PersistenceState.NEW);
changes.remove(nodeId);
registerNode(nodeId, object);
nodeCreated(nodeId);
delegate.finishedProcessDelete(dataObject);
}
break;
}
}
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectStore method objectsUnregistered.
/**
* Evicts a collection of DataObjects from the ObjectStore, invalidates the underlying
* cache snapshots. Changes objects state to TRANSIENT. This method can be used for
* manual cleanup of Cayenne cache.
*/
// this method is exactly the same as "objectsInvalidated", only additionally it
// throws out registered objects
public synchronized void objectsUnregistered(Collection objects) {
if (objects.isEmpty()) {
return;
}
Collection<ObjectId> ids = new ArrayList<>(objects.size());
for (Object object1 : objects) {
Persistent object = (Persistent) object1;
ObjectId id = object.getObjectId();
// remove object but not snapshot
objectMap.remove(id);
changes.remove(id);
ids.add(id);
object.setObjectContext(null);
object.setPersistenceState(PersistenceState.TRANSIENT);
}
// and keep unregister local even for non-nested DC?
if (getDataRowCache() != null) {
// send an event for removed snapshots
getDataRowCache().processSnapshotChanges(this, Collections.<ObjectId, DataRow>emptyMap(), Collections.<ObjectId>emptyList(), ids, Collections.<ObjectId>emptyList());
}
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectStore method postprocessAfterPhantomCommit.
/**
* @since 1.2
*/
void postprocessAfterPhantomCommit() {
for (Object id : changes.keySet()) {
Persistent object = objectMap.get(id);
// assume that no new or deleted objects are present (as otherwise commit
// wouldn't have been phantom).
object.setPersistenceState(PersistenceState.COMMITTED);
}
// clear caches
this.changes.clear();
}
use of org.apache.cayenne.Persistent in project cayenne by apache.
the class ObjectStore method processIdChange.
void processIdChange(Object nodeId, Object newId) {
Persistent object = objectMap.remove(nodeId);
if (object != null) {
object.setObjectId((ObjectId) newId);
objectMap.put(newId, object);
ObjectDiff change = changes.remove(nodeId);
if (change != null) {
changes.put(newId, change);
}
}
}
Aggregations