List of usage examples for org.hibernate ScrollableResults next
boolean next();
From source file:com.duroty.application.mail.manager.MailManager.java
License:Open Source License
/** * DOCUMENT ME!//from w w w . j a va 2 s. co m * * @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!/* w w w. j av a2 s . 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 w w.j a v a 2 s.c om*/ * * @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 w w . ja v a2 s .c o m * * @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); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!/*from ww w .ja v a 2 s. com*/ * * @param hsession DOCUMENT ME! * @param token DOCUMENT ME! * * @return DOCUMENT ME! * * @throws ManagerException DOCUMENT ME! */ public Vector suggestContacts(Session hsession, String repositoryName, String token) throws Exception { Vector contacts = new Vector(); try { Criteria crit = hsession.createCriteria(ContactList.class); crit.add(Restrictions.ilike("coliName", token, MatchMode.ANYWHERE)); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); crit.addOrder(Order.asc("coliName")); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { ContactList contactList = (ContactList) scroll.get(0); ContactObj obj = new ContactObj(); obj.setIdint(contactList.getColiIdint()); obj.setName(contactList.getColiName()); obj.setEmail("GROUP"); contacts.addElement(obj); } crit = hsession.createCriteria(Contact.class); crit.add(Restrictions.or(Restrictions.ilike("conName", token, MatchMode.ANYWHERE), Restrictions.ilike("conEmail", token, MatchMode.ANYWHERE))); crit.add(Restrictions.isNotNull("conSentDate")); crit.add(Restrictions.isNotNull("conReceivedDate")); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); crit.addOrder(Order.desc("conCount")); 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()); contacts.addElement(obj); } return contacts; } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!//from ww w. j a v a 2s. com * * @param hsession DOCUMENT ME! * @param token DOCUMENT ME! * * @return DOCUMENT ME! * * @throws ManagerException DOCUMENT ME! */ public SearchContactsObj getContacts(Session hsession, String repositoryName, int page, int byPage, int order, String extra) throws Exception { Vector contacts = new Vector(); SearchContactsObj sobj = new SearchContactsObj(); try { Criteria crit = hsession.createCriteria(Contact.class); crit.add(Restrictions.isNotNull("conSentDate")); crit.add(Restrictions.isNotNull("conReceivedDate")); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); int hits = crit.list().size(); sobj.setHits(hits); crit = hsession.createCriteria(Contact.class); crit.add(Restrictions.isNotNull("conSentDate")); crit.add(Restrictions.isNotNull("conReceivedDate")); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); crit.setFirstResult(page * byPage); crit.setMaxResults(byPage); switch (order) { case ORDER_BY_EMAIL: crit.addOrder(Order.asc("conEmail")); break; case ORDER_BY_FREQUENCY_SENT: crit.addOrder(Order.desc("conCount")); break; case ORDER_BY_FREQUENCY_RECEIVED: crit.addOrder(Order.desc("conCount")); break; default: crit.addOrder(Order.desc("conCount")); break; } 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 w w .j a v a2 s . com * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param page DOCUMENT ME! * @param byPage DOCUMENT ME! * @param order DOCUMENT ME! * @param extra DOCUMENT ME! * * @return DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public SearchGroupsObj getGroups(Session hsession, String repositoryName, int page, int byPage, int order, String extra) throws Exception { Vector contacts = new Vector(); SearchGroupsObj sobj = new SearchGroupsObj(); try { Criteria crit = hsession.createCriteria(ContactList.class); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); int hits = crit.list().size(); sobj.setHits(hits); crit = hsession.createCriteria(ContactList.class); 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().replaceAll("'", "\\\\'") + " "; } emails.append(name + "<" + contact.getConEmail() + ">"); } if (emails.length() > 0) { obj.setEmails(emails.toString() + ", "); } } contacts.addElement(obj); } sobj.setGroups(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 w w. j a va 2s .com*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param idints DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void deleteContacts(Session hsession, String repositoryName, Integer[] idints) throws Exception { try { Users user = getUser(hsession, repositoryName); Criteria crit = hsession.createCriteria(Contact.class); crit.add(Restrictions.eq("users", user)); crit.add(Restrictions.in("conIdint", idints)); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { Contact contact = (Contact) scroll.get(0); Criteria crit1 = hsession.createCriteria(Identity.class); crit1.add(Restrictions.eq("ideEmail", contact.getConEmail())); crit1.add(Restrictions.eq("ideActive", new Boolean(true))); ScrollableResults scroll2 = crit1.scroll(); while (scroll2.next()) { Identity identity = (Identity) scroll2.get(0); Users buddy = identity.getUsers(); if (buddy != null) { Criteria auxCrit = hsession.createCriteria(BuddyList.class); auxCrit.add(Restrictions.eq("usersByBuliOwnerIdint", user)); auxCrit.add(Restrictions.eq("usersByBuliBuddyIdint", buddy)); BuddyList buddyList = (BuddyList) auxCrit.uniqueResult(); if (buddyList != null) { hsession.delete(buddyList); hsession.flush(); } auxCrit = hsession.createCriteria(BuddyList.class); auxCrit.add(Restrictions.eq("usersByBuliOwnerIdint", buddy)); auxCrit.add(Restrictions.eq("usersByBuliBuddyIdint", user)); buddyList = (BuddyList) auxCrit.uniqueResult(); if (buddyList != null) { hsession.delete(buddyList); hsession.flush(); } } } hsession.delete(contact); hsession.flush(); } } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!/*from ww w . java 2 s . c om*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param idints DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void deleteGroups(Session hsession, String repositoryName, Integer[] idints) throws Exception { try { Criteria crit = hsession.createCriteria(ContactList.class); crit.add(Restrictions.eq("users", getUser(hsession, repositoryName))); crit.add(Restrictions.in("coliIdint", idints)); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { hsession.delete(scroll.get(0)); hsession.flush(); } } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!//from ww w . j av a2 s. c o m * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public Vector getFilters(Session hsession, String repositoryName) throws MailException { Vector filters = new Vector(); try { Query query = hsession.getNamedQuery("filters"); query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); ScrollableResults scroll = query.scroll(); while (scroll.next()) { Filter filter = (Filter) scroll.get(0); FilterObj obj = new FilterObj(); Label label = filter.getLabel(); obj.setArchive(filter.isFilArchive()); obj.setDoesntHaveWords(filter.getFilDoesntHaveWords()); obj.setForward(filter.getFilForwardTo()); obj.setFrom(filter.getFilFrom()); obj.setHasAttachment(filter.isFilHasAttacment()); obj.setHasWords(filter.getFilHasWords()); obj.setIdint(filter.getFilIdint()); obj.setImportant(filter.isFilImportant()); obj.setLabel(new LabelObj(label.getLabIdint(), label.getLabName())); obj.setOperator(!filter.isFilOrOperator()); obj.setSubject(filter.getFilSubject()); obj.setTo(filter.getFilTo()); obj.setTrash(filter.isFilTrash()); filters.addElement(obj); } return filters; } catch (Exception e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }