use of com.querydsl.example.dto.ProductL10n in project querydsl by querydsl.
the class ProductDaoImpl method save.
@Override
public Product save(Product p) {
Long id = p.getId();
if (id == null) {
id = populate(queryFactory.insert(product), p).executeWithKey(product.id);
p.setId(id);
} else {
populate(queryFactory.update(product), p).where(product.id.eq(id)).execute();
// delete l10n rows
queryFactory.delete(productL10n).where(productL10n.productId.eq(id)).execute();
}
SQLInsertClause insert = queryFactory.insert(productL10n);
for (ProductL10n l10n : p.getLocalizations()) {
insert.set(productL10n.productId, id).set(productL10n.description, l10n.getDescription()).set(productL10n.lang, l10n.getLang()).set(productL10n.name, l10n.getName()).addBatch();
}
insert.execute();
return p;
}
use of com.querydsl.example.dto.ProductL10n in project querydsl by querydsl.
the class ProductDaoTest method delete.
@Test
public void delete() {
Product product = new Product();
product.setSupplier(supplierDao.findById(1));
product.setName("ProductX");
product.setLocalizations(Collections.singleton(new ProductL10n()));
productDao.save(product);
assertNotNull(productDao.findById(product.getId()));
productDao.delete(product);
assertNull(productDao.findById(product.getId()));
}
Aggregations