本文整理汇总了Java中org.apache.deltaspike.data.api.criteria.Criteria类的典型用法代码示例。如果您正苦于以下问题:Java Criteria类的具体用法?Java Criteria怎么用?Java Criteria使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Criteria类属于org.apache.deltaspike.data.api.criteria包,在下文中一共展示了Criteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paginate
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
public List<T> paginate(Filter<T> filter) {
Criteria<T, T> criteria = configRestrictions(filter);
String sortField = filter.getSortField();
if (sortField != null) {
SingularAttribute sortAttribute = entityManager.getMetamodel().entity(entityClass).getSingularAttribute(sortField);
if (filter.getAdminSort().equals(AdminSort.UNSORTED)) {
filter.setAdminSort(AdminSort.ASCENDING);
}
if (filter.getAdminSort().equals(AdminSort.ASCENDING)) {
criteria.orderAsc(sortAttribute);
} else {
criteria.orderDesc(sortAttribute);
}
}
return criteria.createQuery()
.setFirstResult(filter.getFirst())
.setMaxResults(filter.getPageSize())
.getResultList();
}
示例2: findByNomeETelefone
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
public List<Pessoa> findByNomeETelefone(String nome, String numero) {
log.trace("Entrou em findByNomeETelefone");
Criteria<Pessoa, Pessoa> crit = criteria().
distinct().
fetch(Pessoa_.telefones);
if (nome != null && !nome.trim().isEmpty()) {
log.debug("Filtrando por nome");
crit.like(Pessoa_.nome, "%" + nome + "%");
}
if (numero != null && !numero.trim().isEmpty()) {
log.debug("Filtrando por número");
crit.join(Pessoa_.telefones,
where(Telefone.class).
like(Telefone_.numero, "%" + numero + "%"));
}
log.debug("Retornar os resultados");
return crit.orderAsc(Pessoa_.id).getResultList();
}
示例3: shouldFindCarByMultipleExampleCriteria
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Test
@DataSet("cars-full.yml")
public void shouldFindCarByMultipleExampleCriteria() {
Car carExample = new Car().model("SE");
SalesPoint salesPoint = new SalesPoint(new SalesPointPK(2L, 1L));
List<SalesPoint> salesPoints = new ArrayList<>();
salesPoints.add(salesPoint);
carExample.setSalesPoints(salesPoints);
Brand brand = new Brand(2L);
carExample.setBrand(brand);//model SE, brand: Nissan, salesPint: Nissan Sales
Criteria<Car,Car> criteriaByExample = carService.example(carExample, Car_.model, Car_.brand,Car_.salesPoints);
assertThat(carService.count(criteriaByExample).intValue()).isEqualTo(1);
List<Car> carsFound = criteriaByExample.getResultList();
assertThat(carsFound).isNotNull().hasSize(1)
.extracting("name")
.contains("Sentra");
}
示例4: shouldFindCarByExampleUsingAnExistingCriteria
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Test
@DataSet("cars-full.yml")
public void shouldFindCarByExampleUsingAnExistingCriteria() {
Criteria<Car,Car> criteria = crudService.criteria()
.join(Car_.brand,carService.where(Brand.class)
.eq(Brand_.name,"Nissan")
); //cars with brand nissan
Car carExample = new Car().model("SE");
//will add a restriction by car 'model' using example criteria
Criteria<Car,Car> criteriaByExample = carService.example(criteria,carExample, Car_.model);
criteriaByExample = carService.example(criteriaByExample,carExample,Car_.salesPoints);
assertThat(carService.count(criteriaByExample).intValue()).isEqualTo(1);
List<Car> carsFound = criteriaByExample.getResultList();
assertThat(carsFound).isNotNull().hasSize(1)
.extracting("name")
.contains("Sentra");
}
示例5: addEqExampleRestriction
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
private void addEqExampleRestriction(Criteria criteria, T example, Attribute<T, ?> attribute) {
if (attribute.getJavaMember() instanceof Field) {
Field field = (Field) attribute.getJavaMember();
field.setAccessible(true);
try {
Object value = field.get(example);
if (value != null) {
LOG.fine(String.format("Adding an 'eq' restriction on attribute %s using value %s.", attribute.getName(), value));
criteria.eq((SingularAttribute) attribute, value);
}
} catch (IllegalAccessException e) {
LOG.warning(String.format("Could not get value from field %s of entity %s.", field.getName(), example.getClass().getName()));
}
}
}
示例6: addInExampleRestriction
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
private void addInExampleRestriction(Criteria criteria, T example, Attribute<T, ?> attribute) {
PluralAttribute<T, ?, ?> listAttribute = (PluralAttribute<T, ?, ?>) attribute;
Class joinClass = listAttribute.getElementType().getJavaType();
Criteria joinCriteria = where(joinClass, JoinType.LEFT);
if (listAttribute instanceof ListAttribute) {
criteria.join((ListAttribute) listAttribute, joinCriteria);
} else if (listAttribute instanceof SetAttribute) {
criteria.join((SetAttribute) listAttribute, joinCriteria);
} else if (listAttribute instanceof MapAttribute) {
criteria.join((MapAttribute) listAttribute, joinCriteria);
} else if (listAttribute instanceof CollectionAttribute) {
criteria.join((CollectionAttribute) listAttribute, joinCriteria);
}
if (attribute.getJavaMember() instanceof Field) {
Field field = (Field) attribute.getJavaMember();
field.setAccessible(true);
try {
Object value = field.get(example);
if (value != null) {
LOG.fine(String.format("Adding an ín'restriction on attribute %s using value %s.", attribute.getName(), value));
Collection<PersistenceEntity> association = (Collection<PersistenceEntity>) value;
SingularAttribute id = getEntityManager().getMetamodel().entity(listAttribute.getElementType().getJavaType()).getId(association.iterator().next().getId().getClass());
List<Serializable> ids = new ArrayList<>();
for (PersistenceEntity persistenceEntity : association) {
ids.add(persistenceEntity.getId());
}
joinCriteria.in(id, ids);
}
} catch (IllegalAccessException e) {
LOG.warning(String.format("Could not get value from field %s of entity %s.", field.getName(), example.getClass().getName()));
}
}
}
示例7: exampleLike
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
/**
* @param criteria a pre populated criteria to add example based <code>like</code> restrictions
* @param example An entity whose attribute's value will be used for creating a criteria
* @param usingAttributes attributes from example entity to consider.
* @return A criteria restricted by example using <code>likeIgnoreCase</code> for comparing attributes
* @throws RuntimeException If no attribute is provided.
*/
public Criteria exampleLike(Criteria criteria, T example, SingularAttribute<T, String>... usingAttributes) {
if (usingAttributes == null || usingAttributes.length == 0) {
throw new RuntimeException("Please provide attributes to example criteria.");
}
if (criteria == null) {
criteria = criteria();
}
for (SingularAttribute<T, ?> attribute : usingAttributes) {
if (attribute.getJavaMember() instanceof Field) {
Field field = (Field) attribute.getJavaMember();
field.setAccessible(true);
try {
Object value = field.get(example);
if (value != null) {
LOG.fine(String.format("Adding restriction by example on attribute %s using value %s.", attribute.getName(), value));
criteria.likeIgnoreCase(attribute, value.toString());
}
} catch (IllegalAccessException e) {
LOG.warning(String.format("Could not get value from field %s of entity %s.", field.getName(), example.getClass().getName()));
}
}
}
return criteria;
}
示例8: configRestrictions
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
protected Criteria<Car, Car> configRestrictions(Filter<Car> filter) {
Criteria<Car, Car> criteria = criteria();
//create restrictions based on parameters map
if (filter.hasParam("id")) {
criteria.eq(Car_.id, filter.getIntParam("id"));
}
if (filter.hasParam("minPrice") && filter.hasParam("maxPrice")) {
criteria.between(Car_.price, filter.getDoubleParam("minPrice"), filter.getDoubleParam("maxPrice"));
} else if (filter.hasParam("minPrice")) {
criteria.gtOrEq(Car_.price, filter.getDoubleParam("minPrice"));
} else if (filter.hasParam("maxPrice")) {
criteria.ltOrEq(Car_.price, filter.getDoubleParam("maxPrice"));
}
//create restrictions based on filter entity
if (filter.getEntity() != null) {
Car filterEntity = filter.getEntity();
if (filterEntity.hasModel()) {
criteria.likeIgnoreCase(Car_.model, "%" + filterEntity.getModel());
}
if (filterEntity.getPrice() != null) {
criteria.eq(Car_.price, filterEntity.getPrice());
}
if (filterEntity.hasName()) {
criteria.likeIgnoreCase(Car_.name, "%" + filterEntity.getName() + "%");
}
}
return criteria;
}
示例9: select
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public <N> Criteria<C, N> select(Class<N> resultClass, QuerySelection<? super C, ?>... selection)
{
QueryCriteria<C, N> result = new QueryCriteria<C, N>(entityClass, resultClass, entityManager, joinType);
result.builders.addAll(this.builders);
result.distinct = this.distinct;
result.processors.addAll(this.processors);
result.selections.addAll(Arrays.asList(selection));
return result;
}
示例10: internalOr
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@SuppressWarnings("unchecked")
Criteria<C, R> internalOr(Criteria<C, R>... others)
{
List<Criteria<C, R>> list = new LinkedList<Criteria<C, R>>();
list.addAll(Arrays.asList(others));
add(new OrBuilder<C>(list.toArray(new Criteria[list.size()])));
return this;
}
示例11: between
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public <P extends Comparable<? super P>> Criteria<C, R> between(SingularAttribute<? super C, P> att, P lower,
P upper)
{
add(new Between<C, P>(att, lower, upper));
return this;
}
示例12: build
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
{
List<Predicate> and = new ArrayList<Predicate>(criteria.length);
for (Criteria<P, P> c : criteria)
{
and.add(builder.and(
c.predicates(builder, path).toArray(new Predicate[0])));
}
return Arrays.asList(builder.or(and.toArray(new Predicate[0])));
}
示例13: or
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public Criteria<C, R> or(Criteria<C, R>... criteria)
{
return internalOr(criteria);
}
示例14: join
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public <P, E> Criteria<C, R> join(SingularAttribute<? super C, P> att, Criteria<P, P> criteria)
{
add(new JoinBuilder<C, P, E>(criteria, joinType, att));
return this;
}
示例15: fetch
import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public <P, E> Criteria<C, R> fetch(SingularAttribute<? super C, P> att)
{
add(new FetchBuilder<C, P, E>(att, null));
return this;
}