org.apache.deltaspike.data.api.criteria.Criteria Java Examples
The following examples show how to use
org.apache.deltaspike.data.api.criteria.Criteria.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreditCardInvoiceRepository.java From web-budget with GNU General Public License v3.0 | 6 votes |
/** * Build the {@link Criteria} to search for {@link CreditCardInvoice} * * @param filter value * @param invoiceState to filter * @return the {@link Criteria} ready to search */ @SuppressWarnings("unchecked") default Criteria<CreditCardInvoice, CreditCardInvoice> buildCriteria(String filter, InvoiceState invoiceState) { final Criteria<CreditCardInvoice, CreditCardInvoice> criteria = this.criteria(); if (invoiceState != null) { criteria.eq(CreditCardInvoice_.invoiceState, invoiceState); } if (StringUtils.isNotBlank(filter)) { criteria.or( this.criteria().join(CreditCardInvoice_.card, where(Card.class) .likeIgnoreCase(Card_.name, this.likeAny(filter))), this.criteria().join(CreditCardInvoice_.financialPeriod, where(FinancialPeriod.class) .likeIgnoreCase(FinancialPeriod_.identification, this.likeAny(filter))) ); } criteria.orderAsc(CreditCardInvoice_.financialPeriod); return criteria; }
Example #2
Source File: CreditCardInvoiceRepository.java From web-budget with GNU General Public License v3.0 | 6 votes |
/** * Build the {@link Criteria} to search for {@link CreditCardInvoice} * * @param filter value * @param invoiceState to filter * @return the {@link Criteria} ready to search */ @SuppressWarnings("unchecked") default Criteria<CreditCardInvoice, CreditCardInvoice> buildCriteria(String filter, InvoiceState invoiceState) { final Criteria<CreditCardInvoice, CreditCardInvoice> criteria = this.criteria(); if (invoiceState != null) { criteria.eq(CreditCardInvoice_.invoiceState, invoiceState); } if (StringUtils.isNotBlank(filter)) { criteria.or( this.criteria().join(CreditCardInvoice_.card, where(Card.class) .likeIgnoreCase(Card_.name, this.likeAny(filter))), this.criteria().join(CreditCardInvoice_.financialPeriod, where(FinancialPeriod.class) .likeIgnoreCase(FinancialPeriod_.identification, this.likeAny(filter))) ); } criteria.orderAsc(CreditCardInvoice_.financialPeriod); return criteria; }
Example #3
Source File: PeriodMovementRepository.java From web-budget with GNU General Public License v3.0 | 6 votes |
/** * Use this method to find all {@link PeriodMovement} using the lazy load strategy * * @param filter the {@link PeriodMovementFilter} * @param start starting row * @param pageSize page size * @return the {@link Page} filled with the {@link PeriodMovement} found */ default Page<PeriodMovement> findAllBy(PeriodMovementFilter filter, int start, int pageSize) { final int totalRows = this.countPages(filter); final Criteria<PeriodMovement, PeriodMovement> criteria = this.buildCriteria(filter); criteria.orderDesc(PeriodMovement_.financialPeriod); criteria.orderDesc(PeriodMovement_.createdOn); final List<PeriodMovement> data = criteria.createQuery() .setFirstResult(start) .setMaxResults(pageSize) .getResultList(); return Page.of(data, totalRows); }
Example #4
Source File: CostCenterRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<CostCenter, CostCenter>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(CostCenter_.description, this.likeAny(filter)), this.criteria().likeIgnoreCase(CostCenter_.name, this.likeAny(filter))); }
Example #5
Source File: DeltaSpikeRepository.java From library with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @return */ @Override default List<T> findAllInactive() { final Criteria<T, T> criteria = criteria() .eq(this.getEntityStateProperty(), false); this.applyOrder(criteria); return criteria.getResultList(); }
Example #6
Source File: OrBuilder.java From deltaspike with Apache License 2.0 | 5 votes |
@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]))); }
Example #7
Source File: RefuelingRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Refueling, Refueling>> getRestrictions(String filter) { final String anyFilter = this.likeAny(filter); return List.of( this.criteria().likeIgnoreCase(Refueling_.place, this.likeAny(filter)), this.criteria().join(Refueling_.vehicle, where(Vehicle.class).likeIgnoreCase(Vehicle_.identification, anyFilter)), this.criteria().join(Refueling_.movementClass, where(MovementClass.class).likeIgnoreCase(MovementClass_.name, anyFilter)), this.criteria().join(Refueling_.financialPeriod, where(FinancialPeriod.class).likeIgnoreCase(FinancialPeriod_.identification, anyFilter))); }
Example #8
Source File: UserRepository.java From library with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<User, User>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(User_.name, this.likeAny(filter)), this.criteria().likeIgnoreCase(User_.username, this.likeAny(filter)), this.criteria().likeIgnoreCase(User_.email, this.likeAny(filter))); }
Example #9
Source File: DeltaSpikeRepository.java From library with Apache License 2.0 | 5 votes |
/** * Method used to apply the filters to the current query * * @param filter to be applied * @param active entity state indicating active or inactive (true or false) * @return {@link List} of all {@link Criteria} to be used as query filters */ default Criteria<T, T> applyFilters(String filter, Boolean active) { final Criteria<T, T> criteria = criteria(); if (isNotBlank(filter)) { criteria.or(this.getRestrictions(filter)); } if (active != null) { criteria.eq(this.getEntityStateProperty(), active); } return criteria; }
Example #10
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 5 votes |
@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; }
Example #11
Source File: MovementClassRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<MovementClass, MovementClass>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(MovementClass_.name, this.likeAny(filter)), this.criteria().join(MovementClass_.costCenter, where(CostCenter.class).likeIgnoreCase(CostCenter_.name, this.likeAny(filter)))); }
Example #12
Source File: VehicleRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Vehicle, Vehicle>> getRestrictions(String filter) { return List.of( this.criteria().eqIgnoreCase(Vehicle_.identification, this.likeAny(filter)), this.criteria().eqIgnoreCase(Vehicle_.brand, this.likeAny(filter)), this.criteria().eqIgnoreCase(Vehicle_.model, this.likeAny(filter)), this.criteria().eqIgnoreCase(Vehicle_.licensePlate, this.likeAny(filter))); }
Example #13
Source File: DeltaSpikeRepository.java From library with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @return */ @Override default List<T> findAllActive() { final Criteria<T, T> criteria = criteria() .eq(this.getEntityStateProperty(), true); this.applyOrder(criteria); return criteria.getResultList(); }
Example #14
Source File: WalletBalanceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Find the {@link WalletBalance} by a given filter * * @param filter to be used on the search process * @return a {@link List} of the {@link WalletBalance} found */ default List<WalletBalance> findByFilter(WalletBalanceFilter filter) { final Criteria<WalletBalance, WalletBalance> criteria = this.criteria(); final List<Criteria<WalletBalance, WalletBalance>> restrictions = new ArrayList<>(); if (filter.getReasonType() != null) { restrictions.add(this.criteria().eq(WalletBalance_.reasonType, filter.getReasonType())); } if (filter.getBalanceType() != null) { restrictions.add(this.criteria().eq(WalletBalance_.balanceType, filter.getBalanceType())); } if (filter.getOperationDate() != null) { final var start = filter.getOperationDate().atTime(0, 0); final var end = filter.getOperationDate().atTime(23, 59); restrictions.add(this.criteria().between(WalletBalance_.movementDateTime, start, end)); } if (!restrictions.isEmpty()) { criteria.or(restrictions); } criteria.join(WalletBalance_.wallet, where(Wallet.class).eq(Wallet_.id, filter.getWallet().getId())); return criteria.getResultList(); }
Example #15
Source File: TransferenceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Find all transference using a given filter * * @param filter used to search for {@link Transference} * @return a list of {@link Transference} found */ default List<Transference> findByFilter(TransferenceFilter filter) { final Criteria<Transference, Transference> criteria = this.criteria(); final List<Criteria<Transference, Transference>> restrictions = new ArrayList<>(); if (filter.getOriginWallet() != null) { restrictions.add(this.criteria().join(Transference_.origin, where(Wallet.class).eq(Wallet_.id, filter.getOriginWallet().getId()))); } if (filter.getDestinationWallet() != null) { restrictions.add(this.criteria().join(Transference_.destination, where(Wallet.class).eq(Wallet_.id, filter.getDestinationWallet().getId()))); } if (filter.getOperationDate() != null) { restrictions.add(this.criteria().eq(Transference_.transferDate, filter.getOperationDate())); } if (!restrictions.isEmpty()) { criteria.or(restrictions); } return criteria.getResultList(); }
Example #16
Source File: RefuelingRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Refueling, Refueling>> getRestrictions(String filter) { final String anyFilter = this.likeAny(filter); return List.of( this.criteria().likeIgnoreCase(Refueling_.place, this.likeAny(filter)), this.criteria().join(Refueling_.vehicle, where(Vehicle.class).likeIgnoreCase(Vehicle_.identification, anyFilter)), this.criteria().join(Refueling_.movementClass, where(MovementClass.class).likeIgnoreCase(MovementClass_.name, anyFilter)), this.criteria().join(Refueling_.financialPeriod, where(FinancialPeriod.class).likeIgnoreCase(FinancialPeriod_.identification, anyFilter))); }
Example #17
Source File: UserRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<User, User>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(User_.name, this.likeAny(filter)), this.criteria().likeIgnoreCase(User_.username, this.likeAny(filter)), this.criteria().likeIgnoreCase(User_.email, this.likeAny(filter))); }
Example #18
Source File: DefaultRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Helper method to create {@link Criteria} instances, do not override this method or if you do this, keep in mind * that you are change a core behavior and problems here means problems in all queries inside de the application * * @param filter the filters provided by the {@link #getRestrictions(String)} * @param active the active property provided by the {@link #getEntityStateProperty()} * @return a new criteria ready to query */ default Criteria<T, T> buildCriteria(String filter, Boolean active) { final Criteria<T, T> criteria = criteria(); if (isNotBlank(filter)) { criteria.or(this.getRestrictions(filter)); } if (active != null) { criteria.eq(this.getEntityStateProperty(), active); } return criteria; }
Example #19
Source File: MovementClassRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<MovementClass, MovementClass>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(MovementClass_.name, this.likeAny(filter)), this.criteria().join(MovementClass_.costCenter, where(CostCenter.class).likeIgnoreCase(CostCenter_.name, this.likeAny(filter)))); }
Example #20
Source File: CardRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Card, Card>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(Card_.name, this.likeAny(filter)), this.criteria().likeIgnoreCase(Card_.number, this.likeAny(filter)), this.criteria().likeIgnoreCase(Card_.flag, this.likeAny(filter)), this.criteria().likeIgnoreCase(Card_.owner, this.likeAny(filter))); }
Example #21
Source File: ContactRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Contact, Contact>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(Contact_.name, this.likeAny(filter)), this.criteria().likeIgnoreCase(Contact_.city, this.likeAny(filter)), this.criteria().likeIgnoreCase(Contact_.email, this.likeAny(filter)), this.criteria().likeIgnoreCase(Contact_.city, this.likeAny(filter)), this.criteria().likeIgnoreCase(Contact_.document, this.likeAny(filter))); }
Example #22
Source File: WalletBalanceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Find the {@link WalletBalance} by a given filter * * @param filter to be used on the search process * @return a {@link List} of the {@link WalletBalance} found */ default List<WalletBalance> findByFilter(WalletBalanceFilter filter) { final Criteria<WalletBalance, WalletBalance> criteria = this.criteria(); final List<Criteria<WalletBalance, WalletBalance>> restrictions = new ArrayList<>(); if (filter.getReasonType() != null) { restrictions.add(this.criteria().eq(WalletBalance_.reasonType, filter.getReasonType())); } if (filter.getBalanceType() != null) { restrictions.add(this.criteria().eq(WalletBalance_.balanceType, filter.getBalanceType())); } if (filter.getOperationDate() != null) { final var start = filter.getOperationDate().atTime(0, 0); final var end = filter.getOperationDate().atTime(23, 59); restrictions.add(this.criteria().between(WalletBalance_.movementDateTime, start, end)); } if (!restrictions.isEmpty()) { criteria.or(restrictions); } criteria.join(WalletBalance_.wallet, where(Wallet.class).eq(Wallet_.id, filter.getWallet().getId())); return criteria.getResultList(); }
Example #23
Source File: WalletRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Collection<Criteria<Wallet, Wallet>> getRestrictions(String filter) { return List.of( this.criteria().likeIgnoreCase(Wallet_.name, this.likeAny(filter)), this.criteria().likeIgnoreCase(Wallet_.account, this.likeAny(filter)), this.criteria().likeIgnoreCase(Wallet_.agency, this.likeAny(filter)), this.criteria().likeIgnoreCase(Wallet_.bank, this.likeAny(filter))); }
Example #24
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 5 votes |
@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; }
Example #25
Source File: JoinBuilder.java From deltaspike with Apache License 2.0 | 4 votes |
public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, ListAttribute<? super P, R> list) { this(criteria, joinType); this.list = list; }
Example #26
Source File: JoinBuilder.java From deltaspike with Apache License 2.0 | 4 votes |
public JoinBuilder(Criteria<R, R> criteria, JoinType joinType, MapAttribute<? super P, E, R> map) { this(criteria, joinType); this.map = map; }
Example #27
Source File: FixedMovementRepository.java From web-budget with GNU General Public License v3.0 | 4 votes |
/** * Method used to search for {@link FixedMovement} using pagination * * @param filter to be applied * @param start starting point * @param pageSize maximum size of the page * @return a {@link Page} with the {@link FixedMovement} found */ default Page<FixedMovement> findAllBy(FixedMovementFilter filter, int start, int pageSize) { final int totalRows = this.countPages(filter); final Criteria<FixedMovement, FixedMovement> criteria = this.buildCriteria(filter); criteria.orderDesc(FixedMovement_.createdOn); final List<FixedMovement> data = criteria.createQuery() .setFirstResult(start) .setMaxResults(pageSize) .getResultList(); return Page.of(data, totalRows); }
Example #28
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public <P extends Collection<?>> Criteria<C, R> notEmpty(SingularAttribute<? super C, P> att) { add(new IsNotEmpty<C, P>(att)); return this; }
Example #29
Source File: CriteriaSupportHandler.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public Criteria<E, E> criteria() { return new QueryCriteria<E, E>(getEntityClass(), getEntityClass(), getEntityManager()); }
Example #30
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public <P extends Comparable<? super P>> Criteria<C, R> ltOrEq(SingularAttribute<? super C, P> att, P value) { add(new LessThanOrEqual<C, P>(att, value), value); return this; }