List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:com.kodemore.hibernate.criteria.KmAbstractCriteria.java
License:Open Source License
public void addLessThan(String property, Object value) { _add(Restrictions.lt(property, value)); }
From source file:com.krawler.common.util.BuildCriteria.java
License:Open Source License
private static Criterion getCriteriaByCondition(Object value, Integer criteriaVal, String propertyname) { Criterion Criteriaobj;/*w w w . j a va 2s .c o m*/ switch (criteriaVal) { case ISNOTNULL: Criteriaobj = Restrictions.isNotNull(propertyname); break; case NOTIN: String[] strArr = String.valueOf(value).split(","); List ls = Arrays.asList(strArr); Criteriaobj = Restrictions.not(Restrictions.in(propertyname, ls)); break; case LIKE: Criteriaobj = Restrictions.or(Restrictions.like(propertyname, value + "%"), Restrictions.like(propertyname, "% " + value + "%")); break; case LE: Criteriaobj = Restrictions.le(propertyname, value); break; case GE: Criteriaobj = Restrictions.ge(propertyname, value); break; case ISNULL: Criteriaobj = Restrictions.isNull(propertyname); break; case IN: strArr = String.valueOf(value).split(","); ls = Arrays.asList(strArr); Criteriaobj = Restrictions.in(propertyname, ls); break; case NE: Criteriaobj = Restrictions.ne(propertyname, value); break; case LT: Criteriaobj = Restrictions.lt(propertyname, value); break; case GT: Criteriaobj = Restrictions.gt(propertyname, value); break; case EQ: default: Criteriaobj = Restrictions.eq(propertyname, value); break; } return Criteriaobj; }
From source file:com.lakeside.data.sqldb.PageBaseDao.java
License:Apache License
/** * ??Criterion,.//from w w w . j a va 2 s .c o m */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; try { //?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
protected Criteria buildTaskInstanceExtensionSearchCriteria(String taskName, String assetType, Long[] assetPrimaryKeys, Date dueDateGT, Date dueDateLT, Boolean completed, Boolean searchByUserRoles, boolean andOperator, ServiceContext serviceContext) throws SystemException { Criteria criteria = _session.createCriteria(TaskInstanceExtensionImpl.class); criteria.createAlias("taskInstance", "taskInstance"); criteria.add(Restrictions.eq("companyId", serviceContext.getCompanyId())); if (Validator.isNotNull(taskName) || Validator.isNotNull(assetType) || (dueDateGT != null) || (dueDateLT != null)) {/*from w ww. j av a 2 s .c o m*/ Junction junction = null; if (andOperator) { junction = Restrictions.conjunction(); } else { junction = Restrictions.disjunction(); } if (Validator.isNotNull(taskName)) { String[] taskNameKeywords = StringUtil.split(taskName, StringPool.SPACE); for (String taskNameKeyword : taskNameKeywords) { junction.add(Restrictions.like("taskInstance.name", "%" + taskNameKeyword + "%")); } } if (Validator.isNotNull(assetType)) { String[] assetTypeKeywords = StringUtil.split(assetType, StringPool.SPACE); for (String assetTypeKeyword : assetTypeKeywords) { junction.add( Restrictions.like("workflowContext", "%\"entryType\":\"%" + assetTypeKeyword + "%\"%")); } } if (Validator.isNotNull(assetPrimaryKeys)) { for (Long assetPrimaryKey : assetPrimaryKeys) { junction.add(Restrictions.like("workflowContext", "%\"entryClassPK\":\"%" + assetPrimaryKey + "%\"%")); } } if (dueDateGT != null) { junction.add(Restrictions.ge("taskInstance.dueDate", dueDateGT)); } if (dueDateLT != null) { junction.add(Restrictions.lt("taskInstance.dueDate", dueDateGT)); } criteria.add(junction); } addSearchByUserRolesCriterion(criteria, searchByUserRoles, serviceContext); if (completed != null) { if (completed.booleanValue()) { criteria.add(Restrictions.isNotNull("taskInstance.end")); } else { criteria.add(Restrictions.isNull("taskInstance.end")); } } return criteria; }
From source file:com.llaf.elementos.model.DAOUsuario.java
public String obtenerPorNOmbre(String nombre) throws Exception { SessionFactory factory = HIbernateUtilidades.getSessionFactory(); Session sesion = factory.openSession(); Transaction tranza = sesion.beginTransaction(); Criteria cri = sesion.createCriteria(Usuarios.class).add(Restrictions.like("nombre", nombre + "%")); Criteria cri2 = sesion.createCriteria(Usuarios.class).add(Restrictions.eq("nombre", nombre)); Criteria cri3 = sesion.createCriteria(Usuarios.class).add(Restrictions.between("edad", 18, 40)) .addOrder(Order.asc("nombre")); Criteria cri4 = sesion.createCriteria(Usuarios.class).add(Restrictions.lt("sueldo", new Integer(4000))); Criteria cri5 = sesion.createCriteria(Usuarios.class).add(Restrictions.gt("sueldo", new Integer(4000))); ArrayList<Usuarios> usuarios = (ArrayList<Usuarios>) cri.list(); ObjectMapper mapper = new ObjectMapper(); Map<String, ArrayList<Usuarios>> singletonMap = Collections.singletonMap("usuarios", usuarios); tranza.commit();//from w ww . j ava2 s .co m sesion.close(); return mapper.writeValueAsString(singletonMap); }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
public Integer findNumInUseLicenses(String isvId, String prodId, String prodDefId, String storeId, String platformId, Date startDate, Date endDate) { Integer numLics = 0;// w w w . ja va 2s . co m try { Long lisvid = null; if (StringUtils.hasText(isvId)) lisvid = Long.parseLong(isvId); Long lpid = null; if (StringUtils.hasText(prodId)) lpid = Long.parseLong(prodId); Long lppid = null; if (StringUtils.hasText(prodDefId)) lppid = Long.parseLong(prodDefId); Long lsid = null; if (StringUtils.hasText(storeId)) lsid = Long.parseLong(storeId); Long lfid = null; if (StringUtils.hasText(platformId)) lfid = Long.parseLong(platformId); Criteria criteria = getSession().createCriteria(License.class); criteria.add(Restrictions.eq("isv.id", lisvid)); Criteria prodCriteria = criteria.createCriteria("product"); // If the child product is specified, this supercedes the wider selection of the product // definition. // Only check for htye product definition if the child product was not selected. if (lpid != null) criteria.add(Restrictions.eq("product.id", lpid)); else if (lppid != null) prodCriteria.add(Restrictions.eq("productDef.id", lppid)); if (lsid != null) prodCriteria.add(Restrictions.eq("listingStore.id", lsid)); if (lfid != null) prodCriteria.add(Restrictions.eq("platform.id", lfid)); criteria.add(Restrictions.eq("inUse", true)); criteria.add(Restrictions.eq("decom", false)); if (startDate != null && endDate != null) criteria.add(Restrictions.between(TIME_ACTIVATED, startDate, endDate)); else { if (startDate != null) criteria.add(Restrictions.gt(TIME_ACTIVATED, startDate)); if (endDate != null) criteria.add(Restrictions.lt(TIME_ACTIVATED, endDate)); } criteria.setProjection(Projections.rowCount()); numLics = (Integer) criteria.list().get(0); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return numLics; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
public Integer findNumIssuedLicenses(String isvId, String prodId, String prodDefId, String storeId, String platformId, Date startDate, Date endDate) { Integer numLics = 0;/*from ww w . j a v a 2 s .c o m*/ try { Long lisvid = null; if (StringUtils.hasText(isvId)) lisvid = Long.parseLong(isvId); Long lpid = null; if (StringUtils.hasText(prodId)) lpid = Long.parseLong(prodId); Long lppid = null; if (StringUtils.hasText(prodDefId)) lppid = Long.parseLong(prodDefId); Long lsid = null; if (StringUtils.hasText(storeId)) lsid = Long.parseLong(storeId); Long lfid = null; if (StringUtils.hasText(platformId)) lfid = Long.parseLong(platformId); Criteria criteria = getSession().createCriteria(License.class); criteria.add(Restrictions.eq("isv.id", lisvid)); Criteria prodCriteria = criteria.createCriteria("product"); // If the child product is specified, this supercedes the wider selection of the product // definition. // Only check for htye product definition if the child product was not selected. if (lpid != null) criteria.add(Restrictions.eq("product.id", lpid)); else if (lppid != null) prodCriteria.add(Restrictions.eq("productDef.id", lppid)); if (lsid != null) prodCriteria.add(Restrictions.eq("listingStore.id", lsid)); if (lfid != null) prodCriteria.add(Restrictions.eq("platform.id", lfid)); criteria.add(Restrictions.eq("inUse", true)); // criteria.add(Restrictions.eq("decom", false)); if (startDate != null && endDate != null) criteria.add(Restrictions.between(TIME_ACTIVATED, startDate, endDate)); else { if (startDate != null) criteria.add(Restrictions.gt(TIME_ACTIVATED, startDate)); if (endDate != null) criteria.add(Restrictions.lt(TIME_ACTIVATED, endDate)); } criteria.setProjection(Projections.rowCount()); numLics = (Integer) criteria.list().get(0); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return numLics; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
public Integer findNumInUseIsvLicenses(String isvId, String storeId, String platformId, Date startDate, Date endDate) {/* w w w .j a va 2s . c o m*/ Integer numLics = 0; try { Long lisvid = Long.parseLong(isvId); Criteria criteria = getSession().createCriteria(License.class); criteria.add(Restrictions.eq("isv.id", lisvid)); criteria.add(Restrictions.eq("inUse", true)); criteria.add(Restrictions.eq("decom", false)); Criteria prodCriteria = null; if (StringUtils.hasText(storeId)) { Long lsid = Long.parseLong(storeId); prodCriteria = criteria.createCriteria("product"); prodCriteria.add(Restrictions.eq("listingStore.id", lsid)); } if (StringUtils.hasText(platformId)) { Long lfid = Long.parseLong(platformId); if (prodCriteria == null) prodCriteria = criteria.createCriteria("product"); prodCriteria.add(Restrictions.eq("platform.id", lfid)); } if (startDate != null && endDate != null) criteria.add(Restrictions.between(TIME_ACTIVATED, startDate, endDate)); else { if (startDate != null) criteria.add(Restrictions.gt(TIME_ACTIVATED, startDate)); if (endDate != null) criteria.add(Restrictions.lt(TIME_ACTIVATED, endDate)); } criteria.setProjection(Projections.rowCount()); numLics = (Integer) criteria.list().get(0); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return numLics; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseIsvProdTrialLicenses(String isvId, String prodId, String prodDefId, String storeId, String platformId, Integer firstResult, Integer maxResults, String orderBy, String orderDir, Date startDate, Date endDate) { List<License> licenses = null; try {/*www . j a v a 2s . c o m*/ Criteria mainCriteria = getSession().createCriteria(License.class); ProductInstanceCriterias prodInstCriterias = addIsvProductInstProductDefStorePlatfrmCriteria(isvId, prodId, prodDefId, storeId, platformId, mainCriteria); addDateRangeRestrictions(TIME_ACTIVATED, startDate, endDate, mainCriteria); mainCriteria.add(Restrictions.eq("inUse", true)); mainCriteria.add(Restrictions.eq("decom", false)); mainCriteria.add(Restrictions.lt("lifeInDays", 365)); mainCriteria.setFirstResult(firstResult); mainCriteria.setMaxResults(maxResults); addOrderByToCriteria(orderBy, orderDir, mainCriteria, prodInstCriterias); licenses = mainCriteria.list(); } catch (RuntimeException re) { log.error("findInUseIsvProdTrialLicenses failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseVerifIncidentDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<LicenseVerifIncident> findIsvVerifs(Long isvId, String licType, String respType, Integer firstResult, Integer maxResults, String orderBy, String orderDir, Date startDate, Date endDate) {// www . j a v a 2 s . c om List<LicenseVerifIncident> rfls = null; try { Criteria mainCriteria = getSession().createCriteria(LicenseVerifIncident.class); mainCriteria.add(Restrictions.eq("isv.id", isvId)); Criteria prodCriteria = addEnabledUnDeletedProductCriteria(mainCriteria); addLicTypeRespTypeCrit(licType, respType, mainCriteria, prodCriteria); mainCriteria.setFirstResult(firstResult); mainCriteria.setMaxResults(maxResults); if (startDate != null && endDate != null) mainCriteria.add(Restrictions.between(TIME_REQUESTED, startDate, endDate)); else { if (startDate != null) mainCriteria.add(Restrictions.gt(TIME_REQUESTED, startDate)); if (endDate != null) mainCriteria.add(Restrictions.lt(TIME_REQUESTED, endDate)); } createOrderByFieldAliasIfApplicable(orderBy, orderDir, mainCriteria, prodCriteria); rfls = mainCriteria.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return rfls; }