Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(String name, int val) 

Source Link

Document

Bind a named int-valued parameter.

Usage

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

License:Open Source License

/**
 * DOCUMENT ME!/* ww  w .  java  2  s.c  o  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!/*from   ww  w.jav  a  2 s.  c  om*/
 *
 * @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  .ja v  a 2 s . c om*/
 *
 * @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.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from  w  w w. java 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  . ja va 2  s  . c  o  m
 *
 * @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.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from w w w.java2  s  .  c  o  m
 *
 * @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 .  jav a 2 s . co  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);
    }
}

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

License:Open Source License

/**
 * DOCUMENT ME!/*from  www .j a v a2  s.  co m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param label DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public int getCountMessages(Session hsession, String repositoryName, Label label) throws MailException {
    try {
        Query query = hsession.getNamedQuery("count-messages-by-label");
        query.setInteger("label", label.getLabIdint());
        query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        query.setString("folderSpam", this.folderSpam);
        query.setString("folderTrash", this.folderTrash);
        query.setString("folderDelete", FOLDER_DELETE);

        return ((Integer) query.uniqueResult()).intValue();
    } 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.j  av  a2s .  c om*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Counters getInfoCounters(Session hsession, String repositoryName) throws MailException {
    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.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!// www. j  a va2s  .c  o  m
 *
 * @param username DOCUMENT ME!
 * @param password DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws DMailException DOCUMENT ME!
 */
protected int getUsedQuotaSize(org.hibernate.Session hsession, Users user) throws MailException {
    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 {
    }
}