List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:com.duroty.application.mail.manager.MailManager.java
License:Open Source License
/** * DOCUMENT ME!/* www .j av a2 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!//from ww w .ja v a 2 s .co m * * @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!/*w w w . j ava2 s . c o 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!/*from ww w . jav a 2s . c o m*/ * * @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!/*from w w w .ja va 2 s .c o m*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param label 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, Label label, 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); Query hquery = hsession.getNamedQuery("messages-by-label"); String aux = hquery.getQueryString(); switch (order) { case ORDER_BY_IMPORTANT: if (orderType.equals("ASC")) { aux += " order by mes_flagged asc"; } else { aux += " order by mes_flagged desc"; } break; case ORDER_BY_ADDRESS: if (orderType.equals("ASC")) { aux += " order by mes_from asc"; } else { aux += " order by mes_from desc"; } break; case ORDER_BY_SIZE: if (orderType.equals("ASC")) { aux += " order by mes_size asc"; } else { aux += " order by mes_size desc"; } break; case ORDER_BY_SUBJECT: if (orderType.equals("ASC")) { aux += " order by mes_subject asc"; } else { aux += " order by mes_subject desc"; } break; case ORDER_BY_DATE: if (orderType.equals("ASC")) { aux += " order by mes_date asc"; } else { aux += " order by mes_date desc"; } break; case ORDER_BY_UNREAD: if (orderType.equals("ASC")) { aux += " order by mes_recent asc"; } else { aux += " order by mes_recent desc"; } break; default: aux += " order by mes_date desc"; break; } SQLQuery h2query = hsession.createSQLQuery(aux); h2query.addEntity("i", Message.class); h2query.setInteger("label", label.getLabIdint()); h2query.setInteger("user", user.getUseIdint()); h2query.setString("folderTrash", this.folderTrash); h2query.setString("folderSpam", this.folderSpam); h2query.setString("folderDelete", FOLDER_DELETE); h2query.setFirstResult(page * messagesByPage); h2query.setMaxResults(messagesByPage); ScrollableResults scroll = h2query.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 buff = new StringBuffer(); while (it.hasNext()) { if (buff.length() > 0) { buff.append(", "); } LabMes labMes = (LabMes) it.next(); buff.append(labMes.getId().getLabel().getLabName()); } obj.setLabel(buff.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!/*from w ww .ja v a 2s . c o m*/ * * @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!// w w w .j a v a 2s . co m * * @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!// w w w .j av a2s.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!/*from w ww .j av a2s.com*/ * * @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!//from ww w .ja va2 s. co m * * @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); } }