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