Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

From source file:com.duroty.application.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from   w w w .j  av  a 2 s. co  m
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public Counters getInfoCounters(Session hsession, String repositoryName) throws FilesException {
    Counters counters = new Counters();

    try {
        Users user = getUser(hsession, repositoryName);

        Query query = hsession.getNamedQuery("count-new-messages-by-folder");
        query.setString("folder", this.folderInbox);
        query.setInteger("user", user.getUseIdint());
        counters.setInbox(((Integer) query.uniqueResult()).intValue());

        query = hsession.getNamedQuery("count-new-messages-by-folder");
        query.setString("folder", this.folderSpam);
        query.setInteger("user", user.getUseIdint());
        counters.setSpam(((Integer) query.uniqueResult()).intValue());

        query = hsession.getNamedQuery("group-count-new-messages-by-label");
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

        while (scroll.next()) {
            Integer idint = (Integer) scroll.get(0);
            Integer count = (Integer) scroll.get(1);

            counters.addLabel(idint.intValue(), count.intValue());
        }

        counters.setQuota(getQuotaLayer(hsession, user));
    } catch (Exception ex) {
        return null;
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }

    return counters;
}

From source file:com.duroty.application.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from w w  w .  j av a 2 s  .  com*/
 *
 * @param username DOCUMENT ME!
 * @param password DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws DFilesException DOCUMENT ME!
 */
protected int getUsedQuotaSize(org.hibernate.Session hsession, Users user) throws FilesException {
    try {
        Query query = hsession.getNamedQuery("used-quota-size");
        query.setInteger("user", new Integer(user.getUseIdint()));

        Integer value = (Integer) query.uniqueResult();

        int uqs = value.intValue();
        int pc = ((uqs * 25) / 100);

        return uqs + pc;
    } catch (Exception ex) {
        return 0;
    } finally {
    }
}

From source file:com.duroty.application.files.manager.SearchManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from   w ww. j  a v a 2s  .c  o  m
 *
 * @param username DOCUMENT ME!
 * @param password DOCUMENT ME!
 * @param label DOCUMENT ME!
 * @param box DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
private ChainedFilter getChainedFilter(Session hsession, String username, int label) throws Exception {
    ChainedFilter filter = null;

    try {
        Users user = getUser(hsession, username);

        org.hibernate.Query query1 = null;
        org.hibernate.Query query2 = null;

        query1 = hsession.getNamedQuery("count-messages-by-label");
        query1.setInteger("label", label);
        query1.setInteger("user", user.getUseIdint());
        query1.setString("folderTrash", this.folderTrash);
        query1.setString("folderSpam", this.folderSpam);
        query1.setString("folderDelete", FOLDER_DELETE);

        query2 = hsession.getNamedQuery("messages-by-label");
        query2.setInteger("label", label);
        query2.setInteger("user", user.getUseIdint());
        query2.setString("folderTrash", this.folderTrash);
        query2.setString("folderSpam", this.folderSpam);
        query2.setString("folderDelete", FOLDER_DELETE);

        Integer count = (Integer) query1.uniqueResult();

        if (count.intValue() > 0) {
            QueryFilter[] qFilters = new QueryFilter[count.intValue()];

            ScrollableResults scroll = query2.scroll();

            int i = 0;

            while (scroll.next()) {
                Message message = (Message) scroll.get(0);
                qFilters[i] = new QueryFilter(
                        new TermQuery(new Term(LuceneMessageConstants.Field_idint, message.getMesName())));
                i++;
            }

            filter = new ChainedFilter(qFilters);
        } else {
            QueryFilter[] qFilters = new QueryFilter[0];
            filter = new ChainedFilter(qFilters);
        }

        return filter;
    } finally {
    }
}

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

License:Open Source License

