Skip to content

Commit

Permalink
#304 remove types from Operator
Browse files Browse the repository at this point in the history
  • Loading branch information
timowest committed Dec 16, 2012
1 parent 7c6f7c1 commit 9f0d281
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,21 @@ public final S handle(JoinFlag joinFlag) {
}

public final S handle(final String sep, final Expression<?>[] expressions) {
boolean first = true;
for (final Expression<?> expr : expressions) {
if (!first) {
for (int i = 0; i< expressions.length; i++) {
if (i != 0) {
append(sep);
}
handle(expr);
first = false;
handle(expressions[i]);
}
return self;
}

public final S handle(final String sep, final List<?> expressions) {
boolean first = true;
for (final Object expr : expressions) {
if (!first) {
for (int i = 0; i < expressions.size(); i++) {
if (i != 0) {
append(sep);
}
handle((Expression<?>)expr);
first = false;
handle((Expression<?>)expressions.get(i));
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
@Immutable
public class OperationImpl<T> extends ExpressionBase<T> implements Operation<T> {

private static final long serialVersionUID = 4796432056083507588L;

private final ImmutableList<Expression<?>> args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.mysema.query.types;

import java.io.Serializable;
import java.util.List;

/**
* Operator represents operator symbols
Expand All @@ -32,11 +31,4 @@ public interface Operator<T> extends Serializable{
*/
String getId();

/**
* Get the types related to this operator symbols
*
* @return
*/
List<Class<?>> getTypes();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,27 @@
package com.mysema.query.types;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.concurrent.Immutable;

import com.google.common.collect.ImmutableList;

/**
* OperatorImpl is the default implementation of the {@link Operator} interface
*/
@Immutable
public final class OperatorImpl<T> implements Operator<T> {

static final Map<String, Operator<?>> OPS = new HashMap<String, Operator<?>>(1000);
static final Map<String, Operator<?>> OPS = new HashMap<String, Operator<?>>(150);

private static final long serialVersionUID = -2435035383548549877L;

private final String id;

private final ImmutableList<Class<?>> types;

private final int hashCode;

public OperatorImpl(String id, Class<?>... types) {
this(id, ImmutableList.copyOf(types));
}

public OperatorImpl(String id, ImmutableList<Class<?>> types) {
public OperatorImpl(String id) {
this.id = id;
this.hashCode = id.hashCode();
this.types = types;
OPS.put(id, this);
}

Expand All @@ -57,15 +47,6 @@ public String getId() {
return id;
}

/**
* Get the types related to this operator symbols
*
* @return
*/
public List<Class<?>> getTypes() {
return types;
}

@Override
public String toString(){
return id;
Expand Down
235 changes: 110 additions & 125 deletions querydsl-core/src/main/java/com/mysema/query/types/Ops.java

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions querydsl-core/src/main/java/com/mysema/query/types/PathType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
*/
package com.mysema.query.types;

import java.util.List;

import com.google.common.collect.ImmutableList;


/**
* PathType represents the relation of a {@link Path} to its parent
*/
Expand Down Expand Up @@ -76,10 +71,5 @@ public enum PathType implements Operator<Object> {
public String getId() {
return name();
}

@Override
public List<Class<?>> getTypes() {
return ImmutableList.of();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class JPQLTemplates extends Templates {

public static final char DEFAULT_ESCAPE = '!';

public static final Operator<String> TYPE = new OperatorImpl<String>("TYPE", Object.class);
public static final Operator<String> TYPE = new OperatorImpl<String>("TYPE");

public static final Operator<Object> CAST = new OperatorImpl<Object>("CAST",Object.class, Object.class);
public static final Operator<Object> CAST = new OperatorImpl<Object>("CAST");

public static final Operator<Boolean> MEMBER_OF = new OperatorImpl<Boolean>("MEMBER_OF",Object.class, Object.class);
public static final Operator<Boolean> MEMBER_OF = new OperatorImpl<Boolean>("MEMBER_OF");

public static final JPQLTemplates DEFAULT = new JPQLTemplates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
import com.mysema.query.types.expr.BooleanExpression;

/**
* Utility methods to create filter expressions for Lucene queries that are not covered by the Querydsl standard expression model
* Utility methods to create filter expressions for Lucene queries that are not covered by the
* Querydsl standard expression model
*
* @author tiwe
*
*/
public final class LuceneExpressions {

static final Operator<Object> LUCENE_QUERY = new OperatorImpl<Object>("LUCENE_QUERY", Object.class);
static final Operator<Object> LUCENE_QUERY = new OperatorImpl<Object>("LUCENE_QUERY");

static final Operator<String> PHRASE = new OperatorImpl<String>("PHRASE", String.class);
static final Operator<String> PHRASE = new OperatorImpl<String>("PHRASE");

static final Operator<String> TERM = new OperatorImpl<String>("TERM", String.class);
static final Operator<String> TERM = new OperatorImpl<String>("TERM");

/**
* Create a fuzzy query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
public final class MongodbExpressions {

public static final Operator<Boolean> NEAR = new OperatorImpl<Boolean>("NEAR", Number.class, Number.class);
public static final Operator<Boolean> NEAR = new OperatorImpl<Boolean>("NEAR");

public static final Operator<Boolean> ELEM_MATCH = new OperatorImpl<Boolean>("ELEM_MATCH", Object.class, Object.class);
public static final Operator<Boolean> ELEM_MATCH = new OperatorImpl<Boolean>("ELEM_MATCH");

private MongodbExpressions(){}

Expand Down
26 changes: 18 additions & 8 deletions querydsl-sql/src/main/java/com/mysema/query/sql/SQLSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,25 @@ private void serializeForQuery(QueryMetadata metadata, boolean forCountRow) {
final List<OrderSpecifier<?>> orderBy = metadata.getOrderBy();
final Set<QueryFlag> flags = metadata.getFlags();
final boolean hasFlags = !flags.isEmpty();

final List<Expression<?>> sqlSelect = new ArrayList<Expression<?>>(select.size());
for (Expression<?> selectExpr : select) {
if (selectExpr instanceof FactoryExpression) {
// transforms constructor arguments into individual select expressions
sqlSelect.addAll(((FactoryExpression<?>) selectExpr).getArgs());
List<Expression<?>> sqlSelect;
if (select.size() == 1) {
final Expression<?> first = select.get(0);
if (first instanceof FactoryExpression) {
sqlSelect = ((FactoryExpression<?>)first).getArgs();
} else {
sqlSelect.add(selectExpr);
}
sqlSelect = (List)select;
}
} else {
sqlSelect = new ArrayList<Expression<?>>(select.size());
for (Expression<?> selectExpr : select) {
if (selectExpr instanceof FactoryExpression) {
// transforms constructor arguments into individual select expressions
sqlSelect.addAll(((FactoryExpression<?>) selectExpr).getArgs());
} else {
sqlSelect.add(selectExpr);
}
}
}

// start
Expand Down
Loading

0 comments on commit 9f0d281

Please sign in to comment.