use of org.apache.cayenne.access.flush.operation.InsertDbRowOp in project cayenne by apache.
the class DefaultDataDomainFlushActionTest method createQueries.
@Test
public void createQueries() {
ObjectId id1 = ObjectId.of("test", "id", 1);
ObjectId id2 = ObjectId.of("test", "id", 2);
ObjectId id3 = ObjectId.of("test2", "id", 3);
ObjectId id4 = ObjectId.of("test2", "id", 4);
ObjectId id5 = ObjectId.of("test", "id", 5);
ObjectId id6 = ObjectId.of("test2", "id", 6);
ObjectId id7 = ObjectId.of("test", "id", 7);
DbEntity test = mockEntity("test");
DbEntity test2 = mockEntity("test2");
List<DbRowOp> ops = new ArrayList<>();
ops.add(new InsertDbRowOp(mockObject(id1), test, id1));
ops.add(new InsertDbRowOp(mockObject(id2), test, id2));
ops.add(new InsertDbRowOp(mockObject(id3), test2, id5));
ops.add(new InsertDbRowOp(mockObject(id4), test2, id7));
ops.add(new UpdateDbRowOp(mockObject(id5), test, id3));
ops.add(new DeleteDbRowOp(mockObject(id6), test2, id6));
ops.add(new DeleteDbRowOp(mockObject(id7), test, id4));
DefaultDataDomainFlushAction action = mock(DefaultDataDomainFlushAction.class);
when(action.createQueries((List<DbRowOp>) any(List.class))).thenCallRealMethod();
List<? extends Query> queries = action.createQueries(ops);
assertEquals(4, queries.size());
assertThat(queries.get(0), instanceOf(InsertBatchQuery.class));
InsertBatchQuery insert1 = (InsertBatchQuery) queries.get(0);
assertSame(test, insert1.getDbEntity());
assertEquals(2, insert1.getRows().size());
assertThat(queries.get(1), instanceOf(InsertBatchQuery.class));
InsertBatchQuery insert2 = (InsertBatchQuery) queries.get(1);
assertSame(test2, insert2.getDbEntity());
assertEquals(2, insert2.getRows().size());
assertThat(queries.get(2), instanceOf(DeleteBatchQuery.class));
DeleteBatchQuery delete1 = (DeleteBatchQuery) queries.get(2);
assertSame(test2, delete1.getDbEntity());
assertEquals(1, delete1.getRows().size());
assertThat(queries.get(3), instanceOf(DeleteBatchQuery.class));
DeleteBatchQuery delete2 = (DeleteBatchQuery) queries.get(3);
assertSame(test, delete2.getDbEntity());
assertEquals(1, delete2.getRows().size());
}
use of org.apache.cayenne.access.flush.operation.InsertDbRowOp 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);
}
Aggregations