#633128 : added as-alias shortcuts

This commit is contained in:
Timo Westkämper 2010-09-08 14:59:04 +00:00
parent 5836006fd5
commit 7b3fe8acca
21 changed files with 388 additions and 115 deletions

View File

@ -44,6 +44,8 @@ public abstract class Expr<D> implements Serializable{
public abstract <R,C> R accept(Visitor<R,C> v, @Nullable C context);
public abstract Expr<D> as(Path<D> alias);
public abstract Expr<D> as(String alias);
/**
* Get the <code>count(this)</code> expression

View File

@ -10,6 +10,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* EBoolean represents boolean expressions
@ -52,6 +53,12 @@ public abstract class EBoolean extends EComparable<Boolean> {
public EBoolean as(Path<Boolean> alias) {
return OBoolean.create((Operator)Ops.ALIAS, this, alias.asExpr());
}
@SuppressWarnings("unchecked")
@Override
public EBoolean as(String alias) {
return OBoolean.create((Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get an intersection of this and the given expression

View File

@ -9,6 +9,7 @@ import com.mysema.query.types.Expr;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* EComparable extends EComparableBase to provide comparison methods.
@ -25,11 +26,16 @@ public abstract class EComparable<D extends Comparable> extends EComparableBase<
public EComparable(Class<? extends D> type) {
super(type);
}
@Override
public EComparable<D> as(Path<D> alias) {
return OComparable.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@Override
public EComparable<D> as(String alias) {
return OComparable.create(getType(),(Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get a <code>from &lt; this &lt; to</code> expression

View File

@ -12,6 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* EDate represents Date expressions
@ -65,6 +66,11 @@ public abstract class EDate<D extends Comparable> extends EDateOrTime<D> {
return ODate.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@Override
public EDate as(String alias) {
return ODate.create(getType(), (Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get a day of month expression (range 1-31)
*

View File

@ -12,6 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* EDateTime represents Date / Time expressions
@ -81,6 +82,11 @@ public abstract class EDateTime<D extends Comparable> extends EDate<D> {
public EDateTime<D> as(Path<D> alias) {
return ODateTime.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@Override
public EDateTime as(String alias) {
return ODateTime.create(getType(), (Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get a hours expression (range 0-23)

View File

@ -5,7 +5,10 @@
*/
package com.mysema.query.types.expr;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* @author tiwe
@ -19,6 +22,18 @@ public abstract class EEnum<T extends Enum<T>> extends EComparable<T> {
public EEnum(Class<? extends T> type) {
super(type);
}
@SuppressWarnings("unchecked")
@Override
public EEnum<T> as(Path<T> alias) {
return OEnum.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@SuppressWarnings("unchecked")
@Override
public EEnum<T> as(String alias) {
return OEnum.create(getType(),(Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* @return

View File

@ -17,6 +17,7 @@ import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.Ops.MathOps;
import com.mysema.query.types.path.PSimple;
import com.mysema.util.MathUtils;
/**
@ -81,6 +82,12 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
public ENumber<D> as(Path<D> alias) {
return ONumber.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@SuppressWarnings("unchecked")
@Override
public ENumber<D> as(String alias) {
return ONumber.create(getType(),(Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get the absolute value of this expression

View File

@ -14,6 +14,7 @@ import com.mysema.query.types.Expr;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* ESimple is the base class for Expr implementations. It provides default implementations
@ -134,13 +135,23 @@ public abstract class ESimple<D> extends Expr<D> {
}
/**
* Create an alias for the operation
* Create an alias for the expression
*
* @return
*/
@SuppressWarnings("unchecked")
public Expr<D> as(Path<D> alias) {
public ESimple<D> as(Path<D> alias) {
return OSimple.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
/**
* Create an alias for the expression
*
* @return
*/
@SuppressWarnings("unchecked")
public ESimple<D> as(String alias) {
return OSimple.create(getType(),(Operator)Ops.ALIAS, this, new PSimple<D>(getType(), alias));
}
}

View File

@ -11,6 +11,7 @@ import com.mysema.query.types.Expr;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* EString represents String expressions
@ -40,6 +41,12 @@ public abstract class EString extends EComparable<String> {
public EString as(Path<String> alias) {
return OString.create((Operator)Ops.ALIAS, this, alias.asExpr());
}
@SuppressWarnings("unchecked")
@Override
public EString as(String alias) {
return OString.create((Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get the concatenation of this and str

View File

@ -12,6 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PSimple;
/**
* ETime represents Time expressions
@ -38,6 +39,11 @@ public abstract class ETime<D extends Comparable> extends EDateOrTime<D> {
public ETime<D> as(Path<D> alias) {
return OTime.create(getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
}
@Override
public ETime<D> as(String alias) {
return OTime.create(getType(), (Operator)Ops.ALIAS, this, new PSimple(getType(), alias));
}
/**
* Get a hours expression (range 0-23)

View File

@ -33,7 +33,7 @@ public class OSimple<D> extends ESimple<D> implements Operation<D> {
* @param args
* @return
*/
public static <D> Expr<D> create(Class<D> type, Operator<? super D> op, Expr<?>... args){
public static <D> ESimple<D> create(Class<D> type, Operator<? super D> op, Expr<?>... args){
return new OSimple<D>(type, op, args);
}

View File

@ -0,0 +1,45 @@
package com.mysema.query.types.expr;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PString;
public class ESimpleTest {
@Test
public void as_usage(){
ESimple<String> str = new PString("str");
assertEquals("str as alias", str.as("alias").toString());
assertEquals("str as alias", str.as(new PString("alias")).toString());
}
@Test
public void Subclasses_Override_As() throws SecurityException, NoSuchMethodException{
List<Class<?>> classes = Arrays.<Class<?>>asList(
EBoolean.class,
EComparable.class,
EDate.class,
EDateTime.class,
EEnum.class,
ENumber.class,
ESimple.class,
EString.class,
ETime.class);
for (Class<?> cl : classes){
Method asPath = cl.getDeclaredMethod("as", Path.class);
assertEquals(cl, asPath.getReturnType());
Method asString = cl.getDeclaredMethod("as", String.class);
assertEquals(cl, asString.getReturnType());
}
}
}

View File

@ -32,6 +32,8 @@ import com.mysema.query.types.expr.ExprConst;
* @version $Id$
*/
public class SQLSerializer extends SerializerBase<SQLSerializer> {
enum Stage {SELECT, FROM, WHERE, GROUP_BY, HAVING, ORDER_BY}
private final SerializationContext context = new SerializationContext(){
@ -65,6 +67,8 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
private final List<Object> constants = new ArrayList<Object>();
private final boolean dml;
private Stage stage = Stage.SELECT;
private boolean skipParent;
@ -152,10 +156,13 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
}
}
// start
serialize(Position.START, flags);
// select
Stage oldStage = stage;
stage = Stage.SELECT;
if (forCountRow) {
append(templates.getSelect());
serialize(Position.AFTER_SELECT, flags);
@ -185,9 +192,11 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
serialize(Position.AFTER_PROJECTION, flags);
// from
stage = Stage.FROM;
serializeSources(joins);
// where
// where
stage = Stage.WHERE;
serialize(Position.BEFORE_FILTERS, flags);
if (where != null) {
append(templates.getWhere()).handle(where);
@ -195,6 +204,7 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
}
// group by
stage = Stage.GROUP_BY;
serialize(Position.BEFORE_GROUP_BY, flags);
if (!groupBy.isEmpty()) {
append(templates.getGroupBy()).handle(COMMA, groupBy);
@ -202,6 +212,7 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
}
// having
stage = Stage.HAVING;
serialize(Position.BEFORE_HAVING, flags);
if (having != null) {
if (groupBy.isEmpty()) {
@ -212,6 +223,7 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
}
// order by
stage = Stage.ORDER_BY;
serialize(Position.BEFORE_ORDER, flags);
if (!orderBy.isEmpty() && !forCountRow) {
append(templates.getOrderBy());
@ -229,6 +241,9 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
// end
serialize(Position.END, flags);
// reset stage
stage = oldStage;
}
@ -503,6 +518,14 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
String typeName = templates.getTypeForClass(targetType);
visitOperation(targetType, SQLTemplates.CAST, Arrays.<Expr<?>>asList(args.get(0), ExprConst.create(typeName)));
} else if (operator.equals(Ops.ALIAS)){
if (stage == Stage.SELECT || stage == Stage.FROM){
super.visitOperation(type, operator, args);
}else{
// handle only target
handle(args.get(1));
}
} else {
super.visitOperation(type, operator, args);
}

View File

@ -65,7 +65,7 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
public static class SimpleProjection {
public SimpleProjection(String str, String str2) {
public SimpleProjection(String str, String str2) {
}
}
@ -74,30 +74,30 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
@Override
protected Pair<Projectable, List<Expr<?>>> createQuery() {
return Pair.of(
(Projectable)query().from(employee, employee2),
Collections.<Expr<?>>emptyList());
(Projectable)query().from(employee, employee2),
Collections.<Expr<?>>emptyList());
}
@Override
protected Pair<Projectable, List<Expr<?>>> createQuery(EBoolean filter) {
return Pair.of(
(Projectable)query().from(employee, employee2).where(filter),
Collections.<Expr<?>>singletonList(employee.firstname));
(Projectable)query().from(employee, employee2).where(filter),
Collections.<Expr<?>>singletonList(employee.firstname));
}
};
@Test
public void wildcardAll() {
expectedQuery = "select * from EMPLOYEE2 e";
query().from(employee).uniqueResult(Wildcard.all);
}
@Test
public void countAll() {
expectedQuery = "select count(*) as rowCount from EMPLOYEE2 e";
PNumber<Long> rowCount = new PNumber<Long>(Long.class, "rowCount");
query().from(employee).uniqueResult(Wildcard.count().as(rowCount));
}
@Test
public void aggregate(){
int min = 30000, avg = 65000, max = 160000;
@ -171,7 +171,7 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
@Test
public void join() throws Exception {
for (String name : query().from(survey, survey2)
.where(survey.id.eq(survey2.id)).list(survey.name)) {
.where(survey.id.eq(survey2.id)).list(survey.name)) {
System.out.println(name);
}
}
@ -190,13 +190,13 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
public void compactJoin(){
// verbose
query().from(employee).innerJoin(employee2)
.on(employee.superiorId.eq(employee2.id))
.list(employee.id, employee2.id);
.on(employee.superiorId.eq(employee2.id))
.list(employee.id, employee2.id);
// compact
query().from(employee)
.innerJoin(employee.superiorIdKey, employee2)
.list(employee.id, employee2.id);
.innerJoin(employee.superiorIdKey, employee2)
.list(employee.id, employee2.id);
}
@ -204,13 +204,13 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
public void limitAndOffset() throws SQLException {
// limit
query().from(employee)
.orderBy(employee.firstname.asc())
.limit(4).list(employee.id);
.orderBy(employee.firstname.asc())
.limit(4).list(employee.id);
// limit and offset
query().from(employee)
.orderBy(employee.firstname.asc())
.limit(4).offset(3).list(employee.id);
.orderBy(employee.firstname.asc())
.limit(4).offset(3).list(employee.id);
}
@Test
@ -225,7 +225,7 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
query().from(employee).limit(4).offset(3).list(employee.id);
}
@Test
public void limitAndOffsetAndOrder(){
// limit
@ -243,34 +243,34 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
.list(employee.firstname));
}
// @SuppressWarnings("unchecked")
// @Test
// @ExcludeIn({DERBY})
// public void mathFunctions() throws SQLException {
// Expr<Double> d = ENumberConst.create(1.0);
// for (Expr<?> e : Arrays.<Expr<?>> asList(
// MathFunctions.acos(d),
// MathFunctions.asin(d),
// MathFunctions.atan(d),
// MathFunctions.cos(d),
// MathFunctions.tan(d),
// MathFunctions.sin(d),
// ENumber.random(),
// MathFunctions.pow(d, d),
// MathFunctions.log10(d),
// MathFunctions.log(d),
// MathFunctions.exp(d))) {
// query().from(employee).list((Expr<? extends Comparable>) e);
// }
// }
// @SuppressWarnings("unchecked")
// @Test
// @ExcludeIn({DERBY})
// public void mathFunctions() throws SQLException {
// Expr<Double> d = ENumberConst.create(1.0);
// for (Expr<?> e : Arrays.<Expr<?>> asList(
// MathFunctions.acos(d),
// MathFunctions.asin(d),
// MathFunctions.atan(d),
// MathFunctions.cos(d),
// MathFunctions.tan(d),
// MathFunctions.sin(d),
// ENumber.random(),
// MathFunctions.pow(d, d),
// MathFunctions.log10(d),
// MathFunctions.log(d),
// MathFunctions.exp(d))) {
// query().from(employee).list((Expr<? extends Comparable>) e);
// }
// }
@Test
@ExcludeIn({HSQLDB, H2, MYSQL})
public void offsetOnly(){
// offset
query().from(employee)
.orderBy(employee.firstname.asc())
.offset(3).list(employee.id);
.orderBy(employee.firstname.asc())
.offset(3).list(employee.id);
}
@Test
@ -392,11 +392,11 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
public void subQueries() throws SQLException {
// subquery in where block
expectedQuery = "select e.ID from EMPLOYEE2 e "
+ "where e.ID = (select max(e.ID) "
+ "from EMPLOYEE2 e)";
+ "where e.ID = (select max(e.ID) "
+ "from EMPLOYEE2 e)";
List<Integer> list = query().from(employee)
.where(employee.id.eq(sq().from(employee).unique(employee.id.max())))
.list(employee.id);
.where(employee.id.eq(sq().from(employee).unique(employee.id.max())))
.list(employee.id);
assertFalse(list.isEmpty());
}
@ -413,17 +413,21 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
PNumber<BigDecimal> sal = new PNumber<BigDecimal>(BigDecimal.class, "sal");
PathBuilder<Object[]> sq = new PathBuilder<Object[]>(Object[].class, "sq");
SQLSerializer serializer = new SQLSerializer(SQLTemplates.DEFAULT);
serializer.handle(sq().from(employee)
.list(employee.salary.add(employee.salary).add(employee.salary).as(sal)).as(sq));
serializer.handle(
sq()
.from(employee)
.list(employee.salary.add(employee.salary).add(employee.salary).as(sal))
.as(sq));
assertEquals("(select (e.SALARY + e.SALARY + e.SALARY) as sal\nfrom EMPLOYEE2 e) as sq", serializer.toString());
}
@Test
public void complexSubQuery(){
// query.from(
// subQuery.from(Table.table)
// .list(Table.table.field1.add(Table.table.field2).add(Table.table.field3).as("myCalculation"))).
// list(myCalculation.avg(), myCalculation.min(). myCalculation.max());
// query.from(
// subQuery.from(Table.table)
// .list(Table.table.field1.add(Table.table.field2).add(Table.table.field3).as("myCalculation"))).
// list(myCalculation.avg(), myCalculation.min(). myCalculation.max());
// alias for the salary
PNumber<BigDecimal> sal = new PNumber<BigDecimal>(BigDecimal.class, "sal");
@ -433,9 +437,9 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
query().from(
sq().from(employee)
.list(employee.salary.add(employee.salary).add(employee.salary).as(sal)).as(sq)
).list(sq.get(sal).avg(), sq.get(sal).min(), sq.get(sal).max());
).list(sq.get(sal).avg(), sq.get(sal).min(), sq.get(sal).max());
// select avg(sq.sal), min(sq.sal), max(sq.sal) from (select (e.SALARY + e.SALARY + e.SALARY) as sal from EMPLOYEE2 e) as sq
// select avg(sq.sal), min(sq.sal), max(sq.sal) from (select (e.SALARY + e.SALARY + e.SALARY) as sal from EMPLOYEE2 e) as sq
}
@Test
@ -451,29 +455,29 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
// right join
// FIXME
// query().from(employee).rightJoin(sq, sqEmp).on(sqEmp.id.eq(employee.id)).list(employee.id);
// query().from(employee).rightJoin(sq, sqEmp).on(sqEmp.id.eq(employee.id)).list(employee.id);
// FIXME
// full join
// query().from(employee).fullJoin(sq, sqEmp).on(sqEmp.id.eq(employee.id)).list(employee.id);
// query().from(employee).fullJoin(sq, sqEmp).on(sqEmp.id.eq(employee.id)).list(employee.id);
}
@Test
public void syntaxForEmployee() throws SQLException {
query().from(employee).groupBy(employee.superiorId)
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(),employee.id.max());
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(),employee.id.max());
query().from(employee).groupBy(employee.superiorId)
.having(employee.id.max().gt(5))
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(), employee.id.max());
.having(employee.id.max().gt(5))
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(), employee.id.max());
query().from(employee).groupBy(employee.superiorId)
.having(employee.superiorId.isNotNull())
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(),employee.id.max());
.having(employee.superiorId.isNotNull())
.orderBy(employee.superiorId.asc())
.list(employee.salary.avg(),employee.id.max());
}
@SuppressWarnings("unchecked")
@ -497,19 +501,19 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
List<Object[]> list2 = query().union(sq3, sq4).list();
assertFalse(list2.isEmpty());
}
@SuppressWarnings("unchecked")
@Test
public void union_single_column_projections() throws IOException{
SubQueryExpression<Integer> sq1 = sq().from(employee).unique(employee.id.max());
SubQueryExpression<Integer> sq2 = sq().from(employee).unique(employee.id.min());
// list
List<Integer> list = query().union(sq1, sq2).list();
assertEquals(2, list.size());
assertTrue(list.get(0) != null);
assertTrue(list.get(1) != null);
// iterator
CloseableIterator<Integer> iterator = query().union(sq1,sq2).iterate();
try{
@ -521,18 +525,18 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
iterator.close();
}
}
@Test
public void union_multi_column_projection() throws IOException{
SubQueryExpression<Object[]> sq1 = sq().from(employee).unique(employee.id.max(), employee.id.max().subtract(1));
SubQueryExpression<Object[]> sq2 = sq().from(employee).unique(employee.id.min(), employee.id.min().subtract(1));
// list
List<Object[]> list = query().union(sq1, sq2).list();
assertEquals(2, list.size());
assertTrue(list.get(0) != null);
assertTrue(list.get(1) != null);
// iterator
CloseableIterator<Object[]> iterator = query().union(sq1,sq2).iterate();
try{
@ -599,7 +603,7 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
assertNotNull(row[1]);
}
@Test
public void all(){
for (Expr<?> expr : survey.all()){
@ -618,18 +622,18 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
}
// column and wildcard
// for (Object[] row : query().from(survey).list(survey.id, survey.all())){
// assertEquals(3, row.length);
// assertEquals(Integer.class, row[0].getClass());
// assertNotNull(row[1]);
// assertNotNull(row[2]);
// }
// for (Object[] row : query().from(survey).list(survey.id, survey.all())){
// assertEquals(3, row.length);
// assertEquals(Integer.class, row[0].getClass());
// assertNotNull(row[1]);
// assertNotNull(row[2]);
// }
// projection and wildcard
// for (Object[] row : query().from(survey).list(new QIdName(survey.id, survey.name), survey.all())){
// assertEquals(3, row.length);
// assertEquals(IdName.class, row[0].getClass());
// }
// for (Object[] row : query().from(survey).list(new QIdName(survey.id, survey.name), survey.all())){
// assertEquals(3, row.length);
// assertEquals(IdName.class, row[0].getClass());
// }
// projection and two columns
for (Object[] row : query().from(survey).list(new QIdName(survey.id, survey.name), survey.id, survey.name)){
@ -646,14 +650,14 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
assertEquals(String.class, row[1].getClass());
assertEquals(IdName.class, row[2].getClass());
}
// wildcard and QTuple
for (Tuple tuple : query().from(survey).list(new QTuple(survey.all()))){
assertNotNull(tuple.get(survey.id));
assertNotNull(tuple.get(survey.name));
}
}
@Test
@ -667,43 +671,43 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
@Test
public void tupleProjection(){
List<Tuple> tuples = query().from(employee).list(new QTuple(employee.firstname, employee.lastname));
assertFalse(tuples.isEmpty());
for (Tuple tuple : tuples){
assertNotNull(tuple.get(employee.firstname));
assertNotNull(tuple.get(employee.lastname));
}
List<Tuple> tuples = query().from(employee).list(new QTuple(employee.firstname, employee.lastname));
assertFalse(tuples.isEmpty());
for (Tuple tuple : tuples){
assertNotNull(tuple.get(employee.firstname));
assertNotNull(tuple.get(employee.lastname));
}
}
@Test
public void customProjection(){
List<Projection> tuples = query().from(employee).list(new QProjection(employee.firstname, employee.lastname));
assertFalse(tuples.isEmpty());
for (Projection tuple : tuples){
assertNotNull(tuple.get(employee.firstname));
assertNotNull(tuple.get(employee.lastname));
assertNotNull(tuple.getExpr(employee.firstname));
assertNotNull(tuple.getExpr(employee.lastname));
}
List<Projection> tuples = query().from(employee).list(new QProjection(employee.firstname, employee.lastname));
assertFalse(tuples.isEmpty());
for (Projection tuple : tuples){
assertNotNull(tuple.get(employee.firstname));
assertNotNull(tuple.get(employee.lastname));
assertNotNull(tuple.getExpr(employee.firstname));
assertNotNull(tuple.getExpr(employee.lastname));
}
}
@SuppressWarnings("unchecked")
@Test
public void arrayProjection(){
List<String[]> results = query().from(employee).list(new EArrayConstructor<String>(String[].class, employee.firstname));
assertFalse(results.isEmpty());
for (String[] result : results){
assertNotNull(result[0]);
}
List<String[]> results = query().from(employee).list(new EArrayConstructor<String>(String[].class, employee.firstname));
assertFalse(results.isEmpty());
for (String[] result : results){
assertNotNull(result[0]);
}
}
@Test
public void constructorProjection(){
List<SimpleProjection> projections =query().from(employee).list(EConstructor.create(SimpleProjection.class, employee.firstname, employee.lastname));
assertFalse(projections.isEmpty());
for (SimpleProjection projection : projections){
assertNotNull(projection);
}
List<SimpleProjection> projections =query().from(employee).list(EConstructor.create(SimpleProjection.class, employee.firstname, employee.lastname));
assertFalse(projections.isEmpty());
for (SimpleProjection projection : projections){
assertNotNull(projection);
}
}
@Test
@ -739,9 +743,21 @@ public abstract class SelectBaseTest extends AbstractBaseTest{
assertEquals(2, query().from(employee).where(first.or(second)).count());
assertEquals(0, query().from(employee).where(
employee.firstname.eq("Mike"),
employee.lastname.eq("Smith").or(employee.firstname.eq("Joe")),
employee.lastname.eq("Divis")
employee.firstname.eq("Mike"),
employee.lastname.eq("Smith").or(employee.firstname.eq("Joe")),
employee.lastname.eq("Divis")
).count());
}
@Test
@ExcludeIn({DERBY,HSQLDB})
public void path_alias(){
expectedQuery = "select e.LASTNAME, sum(e.SALARY) as salarySum from EMPLOYEE2 e group by e.LASTNAME having salarySum > ?";
ENumber<BigDecimal> salarySum = employee.salary.sum().as("salarySum");
query().from(employee)
.groupBy(employee.lastname)
.having(salarySum.gt(10000))
.list(employee.lastname, salarySum);
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -43,5 +44,20 @@ public class SelectDerbyQuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -5,15 +5,20 @@
*/
package com.mysema.query._h2;
import static com.mysema.query.Constants.employee;
import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
import com.mysema.query.Target;
import com.mysema.query.sql.H2Templates;
import com.mysema.query.sql.Wildcard;
import com.mysema.query.types.path.PNumber;
import com.mysema.testutil.Label;
@Label(Target.H2)
@ -43,5 +48,20 @@ public class SelectH2QuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -43,4 +44,20 @@ public class SelectHsqldbQuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -45,5 +46,20 @@ public class SelectMSSQLQuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -45,5 +46,20 @@ public class SelectMySQLQuotedTest extends SelectBaseTest{
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -45,5 +46,19 @@ public class SelectOracleQuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}

View File

@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mysema.query.Connections;
import com.mysema.query.SelectBaseTest;
@ -45,4 +46,19 @@ public class SelectPostgresQuotedTest extends SelectBaseTest {
public void subQueries() throws SQLException {
}
@Test
public void wildcardAll() {
}
@Test
public void countAll() {
}
@Test
public void path_alias(){
}
}