Search in sources :

Example 6 with SQLMergeClause

use of com.querydsl.sql.dml.SQLMergeClause in project querydsl by querydsl.

the class MergeBase method mergeBatch_templates.

@Test
@IncludeIn(H2)
public void mergeBatch_templates() {
    SQLMergeClause merge = merge(survey).keys(survey.id).set(survey.id, 5).set(survey.name, Expressions.stringTemplate("'5'")).addBatch();
    merge.keys(survey.id).set(survey.id, 6).set(survey.name, Expressions.stringTemplate("'6'")).addBatch();
    assertEquals(2, merge.execute());
    assertEquals(1L, query().from(survey).where(survey.name.eq("5")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.eq("6")).fetchCount());
}
Also used : SQLMergeClause(com.querydsl.sql.dml.SQLMergeClause) Test(org.junit.Test) IncludeIn(com.querydsl.core.testutil.IncludeIn)

Example 7 with SQLMergeClause

use of com.querydsl.sql.dml.SQLMergeClause in project querydsl by querydsl.

the class MergeBase method merge_listener.

@Test
public void merge_listener() {
    final AtomicInteger calls = new AtomicInteger(0);
    SQLListener listener = new SQLBaseListener() {

        @Override
        public void end(SQLListenerContext context) {
            if (context.getData(AbstractSQLQuery.PARENT_CONTEXT) == null) {
                calls.incrementAndGet();
            }
        }
    };
    SQLMergeClause clause = merge(survey).keys(survey.id).set(survey.id, 5).set(survey.name, "Hello World");
    clause.addListener(listener);
    assertEquals(1, clause.execute());
    assertEquals(1, calls.intValue());
}
Also used : SQLMergeClause(com.querydsl.sql.dml.SQLMergeClause) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

SQLMergeClause (com.querydsl.sql.dml.SQLMergeClause)7 Test (org.junit.Test)6 IncludeIn (com.querydsl.core.testutil.IncludeIn)4 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)1 ResultSet (java.sql.ResultSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1