Search in sources :

Example 11 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SQLSerializerTest method schemaInWhere.

@Test
public void schemaInWhere() {
    Configuration derbyWithPrintSchema = new Configuration(DerbyTemplates.builder().printSchema().build());
    QEmployee e = QEmployee.employee;
    SQLDeleteClause delete = new SQLDeleteClause(EasyMock.createNiceMock(Connection.class), derbyWithPrintSchema, e);
    delete.where(e.id.gt(100));
    assertEquals("delete from \"PUBLIC\".EMPLOYEE\n" + "where \"PUBLIC\".EMPLOYEE.ID > ?", delete.toString());
}
Also used : SQLDeleteClause(com.querydsl.sql.dml.SQLDeleteClause) Connection(java.sql.Connection) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 12 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SQLSubQueryTest method complex.

@Test
public void complex() {
    // related to #584795
    QSurvey survey = new QSurvey("survey");
    QEmployee emp1 = new QEmployee("emp1");
    QEmployee emp2 = new QEmployee("emp2");
    SubQueryExpression<?> subQuery = select(survey.id, emp2.firstname).from(survey).innerJoin(emp1).on(survey.id.eq(emp1.id)).innerJoin(emp2).on(emp1.superiorId.eq(emp2.superiorId), emp1.firstname.eq(emp2.firstname));
    assertEquals(3, subQuery.getMetadata().getJoins().size());
}
Also used : QSurvey(com.querydsl.sql.domain.QSurvey) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 13 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SQLSubQueryTest method list_entity.

@Test
public void list_entity() {
    QEmployee employee2 = new QEmployee("employee2");
    Expression<?> expr = select(employee, employee2.id).from(employee).innerJoin(employee.superiorIdKey, employee2);
    SQLSerializer serializer = new SQLSerializer(new Configuration(SQLTemplates.DEFAULT));
    serializer.handle(expr);
    assertEquals("(select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.LASTNAME, EMPLOYEE.SALARY, EMPLOYEE.DATEFIELD, EMPLOYEE.TIMEFIELD, EMPLOYEE.SUPERIOR_ID, employee2.ID as col__ID7\n" + "from EMPLOYEE EMPLOYEE\n" + "inner join EMPLOYEE employee2\n" + "on EMPLOYEE.SUPERIOR_ID = employee2.ID)", serializer.toString());
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 14 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class RelationalPathExtractorTest method joins.

@Test
public void joins() {
    QEmployee employee2 = new QEmployee("employee2");
    SQLQuery<?> query = query().from(employee).innerJoin(employee2).on(employee.superiorId.eq(employee2.id));
    assertEquals(ImmutableSet.of(employee, employee2), extract(query.getMetadata()));
}
Also used : QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 15 with QEmployee

use of com.querydsl.sql.domain.QEmployee in project querydsl by querydsl.

the class SQLSerializerTest method withRecursive.

@SuppressWarnings("unchecked")
@Test
public void withRecursive() {
    /*with sub (id, firstname, superior_id) as (
            select id, firstname, superior_id from employee where firstname like 'Mike'
            union all
            select employee.id, employee.firstname, employee.superior_id from sub, employee
            where employee.superior_id = sub.id)
        select * from sub;*/
    QEmployee e = QEmployee.employee;
    PathBuilder<Tuple> sub = new PathBuilder<Tuple>(Tuple.class, "sub");
    SQLQuery<?> query = new SQLQuery<Void>(SQLTemplates.DEFAULT);
    query.withRecursive(sub, unionAll(select(e.id, e.firstname, e.superiorId).from(e).where(e.firstname.eq("Mike")), select(e.id, e.firstname, e.superiorId).from(e, sub).where(e.superiorId.eq(sub.get(e.id))))).from(sub);
    QueryMetadata md = query.getMetadata();
    md.setProjection(Wildcard.all);
    SQLSerializer serializer = new SQLSerializer(Configuration.DEFAULT);
    serializer.serialize(md, false);
    assertEquals("with recursive sub as ((select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE\n" + "where EMPLOYEE.FIRSTNAME = ?)\n" + "union all\n" + "(select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE, sub\n" + "where EMPLOYEE.SUPERIOR_ID = sub.ID))\n" + "select *\n" + "from sub", serializer.toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) QEmployee(com.querydsl.sql.domain.QEmployee) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Aggregations

QEmployee (com.querydsl.sql.domain.QEmployee)27 Test (org.junit.Test)27 QSurvey (com.querydsl.sql.domain.QSurvey)10 SQLDeleteClause (com.querydsl.sql.dml.SQLDeleteClause)6 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)4 SQLUpdateClause (com.querydsl.sql.dml.SQLUpdateClause)4 Tuple (com.querydsl.core.Tuple)3 QueryMetadata (com.querydsl.core.QueryMetadata)2 Param (com.querydsl.core.types.dsl.Param)2 Employee (com.querydsl.sql.domain.Employee)2 Connection (java.sql.Connection)2 QueryModifiers (com.querydsl.core.QueryModifiers)1 QueryMixin (com.querydsl.core.support.QueryMixin)1 IncludeIn (com.querydsl.core.testutil.IncludeIn)1 SubQueryExpression (com.querydsl.core.types.SubQueryExpression)1 Ignore (org.junit.Ignore)1