use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class SerializationTest method insert.
@Test
public void insert() {
SQLInsertClause insertClause = new SQLInsertClause(connection, SQLTemplates.DEFAULT, survey);
insertClause.set(survey.id, 1);
insertClause.set(survey.name, (String) null);
assertEquals("insert into SURVEY (ID, NAME)\nvalues (?, ?)", insertClause.toString());
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class CustomerDaoImpl method save.
@Override
public Customer save(Customer c) {
Long id = c.getId();
if (id == null) {
id = queryFactory.insert(customer).set(customer.name, c.getName()).set(customer.contactPersonId, c.getContactPerson().getId()).executeWithKey(customer.id);
c.setId(id);
} else {
queryFactory.update(customer).set(customer.name, c.getName()).set(customer.contactPersonId, c.getContactPerson().getId()).where(customer.id.eq(c.getId())).execute();
// delete address rows
queryFactory.delete(customerAddress).where(customerAddress.customerId.eq(id)).execute();
}
SQLInsertClause insert = queryFactory.insert(customerAddress);
for (CustomerAddress ca : c.getAddresses()) {
if (ca.getAddress().getId() == null) {
ca.getAddress().setId(queryFactory.insert(address).populate(ca.getAddress()).executeWithKey(address.id));
}
insert.set(customerAddress.customerId, id).set(customerAddress.addressId, ca.getAddress().getId()).set(customerAddress.addressTypeCode, ca.getAddressTypeCode()).set(customerAddress.fromDate, ca.getFromDate()).set(customerAddress.toDate, ca.getToDate()).addBatch();
}
insert.execute();
c.setId(id);
return c;
}
use of com.querydsl.sql.dml.SQLInsertClause 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.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class MySQLQueryFactory method insertOnDuplicateKeyUpdate.
/**
* Create a INSERT ... ON DUPLICATE KEY UPDATE clause
*
* @param entity table to insert to
* @param clause clause
* @return insert clause
*/
public SQLInsertClause insertOnDuplicateKeyUpdate(RelationalPath<?> entity, Expression<?> clause) {
SQLInsertClause insert = insert(entity);
insert.addFlag(Position.END, ExpressionUtils.template(String.class, " on duplicate key update {0}", clause));
return insert;
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class InsertBase method insertBatch_with_subquery.
@Test
// too slow
@ExcludeIn(FIREBIRD)
public void insertBatch_with_subquery() {
SQLInsertClause insert = insert(survey).columns(survey.id, survey.name).select(query().from(survey2).select(survey2.id.add(20), survey2.name)).addBatch();
insert(survey).columns(survey.id, survey.name).select(query().from(survey2).select(survey2.id.add(40), survey2.name)).addBatch();
assertEquals(1, insert.execute());
}
Aggregations