List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:com.duroty.service.analyzer.LuceneFiltersAnalysis.java
License:Open Source License
/** * DOCUMENT ME!/*from w w w . j a va 2 s . c o m*/ * * @param hsession DOCUMENT ME! * @param username DOCUMENT ME! * * @return DOCUMENT ME! */ private Vector getFilters(Session hsession, String username) { try { Vector filters = new Vector(); Criteria crit = hsession.createCriteria(Users.class); crit.add(Restrictions.eq("useUsername", username)); crit.add(Restrictions.eq("useActive", new Boolean(true))); Users user = (Users) crit.uniqueResult(); Query query = hsession.getNamedQuery("filter-by-user"); query.setInteger("user", user.getUseIdint()); ScrollableResults scroll = query.scroll(); while (scroll.next()) { filters.addElement(scroll.get(0)); } return filters; } catch (Exception ex) { DLog.log(DLog.ERROR, this.getClass(), ex); } finally { GeneralOperations.closeHibernateSession(hsession); } return null; }
From source file:com.duroty.task.BookmarkServiceTask.java
License:Open Source License
/** * DOCUMENT ME!/*from w w w . j a va 2s . c o m*/ */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Criteria crit = hsession.createCriteria(Bookmark.class); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { if (pool.size() >= poolSize) { break; } Bookmark bookmark = (Bookmark) scroll.get(0); Users user = bookmark.getUsers(); String idint = NumberUtils.pad(Long.parseLong(String.valueOf(bookmark.getBooIdint()))); String key = idint + "--" + user.getUseUsername(); if (!poolContains(key)) { addPool(key); BookmarkObj bookmarkObj = new BookmarkObj(); bookmarkObj.setIdint(idint); bookmarkObj.setUrl(bookmark.getBooUrl()); Bookmarklet bookmarklet = new Bookmarklet(this, idint, user.getUseUsername(), bookmarkObj); Thread thread = new Thread(bookmarklet, key); thread.start(); hsession.delete(bookmark); hsession.flush(); } Thread.sleep(100); } } catch (Exception e) { pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); System.gc(); } catch (OutOfMemoryError e) { pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); System.gc(); } catch (Throwable e) { pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.duroty.task.ChatConversationsTask.java
License:Open Source License
/** * DOCUMENT ME!//from www . ja v a 2s .c o m * * @param dirUsers DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void flush() throws Exception { SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Calendar cal = new GregorianCalendar(); //int hour = cal.get(Calendar.HOUR_OF_DAY); //int minute = cal.get(Calendar.MINUTE); //int second = cal.get(Calendar.SECOND); Calendar cal1 = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE) - 1, cal.get(Calendar.SECOND)); Date date = new Date(cal1.getTimeInMillis()); Criteria crit = hsession.createCriteria(Conversations.class); crit.add(Restrictions.le("convStamp", date)); crit.addOrder(Order.asc("convStamp")); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { hsession.delete(scroll.get(0)); hsession.flush(); } } catch (Exception e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (OutOfMemoryError e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (Throwable e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); System.gc(); } }
From source file:com.duroty.task.ChatTask.java
License:Open Source License
/** * DOCUMENT ME!/*from w w w .j a v a 2 s. c o m*/ * * @param dirUsers DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public void flush() throws Exception { SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Calendar cal = new GregorianCalendar(); //int hour = cal.get(Calendar.HOUR_OF_DAY); //int minute = cal.get(Calendar.MINUTE); //int second = cal.get(Calendar.SECOND); Calendar cal1 = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE) - 5, cal.get(Calendar.SECOND)); Date date = new Date(cal1.getTimeInMillis()); Criteria crit = hsession.createCriteria(Users.class); crit.add(Restrictions.le("useLastPing", date)); crit.add(Restrictions.not(Restrictions.eq("useIsOnline", new Integer(0)))); crit.add(Restrictions.isNotNull("useIsOnline")); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { Users user = (Users) scroll.get(0); user.setUseIsOnline(0); hsession.update(user); hsession.flush(); } /*cal1 = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE) - 1, cal.get(Calendar.SECOND)); date = new Date(cal1.getTimeInMillis()); crit = hsession.createCriteria(Conversations.class); crit.add(Restrictions.le("convStamp", date)); scroll = crit.scroll(); while (scroll.next()) { Conversations conv = (Conversations) scroll.get(0); hsession.update(conv); hsession.flush(); }*/ } catch (Exception e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (OutOfMemoryError e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (Throwable e) { System.gc(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); System.gc(); } }
From source file:com.duroty.task.DeleteMessagesTask.java
License:Open Source License
/** * DOCUMENT ME!//from w w w . j ava 2 s .c o m */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Criteria crit = hsession.createCriteria(Message.class); crit.add(Restrictions.eq("mesBox", folderDelete)); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); Users user = message.getUsers(); String mid = message.getMesName(); hsession.delete(message); hsession.flush(); this.messageable.deleteMimeMessage(mid, user); /*try { } catch (HibernateException e) { } catch (OutOfMemoryError e) { System.gc(); } catch (Exception e) { } catch (Throwable e) { }*/ Thread.sleep(100); } } catch (Exception e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.duroty.task.IMAPServiceTask.java
License:Open Source License
/** * DOCUMENT ME!/*from w ww . j a v a 2 s . co m*/ */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; javax.mail.Session msession = null; Store store = null; Folder rootFolder = null; Folder folder = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); msession = (javax.mail.Session) ctx.lookup(durotyMailFactory); store = msession.getStore("imap"); String imapHost = msession.getProperty("mail.imap.host"); Query query = hsession.getNamedQuery("users-mail"); query.setBoolean("active", true); query.setString("role", "mail"); ScrollableResults scroll = query.scroll(); while (scroll.next()) { Users user = (Users) scroll.get(0); String repositoryName = user.getUseUsername(); store.connect(imapHost, repositoryName, user.getUsePassword()); rootFolder = store.getDefaultFolder(); if ((rootFolder.getType() & Folder.HOLDS_FOLDERS) != 0) { folder = store.getFolder(this.imapInbox); Message[] messages = getMimeMessages(folder, new Flags(Flags.Flag.SEEN), false); MailUtilities.setFolderOpenAndReady(folder, Folder.READ_WRITE); if ((messages != null) && (messages.length > 0)) { for (int i = 0; i < messages.length; i++) { if (pool.size() >= poolSize) { DLog.log(DLog.WARN, this.getClass(), "PoolSize " + pool.size()); break; } MimeMessage mime = null; if (messages[i] instanceof MimeMessage) { mime = new MimeMessage((MimeMessage) messages[i]); String messageName = null; if (folder instanceof IMAPFolder) { messageName = String.valueOf(((IMAPFolder) folder).getUID(messages[i])); } else { messageName = String.valueOf(messages[i].getMessageNumber()); } messageName += this.imapInbox; boolean existMessage = existMessageName(hfactory.openSession(), user, messageName); if (existMessage) { messages[i].setFlag(Flags.Flag.SEEN, true); } else { String key = messageName + "--" + repositoryName; if (!poolContains(key)) { addPool(key); if (!isSpam(user, mime)) { Mailet mailet = new Mailet(this, messageName, repositoryName, mime); Thread thread = new Thread(mailet, key); thread.start(); //cal controlar si el borrem messages[i].setFlag(Flags.Flag.SEEN, true); } else { messages[i].setFlag(Flags.Flag.SEEN, true); messages[i].setFlag(Flags.Flag.DELETED, true); } } } Thread.sleep(100); } } } MailUtilities.setFolderClose(folder, true); folder = null; messages = null; folder = store.getFolder(this.imapSent); messages = getMimeMessages(folder, new Flags(Flags.Flag.SEEN), false); MailUtilities.setFolderOpenAndReady(folder, Folder.READ_WRITE); if (!folder.exists()) { folder.create(Folder.HOLDS_MESSAGES); } if (!folder.isSubscribed()) { folder.setSubscribed(true); } if ((messages != null) && (messages.length > 0)) { for (int i = 0; i < messages.length; i++) { if (pool.size() >= poolSize) { DLog.log(DLog.WARN, this.getClass(), "PoolSize " + pool.size()); break; } MimeMessage mime = null; if (messages[i] instanceof MimeMessage) { mime = new MimeMessage((MimeMessage) messages[i]); mime.addHeader("X-DBox", "SENT"); String messageName = null; if (folder instanceof IMAPFolder) { messageName = String.valueOf(((IMAPFolder) folder).getUID(messages[i])); } else { messageName = String.valueOf(messages[i].getMessageNumber()); } messageName += this.imapSent; boolean existMessage = existMessageName(hfactory.openSession(), user, messageName); if (existMessage) { messages[i].setFlag(Flags.Flag.SEEN, true); } else { String key = messageName + "--" + repositoryName; if (!poolContains(key)) { addPool(key); if (!isSpam(user, mime)) { Mailet mailet = new Mailet(this, messageName, repositoryName, mime); Thread thread = new Thread(mailet, key); thread.start(); //cal controlar si el borrem messages[i].setFlag(Flags.Flag.SEEN, true); } else { messages[i].setFlag(Flags.Flag.SEEN, true); messages[i].setFlag(Flags.Flag.DELETED, true); } } } Thread.sleep(100); } } } MailUtilities.setFolderClose(folder, true); folder = null; messages = null; folder = store.getFolder(this.imapDraft); messages = getMimeMessages(folder, new Flags(Flags.Flag.SEEN), false); MailUtilities.setFolderOpenAndReady(folder, Folder.READ_WRITE); if (!folder.exists()) { folder.create(Folder.HOLDS_MESSAGES); } if (!folder.isSubscribed()) { folder.setSubscribed(true); } if ((messages != null) && (messages.length > 0)) { for (int i = 0; i < messages.length; i++) { if (pool.size() >= poolSize) { DLog.log(DLog.WARN, this.getClass(), "PoolSize " + pool.size()); break; } MimeMessage mime = null; if (messages[i] instanceof MimeMessage) { mime = new MimeMessage((MimeMessage) messages[i]); mime.addHeader("X-DBox", "DRAFT"); String messageName = null; if (folder instanceof IMAPFolder) { messageName = String.valueOf(((IMAPFolder) folder).getUID(messages[i])); } else { messageName = String.valueOf(messages[i].getMessageNumber()); } messageName += this.imapDraft; boolean existMessage = existMessageName(hfactory.openSession(), user, messageName); if (existMessage) { messages[i].setFlag(Flags.Flag.SEEN, true); } else { String key = messageName + "--" + repositoryName; if (!poolContains(key)) { addPool(key); if (!isSpam(user, mime)) { Mailet mailet = new Mailet(this, messageName, repositoryName, mime); Thread thread = new Thread(mailet, key); thread.start(); //cal controlar si el borrem messages[i].setFlag(Flags.Flag.SEEN, true); } else { messages[i].setFlag(Flags.Flag.SEEN, true); messages[i].setFlag(Flags.Flag.DELETED, true); } } } Thread.sleep(100); } } } MailUtilities.setFolderClose(folder, true); folder = null; } MailUtilities.setFolderClose(rootFolder, true); MailUtilities.setStoreClose(store); } } catch (Exception e) { System.gc(); pool.clear(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (OutOfMemoryError e) { System.gc(); pool.clear(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } catch (Throwable e) { System.gc(); pool.clear(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); DLog.log(DLog.ERROR, this.getClass(), writer.toString()); } finally { System.gc(); GeneralOperations.closeMailFolder(folder, false); GeneralOperations.closeMailFolder(rootFolder, false); GeneralOperations.closeMailStore(store); GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.duroty.task.POP3ServiceTask.java
License:Open Source License
/** * DOCUMENT ME!// www . ja v a2s . c o m */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; javax.mail.Session msession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); msession = (javax.mail.Session) ctx.lookup(durotyMailFactory); String pop3Host = msession.getProperty("mail.pop3.host"); int port = 0; try { port = Integer.parseInt(msession.getProperty("mail.pop3.port")); } catch (Exception ex) { port = 0; } Query query = hsession.getNamedQuery("users-mail"); query.setBoolean("active", true); query.setString("role", "mail"); ScrollableResults scroll = query.scroll(); while (scroll.next()) { POP3Client client = new POP3Client(); try { if (port > 0) { client.connect(pop3Host, port); } else { client.connect(pop3Host); } client.setState(POP3Client.AUTHORIZATION_STATE); //client.setDefaultTimeout() Users user = (Users) scroll.get(0); String repositoryName = user.getUseUsername(); if (client.login(repositoryName, user.getUsePassword())) { POP3MessageInfo[] info = client.listUniqueIdentifiers(); if ((info != null) && (info.length > 0)) { for (int i = 0; i < info.length; i++) { if (pool.size() >= poolSize) { break; } Reader reader = client.retrieveMessage(info[i].number); boolean existMessage = existMessageName(hfactory.openSession(), user, info[i].identifier); String key = info[i].identifier + "--" + repositoryName; if (existMessage) { client.deleteMessage(info[i].number); } else { if (!poolContains(key)) { addPool(key); MimeMessage mime = buildMimeMessage(info[i].identifier, reader, user); if (!isSpam(user, mime)) { client.deleteMessage(info[i].number); Mailet mailet = new Mailet(this, info[i].identifier, repositoryName, mime); Thread thread = new Thread(mailet, key); thread.start(); } else { client.deleteMessage(info[i].number); } } } Thread.sleep(100); } } } else { } } catch (Exception e) { } finally { System.gc(); try { client.logout(); client.disconnect(); } catch (Exception e) { } } } } catch (Exception e) { System.gc(); pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); pool.clear(); DLog.log(DLog.ERROR, this.getClass(), e.getMessage()); } finally { System.gc(); GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.duroty.task.PurgeTrashAndSpam.java
License:Open Source License
/** * DOCUMENT ME!/*from ww w . j a v a2s .com*/ */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); // 2002 int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ... int day = cal.get(Calendar.DAY_OF_MONTH); // 1... Calendar cal1 = new GregorianCalendar(year, month - 1, day, 0, 0, 0); Date date = new Date(cal1.getTimeInMillis()); Criteria criteria = hsession.createCriteria(Message.class); criteria.add(Restrictions.in("mesBox", new String[] { this.folderSpam, this.folderTrash })); criteria.add(Restrictions.le("mesDate", date)); criteria.addOrder(Order.asc("mesDate")); ScrollableResults scroll = criteria.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); Users user = message.getUsers(); try { messageable.deleteMimeMessage(message.getMesName(), user); } catch (Exception e) { DLog.log(DLog.INFO, this.getClass(), e.getMessage() + " for user " + user.getUseUsername()); } hsession.delete(message); hsession.flush(); Thread.sleep(100); } } catch (Exception e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricManager.java
License:Open Source License
private static MetricEntity getMetricEntity(ScrollableResults results) { Double sampleMax = (Double) results.get(0); Double sampleMin = (Double) results.get(1); Double sampleSize = (Double) results.get(2); Double sampleSum = (Double) results.get(3); Units resultUnits = (Units) results.get(4); Date timestamp = (Date) results.get(5); String accountId = (String) results.get(6); String metricName = (String) results.get(7); MetricType metricType = (MetricType) results.get(8); String namespace = (String) results.get(9); String hash = (String) results.get(10); MetricEntity me = MetricEntityFactory.getNewMetricEntity(metricType, hash); me.setAccountId(accountId);/*from w ww .j ava 2s. c om*/ me.setNamespace(namespace); me.setMetricName(metricName); me.setMetricType(metricType); me.setDimensionHash(hash); me.setSampleMax(sampleMax); me.setSampleMin(sampleMin); me.setSampleSize(sampleSize); me.setSampleSum(sampleSum); me.setTimestamp(timestamp); me.setUnits(resultUnits); return me; }
From source file:com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricManager.java
License:Open Source License
private static MetricEntity getMetricEntity(String accountId, String metricName, String namespace, MetricType metricType, String hash, ScrollableResults results) { Double sampleMax = (Double) results.get(0); Double sampleMin = (Double) results.get(1); Double sampleSize = (Double) results.get(2); Double sampleSum = (Double) results.get(3); Units resultUnits = (Units) results.get(4); Date timestamp = (Date) results.get(5); MetricEntity me = MetricEntityFactory.getNewMetricEntity(metricType, hash); me.setAccountId(accountId);/*from ww w.j a v a 2 s . com*/ me.setNamespace(namespace); me.setMetricName(metricName); me.setMetricType(metricType); me.setDimensionHash(hash); me.setSampleMax(sampleMax); me.setSampleMin(sampleMin); me.setSampleSize(sampleSize); me.setSampleSum(sampleSum); me.setTimestamp(timestamp); me.setUnits(resultUnits); return me; }