List of usage examples for org.hibernate.criterion Example excludeZeroes
public Example excludeZeroes()
From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java
License:Apache License
/** * Used by {@link #findByExample(Object)} to create an {@link Example} instance. * /* w w w .j ava 2 s . co m*/ * @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:com.github.javarch.persistence.orm.hibernate.DefaultHibernateRepository.java
License:Apache License
/** * Mtodo utilizado para criar o objeto Example. Este objeto utilizado * para realizar a busca por exemplo./*from w w w . j a v a2 s.c o m*/ * * @param objeto * sobre o qual o Example ser criado * @return em objeto do tipo Example */ protected Example createExemple(Object objeto) { Example example = Example.create(objeto); example.enableLike(MatchMode.ANYWHERE); example.excludeZeroes(); example.ignoreCase(); return example; }
From source file:com.wavemaker.runtime.data.task.SearchTask.java
License:Open Source License
private static void addExample(Object o, Criteria c, QueryOptions options) { Example e = Example.create(o); c.add(e);/*from ww w .j av a2s . c o m*/ if (DataServiceLoggers.taskLogger.isDebugEnabled()) { DataServiceLoggers.taskLogger.debug("Added example for " + ObjectUtils.objectToString(o)); } if (options.getTypedMatchMode() != null) { e.enableLike(options.getTypedMatchMode()); } if (options.getExcludeNone()) { e.excludeNone(); } if (options.getExcludeZeros()) { e.excludeZeroes(); } if (options.getIgnoreCase()) { e.ignoreCase(); } }
From source file:edu.utah.further.core.data.service.DaoHibernateImpl.java
License:Apache License
/** * @param <T>/*from ww w .j a v a2s .c om*/ * @param exampleInstance * @param excludeZeros * @param excludeProperty * @return * @see edu.utah.further.core.api.data.Dao#findByExample(edu.utah.further.core.api.data.PersistentEntity, * boolean, java.lang.String[]) */ @Override public <T extends PersistentEntity<?>> List<T> findByExample(final T exampleInstance, final boolean excludeZeros, final String... excludeProperty) { final GenericCriteria crit = createCriteria(exampleInstance.getClass()); final Example example = Example.create(exampleInstance); if (excludeZeros) { example.excludeZeroes(); } for (final String exclude : excludeProperty) { example.excludeProperty(exclude); } crit.add(example); return getNullSafeList(crit.<T>list()); }
From source file:es.urjc.mctwp.dao.GenericDAO.java
License:Open Source License
/** * Create a wuery by example, from object * //from w w w . j a v a2 s . co m * @param obj * @param exclude * @return */ protected Example createExample(Object obj, String[] exclude) { Example result = null; if (obj != null) { result = Example.create(obj); result.enableLike(MatchMode.ANYWHERE); result.excludeZeroes(); result.ignoreCase(); if (exclude != null) for (String prop : exclude) result.excludeProperty(prop); } return result; }
From source file:gov.nih.nci.caarray.dao.AbstractCaArrayDaoImpl.java
License:BSD License
Criterion createExample(Object entity, MatchMode matchMode, boolean excludeNulls, boolean excludeZeroes, Collection<String> excludeProperties) { final Example example = Example.create(entity).enableLike(matchMode).ignoreCase(); if (excludeZeroes) { example.excludeZeroes(); } else if (!excludeNulls) { example.excludeNone();/*from www. ja v a2 s.co m*/ } for (final String property : excludeProperties) { example.excludeProperty(property); } // ID property is not handled by Example, so we have to special case it final PersistentClass pclass = getClassMapping(entity.getClass()); Object idVal = null; if (pclass != null && pclass.hasIdentifierProperty()) { try { idVal = PropertyUtils.getProperty(entity, pclass.getIdentifierProperty().getName()); } catch (final Exception e) { LOG.warn("Could not retrieve identifier value in a by example query, ignoring it", e); } } if (idVal == null) { return example; } else { return Restrictions.and(Restrictions.idEq(idVal), 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();//from www. j a v a 2 s.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.jason.mapmaker.repository.impl.HibernateGenericRepository.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> getByExample(T example) { Example ex = Example.create(example); ex.excludeZeroes(); List<T> results = (List<T>) sessionFactory.getCurrentSession().createCriteria(clazz).add(ex).list(); return results; }
From source file:py.una.pol.karaku.dao.impl.BaseDAOImpl.java
License:Open Source License
protected Criteria generateWhere(final Where<T> where, @Nonnull final Map<String, String> alias, Criteria criteria) {//from ww w.ja v a 2 s. c o m if (where != null) { EntityExample<T> example = where.getExample(); if (example != null && example.getEntity() != null) { Example ejemplo = Example.create(example.getEntity()); ejemplo.enableLike(example.getMatchMode().getMatchMode()); ejemplo.setEscapeCharacter('\\'); if (example.isIgnoreCase()) { ejemplo.ignoreCase(); } if (example.isExcludeZeroes()) { ejemplo.excludeZeroes(); } criteria.add(ejemplo); if (example.getExcluded() != null) { for (String excluded : example.getExcluded()) { ejemplo.excludeProperty(excluded); } } this.configureExample(criteria, example.getEntity()); } for (String s : where.getFetchs()) { criteria.setFetchMode(s, FetchMode.JOIN); } helper.applyClauses(criteria, where, alias); } return criteria; }