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());
}
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());
}
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())));
}
}
}
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);
}
}
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());
}
Aggregations