Example usage for org.hibernate Criteria scroll

List of usage examples for org.hibernate Criteria scroll

Introduction

In this page you can find the example usage for org.hibernate Criteria scroll.

Prototype

public ScrollableResults scroll() throws HibernateException;

Source Link

Document

Get the results as an instance of ScrollableResults .

Usage

From source file:com.duroty.application.home.manager.HomeManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*  w ww.ja  v a2 s.  c o  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param idintChannel DOCUMENT ME!
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws HomeException DOCUMENT ME!
 */
public Vector getAllFeed(Session hsession, String repositoryName, int idintChannel) throws HomeException {
    Vector feeds = new Vector();

    try {
        FeedChannel channel = null;

        Users user = getUser(hsession, repositoryName);

        if (idintChannel == 0) {
            Criteria criteria = hsession.createCriteria(FeedChannel.class);
            criteria.add(Restrictions.eq("users", user));
            criteria.add(Restrictions.eq("fechName", "Main"));

            channel = (FeedChannel) criteria.uniqueResult();

            if (channel == null) {
                channel = new FeedChannel();
                channel.setFechName("Main");
                channel.setUsers(user);

                hsession.saveOrUpdate(channel);
                hsession.flush();
            }
        } else {
            Criteria criteria = hsession.createCriteria(FeedChannel.class);
            criteria.add(Restrictions.eq("users", user));
            criteria.add(Restrictions.eq("fechIdint", new Integer(idintChannel)));

            channel = (FeedChannel) criteria.uniqueResult();
        }

        Criteria crit = hsession.createCriteria(FeedData.class);
        crit.add(Restrictions.eq("feedChannel", channel));
        crit.addOrder(Order.asc("fedaName"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            FeedData feed = (FeedData) scroll.get(0);
            feeds.addElement(feed.getFedaValue());
        }

        return feeds;
    } catch (Exception e) {
        throw new HomeException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from   w w  w .  ja  v  a 2  s. c  o  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Vector getLabels(Session hsession, String repositoryName) throws MailException {
    Vector labels = new Vector();

    try {
        Criteria criteria = hsession.createCriteria(Label.class);
        criteria.add(Restrictions.eq("users", getUser(hsession, repositoryName)));
        criteria.addOrder(Order.asc("labName"));

        ScrollableResults scroll = criteria.scroll();

        while (scroll.next()) {
            Label label = (Label) scroll.get(0);

            LabelObj obj = new LabelObj(label.getLabIdint(), label.getLabName());

            labels.addElement(obj);
        }

        return labels;
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!//w w w .  j  a  v a  2 s. c om
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Vector getContactList(Session hsession, String repositoryName) throws MailException {
    Vector lists = new Vector();

    try {
        Criteria criteria = hsession.createCriteria(ContactList.class);
        criteria.add(Restrictions.eq("users", getUser(hsession, repositoryName)));
        criteria.addOrder(Order.asc("coliName"));

        ScrollableResults scroll = criteria.scroll();

        while (scroll.next()) {
            ContactList contactList = (ContactList) scroll.get(0);

            ContactListObj obj = new ContactListObj(contactList.getColiIdint(), contactList.getColiName());

            lists.addElement(obj);
        }

        return lists;
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from w w w .  ja  v a 2s  .co  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void applyLabel(Session hsession, String repositoryName, Integer label, String[] mids)
        throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        if ((label == null) || (label.intValue() <= 0)) {
            return;
        }

        Users user = getUser(hsession, repositoryName);

        Criteria crit = hsession.createCriteria(Label.class);
        crit.add(Restrictions.eq("labIdint", label));
        crit.add(Restrictions.eq("users", user));

        Label hlabel = (Label) crit.uniqueResult();

        crit = hsession.createCriteria(Message.class);
        crit.add(Restrictions.in("mesName", mids));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            LabMes labMes = new LabMes(new LabMesId(message, hlabel));
            hsession.saveOrUpdate(labMes);
            hsession.flush();
        }

        hsession.flush();
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*www  . ja v a2  s. com*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param folderName DOCUMENT ME!
 * @param page DOCUMENT ME!
 * @param messagesByPage DOCUMENT ME!
 * @param order DOCUMENT ME!
 * @param orderType DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Vector getMessages(Session hsession, String repositoryName, String folderName, int page,
        int messagesByPage, int order, String orderType) throws MailException {
    Vector messages = new Vector();

    try {
        Users user = getUser(hsession, repositoryName);
        Locale locale = new Locale(user.getUseLanguage());
        TimeZone timeZone = TimeZone.getDefault();

        Date now = new Date();
        Calendar calendar = Calendar.getInstance(timeZone, locale);
        calendar.setTime(now);

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale);
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale);
        SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale);

        Criteria crit = hsession.createCriteria(Message.class);
        crit.add(Restrictions.eq("users", user));

        if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) {
            crit.add(Restrictions.not(Restrictions.in("mesBox",
                    new String[] { this.folderTrash, this.folderSpam, this.folderChat, FOLDER_DELETE })));
        } else if (folderName.equals(this.folderImportant)) {
            crit.add(Restrictions.eq("mesFlagged", new Boolean(true)));
        } else {
            crit.add(Restrictions.eq("mesBox", folderName));
        }

        switch (order) {
        case ORDER_BY_IMPORTANT:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesFlagged"));
            } else {
                crit.addOrder(Order.desc("mesFlagged"));
            }

            break;

        case ORDER_BY_ADDRESS:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesFrom"));
            } else {
                crit.addOrder(Order.desc("mesFrom"));
            }

            break;

        case ORDER_BY_SIZE:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesSize"));
            } else {
                crit.addOrder(Order.desc("mesSize"));
            }

            break;

        case ORDER_BY_SUBJECT:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesSubject"));
            } else {
                crit.addOrder(Order.desc("mesSubject"));
            }

            break;

        case ORDER_BY_DATE:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesDate"));
            } else {
                crit.addOrder(Order.desc("mesDate"));
            }

            break;

        case ORDER_BY_UNREAD:

            if (orderType.equals("ASC")) {
                crit.addOrder(Order.asc("mesRecent"));
            } else {
                crit.addOrder(Order.desc("mesRecent"));
            }

            break;

        default:
            crit.addOrder(Order.desc("mesDate"));

            break;
        }

        crit.setFirstResult(page * messagesByPage);
        crit.setMaxResults(messagesByPage);

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            MessageObj obj = new MessageObj(message.getMesName());

            obj.setBox(message.getMesBox());

            obj.setFrom(message.getMesFrom());

            if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) {
                obj.setHasAttachment(true);
            } else {
                obj.setHasAttachment(false);
            }

            int size = message.getMesSize();
            size /= 1024;

            if (size > 1024) {
                size /= 1024;
                obj.setSize(size + " MB");
            } else {
                obj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
            }

            if (message.getMesBox().equals(folderSent)) {
                try {
                    obj.setEmail(message.getMesTo());
                } catch (Exception e) {
                    obj.setEmail("unknown to");
                }
            } else {
                obj.setEmail(message.getMesFrom());
            }

            Date date = message.getMesDate();

            if (date != null) {
                Calendar calendar2 = Calendar.getInstance(timeZone, locale);
                calendar2.setTime(date);

                if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR))
                        && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH))
                        && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) {
                    obj.setDateStr(formatter2.format(calendar2.getTime()));
                } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
                    obj.setDateStr(formatter1.format(calendar2.getTime()));
                } else {
                    obj.setDateStr(formatter3.format(calendar2.getTime()));
                }
            }

            obj.setDate(date);

            if (message.getLabMeses() != null) {
                Iterator it = message.getLabMeses().iterator();
                StringBuffer label = new StringBuffer();

                while (it.hasNext()) {
                    if (label.length() > 0) {
                        label.append(", ");
                    }

                    LabMes labMes = (LabMes) it.next();
                    label.append(labMes.getId().getLabel().getLabName());
                }

                obj.setLabel(label.toString());
            }

            try {
                if (StringUtils.isBlank(message.getMesSubject())) {
                    obj.setSubject("(no subject)");
                } else {
                    obj.setSubject(message.getMesSubject());
                }
            } catch (Exception ex) {
                obj.setSubject("(no subject)");
            }

            if (message.isMesFlagged()) {
                obj.setFlagged(true);
            } else {
                obj.setFlagged(false);
            }

            if (message.isMesRecent()) {
                obj.setRecent(true);
            } else {
                obj.setRecent(false);
            }

            String priority = "normal";

            if (MessageUtilities.isHighPriority(message.getMesHeaders())) {
                priority = "high";
            } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) {
                priority = "low";
            }

            obj.setPriority(priority);

            messages.addElement(obj);
        }

        return messages;
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!// www . j a  va2  s. c  om
 *
 * @param hsession DOCUMENT ME!
 * @param user DOCUMENT ME!
 * @param mid DOCUMENT ME!
 * @param midReferences DOCUMENT ME!
 * @param date DOCUMENT ME!
 * @param beforeSent DOCUMENT ME!
 * @param isHtml DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private Vector readReference(Session hsession, Users user, String mid, String midReferences, Date date1,
        boolean beforeSent, boolean isHtml, boolean displayImages) {
    Vector references = new Vector();
    ByteArrayOutputStream baos = null;

    try {
        Locale locale = new Locale(user.getUseLanguage());
        TimeZone timeZone = TimeZone.getDefault();

        Date now = new Date();
        Calendar calendar = Calendar.getInstance(timeZone, locale);
        calendar.setTime(now);

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale);
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale);
        SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale);

        Criteria crit = hsession.createCriteria(Message.class);
        crit.add(Restrictions.not(Restrictions.eq("mesName", mid)));
        crit.add(Restrictions.eq("mesReferences", midReferences));
        crit.add(Restrictions.eq("users", user));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", this.folderSpam)));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", this.folderTrash)));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", FOLDER_DELETE)));

        if (beforeSent) {
            crit.add(Restrictions.le("mesDate", date1));
        } else {
            crit.add(Restrictions.gt("mesDate", date1));
        }

        crit.addOrder(Order.asc("mesDate"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            message.setMesRecent(false);
            hsession.update(message);
            hsession.flush();

            MessageObj obj = new MessageObj(message.getMesName());

            obj.setBox(message.getMesBox());

            obj.setFrom(message.getMesFrom());
            obj.setTo(message.getMesTo());
            obj.setReplyTo(message.getMesReplyTo());
            obj.setCc(message.getMesCc());

            if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) {
                obj.setHasAttachment(true);

                Set set = message.getAttachments();
                Iterator it = set.iterator();
                Vector attachments = new Vector();

                while (it.hasNext()) {
                    Attachment attachment = (Attachment) it.next();
                    AttachmentObj attachmentObj = new AttachmentObj();
                    attachmentObj.setIdint(attachment.getAttPart());
                    attachmentObj.setName(attachment.getAttName());

                    int size = attachment.getAttSize();
                    size /= 1024;

                    if (size > 1024) {
                        size /= 1024;
                        attachmentObj.setSize(size + " MB");
                    } else {
                        attachmentObj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
                    }

                    String extension = (String) this.extensions.get(attachment.getAttContentType());

                    if (StringUtils.isBlank(extension)) {
                        extension = "generic";
                    }

                    attachmentObj.setExtension(extension);

                    attachmentObj.setContentType(attachment.getAttContentType());
                    attachments.addElement(attachmentObj);
                    obj.setAttachments(attachments);
                }
            } else {
                obj.setHasAttachment(false);
            }

            int size = message.getMesSize();
            size /= 1024;

            if (size > 1024) {
                size /= 1024;
                obj.setSize(size + " MB");
            } else {
                obj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
            }

            if (message.getMesBox().equals(folderSent)) {
                try {
                    obj.setEmail(message.getMesTo());
                } catch (Exception e) {
                    obj.setEmail("unknown to");
                }
            } else {
                obj.setEmail(message.getMesFrom());
            }

            Date date = message.getMesDate();

            if (date != null) {
                Calendar calendar2 = Calendar.getInstance(timeZone, locale);
                calendar2.setTime(date);

                if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR))
                        && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH))
                        && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) {
                    obj.setDateStr(formatter2.format(calendar2.getTime()));
                } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
                    obj.setDateStr(formatter1.format(calendar2.getTime()));
                } else {
                    obj.setDateStr(formatter3.format(calendar2.getTime()));
                }
            }

            obj.setDate(date);

            if (message.getLabMeses() != null) {
                Iterator it = message.getLabMeses().iterator();
                StringBuffer label = new StringBuffer();

                while (it.hasNext()) {
                    if (label.length() > 0) {
                        label.append(", ");
                    }

                    LabMes labMes = (LabMes) it.next();
                    label.append(labMes.getId().getLabel().getLabName());
                }

                obj.setLabel(label.toString());
            }

            try {
                if (StringUtils.isBlank(message.getMesSubject())) {
                    obj.setSubject("(no subject)");
                } else {
                    obj.setSubject(message.getMesSubject());
                }
            } catch (Exception ex) {
                obj.setSubject("(no subject)");
            }

            if (message.isMesFlagged()) {
                obj.setFlagged(true);
            } else {
                obj.setFlagged(false);
            }

            if (message.isMesRecent()) {
                obj.setRecent(true);
            } else {
                obj.setRecent(false);
            }

            String priority = "normal";

            if (MessageUtilities.isHighPriority(message.getMesHeaders())) {
                priority = "high";
            } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) {
                priority = "low";
            }

            obj.setPriority(priority);

            String body = message.getMesBody();

            if (!StringUtils.isBlank(body)) {
                obj.setBody(bodyCleaner(body, displayImages));
            } else {
                obj.setBody("");
            }

            references.addElement(obj);
        }

        scroll.close();
    } catch (Exception ex) {
        return null;
    } finally {
        IOUtils.closeQuietly(baos);
    }

    if (references.size() <= 0) {
        return null;
    }

    return references;
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from   w w w.jav a2 s  . c  om
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 * @param folder DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void moveMessages(Session hsession, String repositoryName, String[] mids, String folder)
        throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        folder = parseFolder(folder);

        if (folder.equals(this.folderAll)) {
            folder = this.folderHidden;
        }

        Criteria crit = hsession.createCriteria(Message.class);
        crit.add(Restrictions.in("mesName", mids));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            message.setMesBox(folder);

            hsession.update(message);
            hsession.flush();
        }
    } catch (Exception ex) {
        throw new MailException(ex);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.PreferencesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from   w  ww .j  a  v  a  2s .  c  om*/
 *
 * @param hsession DOCUMENT ME!
 * @param username DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Vector getIdentities(Session hsession, String username) throws MailException {
    Vector identities = new Vector();

    try {
        Criteria crit = hsession.createCriteria(Identity.class);
        crit.add(Restrictions.eq("users", getUser(hsession, username)));
        crit.add(Restrictions.eq("ideActive", new Boolean(true)));
        crit.addOrder(Order.asc("ideEmail"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Identity identity = (Identity) scroll.get(0);
            IdentityObj obj = new IdentityObj();
            obj.setIdint(identity.getIdeIdint());
            obj.setEmail(identity.getIdeEmail());
            obj.setImportant(identity.isIdeDefault());
            obj.setName(identity.getIdeName());
            obj.setReplyTo(identity.getIdeReplyTo());

            identities.addElement(obj);
        }

        return identities;
    } catch (Exception ex) {
        return null;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.PreferencesManager.java

License:Open Source License

/**
 * DOCUMENT ME!// w ww.  j  a  va 2  s  .com
 *
 * @param hsession DOCUMENT ME!
 * @param token DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws ManagerException DOCUMENT ME!
 */
public SearchContactsObj searchContacts(Session hsession, String repositoryName, String token, int page,
        int byPage, int order, String extra) throws Exception {
    SearchContactsObj sobj = new SearchContactsObj();
    Vector contacts = new Vector();

    try {
        Criteria crit = hsession.createCriteria(Contact.class);
        crit.add(Restrictions.or(Restrictions.ilike("conName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("conEmail", token, MatchMode.ANYWHERE)));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));
        crit.add(Restrictions.isNotNull("conSentDate"));
        crit.add(Restrictions.isNotNull("conReceivedDate"));

        int hits = crit.list().size();

        sobj.setHits(hits);

        crit = hsession.createCriteria(Contact.class);
        crit.add(Restrictions.or(Restrictions.ilike("conName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("conEmail", token, MatchMode.ANYWHERE)));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));
        crit.add(Restrictions.isNotNull("conSentDate"));
        crit.add(Restrictions.isNotNull("conReceivedDate"));

        switch (order) {
        case ORDER_BY_EMAIL:
            crit.addOrder(Order.asc("conEmail"));

            break;

        case ORDER_BY_FREQUENCY_SENT:
            crit.addOrder(Order.asc("conSentDate"));

            break;

        case ORDER_BY_FREQUENCY_RECEIVED:
            crit.addOrder(Order.asc("conReceivedDate"));

            break;

        default:
            crit.addOrder(Order.asc("conSentDate"));

            break;
        }

        if (byPage > 0) {
            crit.setFirstResult(page * byPage);
            crit.setMaxResults(byPage);
        }

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Contact contact = (Contact) scroll.get(0);

            ContactObj obj = new ContactObj();
            obj.setIdint(contact.getConIdint());
            obj.setName(contact.getConName());
            obj.setEmail(contact.getConEmail());

            if (!StringUtils.isBlank(contact.getConDescription())) {
                obj.setDescription(contact.getConDescription().replaceAll("\n", "\\\\n")
                        .replaceAll("\r", "\\\\r").replaceAll("'", "''"));
            }

            contacts.addElement(obj);
        }

        sobj.setContacts(contacts);

        return sobj;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.PreferencesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from  w  ww  .  j  av a 2s  . c  om*/
 *
 * @param hsession DOCUMENT ME!
 * @param token DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws ManagerException DOCUMENT ME!
 */
public SearchGroupsObj searchGroups(Session hsession, String repositoryName, String token, int page, int byPage,
        int order, String extra) throws Exception {
    SearchGroupsObj sobj = new SearchGroupsObj();
    Vector groups = new Vector();

    try {
        Criteria crit = hsession.createCriteria(ContactList.class);
        crit.add(Restrictions.or(Restrictions.ilike("coliName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("coliName", token, MatchMode.ANYWHERE)));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));

        int hits = crit.list().size();

        sobj.setHits(hits);

        crit = hsession.createCriteria(ContactList.class);
        crit.add(Restrictions.or(Restrictions.ilike("coliName", token, MatchMode.ANYWHERE),
                Restrictions.ilike("coliName", token, MatchMode.ANYWHERE)));
        crit.add(Restrictions.eq("users", getUser(hsession, repositoryName)));
        crit.addOrder(Order.asc("coliName"));

        if (byPage > 0) {
            crit.setFirstResult(page * byPage);
            crit.setMaxResults(byPage);
        }

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            ContactList contactList = (ContactList) scroll.get(0);

            ContactListObj obj = new ContactListObj();
            obj.setIdint(contactList.getColiIdint());
            obj.setName(contactList.getColiName());

            Set set = contactList.getConColis();

            StringBuffer emails = new StringBuffer();

            if (set != null) {
                Iterator it = set.iterator();

                while (it.hasNext()) {
                    ConColi conColi = (ConColi) it.next();
                    Contact contact = conColi.getId().getContact();

                    if (emails.length() > 0) {
                        emails.append(", ");
                    }

                    String name = "";

                    if (!StringUtils.isBlank(contact.getConName())) {
                        name = contact.getConName() + " ";
                    }

                    emails.append(name + "<" + contact.getConEmail() + ">");
                }

                if (emails.length() > 0) {
                    obj.setEmails(emails.toString() + ", ");
                }
            }

            groups.addElement(obj);
        }

        sobj.setGroups(groups);

        return sobj;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}