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