Search in sources :

Example 1 with ProductL10n

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;
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) ProductL10n(com.querydsl.example.dto.ProductL10n)

Example 2 with ProductL10n

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()));
}
Also used : Product(com.querydsl.example.dto.Product) ProductL10n(com.querydsl.example.dto.ProductL10n) Test(org.junit.Test)

Aggregations

ProductL10n (com.querydsl.example.dto.ProductL10n)2 Product (com.querydsl.example.dto.Product)1 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)1 Test (org.junit.Test)1