added tests for domain types

This commit is contained in:
Timo Westkämper 2008-04-04 23:28:28 +00:00
parent ae25a8fe91
commit 86d54c584e
10 changed files with 80 additions and 43 deletions

View File

@ -10,8 +10,8 @@ import static com.mysema.query.grammar.types.Factory.createBoolean;
import static com.mysema.query.grammar.types.Factory.createConstant;
import static com.mysema.query.grammar.types.Factory.createNumber;
import com.mysema.query.grammar.types.CollectionType;
import com.mysema.query.grammar.types.Expr;
import com.mysema.query.grammar.types.Expr.CollectionType;
/**
* Grammar provides the factory methods for the fluent grammar

View File

@ -11,7 +11,9 @@ package com.mysema.query.grammar.types;
* @author tiwe
* @version $Id$
*/
public class Alias {
public interface Alias {
Expr<?> getFrom();
public static class Entity<D> extends Expr.Entity<D> implements ToPath{
private final Expr<?> from;
@ -37,7 +39,7 @@ public class Alias {
public Path<?> getTo() {return to;}
}
public static class Simple<D> extends Expr.Simple<D>{
public static class Simple<D> extends Expr.Simple<D> implements Alias{
private final Expr<?> from;
private final java.lang.String to;
public Simple(Expr<D> from, java.lang.String to) {
@ -52,8 +54,7 @@ public class Alias {
public java.lang.String getTo() {return to;}
}
public interface ToPath{
Expr<?> getFrom();
public interface ToPath extends Alias{
Path<?> getTo();
}

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2008 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.grammar.types;
/**
* CollectionType provides
*
* @author tiwe
* @version $Id$
*/
public interface CollectionType<D>{ }

View File

@ -29,8 +29,6 @@ public abstract class Expr<D> {
public Boolean or(Boolean right) {return IntGrammar.or(this, right);}
}
public interface CollectionType<D>{ }
public static abstract class Comparable<D extends java.lang.Comparable<D>> extends Literal<D>{
public Comparable(Class<D> type) {super(type);}
public Boolean after(D right) {return IntGrammar.after(this,right);}

View File

@ -13,7 +13,6 @@ import static com.mysema.query.grammar.types.Factory.createString;
import com.mysema.query.grammar.Ops;
import com.mysema.query.grammar.Order;
import com.mysema.query.grammar.OrderSpecifier;
import com.mysema.query.grammar.types.Expr.CollectionType;
/**
* InternalGrammar provides

View File

@ -24,7 +24,7 @@ public interface Path<C> {
Expr.Boolean isnotnull();
Expr.Boolean isnull();
public static class Boolean extends Expr.Boolean implements Simple<java.lang.Boolean>{
public static class Boolean extends Expr.Boolean implements Path<java.lang.Boolean>{
private final PathMetadata<java.lang.String> metadata;
public Boolean(PathMetadata<java.lang.String> metadata) {
this.metadata = metadata;
@ -34,14 +34,14 @@ public interface Path<C> {
public Expr.Boolean isnull() {return IntGrammar.isnull(this);}
}
public interface Collection<D> extends Path<java.util.Collection<D>>, Expr.CollectionType<D>{
public interface Collection<D> extends Path<java.util.Collection<D>>, CollectionType<D>{
Expr<D> get(Expr<Integer> index);
Expr<D> get(int index);
Class<D> getElementType();
Expr.Comparable<Integer> size();
}
public static class Comparable<D extends java.lang.Comparable<D>> extends Expr.Comparable<D> implements Simple<D>{
public static class Comparable<D extends java.lang.Comparable<D>> extends Expr.Comparable<D> implements Path<D>{
private final PathMetadata<?> metadata;
public Comparable(Class<D> type, PathMetadata<?> metadata) {
super(type);
@ -60,17 +60,16 @@ public interface Path<C> {
this.type = type;
this.metadata = metadata;
}
public Expr.Literal<D> get(Expr<Integer> index) {
return new Path.Literal<D>(type, forListAccess(this, index));
public Expr.Simple<D> get(Expr<Integer> index) {
return new Path.Simple<D>(type, forListAccess(this, index));
}
public Expr.Literal<D> get(int index) {
return new Path.Literal<D>(type, forListAccess(this, index));
public Expr.Simple<D> get(int index) {
return new Path.Simple<D>(type, forListAccess(this, index));
}
public PathMetadata<?> getMetadata() {return metadata;}
public Expr.Boolean isnotnull() {return IntGrammar.isnotnull(this);}
public Expr.Boolean isnull() {return IntGrammar.isnull(this);}
public Expr.Comparable<Integer> size() {
// return IntGrammar.size(this);
return new Path.Comparable<Integer>(Integer.class, forSize(this));
}
public Class<D> getElementType() {return type;}
@ -86,11 +85,11 @@ public interface Path<C> {
this.valueType = valueType;
this.metadata = metadata;
}
public Expr.Literal<V> get(Expr<K> key) {
return new Path.Literal<V>(valueType, forMapAccess(this, key));
public Expr.Simple<V> get(Expr<K> key) {
return new Path.Simple<V>(valueType, forMapAccess(this, key));
}
public Expr.Literal<V> get(K key) {
return new Path.Literal<V>(valueType, forMapAccess(this, key));
public Expr.Simple<V> get(K key) {
return new Path.Simple<V>(valueType, forMapAccess(this, key));
}
public PathMetadata<?> getMetadata() {return metadata;}
public Expr.Boolean isnotnull() {return IntGrammar.isnotnull(this);}
@ -121,8 +120,8 @@ public interface Path<C> {
protected <A> EntityCollection<A> _entitycol(java.lang.String path,Class<A> type) {
return new EntityCollection<A>(type, forProperty(this, path));
}
protected <A> Expr.Literal<A> _simple(java.lang.String path, Class<A> type){
return new Path.Literal<A>(type, forProperty(this, path));
protected <A> Expr.Simple<A> _simple(java.lang.String path, Class<A> type){
return new Path.Simple<A>(type, forProperty(this, path));
}
protected <A> ComponentCollection<A> _simplecol(java.lang.String path,Class<A> type) {
return new ComponentCollection<A>(type, forProperty(this, path));
@ -198,14 +197,10 @@ public interface Path<C> {
Class<K> getKeyType();
Class<V> getValueType();
}
public interface Simple<D> extends Path<D>{
Expr<D> as(java.lang.String to);
}
public static class Literal<D> extends Expr.Literal<D> implements Simple<D>{
public static class Simple<D> extends Expr.Simple<D> implements Path<D>{
private final PathMetadata<?> metadata;
public <T> Literal(Class<D> type, PathMetadata<?> metadata) {
public <T> Simple(Class<D> type, PathMetadata<?> metadata) {
super(type);
this.metadata = metadata;
}
@ -214,7 +209,7 @@ public interface Path<C> {
public Expr.Boolean isnull() {return IntGrammar.isnull(this);}
}
public static class String extends Expr.String implements Simple<java.lang.String>{
public static class String extends Expr.String implements Path<java.lang.String>{
private final PathMetadata<java.lang.String> metadata;
public String(PathMetadata<java.lang.String> metadata) {
this.metadata = metadata;

View File

@ -103,8 +103,6 @@ public abstract class Visitor<T extends Visitor<T>> {
protected abstract void visit(Path.Simple<?> expr);
protected abstract void visit(Path.Literal<?> expr);
protected abstract void visit(Path.String expr);
}

View File

@ -87,10 +87,6 @@ public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visito
visit((Path<?>) expr);
}
@Override
protected void visit(Path.Literal<?> expr) {
visit((Path<?>) expr);
}
@Override
protected void visit(Path.String expr) {
visit((Path<?>) expr);
}

View File

@ -23,13 +23,6 @@ public class VisitorTest {
@Test
public void testIteration() throws SecurityException, NoSuchMethodException{
// for (Class<?> innerType : Types.class.getClasses()){
// if (!innerType.isInterface()
// && Expr.class.isAssignableFrom(innerType)
// && !innerType.getSimpleName().startsWith("Expr")){
// Visitor.class.getDeclaredMethod("visit", innerType);
// }
// }
List<Class<?>> types = new ArrayList<Class<?>>();
types.addAll(Arrays.asList(Alias.class.getClasses()));
types.addAll(Arrays.asList(Operation.class.getClasses()));

View File

@ -0,0 +1,43 @@
package com.mysema.query.grammar.types;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* TypesTest provides
*
* @author tiwe
* @version $Id$
*/
public class TypesTest {
@Test
public void testAlias(){
for (Class<?> cl : Alias.class.getClasses()){
assertTrue(cl.getName(),Alias.class.isAssignableFrom(cl));
if (!cl.isInterface()){
assertTrue(cl.getName(),Expr.class.isAssignableFrom(cl));
}
}
}
@Test
public void testExpr(){
for (Class<?> cl : Expr.class.getClasses()){
assertTrue(cl.getName(),Expr.class.isAssignableFrom(cl));
}
}
@Test
public void testPath(){
for (Class<?> cl : Path.class.getClasses()){
assertTrue(cl.getName(),Path.class.isAssignableFrom(cl));
if (!cl.isInterface()){
assertTrue(cl.getName(),Expr.class.isAssignableFrom(cl));
}
}
}
}