mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-24 21:07:26 +08:00
added reflection based FactoryMap implementation
This commit is contained in:
parent
1274c8b0b4
commit
75fe6532e0
@ -11,6 +11,8 @@ import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
import com.mysema.query.grammar.types.PathMetadata;
|
||||
import com.mysema.query.grammar.types.Path.PSimple;
|
||||
import com.mysema.query.util.FactoryMap;
|
||||
|
||||
/**
|
||||
* AliasFactory provides
|
||||
@ -29,6 +31,20 @@ public class AliasFactory {
|
||||
|
||||
private final ThreadLocal<Expr<?>> current = new ThreadLocal<Expr<?>>();
|
||||
|
||||
// caches top level paths (class/var as key)
|
||||
private FactoryMap<PSimple<?>> pathCache = new FactoryMap<PSimple<?>>(){
|
||||
public <A> PSimple<A> create(Class<A> cl, String var){
|
||||
return new Path.PSimple<A>(cl, PathMetadata.forVariable(var));
|
||||
}
|
||||
};
|
||||
|
||||
// cahces top level proxies (class/var as key)
|
||||
private FactoryMap<Object> proxyCache = new FactoryMap<Object>(){
|
||||
public <A> Object create(Class<A> cl, String var){
|
||||
return createProxy(cl);
|
||||
}
|
||||
};
|
||||
|
||||
public <A> A createAliasForProp(Class<A> cl, Object parent, Expr<?> path){
|
||||
A proxy = createProxy(cl);
|
||||
if (!cl.getPackage().getName().equals("java.lang")){
|
||||
@ -36,11 +52,11 @@ public class AliasFactory {
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <A> A createAliasForVar(Class<A> cl, String var){
|
||||
// TODO : cache cl, var pairs
|
||||
Expr<?> path = new Path.PSimple<A>(cl, PathMetadata.forVariable(var));
|
||||
A proxy = createProxy(cl);
|
||||
Expr<?> path = pathCache.get(cl,var);
|
||||
A proxy = (A) proxyCache.get(cl, var);
|
||||
bindings.get().put(proxy, path);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user