Search in sources :

Example 1 with H2Templates

use of com.querydsl.sql.H2Templates in project querydsl by querydsl.

the class GeneratedKeysMySQLTest method test.

@Test
public void test() throws SQLException {
    stmt.execute("drop table if exists GENERATED_KEYS");
    stmt.execute("create table GENERATED_KEYS(" + "ID int AUTO_INCREMENT PRIMARY KEY, " + "NAME varchar(30))");
    QGeneratedKeysEntity entity = new QGeneratedKeysEntity("entity");
    SQLInsertClause insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    ResultSet rs = insertClause.set(entity.name, "Hello").executeWithKeys();
    ResultSetMetaData md = rs.getMetaData();
    System.out.println(md.getColumnName(1));
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertFalse(rs.next());
    insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    rs = insertClause.set(entity.name, "World").executeWithKeys();
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertFalse(rs.next());
}
Also used : H2Templates(com.querydsl.sql.H2Templates) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) QGeneratedKeysEntity(com.querydsl.sql.QGeneratedKeysEntity) Test(org.junit.Test)

Example 2 with H2Templates

use of com.querydsl.sql.H2Templates in project querydsl by querydsl.

the class SQLMergeClauseTest method clear.

@Test
public void clear() {
    KeyAccessorsTest.QEmployee emp1 = new KeyAccessorsTest.QEmployee("emp1");
    SQLMergeClause merge = new SQLMergeClause(null, new H2Templates(), emp1);
    merge.set(emp1.id, 1);
    merge.addBatch();
    assertEquals(1, merge.getBatchCount());
    merge.clear();
    assertEquals(0, merge.getBatchCount());
}
Also used : H2Templates(com.querydsl.sql.H2Templates) KeyAccessorsTest(com.querydsl.sql.KeyAccessorsTest) Test(org.junit.Test) KeyAccessorsTest(com.querydsl.sql.KeyAccessorsTest)

Example 3 with H2Templates

use of com.querydsl.sql.H2Templates in project querydsl by querydsl.

the class GeneratedKeysH2Test method test.

@Test
public void test() throws SQLException {
    stmt.execute("drop table GENERATED_KEYS if exists");
    stmt.execute("create table GENERATED_KEYS(" + "ID int AUTO_INCREMENT PRIMARY KEY, " + "NAME varchar(30))");
    QGeneratedKeysEntity entity = new QGeneratedKeysEntity("entity");
    SQLInsertClause insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    ResultSet rs = insertClause.set(entity.name, "Hello").executeWithKeys();
    ResultSetMetaData md = rs.getMetaData();
    System.out.println(md.getColumnName(1));
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertFalse(rs.next());
    insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    rs = insertClause.set(entity.name, "World").executeWithKeys();
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertFalse(rs.next());
    insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    assertEquals(3, insertClause.set(entity.name, "World").executeWithKey(entity.id).intValue());
    insertClause = new SQLInsertClause(conn, new H2Templates(), entity);
    assertEquals(Collections.singletonList(4), insertClause.set(entity.name, "World").executeWithKeys(entity.id));
}
Also used : H2Templates(com.querydsl.sql.H2Templates) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) QGeneratedKeysEntity(com.querydsl.sql.QGeneratedKeysEntity) Test(org.junit.Test)

Aggregations

H2Templates (com.querydsl.sql.H2Templates)3 Test (org.junit.Test)3 QGeneratedKeysEntity (com.querydsl.sql.QGeneratedKeysEntity)2 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)2 KeyAccessorsTest (com.querydsl.sql.KeyAccessorsTest)1