/** * Fetches data from the channel. */ protected void runQuery() { this.response = actingContext.getChannel().onQuery(actingContext, query); } }
/** * Fetches data from the channel. */ protected void runQuery() { this.response = actingContext.getChannel().onQuery(actingContext, query); } }
protected Persistent findObject(Object nodeId) { // first do a lookup in ObjectStore; if even a hollow object is found, // return it; // if not - fetch. Persistent object = (Persistent) context.getGraphManager().getNode(nodeId); if (object != null) { return object; } ObjectId id = (ObjectId) nodeId; // this can happen if a NEW object is deleted and after that its // relationships are // modified if (id.isTemporary()) { return null; } // skip context cache lookup, go directly to its channel Query query = new ObjectIdQuery((ObjectId) nodeId); QueryResponse response = context.getChannel().onQuery(context, query); List<?> objects = response.firstList(); if (objects.size() == 0) { throw new CayenneRuntimeException("No object for ID exists: %s", nodeId); } else if (objects.size() > 1) { throw new CayenneRuntimeException("Expected zero or one object, instead query matched: %d", objects.size()); } return (Persistent) objects.get(0); }
QueryResponse response = context.getChannel().onQuery(context, query);
QueryResponse response = context.getChannel().onQuery(context, query);
@Override public GraphDiff onSync(ObjectContext originatingContext, GraphDiff beforeDiff, int syncType, DataChannelFilterChain filterChain) { // process commits only; skip rollback if (syncType != DataChannel.FLUSH_CASCADE_SYNC && syncType != DataChannel.FLUSH_NOCASCADE_SYNC) { return filterChain.onSync(originatingContext, beforeDiff, syncType); } // don't collect changes if there are no listeners if (listeners.isEmpty()) { return filterChain.onSync(originatingContext, beforeDiff, syncType); } MutableChangeMap changes = new MutableChangeMap(); // passing DataDomain, not ObjectContext to speed things up // and avoid capturing changed state when fetching snapshots DataChannel channel = originatingContext.getChannel(); beforeCommit(changes, channel, beforeDiff); GraphDiff afterDiff = filterChain.onSync(originatingContext, beforeDiff, syncType); afterCommit(changes, channel, beforeDiff, afterDiff); notifyListeners(originatingContext, changes); return afterDiff; }
protected Object findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName) { DbRelationship finalRel = toOneRel.getDbRelationships().get(0); ObjectContext context = object.getObjectContext(); // find committed snapshot - so we can't fetch from the context as it // will return // dirty snapshot; must go down the stack instead // how do we handle this for NEW objects correctly? For now bail from // the method if (object.getObjectId().isTemporary()) { return null; } ObjectIdQuery query = new ObjectIdQuery(object.getObjectId(), true, ObjectIdQuery.CACHE); QueryResponse response = context.getChannel().onQuery(null, query); List<?> result = response.firstList(); if (result == null || result.size() == 0) { return null; } DataRow snapshot = (DataRow) result.get(0); ObjectId id = snapshot.createTargetObjectId(targetEntityName, finalRel); // not using 'localObject', looking up in context instead, as within the // sorter // we only care about objects participating in transaction, so no need // to create // hollow objects return (id != null) ? context.getGraphManager().getNode(id) : null; }
&& !(actingContext.getChannel() instanceof BaseContext)) { this.response = new ListResponse(); return DONE;
@Override public GraphDiff onSync(final ObjectContext originatingContext, final GraphDiff changes, final int syncType, final DataChannelFilterChain filterChain) { DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction.getCallbackAction( originatingContext.getChannel().getEntityResolver().getCallbackRegistry(), originatingContext.getGraphManager(), changes, syncType); callbackAction.applyPreCommit(); GraphDiff result; switch (syncType) { case DataChannel.ROLLBACK_CASCADE_SYNC: result = filterChain.onSync(originatingContext, changes, syncType);; break; // including transaction handling logic case DataChannel.FLUSH_NOCASCADE_SYNC: case DataChannel.FLUSH_CASCADE_SYNC: result = transactionManager.performInTransaction(new TransactionalOperation<GraphDiff>() { @Override public GraphDiff perform() { return filterChain.onSync(originatingContext, changes, syncType); } }); break; default: throw new CayenneRuntimeException("Invalid synchronization type: %d", syncType); } callbackAction.applyPostCommit(); return result; }