Search in sources :

Example 1 with Product

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

the class SelectActionWithUnsupportedDistinctTypesIT method testCompositionSelectManyToManyQuery.

@Test
public void testCompositionSelectManyToManyQuery() throws SQLException {
    createCompositionManyToManyDataSet();
    SelectQuery query = new SelectQuery(Product.class);
    query.addPrefetch("contained");
    query.addPrefetch("base");
    List<Product> result = context.performQuery(query);
    assertNotNull(result);
    for (Product product : result) {
        List<Product> productsContained = product.getContained();
        assertNotNull(productsContained);
        List<Product> productsBase = product.getBase();
        assertNotNull(productsBase);
        assertEquals(3, productsContained.size() + productsBase.size());
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Product(org.apache.cayenne.testdo.unsupported_distinct_types.Product) Test(org.junit.Test)

Example 2 with Product

use of org.apache.cayenne.testdo.unsupported_distinct_types.Product 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

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