Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1021 → Rev 1022

/hostadmiral/trunk/src/ak/hostadmiral/util/HibernateUtil.java
188,8 → 188,8
}
}
 
public static List pageableList(int pageSize, int pageNumber,
String query, Class classToLoad, String[] returnAliases, Class[] returnClasses,
public static List pageableListSql(int pageSize, int pageNumber,
String query, String[] returnAliases, Class[] returnClasses,
Object[] values, Type[] types)
throws ModelException
{
207,7 → 207,7
hq.setMaxResults(pageSize);
}
 
return selectClassColumn(classToLoad, hq.list());
return selectFirstClassColumn(hq.list());
// FIXME: really no other way in Hibernate?
}
catch(HibernateException ex)
216,47 → 216,13
}
}
 
protected static List selectClassColumn(Class classToLoad, List list)
protected static List selectFirstClassColumn(List list)
throws ModelException
{
List res = new ArrayList();
 
if(list == null || list.size() == 0) return res;
 
Object o = list.get(0);
if(o == null)
throw new ModelException(
"First element in the list is null, cannot determine it type");
 
if(!(o instanceof Object[])) {
if(classToLoad.isInstance(o))
return list;
else
throw new ModelException("First element in the list is instance of "
+ o.getClass().getName() + ", which is not java.lang.Object[] or "
+ classToLoad.getName());
}
 
Object[] oa = (Object[])o;
int pos = -1;
 
for(int i = 0; i < oa.length; i++) {
if(classToLoad.isInstance(oa[i])) {
if(pos < 0)
pos = i;
else
throw new ModelException("First row of the list has several elements of type "
+ classToLoad.getName());
}
}
if(pos < 0) {
throw new ModelException("First row of the list has no elements of type "
+ classToLoad.getName());
}
 
for(Iterator i = list.iterator(); i.hasNext(); ) {
Object[] e = (Object[])i.next();
res.add(e[pos]);
res.add(((Object[])i.next())[0]);
}
 
return res;