use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class AbstractBaseTest method insert.
protected SQLInsertClause insert(RelationalPath<?> e, SQLQuery<?> sq) {
SQLInsertClause sqlInsertClause = new SQLInsertClause(connection, configuration, e, sq);
sqlInsertClause.addListener(new TestLoggingListener());
return sqlInsertClause;
}
use of com.querydsl.sql.dml.SQLInsertClause 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));
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class MySQLQueryFactoryTest method insertOnDuplicateKeyUpdate_null.
@Test
public void insertOnDuplicateKeyUpdate_null() {
SQLInsertClause clause = queryFactory.insertOnDuplicateKeyUpdate(QSurvey.survey, SQLExpressions.set(QSurvey.survey.name, (String) null));
assertEquals("insert into SURVEY\n" + "values () on duplicate key update SURVEY.NAME = null", clause.toString());
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class MySQLQueryFactoryTest method insertOnDuplicateKeyUpdate2.
@Test
public void insertOnDuplicateKeyUpdate2() {
SQLInsertClause clause = queryFactory.insertOnDuplicateKeyUpdate(QSurvey.survey, QSurvey.survey.id.eq(2));
assertEquals("insert into SURVEY\nvalues () on duplicate key update SURVEY.ID = ?", clause.toString());
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class MySQLQueryFactoryTest method insertOnDuplicateKeyUpdate_multiple.
@Test
public void insertOnDuplicateKeyUpdate_multiple() {
SQLInsertClause clause = queryFactory.insertOnDuplicateKeyUpdate(QSurvey.survey, SQLExpressions.set(QSurvey.survey.id, 2), SQLExpressions.set(QSurvey.survey.name, "B"));
assertEquals("insert into SURVEY\n" + "values () on duplicate key update SURVEY.ID = ?, SURVEY.NAME = ?", clause.toString());
}
Aggregations