Search in sources :

Example 1 with SQLMergeClause

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

the class MergeBase method mergeBatch.

@Test
@IncludeIn(H2)
public void mergeBatch() {
    SQLMergeClause merge = merge(survey).keys(survey.id).set(survey.id, 5).set(survey.name, "5").addBatch();
    assertEquals(1, merge.getBatchCount());
    assertFalse(merge.isEmpty());
    merge.keys(survey.id).set(survey.id, 6).set(survey.name, "6").addBatch();
    assertEquals(2, merge.getBatchCount());
    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 2 with SQLMergeClause

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

the class MergeBase method merge_with_templateExpression_in_batch.

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

Example 3 with SQLMergeClause

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

the class MergeBase method mergeBatch_with_subquery.

@Test
@IncludeIn(H2)
public void mergeBatch_with_subquery() {
    SQLMergeClause merge = merge(survey).keys(survey.id).columns(survey.id, survey.name).select(query().from(survey2).select(survey2.id.add(20), survey2.name)).addBatch();
    merge(survey).keys(survey.id).columns(survey.id, survey.name).select(query().from(survey2).select(survey2.id.add(40), survey2.name)).addBatch();
    assertEquals(1, merge.execute());
}
Also used : SQLMergeClause(com.querydsl.sql.dml.SQLMergeClause) Test(org.junit.Test) IncludeIn(com.querydsl.core.testutil.IncludeIn)

Example 4 with SQLMergeClause

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

the class AbstractBaseTest method merge.

protected SQLMergeClause merge(RelationalPath<?> e) {
    SQLMergeClause sqlMergeClause = new SQLMergeClause(connection, configuration, e);
    sqlMergeClause.addListener(new TestLoggingListener());
    return sqlMergeClause;
}
Also used : SQLMergeClause(com.querydsl.sql.dml.SQLMergeClause)

Example 5 with SQLMergeClause

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

the class MergeBase method merge_with_keys_listener.

@Test
@ExcludeIn({ H2, CUBRID, SQLSERVER })
public void merge_with_keys_listener() throws SQLException {
    final AtomicBoolean result = new AtomicBoolean();
    SQLListener listener = new SQLBaseListener() {

        @Override
        public void end(SQLListenerContext context) {
            result.set(true);
        }
    };
    SQLMergeClause clause = merge(survey).keys(survey.id).set(survey.id, 7).set(survey.name, "Hello World");
    clause.addListener(listener);
    ResultSet rs = clause.executeWithKeys();
    assertTrue(rs.next());
    assertTrue(rs.getObject(1) != null);
    rs.close();
    assertTrue(result.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SQLMergeClause(com.querydsl.sql.dml.SQLMergeClause) ResultSet(java.sql.ResultSet) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

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