Search in sources :

Example 1 with ObjectDiff

use of org.apache.cayenne.access.ObjectDiff in project cayenne by apache.

the class DefaultDataDomainFlushAction method createDbRowOps.

/**
 * Create ops based on incoming graph changes
 * @param objectStore originating object store
 * @param changes object graph diff
 * @return collection of {@link DbRowOp}
 */
protected List<DbRowOp> createDbRowOps(ObjectStore objectStore, ObjectStoreGraphDiff changes) {
    EntityResolver resolver = dataDomain.getEntityResolver();
    Map<Object, ObjectDiff> changesByObjectId = changes.getChangesByObjectId();
    List<DbRowOp> ops = new ArrayList<>(changesByObjectId.size());
    Set<ArcTarget> processedArcs = new HashSet<>();
    DbRowOpFactory factory = new DbRowOpFactory(resolver, objectStore, processedArcs);
    // ops.addAll() method is slower in this case as it will allocate new array for all values
    // noinspection UseBulkOperation
    changesByObjectId.forEach((obj, diff) -> factory.createRows(diff).forEach(ops::add));
    return ops;
}
Also used : ObjectDiff(org.apache.cayenne.access.ObjectDiff) DbRowOp(org.apache.cayenne.access.flush.operation.DbRowOp) UpdateDbRowOp(org.apache.cayenne.access.flush.operation.UpdateDbRowOp) ArrayList(java.util.ArrayList) EntityResolver(org.apache.cayenne.map.EntityResolver) HashSet(java.util.HashSet)

Example 2 with ObjectDiff

use of org.apache.cayenne.access.ObjectDiff 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

ObjectDiff (org.apache.cayenne.access.ObjectDiff)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ObjectId (org.apache.cayenne.ObjectId)1 Persistent (org.apache.cayenne.Persistent)1 ObjectStore (org.apache.cayenne.access.ObjectStore)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 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EntityResolver (org.apache.cayenne.map.EntityResolver)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