Search in sources :

Example 1 with SQLUpdateClause

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

the class CustomTypesTest method insert_query_update.

@Test
public void insert_query_update() {
    QPerson person = QPerson.person;
    // insert
    SQLInsertClause insert = new SQLInsertClause(connection, configuration, person);
    insert.set(person.id, 10);
    insert.set(person.firstname, "Bob");
    insert.set(person.gender, Gender.MALE);
    assertEquals(1L, insert.execute());
    // query
    SQLQuery<?> query = new SQLQuery<Void>(connection, configuration);
    assertEquals(Gender.MALE, query.from(person).where(person.id.eq(10)).select(person.gender).fetchOne());
    // update
    SQLUpdateClause update = new SQLUpdateClause(connection, configuration, person);
    update.set(person.gender, Gender.FEMALE);
    update.set(person.firstname, "Jane");
    update.where(person.id.eq(10));
    update.execute();
    // query
    query = new SQLQuery<Void>(connection, configuration);
    assertEquals(Gender.FEMALE, query.from(person).where(person.id.eq(10)).select(person.gender).fetchOne());
}
Also used : SQLUpdateClause(com.querydsl.sql.dml.SQLUpdateClause) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 2 with SQLUpdateClause

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

the class SerializationTest method update_where.

@Test
public void update_where() {
    SQLUpdateClause updateClause = new SQLUpdateClause(connection, SQLTemplates.DEFAULT, survey);
    updateClause.set(survey.id, 1);
    updateClause.set(survey.name, (String) null);
    updateClause.where(survey.name.eq("XXX"));
    assertEquals("update SURVEY\nset ID = ?, NAME = ?\nwhere SURVEY.NAME = ?", updateClause.toString());
}
Also used : SQLUpdateClause(com.querydsl.sql.dml.SQLUpdateClause) Test(org.junit.Test)

Example 3 with SQLUpdateClause

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

the class UpdateBase method update_with_subQuery_exists2.

@Test
public void update_with_subQuery_exists2() {
    QSurvey survey1 = new QSurvey("s1");
    QEmployee employee = new QEmployee("e");
    SQLUpdateClause update = update(survey1);
    update.set(survey1.name, "AA");
    update.where(selectOne().from(employee).where(survey1.name.eq(employee.lastname)).exists());
    assertEquals(0, update.execute());
}
Also used : SQLUpdateClause(com.querydsl.sql.dml.SQLUpdateClause) QSurvey(com.querydsl.sql.domain.QSurvey) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 4 with SQLUpdateClause

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

the class UpdateBase method update_with_subQuery_exists_Params.

@Test
public void update_with_subQuery_exists_Params() {
    QSurvey survey1 = new QSurvey("s1");
    QEmployee employee = new QEmployee("e");
    Param<Integer> param = new Param<Integer>(Integer.class, "param");
    SQLQuery<?> sq = query().from(employee).where(employee.id.eq(param));
    sq.set(param, -12478923);
    SQLUpdateClause update = update(survey1);
    update.set(survey1.name, "AA");
    update.where(sq.exists());
    assertEquals(0, update.execute());
}
Also used : SQLUpdateClause(com.querydsl.sql.dml.SQLUpdateClause) Param(com.querydsl.core.types.dsl.Param) QSurvey(com.querydsl.sql.domain.QSurvey) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 5 with SQLUpdateClause

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

the class UpdateBase method update_with_subQuery_exists.

@Test
public void update_with_subQuery_exists() {
    QSurvey survey1 = new QSurvey("s1");
    QEmployee employee = new QEmployee("e");
    SQLUpdateClause update = update(survey1);
    update.set(survey1.name, "AA");
    update.where(selectOne().from(employee).where(survey1.id.eq(employee.id)).exists());
    assertEquals(1, update.execute());
}
Also used : SQLUpdateClause(com.querydsl.sql.dml.SQLUpdateClause) QSurvey(com.querydsl.sql.domain.QSurvey) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Aggregations

SQLUpdateClause (com.querydsl.sql.dml.SQLUpdateClause)11 Test (org.junit.Test)10 QEmployee (com.querydsl.sql.domain.QEmployee)4 QSurvey (com.querydsl.sql.domain.QSurvey)4 Param (com.querydsl.core.types.dsl.Param)1 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)1