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;
}
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);
}
Aggregations