当前位置: 首页>>代码示例>>Java>>正文


Java Criteria类代码示例

本文整理汇总了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();
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:22,代码来源:CrudService.java

示例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();
}
 
开发者ID:denisfalqueto,项目名称:jee6poc,代码行数:21,代码来源:PessoaRepository.java

示例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");
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:23,代码来源:CrudServiceIt.java

示例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");
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:23,代码来源:CrudServiceIt.java

示例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()));
        }
    }
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:16,代码来源:CrudService.java

示例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()));
        }
    }
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:35,代码来源:CrudService.java

示例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;
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:36,代码来源:CrudService.java

示例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;
    }
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:35,代码来源:CarService.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:11,代码来源:QueryCriteria.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:9,代码来源:QueryCriteria.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:8,代码来源:QueryCriteria.java

示例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])));
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:12,代码来源:OrBuilder.java

示例13: or

import org.apache.deltaspike.data.api.criteria.Criteria; //导入依赖的package包/类
@Override
public Criteria<C, R> or(Criteria<C, R>... criteria)
{
    return internalOr(criteria);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:6,代码来源:QueryCriteria.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:7,代码来源:QueryCriteria.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:7,代码来源:QueryCriteria.java


注:本文中的org.apache.deltaspike.data.api.criteria.Criteria类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。