Example usage for org.hibernate.criterion Example setPropertySelector

List of usage examples for org.hibernate.criterion Example setPropertySelector

Introduction

In this page you can find the example usage for org.hibernate.criterion Example setPropertySelector.

Prototype

public Example setPropertySelector(PropertySelector selector) 

Source Link

Document

Set the property selector to use.

Usage

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>/* ww w . ja v a2 s . c  om*/
 * <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;
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

License:Apache License

@SuppressWarnings("unchecked")
public List<T> search(final T exampleEntity) throws ServiceException {
    try {//from w w  w  .ja  v  a  2 s  .  c o  m
        Validate.notNull(exampleEntity, "Example entity must not be null");
        logger.debug("Search: " + exampleEntity.toString());
        Session session = ((Session) currentEntityManager().getDelegate());
        Criteria criteria = session.createCriteria(getObjectClass());
        Example example = Example.create(exampleEntity);
        example.setPropertySelector(NOT_NULL_OR_EMPTY);
        example.ignoreCase();
        example.enableLike();
        logger.debug("Search example object: " + example.toString());
        criteria.add(example);
        criteria.setMaxResults(getMaxResults());
        criteria.setCacheable(true);
        return criteria.list();
    } catch (PersistenceException e) {
        logger.error(e.getCause(), e);
        throw new ServiceException("Can't search object list from database", e);
    } finally {
        closeEntityManager();
    }
}