Java tutorial
// ======================================================================== // Copyright (C) YOYO Project Team. All rights reserved. // GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 // http://www.gnu.org/licenses/agpl-3.0.txt // ======================================================================== package yoyo.actor.service.domain.misc; import static yoyo.actor.service.domain.misc.Notice_.*; import java.math.BigDecimal; import javax.enterprise.inject.Default; import javax.inject.Inject; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import org.apache.commons.lang3.StringUtils; import yoyo.actor.service.domain.misc.News; import yoyo.actor.service.domain.misc.PersistenceServiceAnnotation.NewsPersistenceService; import yoyo.framework.enterprise.domain.AbstractQueryRepositoryImpl; import yoyo.framework.enterprise.infra.persistence.QueryPersistenceService; import yoyo.framework.standard.shared.SimpleFilter; /** * ??? * @author nilcy */ @Default // @Tracer public class NewsRepositoryImpl extends AbstractQueryRepositoryImpl<News, BigDecimal, SimpleFilter> implements NewsRepository { /** ?? */ private static final long serialVersionUID = -7181173647550897989L; /** */ @Inject @NewsPersistenceService private QueryPersistenceService<News, BigDecimal> service; /** {@inheritDoc} */ @Override protected QueryPersistenceService<News, BigDecimal> getPersistenceService() { return service; } /** * {@inheritDoc} * <dl> * <dt>??</dt> * <dd>??NULL????</dd> * <dt>?</dt> * <dd>?????????</dd> * </dl> */ @Override protected Predicate expression(final SimpleFilter filter) { assert filter != null; if (StringUtils.isEmpty(filter.getKeyword())) { return super.expression(filter); } final CriteriaBuilder b = service.builder(); final Root<News> r = service.root(); return b.or(b.like(r.get(title), wrapWildcard(filter.getKeyword())), b.like(r.get(description), wrapWildcard(filter.getKeyword())), b.like(r.get(category), wrapWildcard(filter.getKeyword()))); } }