/**
* DOCUMENT ME!//w ww.  j av a 2 s . c o  m
*
* @param hsession DOCUMENT ME!
* @param repositoryName DOCUMENT ME!
* @param mids DOCUMENT ME!
*
* @throws MailException DOCUMENT ME!
*/
public void archiveMessages(Session hsession, String repositoryName, String[] mids) throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        Query query = hsession.getNamedQuery("archive-messages-by-mid");
        query.setString("hidden", this.folderHidden);
        query.setParameterList("mids", mids);
        query.setString("username", repositoryName);

        query.executeUpdate();

        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!/*from  w w w  .ja  v a2  s  .  c om*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void deleteLabelsFromMessages(Session hsession, String repositoryName, String[] mids)
        throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        Query query = hsession.getNamedQuery("delete-labels-by-mid");
        query.setParameterList("mids", mids);
        query.setString("username", repositoryName);

        query.executeUpdate();

        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!//from  ww w.  j av a 2 s  .c  om
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param folderName DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void deleteMessagesInFolder(Session hsession, String repositoryName, String folderName)
        throws MailException {
    try {
        folderName = parseFolder(folderName);
    } catch (Exception ex) {
        return;
    }

    String newFolder = this.folderTrash;

    if ((folderName != null) && (folderName.equals(this.folderTrash) || folderName.equals(this.folderSpam))) {
        newFolder = FOLDER_DELETE;
    }

    try {
        String[] boxes = null;

        if (folderName.equals(this.folderHidden)) {
            boxes = new String[] { this.folderBlog, this.folderChat, this.folderHidden, this.folderInbox,
                    this.folderSent, this.folderDraft };
        } else {
            boxes = new String[] { folderName };
        }

        Query query = hsession.getNamedQuery("delete-messages-by-folder");
        query.setString("trash", newFolder);
        query.setParameterList("box", boxes);
        query.setString("username", repositoryName);

        query.executeUpdate();

        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!/*from w  w  w .  j  av a  2s. com*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param label DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void deleteMessagesInLabel(Session hsession, String repositoryName, Integer label) throws MailException {
    try {
        Query query = hsession.getNamedQuery("delete-messages-by-label");
        query.setString("trash", this.folderTrash);
        query.setInteger("label", label.intValue());
        query.setString("username", repositoryName);

        query.executeUpdate();

        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!/*from   w ww.  ja v a 2  s  .co  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void deleteMessages(Session hsession, String repositoryName, String[] mids, String folderName)
        throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        folderName = parseFolder(folderName);
    } catch (Exception ex) {
    }

    String newFolder = this.folderTrash;

    if ((folderName != null) && (folderName.equals(this.folderTrash) || folderName.equals(this.folderSpam))) {
        newFolder = FOLDER_DELETE;
    }

    try {
        Query query = hsession.getNamedQuery("delete-messages-by-mid");
        query.setString("trash", newFolder);
        query.setParameterList("mids", mids);
        query.setString("username", repositoryName);

        query.executeUpdate();

        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  a 2 s. c om
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 * @param flag DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public void flagMessages(Session hsession, String repositoryName, String[] mids, String flag)
        throws MailException {
    if ((mids == null) || (mids.length == 0)) {
        throw new MailException("ErrorMessages.messages.selection.null");
    }

    try {
        Query query = null;

        if (flag.equals("RECENT")) {
            query = hsession.getNamedQuery("recent-messages-by-mid");
        } else if (flag.equals("FLAGGED")) {
            query = hsession.getNamedQuery("flagged-messages-by-mid");
        }

        query.setParameterList("mids", mids);
        query.setString("username", repositoryName);

        query.executeUpdate();

        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!/*ww w . j a va 2  s.c  o m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param folderName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public int getCountMessages(Session hsession, String repositoryName, String folderName) throws MailException {
    try {
        folderName = parseFolder(folderName);

        Query query = null;

        if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) {
            query = hsession.getNamedQuery("count-all-total-messages");
            query.setString("folderSpam", this.folderSpam);
            query.setString("folderTrash", this.folderTrash);
            query.setString("folderDelete", FOLDER_DELETE);
            query.setString("folderChat", this.folderChat);
        } else {
            query = hsession.getNamedQuery("count-messages-by-folder");
            query.setString("folder", folderName);
        }

        query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());

        return ((Integer) query.uniqueResult()).intValue();
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}