3,7 → 3,7 |
import java.util.*; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionUtils; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.HibernateUtil; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
274,24 → 274,61 |
public Collection listMailAliases(User editor) |
throws ModelException |
{ |
return listMailAliases(null, 0, 0, null, editor); |
} |
|
public Collection listMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
try { |
if(editor.isSuperuser()) |
return HibernateUtil.currentSession().find( |
if(editor.isSuperuser()) { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from MailAlias").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
|
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select a from MailAlias a left join fetch a.domain as d" |
+ " left join fetch a.owner"); |
else |
// FIXME: any problems for big lists or by pages? |
return CollectionUtils.addUnique( |
HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.domain as d" |
+ " left join fetch a.owner" |
+ " where d.owner=?", |
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } ), |
HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.domain as d" |
+ " left join fetch a.owner" |
+ " where a.owner=?", |
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } )); |
+ " left join fetch a.owner" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null); |
} |
else { |
if(info != null) { |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select a.id from mailaliases a" |
+ " where a.owner=?" |
+ " union" |
+ " select a.id from mailaliases a" |
+ " left join domains as d on a.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { editor.getId(), editor.getId() }); |
|
info.init(((Long)countlist.get(0)).intValue(), |
pageNumber, rowsPerPage); |
} |
|
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"(select {a.*}, {d.*}, {o.*}" |
+ " from mailaliases as a" |
+ " left join domains as d on a.domain = d.id" |
+ " left join users as o on a.owner = o.id" |
+ " where a.owner=?)" |
+ " union " |
+ "(select {a.*}, {d.*}, {o.*}" |
+ " from mailaliases as a" |
+ " left join domains as d on a.domain = d.id" |
+ " left join users as o on a.owner = o.id" |
+ " where d.owner=?)" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql), |
new String[] { "a", "d", "o" }, |
new Class[] { MailAlias.class, InetDomain.class, User.class }, |
new Object[] { editor, editor }, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }); |
} |
} |
catch(HibernateException ex) |
{ |
422,6 → 459,23 |
return cascade; |
} |
|
public static final Integer SORT_ADDRESS = new Integer(1); |
public static final Integer SORT_DOMAIN = new Integer(2); |
|
protected static Map sortKeys = new HashMap(); |
|
static { |
sortKeys.put(SORT_ADDRESS, "a.address"); |
sortKeys.put(SORT_DOMAIN, "d.name"); |
} |
|
protected static Map sortKeysSql = new HashMap(); |
|
static { |
sortKeysSql.put(SORT_ADDRESS, "address0_"); |
sortKeysSql.put(SORT_DOMAIN, "name1_"); |
} |
|
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator(); |
|
private static class AddressComparator |