mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-27 21:01:15 +08:00
This commit is contained in:
parent
90ed0e6b9b
commit
c8a1e1d841
@ -11,10 +11,10 @@ package com.mysema.query.types.expr;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D>
|
||||
* @param <E>
|
||||
* @see java.util.Collection
|
||||
*/
|
||||
public interface ECollection<D>{
|
||||
public interface ECollection<E>{
|
||||
|
||||
/**
|
||||
* Get an expression for <code>this.contains(child)</code>
|
||||
@ -23,7 +23,7 @@ public interface ECollection<D>{
|
||||
* @return this.contains(child)
|
||||
* @see java.util.Collection#contains(Object)
|
||||
*/
|
||||
EBoolean contains(D child);
|
||||
EBoolean contains(E child);
|
||||
|
||||
/**
|
||||
* Get an expression for <code>this.contains(child)</code>
|
||||
@ -32,13 +32,13 @@ public interface ECollection<D>{
|
||||
* @return
|
||||
* @see java.util.Collection#contains(Object)
|
||||
*/
|
||||
EBoolean contains(Expr<D> child);
|
||||
EBoolean contains(Expr<E> child);
|
||||
|
||||
/**
|
||||
* Get the element type of this path
|
||||
*
|
||||
*/
|
||||
Class<D> getElementType();
|
||||
Class<E> getElementType();
|
||||
|
||||
/**
|
||||
* Get an expression for <code>this.isEmpty()</code>
|
||||
|
||||
@ -13,10 +13,10 @@ import javax.annotation.Nonnegative;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
* @see java.util.List
|
||||
*/
|
||||
public interface EList<D> extends ECollection<D> {
|
||||
public interface EList<E> extends ECollection<E> {
|
||||
|
||||
/**
|
||||
* Indexed access
|
||||
@ -25,7 +25,7 @@ public interface EList<D> extends ECollection<D> {
|
||||
* @return this.get(index)
|
||||
* @see java.util.List#get(int)
|
||||
*/
|
||||
Expr<D> get(Expr<Integer> index);
|
||||
Expr<E> get(Expr<Integer> index);
|
||||
|
||||
/**
|
||||
* Indexed access
|
||||
@ -34,5 +34,5 @@ public interface EList<D> extends ECollection<D> {
|
||||
* @return this.get(index)
|
||||
* @see java.util.List#get(int)
|
||||
*/
|
||||
Expr<D> get(@Nonnegative int index);
|
||||
Expr<E> get(@Nonnegative int index);
|
||||
}
|
||||
@ -12,9 +12,9 @@ import com.mysema.query.types.expr.ECollection;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D>
|
||||
* @param <E>
|
||||
* @see java.util.Collection
|
||||
*/
|
||||
public interface PCollection<D> extends Path<java.util.Collection<D>>, ECollection<D> {
|
||||
public interface PCollection<E> extends Path<java.util.Collection<E>>, ECollection<E> {
|
||||
|
||||
}
|
||||
@ -20,12 +20,12 @@ import com.mysema.query.util.NotEmpty;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PComponentCollection<D> extends ECollectionBase<D> implements PCollection<D> {
|
||||
public class PComponentCollection<E> extends ECollectionBase<E> implements PCollection<E> {
|
||||
|
||||
protected final Class<D> type;
|
||||
protected final Class<E> type;
|
||||
|
||||
private final Path<?> root;
|
||||
|
||||
@ -34,18 +34,18 @@ public class PComponentCollection<D> extends ECollectionBase<D> implements PColl
|
||||
private volatile EBoolean isnull, isnotnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PComponentCollection(Class<? super D> type, PathMetadata<?> metadata) {
|
||||
public PComponentCollection(Class<? super E> type, PathMetadata<?> metadata) {
|
||||
super((Class)Collection.class);
|
||||
this.type = (Class)type;
|
||||
this.metadata = metadata;
|
||||
this.root = metadata.getRoot() != null ? metadata.getRoot() : this;
|
||||
}
|
||||
|
||||
public PComponentCollection(Class<? super D> type, @NotEmpty String var) {
|
||||
public PComponentCollection(Class<? super E> type, @NotEmpty String var) {
|
||||
this(type, PathMetadata.forVariable(var));
|
||||
}
|
||||
|
||||
public PComponentCollection(Class<? super D> type, Path<?> parent, @NotEmpty String property) {
|
||||
public PComponentCollection(Class<? super E> type, Path<?> parent, @NotEmpty String property) {
|
||||
this(type, PathMetadata.forProperty(parent, property));
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class PComponentCollection<D> extends ECollectionBase<D> implements PColl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<D> getElementType() {
|
||||
public Class<E> getElementType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public class PComponentCollection<D> extends ECollectionBase<D> implements PColl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expr<Collection<D>> asExpr() {
|
||||
public Expr<Collection<E>> asExpr() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -15,34 +15,34 @@ import com.mysema.query.types.expr.Expr;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PComponentList<D> extends PComponentCollection<D> implements PList<D> {
|
||||
public class PComponentList<E> extends PComponentCollection<E> implements PList<E> {
|
||||
|
||||
private final Map<Integer,PSimple<D>> cache = new HashMap<Integer,PSimple<D>>();
|
||||
private final Map<Integer,PSimple<E>> cache = new HashMap<Integer,PSimple<E>>();
|
||||
|
||||
public PComponentList(Class<? super D> type, PathMetadata<?> metadata) {
|
||||
public PComponentList(Class<? super E> type, PathMetadata<?> metadata) {
|
||||
super(type, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PSimple<D> get(Expr<Integer> index) {
|
||||
return new PSimple<D>(type, PathMetadata.forListAccess(this, index));
|
||||
public PSimple<E> get(Expr<Integer> index) {
|
||||
return new PSimple<E>(type, PathMetadata.forListAccess(this, index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PSimple<D> get(int index) {
|
||||
public PSimple<E> get(int index) {
|
||||
if (cache.containsKey(index)){
|
||||
return cache.get(index);
|
||||
}else{
|
||||
PSimple<D> rv = create(index);
|
||||
PSimple<E> rv = create(index);
|
||||
cache.put(index, rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
private PSimple<D> create(int index){
|
||||
return new PSimple<D>(type, PathMetadata.forListAccess(this, index));
|
||||
private PSimple<E> create(int index){
|
||||
return new PSimple<E>(type, PathMetadata.forListAccess(this, index));
|
||||
}
|
||||
}
|
||||
@ -24,14 +24,14 @@ import com.mysema.query.util.NotEmpty;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> implements PCollection<D> {
|
||||
public class PEntityCollection<E> extends EEntity<java.util.Collection<E>> implements PCollection<E> {
|
||||
|
||||
private final PathMetadata<?> metadata;
|
||||
|
||||
protected final Class<D> elementType;
|
||||
protected final Class<E> elementType;
|
||||
|
||||
protected final String entityName;
|
||||
|
||||
@ -42,29 +42,29 @@ public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> imple
|
||||
private final Path<?> root;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PEntityCollection(Class<? super D> type, @NotEmpty String entityName, PathMetadata<?> metadata) {
|
||||
public PEntityCollection(Class<? super E> type, @NotEmpty String entityName, PathMetadata<?> metadata) {
|
||||
super((Class)Collection.class);
|
||||
this.elementType = (Class<D>) Assert.notNull(type,"type is null");
|
||||
this.elementType = (Class<E>) Assert.notNull(type,"type is null");
|
||||
this.metadata = Assert.notNull(metadata,"metadata is null");
|
||||
this.entityName = Assert.notNull(entityName,"entityName is null");
|
||||
this.root = metadata.getRoot() != null ? metadata.getRoot() : this;
|
||||
}
|
||||
|
||||
public PEntityCollection(Class<? super D> type, @NotEmpty String entityName, @NotEmpty String var) {
|
||||
public PEntityCollection(Class<? super E> type, @NotEmpty String entityName, @NotEmpty String var) {
|
||||
this(type, entityName, PathMetadata.forVariable(var));
|
||||
}
|
||||
|
||||
public PEntityCollection(Class<? super D> type, @NotEmpty String entityName, Path<?> parent, @NotEmpty String property) {
|
||||
public PEntityCollection(Class<? super E> type, @NotEmpty String entityName, Path<?> parent, @NotEmpty String property) {
|
||||
this(type, entityName, PathMetadata.forProperty(parent, property));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean contains(D child) {
|
||||
public EBoolean contains(E child) {
|
||||
return OBoolean.create(Ops.IN, ExprConst.create(child), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean contains(Expr<D> child) {
|
||||
public EBoolean contains(Expr<E> child) {
|
||||
return OBoolean.create(Ops.IN, child, this);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<D> getElementType() {
|
||||
public Class<E> getElementType() {
|
||||
return elementType;
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expr<Collection<D>> asExpr() {
|
||||
public Expr<Collection<E>> asExpr() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -15,22 +15,22 @@ import com.mysema.query.types.expr.Expr;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PEntityList<D, E extends PEntity<D>> extends PEntityCollection<D> implements PList<D> {
|
||||
public class PEntityList<E, Q extends PEntity<E>> extends PEntityCollection<E> implements PList<E> {
|
||||
|
||||
private final Class<E> queryType;
|
||||
private final Class<Q> queryType;
|
||||
|
||||
private final Map<Integer,E> cache = new HashMap<Integer,E>();
|
||||
private final Map<Integer,Q> cache = new HashMap<Integer,Q>();
|
||||
|
||||
public PEntityList(Class<? super D> elementType, Class<E> queryType, PathMetadata<?> metadata) {
|
||||
public PEntityList(Class<? super E> elementType, Class<Q> queryType, PathMetadata<?> metadata) {
|
||||
super(elementType, elementType.getSimpleName(), metadata);
|
||||
this.queryType = queryType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(Expr<Integer> index) {
|
||||
public Q get(Expr<Integer> index) {
|
||||
PathMetadata<Integer> md = PathMetadata.forListAccess(this, index);
|
||||
try {
|
||||
return queryType.getConstructor(PathMetadata.class).newInstance(md);
|
||||
@ -40,17 +40,17 @@ public class PEntityList<D, E extends PEntity<D>> extends PEntityCollection<D> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
public Q get(int index) {
|
||||
if (cache.containsKey(index)){
|
||||
return cache.get(index);
|
||||
}else{
|
||||
E rv = create(index);
|
||||
Q rv = create(index);
|
||||
cache.put(index, rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
private E create(int index){
|
||||
private Q create(int index){
|
||||
PathMetadata<Integer> md = PathMetadata.forListAccess(this, index);
|
||||
try {
|
||||
return queryType.getConstructor(PathMetadata.class).newInstance(md);
|
||||
|
||||
@ -12,9 +12,9 @@ import com.mysema.query.types.expr.EList;
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <D> component type
|
||||
* @param <E> component type
|
||||
* @see java.util.List
|
||||
*/
|
||||
public interface PList<D> extends PCollection<D>, EList<D> {
|
||||
public interface PList<E> extends PCollection<E>, EList<E> {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user