List of usage examples for org.hibernate.criterion Example enableLike
public Example enableLike(MatchMode matchMode)
From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java
License:Apache License
/** * Used by {@link #findByExample(Object)} to create an {@link Example} instance. * //from w w w . ja va2 s . com * @todo add criteria for property types not handled by Example (primary keys, associations, * etc) * @return an {@link Example}. */ public Example createExample(T entity) { Example example = Example.create(entity); example.enableLike(MatchMode.ANYWHERE); example.excludeZeroes(); example.ignoreCase(); return example; }
From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java
License:Open Source License
@Override public List listByExample(Object example) { HibernateUtility.getSession().clear(); Criteria criteria = HibernateUtility.getSession().createCriteria(example.getClass()); Example sample = Example.create(example); sample.enableLike(MatchMode.ANYWHERE); sample.ignoreCase();// www .j a v a 2 s.c om criteria.add(sample); return criteria.list(); }
From source file:br.com.itw.commons.persistence.CoreRepository.java
License:Apache License
public Page<T> search(T entity, Pageable pageable) { if (pageable == null) { pageable = new PageRequest(0, 10); }//w ww . j a v a2s .co m Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(entity.getClass()); // Prepare Example Example example = Example.create(entity); criteria.add(example.enableLike(MatchMode.ANYWHERE).ignoreCase()); // Count Long totalItems = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); // Pageable result Result criteria.setProjection(null).setResultTransformer(CriteriaSpecification.ROOT_ENTITY); List<T> result = criteria.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize()) .setMaxResults(pageable.getPageSize()).list(); return (Page<T>) new PageImpl<T>(result, pageable, totalItems); }
From source file:br.com.itw.qopsearch.api.persistence.core.FeatureProductRepositoryImpl.java
License:Apache License
@Override public Page<ProductFeature> search(ProductFeature productFeature, Pageable pageable) { if (pageable == null) { pageable = new PageRequest(0, 10); }/*from w w w.j a v a2 s. c o m*/ Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(ProductFeature.class); // Prepare Example Example example = Example.create(productFeature); criteria.add(example.enableLike(MatchMode.ANYWHERE).ignoreCase()); if (productFeature.getFeature() != null && productFeature.getFeature().getId() != null) { criteria.add(Restrictions.eq("feature.id", productFeature.getFeature().getId())); } if (productFeature.getProduct() != null && productFeature.getProduct().getId() != null) { criteria.add(Restrictions.eq("product.id", productFeature.getProduct().getId())); } return (Page<ProductFeature>) PageableHelper.getPage(criteria, pageable); }
From source file:br.com.itw.qopsearch.api.persistence.core.FeatureRepositoryImpl.java
License:Apache License
@Override public Page<Feature> search(Feature feature, Pageable pageable) { if (pageable == null) { pageable = new PageRequest(0, 10); }// w ww .j av a 2 s .co m Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(Feature.class); // Prepare Example Example example = Example.create(feature); criteria.add(example.enableLike(MatchMode.ANYWHERE).ignoreCase()); return (Page<Feature>) PageableHelper.getPage(criteria, pageable); }
From source file:br.com.itw.qopsearch.api.persistence.core.ProductRepositoryImpl.java
License:Apache License
@Override public Page<Product> search(Product product, Pageable pageable) { if (pageable == null) { pageable = new PageRequest(0, 10); }/* w w w . j av a2s . com*/ Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(Product.class); // Prepare Example Example example = Example.create(product); criteria.add(example.enableLike(MatchMode.ANYWHERE).ignoreCase()); return (Page<Product>) PageableHelper.getPage(criteria, pageable); }
From source file:br.com.reindex.suri.framework.dao.DaoSupport.java
License:Open Source License
/** * Metodo responsavel por recuperar todos os objetos de uma tabela da base de dados de acordo * com o exemplo passado. /* www. j a v a2s. c o m*/ * * @param filtro * @param matchMode * @param ignoreCase * @return lista */ public List<T> retrieveByExample(T filtro, MatchMode matchMode, boolean ignoreCase) { Example example = Example.create(filtro); if (matchMode != null) { example = example.enableLike(matchMode); } if (ignoreCase) { example = example.ignoreCase(); } return getSession().createCriteria(tipo).add(example).list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a lista de entidades filtradas pelos parametros informados * @param <T>//from w w w . j a v a 2 s. co m * @param classe * @param filtro * @param matchMode * @param ignoreCase * @return lista de entidades */ @SuppressWarnings("unchecked") public <T> List<T> retrieveByExample(Class<T> classe, T filtro, MatchMode matchMode, boolean ignoreCase) { Example example = Example.create(filtro); if (matchMode != null) example = example.enableLike(matchMode); if (ignoreCase) example = example.ignoreCase(); return getSession().createCriteria(classe).add(example).list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a entidade filtrada pelos parametros informados * @param <T>/*from w ww .j a va 2s. c om*/ * @param classe * @param filtro * @param matchMode * @param ignoreCase * @return lista de entidades */ @SuppressWarnings("unchecked") public <T> T retrieveUniqueByExample(Class<T> classe, T filtro, MatchMode matchMode, boolean ignoreCase) { Example example = Example.create(filtro); if (matchMode != null) example = example.enableLike(matchMode); if (ignoreCase) example = example.ignoreCase(); return (T) getSession().createCriteria(classe).add(example).uniqueResult(); }
From source file:br.com.tcc.service.persistence.CriteriaHelper.java
/** * Cria um exemplo da etidade para buscas. O padro de buscas por exemplo do framework Celula Tronco Java segue os seguintes termos: * <ol>/*from w w w. ja v a2s .c o m*/ * <li> Case igonorado para propriedades String</li> * <li>O operador "like" habilitado para todos os atributos String, buscando o termo em qualquer parte da String.</li> * <li>PropertySelector ser {@link NotNullOrBlankProperySelector}.</li> * </ol> * @param <T> Tipo de Entidade * @param entity entidade * @return exemplo de T */ public static <T extends IEntity<? extends Serializable>> Example createExample(final T entity) { final Example example = Example.create(entity); example.ignoreCase(); example.enableLike(MatchMode.ANYWHERE); example.setPropertySelector(NotNullOrBlankProperySelector.getInstance()); return example; }