// params
if(params!=null){
QueryPlanCache cache=data.getQueryPlanCache();
HQLQueryPlan plan = cache.getHQLQueryPlan(hql, false, java.util.Collections.EMPTY_MAP);
ParameterMetadata meta = plan.getParameterMetadata();
Type type;
Object obj;
// struct
if(CommonUtil.isStruct(params)) {
Struct sct=CommonUtil.toStruct(params);
Key[] keys = CommonUtil.keys(sct);
String name;
// fix case-senstive
Struct names=CommonUtil.createStruct();
if(meta!=null){
Iterator<String> it = meta.getNamedParameterNames().iterator();
while(it.hasNext()){
name=it.next();
names.setEL(name, name);
}
}
RefBoolean isArray=CommonUtil.createRefBoolean();
for(int i=0;i<keys.length;i++){
obj=sct.get(keys[i],null);
if(meta!=null){
name=(String) names.get(keys[i],null);
if(name==null) continue; // param not needed will be ignored
type = meta.getNamedParameterExpectedType(name);
obj=HibernateCaster.toSQL(type, obj,isArray);
if(isArray.toBooleanValue())
query.setParameterList(name, (Object[])obj,type);
else
query.setParameter(name, obj,type);
}
else
query.setParameter(keys[i].getString(), obj);
}
}
// array
else if(CommonUtil.isArray(params)){
Array arr=CommonUtil.toArray(params);
Iterator it = arr.valueIterator();
int index=0;
SQLItem item;
RefBoolean isArray=null;
while(it.hasNext()){
obj=it.next();
if(obj instanceof SQLItem) {
item=(SQLItem) obj;
obj=item.getValue();
//HibernateCaster.toHibernateType(item.getType(), null); MUST
//query.setParameter(index, item.getValue(),type);
}
if(meta!=null){
type = meta.getOrdinalParameterExpectedType(index+1);
obj=HibernateCaster.toSQL(type, obj,isArray);
// TOOD can the following be done somehow
//if(isArray.toBooleanValue())
// query.setParameterList(index, (Object[])obj,type);
//else
query.setParameter(index, obj,type);
}
else
query.setParameter(index, obj);
index++;
}
if(meta.getOrdinalParameterCount()>index)
throw ExceptionUtil.createException(this,null,"parameter array is to small ["+arr.size()+"], need ["+meta.getOrdinalParameterCount()+"] elements",null);
}
}