Search in sources :

Example 36 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class DeepPopulationTest method deep_population_via_qTuple.

@Test
public void deep_population_via_qTuple() {
    StringPath name = Expressions.stringPath("name");
    StringPath id = Expressions.stringPath("id");
    QBean<Entity2> entity2Bean = new QBean<Entity2>(Entity2.class, name, id);
    QTuple tupleExpr = new QTuple(entity2Bean);
    Tuple tuple = FactoryExpressionUtils.wrap(tupleExpr).newInstance("nameX", "idX");
    assertEquals("nameX", tuple.get(entity2Bean).getName());
    assertEquals("idX", tuple.get(entity2Bean).getId());
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 37 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class JDOSQLQueryTest method scalarQueries.

@Test
public void scalarQueries() {
    BooleanExpression filter = product.name.startsWith("A");
    // fetchCount
    assertEquals(10L, sql().from(product).where(filter).fetchCount());
    // countDistinct
    assertEquals(10L, sql().from(product).where(filter).distinct().fetchCount());
    // fetch
    assertEquals(10, sql().from(product).where(filter).select(product.name).fetch().size());
    // fetch with limit
    assertEquals(3, sql().from(product).limit(3).select(product.name).fetch().size());
    // fetch with offset
    // assertEquals(7, sql().from(product).offset(3).fetch(product.name).size());
    // fetch with limit and offset
    assertEquals(3, sql().from(product).offset(3).limit(3).select(product.name).fetch().size());
    // fetch multiple
    for (Tuple row : sql().from(product).select(product.productId, product.name, product.amount).fetch()) {
        assertNotNull(row.get(0, Object.class));
        assertNotNull(row.get(1, Object.class));
        assertNotNull(row.get(2, Object.class));
    }
    // fetchResults
    QueryResults<String> results = sql().from(product).limit(3).select(product.name).fetchResults();
    assertEquals(3, results.getResults().size());
    assertEquals(30L, results.getTotal());
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 38 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class SpatialBase method asText.

@Test
public void asText() {
    List<Tuple> results = query().from(shapes).select(shapes.geometry, shapes.geometry.asText()).fetch();
    assertFalse(results.isEmpty());
    for (Tuple row : results) {
        if (!(row.get(shapes.geometry) instanceof MultiPoint)) {
            assertEquals(normalize(Wkt.toWkt(row.get(shapes.geometry))), normalize(row.get(shapes.geometry.asText())));
        }
    }
}
Also used : Tuple(com.querydsl.core.Tuple) AbstractBaseTest(com.querydsl.sql.AbstractBaseTest) Test(org.junit.Test)

Example 39 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class SpatialBase method point_distance.

@Test
@ExcludeIn(MYSQL)
public void point_distance() {
    QShapes shapes1 = QShapes.shapes;
    QShapes shapes2 = new QShapes("shapes2");
    for (Tuple tuple : query().from(shapes1, shapes2).where(shapes1.id.loe(5), shapes2.id.loe(5)).select(shapes1.geometry.asPoint(), shapes2.geometry.asPoint(), shapes1.geometry.distance(shapes2.geometry)).fetch()) {
        Point point1 = tuple.get(shapes1.geometry.asPoint());
        Point point2 = tuple.get(shapes2.geometry.asPoint());
        Double distance = tuple.get(shapes1.geometry.distance(shapes2.geometry));
        assertEquals(JTSGeometryOperations.Default.distance(point1, point2), distance, 0.0001);
    }
}
Also used : Tuple(com.querydsl.core.Tuple) AbstractBaseTest(com.querydsl.sql.AbstractBaseTest) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 40 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class SQLSerializerTest method withRecursive2.

@SuppressWarnings("unchecked")
@Test
public void withRecursive2() {
    /*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, sub.get(e.id), sub.get(e.firstname), sub.get(e.superiorId)).as(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 (ID, FIRSTNAME, SUPERIOR_ID) 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

Tuple (com.querydsl.core.Tuple)55 Test (org.junit.Test)41 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)10 Pair (com.mysema.commons.lang.Pair)7 QTuple (com.querydsl.core.types.QTuple)6 Expression (com.querydsl.core.types.Expression)4 StringPath (com.querydsl.core.types.dsl.StringPath)4 AbstractBaseTest (com.querydsl.sql.AbstractBaseTest)4 QCat (com.querydsl.jpa.domain.QCat)3 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)3 QEmployee (com.querydsl.sql.domain.QEmployee)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)2 ResultListRowTransformer (com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 QueryMetadata (com.querydsl.core.QueryMetadata)2 Group (com.querydsl.core.group.Group)2