Search in sources :

Example 26 with SQLInsertClause

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());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 27 with SQLInsertClause

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

Example 28 with SQLInsertClause

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

Example 29 with SQLInsertClause

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

Example 30 with SQLInsertClause

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());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Aggregations

SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)52 Test (org.junit.Test)25 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)6 ColumnMetadata (com.querydsl.sql.ColumnMetadata)4 MAuditDelta (com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta)3 IncludeIn (com.querydsl.core.testutil.IncludeIn)3 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2 H2Templates (com.querydsl.sql.H2Templates)2 QGeneratedKeysEntity (com.querydsl.sql.QGeneratedKeysEntity)2 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 AuditEventRecordCustomColumnPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType)1 AuditEventRecordReferenceType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType)1 AuditEventRecordReferenceValueType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceValueType)1 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)1