Search in sources :

Example 1 with ObjectStore

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;
}
Also used : ObjectStore(org.apache.cayenne.access.ObjectStore) DataContext(org.apache.cayenne.access.DataContext) NestedQueryCache(org.apache.cayenne.cache.NestedQueryCache)

Example 2 with ObjectStore

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;
}
Also used : ObjectStoreGraphDiff(org.apache.cayenne.access.ObjectStoreGraphDiff) ObjectStore(org.apache.cayenne.access.ObjectStore) DbRowOp(org.apache.cayenne.access.flush.operation.DbRowOp) UpdateDbRowOp(org.apache.cayenne.access.flush.operation.UpdateDbRowOp) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) CompoundDiff(org.apache.cayenne.graph.CompoundDiff)

Example 3 with ObjectStore

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);
}
Also used : ObjectStore(org.apache.cayenne.access.ObjectStore)

Example 4 with ObjectStore

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);
}
Also used : InsertDbRowOp(org.apache.cayenne.access.flush.operation.InsertDbRowOp) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjectStore(org.apache.cayenne.access.ObjectStore) DbRowOpVisitor(org.apache.cayenne.access.flush.operation.DbRowOpVisitor) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ObjectDiff(org.apache.cayenne.access.ObjectDiff) ObjectId(org.apache.cayenne.ObjectId) DbRowOpType(org.apache.cayenne.access.flush.operation.DbRowOpType) Values(org.apache.cayenne.access.flush.operation.Values) Persistent(org.apache.cayenne.Persistent) ObjEntity(org.apache.cayenne.map.ObjEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) Before(org.junit.Before)

Aggregations

ObjectStore (org.apache.cayenne.access.ObjectStore)4 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 ObjectId (org.apache.cayenne.ObjectId)1 Persistent (org.apache.cayenne.Persistent)1 DataContext (org.apache.cayenne.access.DataContext)1 ObjectDiff (org.apache.cayenne.access.ObjectDiff)1 ObjectStoreGraphDiff (org.apache.cayenne.access.ObjectStoreGraphDiff)1 DbRowOp (org.apache.cayenne.access.flush.operation.DbRowOp)1 DbRowOpType (org.apache.cayenne.access.flush.operation.DbRowOpType)1 DbRowOpVisitor (org.apache.cayenne.access.flush.operation.DbRowOpVisitor)1 InsertDbRowOp (org.apache.cayenne.access.flush.operation.InsertDbRowOp)1 UpdateDbRowOp (org.apache.cayenne.access.flush.operation.UpdateDbRowOp)1 Values (org.apache.cayenne.access.flush.operation.Values)1 NestedQueryCache (org.apache.cayenne.cache.NestedQueryCache)1 CompoundDiff (org.apache.cayenne.graph.CompoundDiff)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)1 Before (org.junit.Before)1