Search in sources :

Example 1 with Customer

use of org.apache.cayenne.testdo.unsupported_distinct_types.Customer in project cayenne by apache.

the class SelectActionWithUnsupportedDistinctTypesIT method testOrdersSelectManyToManyQuery.

@Test
public void testOrdersSelectManyToManyQuery() throws SQLException {
    createOrdersManyToManyDataSet();
    List assertSizes = new ArrayList(3);
    assertSizes.addAll(Arrays.asList(1, 2, 3));
    SelectQuery productQuery = new SelectQuery(Product.class);
    productQuery.addPrefetch("orderBy");
    List<Product> productResult = context.performQuery(productQuery);
    assertNotNull(productResult);
    List orderBySizes = new ArrayList(3);
    for (Product product : productResult) {
        List<Customer> orderBy = product.getOrderBy();
        assertNotNull(orderBy);
        orderBySizes.add(orderBy.size());
    }
    assertTrue(assertSizes.containsAll(orderBySizes));
    SelectQuery customerQuery = new SelectQuery(Customer.class);
    customerQuery.addPrefetch("order");
    List<Customer> customerResult = context.performQuery(customerQuery);
    assertNotNull(customerResult);
    List orderSizes = new ArrayList(3);
    for (Customer customer : customerResult) {
        List<Product> orders = customer.getOrder();
        assertNotNull(orders);
        orderSizes.add(orders.size());
    }
    assertTrue(assertSizes.containsAll(orderSizes));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Customer(org.apache.cayenne.testdo.unsupported_distinct_types.Customer) ArrayList(java.util.ArrayList) Product(org.apache.cayenne.testdo.unsupported_distinct_types.Product) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 Customer (org.apache.cayenne.testdo.unsupported_distinct_types.Customer)1 Product (org.apache.cayenne.testdo.unsupported_distinct_types.Product)1 Test (org.junit.Test)1