Example usage for org.hibernate.criterion Example enableLike

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

Introduction

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

Prototype

public Example enableLike() 

Source Link

Document

Use the "like" operator for all string-valued properties.

Usage

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 ww  .  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();
    }
}

From source file:gov.nih.nci.cabig.caaers.dao.AdverseEventDao.java

License:BSD License

private Example addOptions(Example example) {
    example.enableLike();
    example.ignoreCase();
    return example;
}

From source file:it.archiworld.addressbook.AddressbookBean.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
public List<Address> searchAddress(Address address) throws Throwable {
    Session session = ((HibernateSession) manager).getHibernateSession();
    Example example = Example.create(address);
    example.ignoreCase();// w  w  w .  j av  a2s  .  c o  m
    example.excludeZeroes();
    example.enableLike();
    if (address instanceof Member)
        return session.createCriteria(Member.class).add(example).addOrder(Order.asc("lastname"))
                .setFetchMode("renewal", FetchMode.SELECT).setFetchMode("specializations", FetchMode.SELECT)
                .setFetchMode("formations", FetchMode.SELECT).setFetchMode("committeemembers", FetchMode.SELECT)
                .list();
    if (address instanceof Person) {
        List<Address> result = session.createCriteria(Person.class).add(example).addOrder(Order.asc("lastname"))
                .list();
        List<Address> result2 = new ArrayList<Address>();
        for (int i = 0; i < result.size(); i++)
            if (!(result.get(i) instanceof Member) && !(result.get(i) instanceof ServiceMember))
                result2.add(result.get(i));
        return result2;
    }
    if (address instanceof Company) {
        return session.createCriteria(Company.class).add(example).addOrder(Order.asc("denomination")).list();
    }
    return new ArrayList<Address>();
}

From source file:org.emonocot.persistence.dao.hibernate.TaxonDaoImpl.java

License:Open Source License

@Override
public Page<Taxon> searchByExample(Taxon example, boolean ignoreCase, boolean useLike) {
    Example criterion = Example.create(example);
    if (ignoreCase) {
        criterion.ignoreCase();//  w w w. j a va  2 s.  c  o m
    }
    if (useLike) {
        criterion.enableLike();
    }
    Session session = getSession();
    Criteria criteria = session.createCriteria(Taxon.class);
    criteria.add(criterion);

    if (example.getNamePublishedIn() != null) {
        Example criterion2 = Example.create(example.getNamePublishedIn());
        if (ignoreCase) {
            criterion2.ignoreCase();
        }
        if (useLike) {
            criterion2.enableLike();
        }
        criteria.createCriteria("namePublishedIn").add(criterion2);
    }

    if (example.getNameAccordingTo() != null) {
        Example criterion3 = Example.create(example.getNameAccordingTo());
        if (ignoreCase) {
            criterion3.ignoreCase();
        }
        if (useLike) {
            criterion3.enableLike();
        }
        criteria.createCriteria("nameAccordingTo").add(criterion3);
    }

    List<Taxon> results = (List<Taxon>) criteria.list();
    logger.debug("List of taxa:" + results.size());
    Page<Taxon> page = new DefaultPageImpl<Taxon>(results.size(), null, null, results, null);
    return page;
}