mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-16 21:01:10 +08:00
#312 renamed various Expression factory classes
This commit is contained in:
parent
e7b4d0bc1b
commit
1761658ca1
@ -29,40 +29,24 @@ import com.mysema.query.types.expr.StringOperation;
|
||||
* @author tiwe
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class JPAGrammar {
|
||||
|
||||
/**
|
||||
* @param col
|
||||
* @return
|
||||
*/
|
||||
public final class JPAExpressions {
|
||||
|
||||
public static <A extends Comparable<? super A>> ComparableExpression<A> avg(CollectionExpression<?,A> col) {
|
||||
return ComparableOperation.create((Class)col.getParameter(0), Ops.QuantOps.AVG_IN_COL, (Expression<?>)col);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param left
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<? super A>> ComparableExpression<A> max(CollectionExpression<?,A> left) {
|
||||
return ComparableOperation.create((Class)left.getParameter(0), Ops.QuantOps.MAX_IN_COL, (Expression<?>)left);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param left
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<? super A>> ComparableExpression<A> min(CollectionExpression<?,A> left) {
|
||||
return ComparableOperation.create((Class)left.getParameter(0), Ops.QuantOps.MIN_IN_COL, (Expression<?>)left);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static StringExpression type(EntityPath<?> path) {
|
||||
return StringOperation.create(JPQLTemplates.TYPE, path);
|
||||
}
|
||||
|
||||
private JPAGrammar() {}
|
||||
private JPAExpressions() {}
|
||||
|
||||
}
|
||||
@ -44,7 +44,7 @@ import com.google.common.collect.Lists;
|
||||
import com.mysema.commons.lang.Pair;
|
||||
import com.mysema.query.group.GroupBy;
|
||||
import com.mysema.query.group.QPair;
|
||||
import com.mysema.query.jpa.JPAGrammar;
|
||||
import com.mysema.query.jpa.JPAExpressions;
|
||||
import com.mysema.query.jpa.JPASubQuery;
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.jpa.domain.Animal;
|
||||
@ -814,14 +814,14 @@ public abstract class AbstractStandardTest {
|
||||
@Ignore
|
||||
public void Type() {
|
||||
assertEquals(Arrays.asList("C","C","C","C","C","C","A"),
|
||||
query().from(animal).orderBy(animal.id.asc()).list(JPAGrammar.type(animal)));
|
||||
query().from(animal).orderBy(animal.id.asc()).list(JPAExpressions.type(animal)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@NoOpenJPA
|
||||
public void Type_Order() {
|
||||
assertEquals(Arrays.asList(10,1,2,3,4,5,6),
|
||||
query().from(animal).orderBy(JPAGrammar.type(animal).asc(), animal.id.asc())
|
||||
query().from(animal).orderBy(JPAExpressions.type(animal).asc(), animal.id.asc())
|
||||
.list(animal.id));
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import com.mysema.query.types.expr.BooleanExpression;
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public final class LuceneUtils {
|
||||
public final class LuceneExpressions {
|
||||
|
||||
static final Operator<Object> LUCENE_QUERY = new OperatorImpl<Object>("LUCENE_QUERY", Object.class);
|
||||
|
||||
@ -75,6 +75,6 @@ public final class LuceneUtils {
|
||||
return new QueryElement(new FuzzyQuery(term, minimumSimilarity, prefixLength));
|
||||
}
|
||||
|
||||
private LuceneUtils(){}
|
||||
private LuceneExpressions(){}
|
||||
|
||||
}
|
||||
@ -140,7 +140,7 @@ public class LuceneSerializer {
|
||||
return ge(operation, metadata);
|
||||
} else if (op == Ops.DELEGATE){
|
||||
return toQuery(operation.getArg(0), metadata);
|
||||
} else if (op == LuceneUtils.LUCENE_QUERY) {
|
||||
} else if (op == LuceneExpressions.LUCENE_QUERY) {
|
||||
return ((Constant<Query>)operation.getArg(0)).getConstant();
|
||||
}
|
||||
throw new UnsupportedOperationException("Illegal operation " + operation);
|
||||
@ -475,9 +475,9 @@ public class LuceneSerializer {
|
||||
protected String[] convert(Path<?> leftHandSide, Expression<?> rightHandSide, QueryMetadata metadata) {
|
||||
if (rightHandSide instanceof Operation) {
|
||||
Operation<?> operation = (Operation<?>)rightHandSide;
|
||||
if (operation.getOperator() == LuceneUtils.PHRASE) {
|
||||
if (operation.getOperator() == LuceneExpressions.PHRASE) {
|
||||
return Iterables.toArray(WS_SPLITTER.split(operation.getArg(0).toString()), String.class);
|
||||
} else if (operation.getOperator() == LuceneUtils.TERM) {
|
||||
} else if (operation.getOperator() == LuceneExpressions.TERM) {
|
||||
return new String[] { operation.getArg(0).toString() };
|
||||
} else {
|
||||
throw new IllegalArgumentException(rightHandSide.toString());
|
||||
|
||||
@ -27,7 +27,7 @@ public class PhraseElement extends StringOperation {
|
||||
private static final long serialVersionUID = 2350215644019186076L;
|
||||
|
||||
public PhraseElement(String str) {
|
||||
super(LuceneUtils.PHRASE, ConstantImpl.create(str));
|
||||
super(LuceneExpressions.PHRASE, ConstantImpl.create(str));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public class QueryElement extends BooleanOperation {
|
||||
private static final long serialVersionUID = 470868107363840155L;
|
||||
|
||||
public QueryElement(Query query){
|
||||
super(LuceneUtils.LUCENE_QUERY, new ConstantImpl<Query>(query));
|
||||
super(LuceneExpressions.LUCENE_QUERY, new ConstantImpl<Query>(query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ public class TermElement extends StringOperation {
|
||||
private static final long serialVersionUID = 2350215644019186076L;
|
||||
|
||||
public TermElement(String str) {
|
||||
super(LuceneUtils.TERM, ConstantImpl.create(str));
|
||||
super(LuceneExpressions.TERM, ConstantImpl.create(str));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.lucene.LuceneSerializer;
|
||||
import com.mysema.query.lucene.LuceneUtils;
|
||||
import com.mysema.query.lucene.LuceneExpressions;
|
||||
import com.mysema.query.lucene.QueryElement;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.Operation;
|
||||
@ -207,17 +207,17 @@ public class LuceneSerializerTest {
|
||||
|
||||
@Test
|
||||
public void FuzzyLike() throws Exception{
|
||||
testQuery(LuceneUtils.fuzzyLike(rating, "Good"), "rating:Good~0.5", 1);
|
||||
testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~0.5", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void FuzzyLike_with_Similarity() throws Exception{
|
||||
testQuery(LuceneUtils.fuzzyLike(rating, "Good", 0.6f), "rating:Good~0.6", 1);
|
||||
testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f), "rating:Good~0.6", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void FuzzyLike_with_Similarity_and_prefix() throws Exception{
|
||||
testQuery(LuceneUtils.fuzzyLike(rating, "Good", 0.6f, 0), "rating:Good~0.6", 1);
|
||||
testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f, 0), "rating:Good~0.6", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -43,7 +43,7 @@ public class AnyEmbeddedBuilder<K> {
|
||||
|
||||
public MongodbQuery<K> on(Predicate... conditions) {
|
||||
return queryMixin.where(PredicateOperation.create(
|
||||
MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions)));
|
||||
MongodbExpressions.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,21 +13,37 @@
|
||||
*/
|
||||
package com.mysema.query.mongodb;
|
||||
|
||||
import com.mysema.query.types.ConstantImpl;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.Operator;
|
||||
import com.mysema.query.types.OperatorImpl;
|
||||
import com.mysema.query.types.expr.BooleanExpression;
|
||||
import com.mysema.query.types.expr.BooleanOperation;
|
||||
|
||||
/**
|
||||
* Mongodb specific operators
|
||||
* Mongodb specific operations
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public final class MongodbOps {
|
||||
public final class MongodbExpressions {
|
||||
|
||||
public static final Operator<Boolean> NEAR = new OperatorImpl<Boolean>("NEAR", Number.class, Number.class);
|
||||
|
||||
public static final Operator<Boolean> ELEM_MATCH = new OperatorImpl<Boolean>("ELEM_MATCH", Object.class, Object.class);
|
||||
|
||||
private MongodbOps(){}
|
||||
private MongodbExpressions(){}
|
||||
|
||||
/**
|
||||
* Finds the closest points relative to the given location and orders the results with decreasing promimity
|
||||
*
|
||||
* @param expr
|
||||
* @param latVal latitude
|
||||
* @param longVal longitude
|
||||
* @return
|
||||
*/
|
||||
public static BooleanExpression near(Expression<Double[]> expr, double latVal, double longVal){
|
||||
return BooleanOperation.create(MongodbExpressions.NEAR, expr, new ConstantImpl<Double[]>(new Double[]{latVal, longVal}));
|
||||
}
|
||||
|
||||
}
|
||||
@ -199,10 +199,10 @@ public class MongodbSerializer implements Visitor<Object, Void> {
|
||||
Expression<?> key = expr.getArg(1);
|
||||
return asDBObject(visit(path, context) + "." + key.toString(), asDBObject("$exists", true));
|
||||
|
||||
} else if (op == MongodbOps.NEAR) {
|
||||
} else if (op == MongodbExpressions.NEAR) {
|
||||
return asDBObject(asDBKey(expr, 0), asDBObject("$near", asDBValue(expr, 1)));
|
||||
|
||||
} else if (op == MongodbOps.ELEM_MATCH) {
|
||||
} else if (op == MongodbExpressions.ELEM_MATCH) {
|
||||
return asDBObject(asDBKey(expr, 0), asDBObject("$elemMatch", asDBValue(expr, 1)));
|
||||
}
|
||||
|
||||
|
||||
@ -13,11 +13,9 @@
|
||||
*/
|
||||
package com.mysema.query.mongodb;
|
||||
|
||||
import com.mysema.query.types.ConstantImpl;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.expr.BooleanExpression;
|
||||
import com.mysema.query.types.expr.BooleanOperation;
|
||||
import com.mysema.query.types.path.ArrayPath;
|
||||
|
||||
/**
|
||||
@ -50,7 +48,7 @@ public class Point extends ArrayPath<Double> {
|
||||
* @return
|
||||
*/
|
||||
public BooleanExpression near(double latVal, double longVal){
|
||||
return BooleanOperation.create(MongodbOps.NEAR, this, new ConstantImpl<Double[]>(new Double[]{latVal, longVal}));
|
||||
return MongodbExpressions.near(this, latVal, longVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user