List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java
License:Mozilla Public License
private Criteria getBasicMapCriteria() { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(StatisticsCounter.class) .createAlias("scanRepeatFindingMap", "mapAlias").add(Restrictions.isNotNull("scanRepeatFindingMap")) .setProjection(property("mapAlias.id")); return sessionFactory.getCurrentSession().createCriteria(ScanRepeatFindingMap.class) .add(Property.forName("id").notIn(detachedCriteria)); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addDefectOptions() { boolean showDefectPresent = parameters.getShowDefectPresent() != null && parameters.getShowDefectPresent(); boolean showDefectNotPresent = parameters.getShowDefectNotPresent() != null && parameters.getShowDefectNotPresent(); boolean showDefectOpen = parameters.getShowDefectOpen() != null && parameters.getShowDefectOpen(); boolean showDefectClosed = parameters.getShowDefectClosed() != null && parameters.getShowDefectClosed(); Criterion defectRestrictions = null; boolean defectAliasCreated = false; if (showDefectPresent) { defectRestrictions = disjoinRestrictions(defectRestrictions, Restrictions.isNotNull("defect")); LOG.debug("Adding defect not null restriction"); }//from w ww .j a v a 2 s . co m if (showDefectNotPresent) { defectRestrictions = disjoinRestrictions(defectRestrictions, Restrictions.isNull("defect")); LOG.debug("Adding defect is null restriction"); } if (showDefectOpen) { if (!defectAliasCreated) { criteria.createAlias("defect", "d", Criteria.LEFT_JOIN); defectAliasCreated = true; } defectRestrictions = disjoinRestrictions(defectRestrictions, Restrictions.in("d.status", Defect.OPEN_CODES)); LOG.debug("Adding defect is open restriction"); } if (showDefectClosed) { if (!defectAliasCreated) { criteria.createAlias("defect", "d", Criteria.LEFT_JOIN); defectAliasCreated = true; } defectRestrictions = disjoinRestrictions(defectRestrictions, Restrictions.in("d.status", Defect.CLOSED_CODES)); LOG.debug("Adding defect is closed restriction"); } if (defectRestrictions != null) { criteria.add(defectRestrictions); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!//from w w w. ja v a 2 s. c o 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); } }
From source file:com.duroty.application.mail.manager.PreferencesManager.java
License:Open Source License
/** * DOCUMENT ME!/*from w ww . j av a 2 s. c o m*/ * * @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 w w w . j a va 2s. co m * * @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.task.ChatTask.java
License:Open Source License
/** * DOCUMENT ME!/*from w ww . j a va2s .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.eharmony.matching.seeking.translator.hibernate.HibernateQueryTranslator.java
License:Apache License
@Override public Criterion notNull(String fieldName) { return Restrictions.isNotNull(fieldName); }
From source file:com.emergya.persistenceGeo.dao.impl.FolderEntityDaoHibernateImpl.java
License:Open Source License
/** * Get all channel folders filtered//from ww w. j a va 2 s. c o m * * @param inZone indicates if obtain channel folders with a zone. If this parameter is null only obtain not zoned channels * @param idZone filter by zone. Obtain only channels of the zone identified by <code>idZone</code> * * @return folder list */ public List<AbstractFolderEntity> getChannelFolders(Boolean inZone, Long idZone) { Criteria criteria = getSession().createCriteria(persistentClass); //FIXME: remove this fixme when merge if (inZone != null) { if (inZone) { criteria.add(Restrictions.isNotNull(ZONE)); } else { criteria.add(Restrictions.isNull(ZONE)); } } if (idZone != null) { criteria.createAlias(ZONE, ZONE).add(Restrictions.eq(ZONE + ".id", idZone)); } // only parent folders criteria.add(Restrictions.isNull(PARENT)); return criteria.list(); }
From source file:com.emergya.persistenceGeo.dao.impl.FolderEntityDaoHibernateImpl.java
License:Open Source License
/** * Get all channel folders filtered//from w w w . j a v a 2s .c o m * * @param inZone indicates if obtain channel folders with a zone. If this parameter is null only obtain not zoned channels * @param idZone filter by zone. Obtain only channels of the zone identified by <code>idZone</code> * @param <code>isEnabled</code> * * @return folder list */ public List<AbstractFolderEntity> getChannelFolders(Boolean inZone, Long idZone, Boolean isEnable) { Criteria criteria = getSession().createCriteria(persistentClass); //FIXME: remove this fixme when merge if (inZone != null) { if (inZone) { criteria.add(Restrictions.isNotNull(ZONE)); } else { criteria.add(Restrictions.isNull(ZONE)); } } if (idZone != null) { criteria.createAlias(ZONE, ZONE).add(Restrictions.eq(ZONE + ".id", idZone)); } if (isEnable != null && isEnable) { criteria.add(Restrictions.eq("enabled", isEnable)); } else if (isEnable != null) { Disjunction dis = Restrictions.disjunction(); dis.add(Restrictions.isNull("enabled")); dis.add(Restrictions.eq("enabled", Boolean.FALSE)); criteria.add(dis); } // only parent folders criteria.add(Restrictions.isNull(PARENT)); criteria.addOrder(Order.asc("name")); return criteria.list(); }
From source file:com.eryansky.common.orm.core.hibernate.restriction.support.NeRestriction.java
License:Apache License
public Criterion build(String propertyName, Object value) { return value == null ? Restrictions.isNotNull(propertyName) : Restrictions.ne(propertyName, value); }