mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
This commit is contained in:
parent
650d06f11f
commit
58e7f61285
@ -46,8 +46,8 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
|
||||
private List<?> distinct(List<?> list) {
|
||||
if (!list.isEmpty() && list.get(0).getClass().isArray()){
|
||||
Set set = new HashSet();
|
||||
List rv = new ArrayList();
|
||||
Set set = new HashSet(list.size());
|
||||
List rv = new ArrayList(list.size());
|
||||
for (Object o : list){
|
||||
if (set.add(Arrays.asList((Object[])o))){
|
||||
rv.add(o);
|
||||
@ -59,17 +59,7 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
}
|
||||
}
|
||||
|
||||
private List evaluateMultipleSources(QueryMetadata metadata, Map<Expr<?>, Iterable<?>> iterables, boolean count) {
|
||||
List<Expr<?>> sources = new ArrayList<Expr<?>>();
|
||||
for (JoinExpression join : metadata.getJoins()){
|
||||
if (join.getType() == JoinType.DEFAULT){
|
||||
sources.add(join.getTarget());
|
||||
}else{
|
||||
Operation target = (Operation) join.getTarget();
|
||||
sources.add(target.getArg(1));
|
||||
}
|
||||
}
|
||||
|
||||
private List evaluateMultipleSources(QueryMetadata metadata, Map<Expr<?>, Iterable<?>> iterables, boolean count) {
|
||||
// from where
|
||||
Evaluator<List<Object[]>> ev = evaluatorFactory.createEvaluator(metadata.getJoins(), metadata.getWhere());
|
||||
List<Iterable<?>> iterableList = new ArrayList<Iterable<?>>(metadata.getJoins().size());
|
||||
@ -80,7 +70,17 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
}
|
||||
List<?> list = ev.evaluate(iterableList.toArray());
|
||||
|
||||
if (!count && !list.isEmpty()){
|
||||
if (!count && !list.isEmpty()){
|
||||
List<Expr<?>> sources = new ArrayList<Expr<?>>();
|
||||
for (JoinExpression join : metadata.getJoins()){
|
||||
if (join.getType() == JoinType.DEFAULT){
|
||||
sources.add(join.getTarget());
|
||||
}else{
|
||||
Operation target = (Operation) join.getTarget();
|
||||
sources.add(target.getArg(1));
|
||||
}
|
||||
}
|
||||
|
||||
// ordered
|
||||
if (!metadata.getOrderBy().isEmpty()){
|
||||
order(metadata, sources, list);
|
||||
@ -91,6 +91,10 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
list = metadata.getModifiers().subList(list);
|
||||
}
|
||||
|
||||
if (list.isEmpty()){
|
||||
return list;
|
||||
}
|
||||
|
||||
// projection
|
||||
list = project(metadata, sources, list);
|
||||
}
|
||||
@ -106,6 +110,7 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
|
||||
private List evaluateSingleSource(QueryMetadata metadata, Map<Expr<?>, Iterable<?>> iterables, boolean count) {
|
||||
Expr<?> source = metadata.getJoins().get(0).getTarget();
|
||||
List<Expr<?>> sources = Collections.<Expr<?>>singletonList(source);
|
||||
Iterable<?> iterable = iterables.values().iterator().next();
|
||||
List<?> list;
|
||||
if (iterable instanceof List){
|
||||
@ -120,13 +125,14 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
list = evaluator.evaluate(list);
|
||||
}
|
||||
|
||||
if (!count && !list.isEmpty()){
|
||||
// clone list
|
||||
list = new ArrayList(list);
|
||||
|
||||
if (!count && !list.isEmpty()){
|
||||
// ordered
|
||||
if (!metadata.getOrderBy().isEmpty()){
|
||||
order(metadata, Collections.<Expr<?>>singletonList(source), list);
|
||||
// clone list
|
||||
if (list == iterable){
|
||||
list = new ArrayList(list);
|
||||
}
|
||||
order(metadata, sources, list);
|
||||
}
|
||||
|
||||
// limit + offset
|
||||
@ -134,13 +140,16 @@ public class DefaultQueryEngine implements QueryEngine {
|
||||
list = metadata.getModifiers().subList(list);
|
||||
}
|
||||
|
||||
if (list.isEmpty()){
|
||||
return list;
|
||||
}
|
||||
|
||||
// projection
|
||||
if (metadata.getProjection().size() > 1 || !metadata.getProjection().get(0).equals(source)){
|
||||
list = project(metadata, Collections.<Expr<?>>singletonList(source), list);
|
||||
list = project(metadata, sources, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// distinct
|
||||
if (metadata.isDistinct()){
|
||||
|
||||
@ -24,20 +24,16 @@ public final class MiniApi {
|
||||
}
|
||||
|
||||
public static <A> ColQuery from(A alias, Iterable<A> col) {
|
||||
return query().from(Alias.$(alias), col);
|
||||
return new ColQueryImpl().from(Alias.$(alias), col);
|
||||
}
|
||||
|
||||
public static <A> ColQuery from(Path<A> path, A... arr) {
|
||||
return query().from(path, Arrays.asList(arr));
|
||||
return new ColQueryImpl().from(path, Arrays.asList(arr));
|
||||
}
|
||||
|
||||
public static <A> ColQuery from(Path<A> path, Iterable<A> col) {
|
||||
return query().from(path, col);
|
||||
}
|
||||
|
||||
private static ColQuery query(){
|
||||
return new ColQueryImpl();
|
||||
}
|
||||
return new ColQueryImpl().from(path, col);
|
||||
}
|
||||
|
||||
public static <A> ColUpdateClause<A> update(Path<A> path, Iterable<A> col){
|
||||
return new ColUpdateClause<A>(path, col);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user