Search in sources :

Example 1 with OrderProduct

use of com.querydsl.example.dto.OrderProduct in project querydsl by querydsl.

the class OrderDaoImpl method save.

@Override
public Order save(Order o) {
    Long id = o.getId();
    if (id == null) {
        id = populate(queryFactory.insert(customerOrder), o).executeWithKey(customerOrder.id);
        o.setId(id);
    } else {
        populate(queryFactory.update(customerOrder), o).where(customerOrder.id.eq(id)).execute();
        // delete orderproduct rows
        queryFactory.delete(customerOrderProduct).where(customerOrderProduct.orderId.eq(id)).execute();
    }
    SQLInsertClause insert = queryFactory.insert(customerOrderProduct);
    for (OrderProduct op : o.getOrderProducts()) {
        insert.set(customerOrderProduct.orderId, id).set(customerOrderProduct.comments, op.getComments()).set(customerOrderProduct.productId, op.getProductId()).set(customerOrderProduct.quantity, op.getQuantity()).addBatch();
    }
    insert.execute();
    o.setId(id);
    return o;
}
Also used : QCustomerOrderProduct.customerOrderProduct(com.querydsl.example.sql.QCustomerOrderProduct.customerOrderProduct) OrderProduct(com.querydsl.example.dto.OrderProduct) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause)

Example 2 with OrderProduct

use of com.querydsl.example.dto.OrderProduct in project querydsl by querydsl.

the class OrderDaoTest method delete.

@Test
public void delete() {
    OrderProduct orderProduct = new OrderProduct();
    orderProduct.setProductId(1L);
    orderProduct.setQuantity(1);
    // FIXME
    CustomerPaymentMethod paymentMethod = new CustomerPaymentMethod();
    Order order = new Order();
    order.setCustomerPaymentMethod(paymentMethod);
    order.setOrderProducts(Collections.singleton(orderProduct));
    orderDao.save(order);
    assertNotNull(order.getId());
    orderDao.delete(order);
    assertNull(orderDao.findById(order.getId()));
}
Also used : CustomerPaymentMethod(com.querydsl.example.dto.CustomerPaymentMethod) Order(com.querydsl.example.dto.Order) OrderProduct(com.querydsl.example.dto.OrderProduct) Test(org.junit.Test)

Aggregations

OrderProduct (com.querydsl.example.dto.OrderProduct)2 CustomerPaymentMethod (com.querydsl.example.dto.CustomerPaymentMethod)1 Order (com.querydsl.example.dto.Order)1 QCustomerOrderProduct.customerOrderProduct (com.querydsl.example.sql.QCustomerOrderProduct.customerOrderProduct)1 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)1 Test (org.junit.Test)1