use of org.apache.cayenne.access.ObjectStore in project cayenne by apache.
the class DataContextFactory method createFromDataContext.
protected ObjectContext createFromDataContext(DataContext parent) {
// child ObjectStore should not have direct access to snapshot cache, so do not
// pass it in constructor.
ObjectStore objectStore = objectStoreFactory.createObjectStore(null);
DataContext context = newInstance(parent, objectStore);
context.setValidatingObjectsOnCommit(parent.isValidatingObjectsOnCommit());
context.setUsingSharedSnapshotCache(parent.isUsingSharedSnapshotCache());
context.setQueryCache(new NestedQueryCache(queryCache));
context.setTransactionFactory(transactionFactory);
return context;
}
use of org.apache.cayenne.access.ObjectStore in project cayenne by apache.
the class DefaultDataDomainFlushAction method flush.
@Override
public GraphDiff flush(DataContext context, GraphDiff changes) {
CompoundDiff afterCommitDiff = new CompoundDiff();
if (changes == null) {
return afterCommitDiff;
}
if (!(changes instanceof ObjectStoreGraphDiff)) {
throw new CayenneRuntimeException("Instance of ObjectStoreGraphDiff expected, got %s", changes.getClass());
}
ObjectStore objectStore = context.getObjectStore();
ObjectStoreGraphDiff objectStoreGraphDiff = (ObjectStoreGraphDiff) changes;
List<DbRowOp> dbRowOps = createDbRowOps(objectStore, objectStoreGraphDiff);
updateObjectIds(dbRowOps);
List<DbRowOp> deduplicatedOps = mergeSameObjectIds(dbRowOps);
List<DbRowOp> filteredOps = filterOps(deduplicatedOps);
List<DbRowOp> sortedOps = sort(filteredOps);
List<? extends Query> queries = createQueries(sortedOps);
executeQueries(queries);
createReplacementIds(objectStore, afterCommitDiff, sortedOps);
postprocess(context, objectStoreGraphDiff, afterCommitDiff, sortedOps);
return afterCommitDiff;
}
use of org.apache.cayenne.access.ObjectStore in project cayenne by apache.
the class DefaultDataDomainFlushAction method postprocess.
/**
* Notify {@link ObjectStore} and it's data row cache about actual changes we performed.
*
* @param context originating context
* @param changes incoming diff
* @param afterCommitDiff resulting diff
* @param dbRowOps collection of {@link DbRowOp}
*/
protected void postprocess(DataContext context, ObjectStoreGraphDiff changes, CompoundDiff afterCommitDiff, List<DbRowOp> dbRowOps) {
ObjectStore objectStore = context.getObjectStore();
PostprocessVisitor postprocessor = new PostprocessVisitor(context);
dbRowOps.forEach(row -> row.accept(postprocessor));
DataDomainIndirectDiffBuilder indirectDiffBuilder = new DataDomainIndirectDiffBuilder(context.getEntityResolver());
indirectDiffBuilder.processChanges(changes);
objectStore.getDataRowCache().processSnapshotChanges(objectStore, postprocessor.getUpdatedSnapshots(), postprocessor.getDeletedIds(), Collections.emptyList(), indirectDiffBuilder.getIndirectModifications());
objectStore.postprocessAfterCommit(afterCommitDiff);
}
use of org.apache.cayenne.access.ObjectStore in project cayenne by apache.
the class ArcValuesCreationHandlerTest method setup.
@SuppressWarnings("unchecked")
@Before
public void setup() {
factory = mock(DbRowOpFactory.class);
handler = new ArcValuesCreationHandler(factory, DbRowOpType.INSERT);
dbRowOp = mock(InsertDbRowOp.class);
values = new Values(dbRowOp, false);
ObjectDiff diff = mock(ObjectDiff.class);
ClassDescriptor descriptor = mock(ClassDescriptor.class);
ObjEntity entity = mock(ObjEntity.class);
ObjRelationship relationship = mock(ObjRelationship.class);
DbRelationship dbRelationship = mock(DbRelationship.class);
ObjectStore store = mock(ObjectStore.class);
Persistent object = mock(Persistent.class);
when(relationship.getDbRelationships()).thenReturn(Collections.singletonList(dbRelationship));
when(entity.getRelationship(anyString())).thenReturn(relationship);
when(descriptor.getEntity()).thenReturn(entity);
when(dbRowOp.accept(any(DbRowOpVisitor.class))).thenCallRealMethod();
when(dbRowOp.getValues()).thenReturn(values);
when(factory.getDiff()).thenReturn(diff);
when(factory.getDescriptor()).thenReturn(descriptor);
when(factory.getStore()).thenReturn(store);
when(factory.getObject()).thenReturn(object);
when(factory.getOrCreate(isNull(), any(ObjectId.class), any(DbRowOpType.class))).thenReturn(dbRowOp);
}
Aggregations