Search in sources :

Example 11 with DbRowOp

use of org.apache.cayenne.access.flush.operation.DbRowOp in project cayenne by apache.

the class DefaultDbRowOpSorterTest method sortByOpEntity.

@Test
public void sortByOpEntity() {
    ObjectId id1 = ObjectId.of("test4", "id", 1);
    ObjectId id2 = ObjectId.of("test2", "id", 2);
    ObjectId id3 = ObjectId.of("test3", "id", 3);
    ObjectId id4 = ObjectId.of("test1", "id", 4);
    DbRowOp op1 = new InsertDbRowOp(mockObject(id1), mockEntity("test4"), id1);
    DbRowOp op2 = new InsertDbRowOp(mockObject(id2), mockEntity("test2"), id2);
    DbRowOp op3 = new InsertDbRowOp(mockObject(id3), mockEntity("test3"), id3);
    DbRowOp op4 = new InsertDbRowOp(mockObject(id4), mockEntity("test1"), id4);
    List<DbRowOp> rows = Arrays.asList(op1, op2, op3, op4);
    List<DbRowOp> expected = Arrays.asList(op4, op2, op3, op1);
    List<DbRowOp> sorted = sorter.sort(rows);
    assertEquals(expected, sorted);
}
Also used : InsertDbRowOp(org.apache.cayenne.access.flush.operation.InsertDbRowOp) ObjectId(org.apache.cayenne.ObjectId) DbRowOp(org.apache.cayenne.access.flush.operation.DbRowOp) DeleteDbRowOp(org.apache.cayenne.access.flush.operation.DeleteDbRowOp) BaseDbRowOp(org.apache.cayenne.access.flush.operation.BaseDbRowOp) UpdateDbRowOp(org.apache.cayenne.access.flush.operation.UpdateDbRowOp) InsertDbRowOp(org.apache.cayenne.access.flush.operation.InsertDbRowOp) Test(org.junit.Test)

Example 12 with DbRowOp

use of org.apache.cayenne.access.flush.operation.DbRowOp in project cayenne by apache.

the class AshwoodEntitySorter method sortObjectsForEntity.

@SuppressWarnings("unchecked")
@Override
public void sortObjectsForEntity(ObjEntity objEntity, List<?> objects, boolean deleteOrder) {
    if (objects == null || objects.size() == 0) {
        return;
    }
    indexSorter();
    DbEntity dbEntity = objEntity.getDbEntity();
    // if no sorting is required
    if (!isReflexive(dbEntity)) {
        return;
    }
    Object probe = objects.get(0);
    if (probe instanceof DbRowOp) {
        sortObjectsForEntity(objEntity, (List<DbRowOp>) objects, deleteOrder, DbRowOp::getObject);
    } else if (probe instanceof Persistent) {
        sortObjectsForEntity(objEntity, (List<Persistent>) objects, deleteOrder, Function.identity());
    } else {
        throw new IllegalArgumentException("Can sort only Persistent or DbRow objects, got " + probe.getClass().getSimpleName());
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbRowOp(org.apache.cayenne.access.flush.operation.DbRowOp) Persistent(org.apache.cayenne.Persistent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DbRowOp (org.apache.cayenne.access.flush.operation.DbRowOp)12 UpdateDbRowOp (org.apache.cayenne.access.flush.operation.UpdateDbRowOp)11 DeleteDbRowOp (org.apache.cayenne.access.flush.operation.DeleteDbRowOp)9 InsertDbRowOp (org.apache.cayenne.access.flush.operation.InsertDbRowOp)9 ObjectId (org.apache.cayenne.ObjectId)8 DbEntity (org.apache.cayenne.map.DbEntity)8 BaseDbRowOp (org.apache.cayenne.access.flush.operation.BaseDbRowOp)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 List (java.util.List)2 DefaultDataDomainFlushAction (org.apache.cayenne.access.flush.DefaultDataDomainFlushAction)2 HashSet (java.util.HashSet)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 Persistent (org.apache.cayenne.Persistent)1 ObjectDiff (org.apache.cayenne.access.ObjectDiff)1 ObjectStore (org.apache.cayenne.access.ObjectStore)1 ObjectStoreGraphDiff (org.apache.cayenne.access.ObjectStoreGraphDiff)1 CompoundDiff (org.apache.cayenne.graph.CompoundDiff)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbJoin (org.apache.cayenne.map.DbJoin)1