Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1019 → Rev 1020

/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java
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;
283,28 → 283,40
public Collection listMailboxes(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner left join fetch mb.systemUser");
else
// FIXME: any problems for big lists or by pages?
return CollectionUtils.addUnique(
HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner left join fetch mb.systemUser"
+ " where mb.owner=?",
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } ),
HibernateUtil.currentSession().find(
" select mb from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner left join fetch mb.systemUser"
+ " where d.owner=?",
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } ));
return listMailboxes(null, 0, 0, null, editor);
}
 
public Collection listMailboxes(CollectionInfo info, int pageSize, int pageNumber,
Integer[] sortingKeys, User editor)
throws ModelException
{
if(editor.isSuperuser()) {
return HibernateUtil.pageableList(info, pageSize, pageNumber,
"select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner as o left join fetch mb.systemUser as su"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
new String[] { "mb", "d", "o", "su" },
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class },
null,
null);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
else {
return HibernateUtil.pageableList(info, pageSize, pageNumber,
"select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner as o left join fetch mb.systemUser as su"
+ " where mb.owner=?"
+ " union"
+ " select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " from Mailbox mb left join fetch mb.domain as d"
+ " left join fetch mb.owner as o left join fetch mb.systemUser as su"
+ " where d.owner=?"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
new String[] { "mb", "d", "o", "su" },
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class },
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) });
}
}
 
475,8 → 487,19
return cascade;
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
public static final Integer SORT_LOGIN = new Integer(1);
public static final Integer SORT_DOMAIN = new Integer(2);
 
protected static Map sortKeys = new HashMap();
 
static {
sortKeys.put(SORT_LOGIN, "mb.login");
sortKeys.put(SORT_DOMAIN, "d.name");
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
public static final Comparator DOMAIN_COMPARATOR = new DomainComparator();
 
private static class LoginComparator
implements Comparator
{
503,4 → 526,31
return (obj instanceof LoginComparator);
}
}
 
private static class DomainComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox))
throw new ClassCastException("not a Mailbox");
 
Mailbox a1 = (Mailbox)o1;
Mailbox a2 = (Mailbox)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getDomain().getName().compareToIgnoreCase(a2.getDomain().getName());
}
 
public boolean equals(Object obj)
{
return (obj instanceof DomainComparator);
}
}
}