List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:com.duroty.application.files.manager.FilesManager.java
License:Open Source License
/** * DOCUMENT ME!//from w w w. j ava 2 s.co m * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public Vector getLabels(Session hsession, String repositoryName) throws FilesException { 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 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 va2 s . c o 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 av a 2 s. co 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 . j a v a 2s . com*/ * * @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 av a2s. 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 www . j av a 2s . co 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 FilesException DOCUMENT ME! */ public Vector getFiles(Session hsession, String repositoryName, String folderName, int label, int page, int messagesByPage, int order, String orderType) throws FilesException { Vector files = 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 = 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("attachments"); } else if ((folderNameList.length > 0) && (label <= 0)) { hquery = hsession.getNamedQuery("attachments-by-folder"); } else if ((folderNameList.length == 0) && (label > 0)) { hquery = hsession.getNamedQuery("attachments-by-label"); } else if ((folderNameList.length > 0) && (label > 0)) { hquery = hsession.getNamedQuery("attachments-by-folder-label"); } String aux = hquery.getQueryString(); switch (order) { case ORDER_BY_SIZE: if (orderType.equals("ASC")) { aux += " order by att_size asc"; } else { aux += " order by att_size 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_TYPE: if (orderType.equals("ASC")) { aux += " order by att_content_type asc"; } else { aux += " order by att_content_type desc"; } break; default: if (!orderType.equals("ASC")) { aux += " order by att_name desc"; } else { aux += " order by att_name asc"; } break; } SQLQuery h2query = hsession.createSQLQuery(aux); if ((folderNameList.length == 0) && (label <= 0)) { h2query.setParameterList("no_boxes", new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE }); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length > 0) && (label <= 0)) { h2query.setParameterList("boxes", folderNameList); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length == 0) && (label > 0)) { h2query.setInteger("label", label); h2query.setParameterList("no_boxes", new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE }); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length > 0) && (label > 0)) { h2query.setInteger("label", label); h2query.setParameterList("boxes", folderNameList); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } h2query.setFirstResult(page * messagesByPage); h2query.setMaxResults(messagesByPage); h2query.addEntity("testo", AttachmentWithDate.class); ScrollableResults scroll = h2query.scroll(); while (scroll.next()) { AttachmentWithDate attachment = (AttachmentWithDate) scroll.get(0); AttachmentObj obj = new AttachmentObj(); obj.setContentType(attachment.getAttContentType()); Date date = attachment.getAttDate(); 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); obj.setDate(date); obj.setIdint(attachment.getAttIdint()); obj.setName(attachment.getAttName()); obj.setPart(attachment.getAttPart()); int size = attachment.getAttSize(); size /= 1024; if (size > 1024) { size /= 1024; obj.setSize(size + " MB"); } else { obj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } String extension = (String) this.extensions.get(attachment.getAttContentType()); if (StringUtils.isBlank(extension)) { extension = "generic"; } obj.setExtension(extension); Message message = attachment.getMessage(); if (message.isMesFlagged()) { obj.setFlagged(true); } else { obj.setFlagged(false); } if (message.getLabMeses() != null) { Iterator it = message.getLabMeses().iterator(); StringBuffer lab = new StringBuffer(); while (it.hasNext()) { if (lab.length() > 0) { lab.append(", "); } LabMes labMes = (LabMes) it.next(); lab.append(labMes.getId().getLabel().getLabName()); } if (lab.length() > 0) { obj.setLabel(lab.toString()); } else { } } obj.setBox(message.getMesBox()); obj.setMid(message.getMesName()); files.addElement(obj); } return files; } 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 .ja v a2 s.c o 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!/*w w w .j a va 2s .c o m*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param mids DOCUMENT ME! * @param folder DOCUMENT ME! * * @throws FilesException DOCUMENT ME! */ public void moveFiles(Session hsession, String repositoryName, String[] mids, String folder) throws FilesException { if ((mids == null) || (mids.length == 0)) { throw new FilesException("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 FilesException(ex); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.duroty.application.files.manager.SearchManager.java
License:Open Source License
/** * DOCUMENT ME!//from ww w.jav a 2 s . com * * @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.home.manager.HomeManager.java
License:Open Source License
/** * DOCUMENT ME!//from w ww . j av a 2s .c o m * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param idintChannel DOCUMENT ME! * @param name DOCUMENT ME! * * @return DOCUMENT ME! * * @throws HomeException DOCUMENT ME! */ public Vector getAllFeed(Session hsession, String repositoryName, int idintChannel) throws HomeException { Vector feeds = new Vector(); try { FeedChannel channel = null; Users user = getUser(hsession, repositoryName); if (idintChannel == 0) { Criteria criteria = hsession.createCriteria(FeedChannel.class); criteria.add(Restrictions.eq("users", user)); criteria.add(Restrictions.eq("fechName", "Main")); channel = (FeedChannel) criteria.uniqueResult(); if (channel == null) { channel = new FeedChannel(); channel.setFechName("Main"); channel.setUsers(user); hsession.saveOrUpdate(channel); hsession.flush(); } } else { Criteria criteria = hsession.createCriteria(FeedChannel.class); criteria.add(Restrictions.eq("users", user)); criteria.add(Restrictions.eq("fechIdint", new Integer(idintChannel))); channel = (FeedChannel) criteria.uniqueResult(); } Criteria crit = hsession.createCriteria(FeedData.class); crit.add(Restrictions.eq("feedChannel", channel)); crit.addOrder(Order.asc("fedaName")); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { FeedData feed = (FeedData) scroll.get(0); feeds.addElement(feed.getFedaValue()); } return feeds; } catch (Exception e) { throw new HomeException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }