Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1027 → Rev 1028

/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainManager.java
3,6 → 3,7
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostadmiral.util.CollectionInfo;
import ak.hostadmiral.util.HibernateUtil;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;
266,14 → 267,39
public Collection listInetDomains(User editor)
throws ModelException
{
return listInetDomains(null, 0, 0, null, editor);
}
 
public Collection listInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber,
Integer[] sortingKeys, User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find(
"select d from InetDomain d left join fetch d.owner");
else
return HibernateUtil.currentSession().find(
"select d from InetDomain d where d.owner=?",
editor, Hibernate.entity(User.class));
if(editor.isSuperuser()) {
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from InetDomain").next()).intValue(),
pageNumber, rowsPerPage);
}
 
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select d from InetDomain d left join fetch d.owner"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null);
}
else {
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from InetDomain where d.owner=?",
editor, Hibernate.entity(User.class)).next()).intValue(),
pageNumber, rowsPerPage);
}
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select d from InetDomain d where d.owner=?"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } );
}
}
catch(HibernateException ex)
{
352,6 → 378,14
}
}
 
public static final Integer SORT_NAME = new Integer(1);
 
protected static Map sortKeys = new HashMap();
 
static {
sortKeys.put(SORT_NAME, "d.name");
}
 
public static final Comparator NAME_COMPARATOR = new NameComparator();
 
private static class NameComparator
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java
304,7 → 304,7
+ " left join domains as d on mb.domain = d.id"
+ " left join users as o on mb.owner = o.id"
+ " left join systemusers as su on mb.systemUser = su.id"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql),
new String[] { "mb", "d", "o", "su" },
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class },
null,
328,20 → 328,20
}
 
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber,
"select {mb.*}, {d.*}, {o.*}, {su.*}"
"(select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " from mailboxes as mb"
+ " left join domains as d on mb.domain = d.id"
+ " left join users as o on mb.owner = o.id"
+ " left join systemusers as su on mb.systemUser = su.id"
+ " where mb.owner=?"
+ " union"
+ " select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " where mb.owner=?)"
+ " union "
+ "(select {mb.*}, {d.*}, {o.*}, {su.*}"
+ " from mailboxes as mb"
+ " left join domains as d on mb.domain = d.id"
+ " left join users as o on mb.owner = o.id"
+ " left join systemusers as su on mb.systemUser = su.id"
+ " where d.owner=?"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
+ " where d.owner=?)"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql),
new String[] { "mb", "d", "o", "su" },
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class },
new Object[] { editor, editor },
526,11 → 526,11
public static final Integer SORT_LOGIN = new Integer(1);
public static final Integer SORT_DOMAIN = new Integer(2);
 
protected static Map sortKeys = new HashMap();
protected static Map sortKeysSql = new HashMap();
 
static {
sortKeys.put(SORT_LOGIN, "login0_");
sortKeys.put(SORT_DOMAIN, "name1_");
sortKeysSql.put(SORT_LOGIN, "login0_");
sortKeysSql.put(SORT_DOMAIN, "name1_");
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserManager.java
3,6 → 3,7
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostadmiral.util.CollectionInfo;
import ak.hostadmiral.util.HibernateUtil;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;
304,15 → 305,39
public Collection listSystemUsers(User editor)
throws ModelException
{
return listSystemUsers(null, 0, 0, null, editor);
}
 
public Collection listSystemUsers(CollectionInfo info, int rowsPerPage, int pageNumber,
Integer[] sortingKeys, User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find(
"select u from SystemUser u left join fetch u.owner");
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from SystemUser").next()).intValue(),
pageNumber, rowsPerPage);
}
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select u from SystemUser u left join fetch u.owner"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null);
}
else {
return HibernateUtil.currentSession().find(
"select u from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class));
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from SystemUser where owner is null or owner = ?",
editor, Hibernate.entity(User.class))
.next()).intValue(),
pageNumber, rowsPerPage);
}
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select u from SystemUser u left join u.owner o"
+ " where u.owner is null or u.owner = ?"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
new Object[] { editor }, new Type[] { Hibernate.entity(User.class) } );
}
}
catch(HibernateException ex)
392,6 → 417,16
}
}
 
public static final Integer SORT_UID = new Integer(1);
public static final Integer SORT_NAME = new Integer(2);
 
protected static Map sortKeys = new HashMap();
 
static {
sortKeys.put(SORT_UID, "u.uid");
sortKeys.put(SORT_NAME, "u.name");
}
 
public static final Comparator UID_COMPARATOR = new UidComparator();
public static final Comparator NAME_COMPARATOR = new NameComparator();
 
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasManager.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;
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
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java
3,6 → 3,7
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostadmiral.util.CollectionInfo;
import ak.hostadmiral.util.HibernateUtil;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;
286,14 → 287,38
public Collection listUsers(User editor)
throws ModelException
{
return listUsers(null, 0, 0, null, editor);
}
 
public Collection listUsers(CollectionInfo info, int rowsPerPage, int pageNumber,
Integer[] sortingKeys, User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find(
"select u from User u left join fetch u.boss");
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from User").next()).intValue(),
pageNumber, rowsPerPage);
}
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select u from User u left join fetch u.boss"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null);
}
else {
return HibernateUtil.currentSession().find(
"select u from User u where u = ? or u.boss = ?",
if(info != null) {
info.init(((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from User u where u = ? or u.boss = ?",
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }
).next()).intValue(),
pageNumber, rowsPerPage);
}
 
return HibernateUtil.pageableList(rowsPerPage, pageNumber,
"select u from User u left join fetch u.boss where u = ? or u.boss = ?"
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys),
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
419,6 → 444,14
}
}
 
public static final Integer SORT_LOGIN = new Integer(1);
 
protected static Map sortKeys = new HashMap();
 
static {
sortKeys.put(SORT_LOGIN, "u.login");
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
public static final Comparator LOGINS_TIME_COMPARATOR = new LoginsTimeComparator();