Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

In this page you can find the example usage for org.hibernate Query setParameterList.

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

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

License:Open Source License

/**
 * DOCUMENT ME!/*w  ww  .ja v a 2s  .  c  om*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void deleteLabelsFromFiles(Session hsession, String repositoryName, String[] mids)
        throws FilesException {
    if ((mids == null) || (mids.length == 0)) {
        throw new FilesException("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 FilesException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

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

License:Open Source License

/**
 * DOCUMENT ME!// w w w.j a  va 2  s .  co m
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void applyLabel(Session hsession, String repositoryName, Integer label, Integer[] idints)
        throws FilesException {
    if ((idints == null) || (idints.length == 0)) {
        throw new FilesException("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();

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.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 FilesException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

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

License:Open Source License

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

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

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

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

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

            hsession.update(message);
            hsession.flush();
        }

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

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

License:Open Source License

/**
 * DOCUMENT ME!/* w w w . java  2s .co  m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param idints DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void deleteFiles(Session hsession, String repositoryName, Integer[] idints) throws FilesException {
    if ((idints == null) || (idints.length == 0)) {
        throw new FilesException("ErrorMessages.messages.selection.null");
    }

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

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

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

            message.setMesBox(this.folderTrash);

            hsession.update(message);
            hsession.flush();
        }

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

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

License:Open Source License

/**
 * DOCUMENT ME!// ww  w. j  a  v  a2  s  . c o m
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param idints DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void restoreFiles(Session hsession, String repositoryName, Integer[] idints) throws FilesException {
    if ((idints == null) || (idints.length == 0)) {
        throw new FilesException("ErrorMessages.messages.selection.null");
    }

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

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

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

            message.setMesBox(this.folderFiles);

            hsession.update(message);
            hsession.flush();
        }

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

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

License:Open Source License

/**
 * DOCUMENT ME!/*from   w w w. j a v  a  2s  .  co m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param folderName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public int getCountFiles(Session hsession, String repositoryName, String folderName, int label)
        throws FilesException {
    try {
        Query hquery = null;

        String[] folderNameList = new String[0];

        try {
            folderName = parseFolder(folderName);

            folderNameList = new String[] { folderName };

            if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) {
                folderNameList = new String[] { this.folderAll, this.folderDraft, this.folderHidden,
                        this.folderImportant, this.folderInbox, this.folderSent };
            }
        } catch (Exception ex) {
        }

        if ((folderNameList.length == 0) && (label <= 0)) {
            hquery = hsession.getNamedQuery("count-attachments");
            hquery.setParameterList("no_boxes",
                    new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE });
            hquery.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length > 0) && (label <= 0)) {
            hquery = hsession.getNamedQuery("count-attachments-by-folder");
            hquery.setParameterList("boxes", folderNameList);
            hquery.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length == 0) && (label > 0)) {
            hquery = hsession.getNamedQuery("count-attachments-by-label");
            hquery.setInteger("label", label);
            hquery.setParameterList("no_boxes",
                    new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE });
            hquery.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length > 0) && (label > 0)) {
            hquery = hsession.getNamedQuery("count-attachments-by-folder-label");
            hquery.setInteger("label", label);
            hquery.setParameterList("boxes", folderNameList);
            hquery.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        }

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

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

License:Open Source License

/**
* DOCUMENT ME!//  ww  w.ja v  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  ww  . jav  a2  s  .  c  o m*/
 *
 * @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 w  w  w .  j a  va2 s  .  co  m
 *
 * @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!// ww w  .j a v  a  2s  . c  o 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);
    }
}