/** * Fetches data from the channel. */ protected void runQuery() { this.response = actingContext.getChannel().onQuery(actingContext, query); } }
CayenneContextGraphManager(CayenneContext context, boolean changeEventsEnabled, boolean lifecycleEventsEnabled) { this.context = context; this.changeEventsEnabled = changeEventsEnabled; this.lifecycleEventsEnabled = lifecycleEventsEnabled; this.stateLog = new ObjectContextStateLog(this); this.changeLog = new ObjectContextChangeLog(); }
void registerNewObject(Persistent object, String entityName, ClassDescriptor descriptor) { /** * We should create new id only if it is not set for this object. It * could have been created, for instance, in child context */ ObjectId id = object.getObjectId(); if (id == null) { id = new ObjectId(entityName); object.setObjectId(id); } injectInitialValue(object); }
private static void checkObjectId(ObjectId id) { if (id.isTemporary() && !id.isReplacementIdAttached()) { throw new CayenneRuntimeException("Can't build a query for temporary id: %s", id); } }
@Override public int firstUpdateCount() { for (QueryResultItem item : resultItems) { if (!item.isSelectResult()) { return item.getUpdateCount(); } } throw new CayenneRuntimeException("Result is not an update count."); }
void graphCommitted(GraphDiff parentSyncDiff) { if (parentSyncDiff != null) { new CayenneContextMergeHandler(context).merge(parentSyncDiff); } remapTargets(); stateLog.graphCommitted(); reset(); if (lifecycleEventsEnabled) { // include all diffs after the commit start marker. // We fire event as if it was posted by parent channel, so that // nested contexts could catch it context.fireDataChannelCommitted(context.getChannel(), parentSyncDiff); } }
@Override public void rollbackChanges() { synchronized (graphManager) { if (graphManager.hasChanges()) { GraphDiff diff = graphManager.getDiffs(); graphManager.graphReverted(); channel.onSync(this, diff, DataChannel.ROLLBACK_CASCADE_SYNC); fireDataChannelRolledback(this, diff); } } }
void graphReverted() { GraphDiff diff = changeLog.getDiffs(); diff.undo(new RollbackChangeHandler()); stateLog.graphReverted(); reset(); if (lifecycleEventsEnabled) { context.fireDataChannelRolledback(context, diff); } }
private Map<?, ?> toMap_DetachedObject(Persistent persistent) { ObjectId oid = persistent.getObjectId(); // returning null here is for backwards compatibility. Should we throw // instead? return (oid != null) ? oid.getIdSnapshot() : null; }
public void writeProperty(String propName, Object val) { if (objectContext != null) { // pass "false" to avoid unneeded fault processing objectContext.prepareForAccess(this, propName, false); // note how we notify ObjectContext of change BEFORE the object is // actually // changed... this is needed to take a valid current snapshot Object oldValue = readPropertyDirectly(propName); objectContext.propertyChanged(this, propName, oldValue, val); } writePropertyDirectly(propName, val); }
public Object readProperty(String propName) { if (objectContext != null) { objectContext.prepareForAccess(this, propName); } Object object = readPropertyDirectly(propName); // must resolve faults immediately if (object instanceof Fault) { object = ((Fault) object).resolveFault(this, propName); writePropertyDirectly(propName, object); } return object; }
public void nodeRemoved(Object nodeId) { Object object = context.internalGraphManager().getNode(nodeId); if (object != null) { context.deleteObject((Persistent) object); } }
void postprocessRemove(Object removedObject) { // notify ObjectContext if (relationshipOwner.getObjectContext() != null) { relationshipOwner.getObjectContext().propertyChanged( relationshipOwner, relationshipName, removedObject, null); } }
public void run() { context.internalGraphManager().graphReverted(); } });
/** * Creates a new CayenneContext, initializing it with a channel. */ public CayenneContext(DataChannel channel, boolean changeEventsEnabled, boolean lifecyleEventsEnabled) { graphManager = new CayenneContextGraphManager(this, changeEventsEnabled, lifecyleEventsEnabled); if (channel != null) { attachToChannel(channel); } }
private void processChange(GraphDiff diff) { changeLog.addOperation(diff); if (changeEventsEnabled) { send(diff, DataChannel.GRAPH_CHANGED_SUBJECT, context); } }
private void processChange(GraphDiff diff) { changeLog.addOperation(diff); if (changeEventsEnabled) { context.fireDataChannelChanged(context, diff); } }
public void rollbackChanges() { synchronized (graphManager) { if (graphManager.hasChanges()) { GraphDiff diff = graphManager.getDiffs(); graphManager.graphReverted(); channel.onSync(this, diff, DataChannel.ROLLBACK_CASCADE_SYNC); } } }
/** * Fetches data from the channel. */ protected void runQuery() { this.response = actingContext.getChannel().onQuery(actingContext, query); } }
@Override public void rollbackChangesLocally() { synchronized (graphManager) { if (graphManager.hasChanges()) { GraphDiff diff = graphManager.getDiffs(); graphManager.graphReverted(); fireDataChannelRolledback(this, diff); } } }