org.apache.deltaspike.data.api.Query Java Examples

The following examples show how to use org.apache.deltaspike.data.api.Query. 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: RepositoryMethodMetadataInitializer.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private void initRequiresTransaction(RepositoryMethodMetadata repositoryMethodMetadata)
{
    boolean requiresTransaction = false;
    
    if (ClassUtils.containsMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod()))
    {
        Method originalMethod = ClassUtils.extractMethod(EntityRepositoryHandler.class,
                repositoryMethodMetadata.getMethod());
        if (originalMethod.isAnnotationPresent(RequiresTransaction.class))
        {
            requiresTransaction = true;
        }
    }

    Query query = repositoryMethodMetadata.getQuery();
    Modifying modifying = repositoryMethodMetadata.getModifying();
    
    if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying != null)
    {
        requiresTransaction = true;
    }
    
    repositoryMethodMetadata.setRequiresTransaction(requiresTransaction);
}
 
Example #2
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of revenues on a list of {@link FinancialPeriod}
 *
 * @return the total value of revenues
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND mc.movementClassType = 'REVENUE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalRevenues();
 
Example #3
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalOpen()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of open {@link PeriodMovement}
 */
@Query("SELECT COALESCE(SUM(mv.value), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "AND fp.id IN (?1) " +
        "AND mv.periodMovementState = 'OPEN'")
BigDecimal calculateTotalOpen(List<Long> periods);
 
Example #4
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalRevenues()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of revenues
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND fp.id IN (?1) " +
        "AND mc.movementClassType = 'REVENUE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalRevenues(List<Long> periods);
 
Example #5
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of revenues on a list of {@link FinancialPeriod}
 *
 * @return the total value of revenues
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND mc.movementClassType = 'REVENUE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalRevenues();
 
Example #6
Source File: AnnotatedQueryBuilder.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CdiQueryInvocationContext context)
{
    Method method = context.getMethod();
    Query query = method.getAnnotation(Query.class);
    javax.persistence.Query jpaQuery = createJpaQuery(query, context);
    return context.executeQuery(jpaQuery);
}
 
Example #7
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of expenses on a list of {@link FinancialPeriod}
 *
 * @return the total value of expenses
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mc.movementClassType = 'EXPENSE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalExpenses();
 
Example #8
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of expenses on a list of {@link FinancialPeriod}
 *
 * @return the total value of expenses
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mc.movementClassType = 'EXPENSE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalExpenses();
 
Example #9
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalExpenses()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of expenses
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND fp.id IN (?1) " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mc.movementClassType = 'EXPENSE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalExpenses(List<Long> periods);
 
Example #10
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalPaidAndReceived()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of paid and received {@link PeriodMovement}
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "AND fp.id IN (?1) " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalPaidAndReceived(List<Long> periods);
 
Example #11
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of paid or received {@link PeriodMovement} on a list of {@link FinancialPeriod}
 *
 * @return the total value of paid and received {@link PeriodMovement}
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalPaidAndReceived();
 
Example #12
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalRevenues()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of revenues
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "INNER JOIN Apportionment ap on ap.movement = mv.id " +
        "INNER JOIN MovementClass mc on mc.id = ap.movementClass.id " +
        "AND fp.id IN (?1) " +
        "AND mc.movementClassType = 'REVENUE' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalRevenues(List<Long> periods);
 
Example #13
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as {@link #calculateTotalPaidAndReceived()} but filtering by {@link FinancialPeriod}
 *
 * @param periods the list of {@link FinancialPeriod} to search for
 * @return the total value of paid and received {@link PeriodMovement}
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN FinancialPeriod fp ON fp.id = mv.financialPeriod.id " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "AND fp.id IN (?1) " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalPaidAndReceived(List<Long> periods);
 
Example #14
Source File: LaunchRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method to count how much {@link Launch} we have for a given {@link FixedMovement} at open {@link FinancialPeriod}
 *
 * @param fixedMovement to search for {@link Launch}
 * @return the total of {@link Launch} found for this {@link FixedMovement}
 */
@Query("SELECT COUNT(*) " +
        "FROM Launch la " +
        "WHERE la.fixedMovement = ?1 " +
        "AND la.financialPeriod.id IN " +
        "   (SELECT fp.id FROM FinancialPeriod fp WHERE fp.closed = false AND fp.expired = false)")
long countByFixedMovementAtCurrentFinancialPeriod(FixedMovement fixedMovement);
 
Example #15
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the total of paid or received {@link PeriodMovement} on a list of {@link FinancialPeriod}
 *
 * @return the total value of paid and received {@link PeriodMovement}
 */
@Query("SELECT COALESCE(SUM(pm.paidValue), 0) " +
        "FROM PeriodMovement mv " +
        "INNER JOIN Payment pm ON pm.id = mv.payment.id " +
        "AND pm.paymentMethod <> 'CREDIT_CARD' " +
        "AND mv.periodMovementState <> 'OPEN'")
BigDecimal calculateTotalPaidAndReceived();
 
Example #16
Source File: SimpleRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(named = Simple.BY_NAME_LIKE, singleResult = OPTIONAL)
public abstract Simple findByNameOptional(String name);
 
Example #17
Source File: DeltaSpikeTransactionalRepositoryInterface.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(lock = PESSIMISTIC_READ)
Simple findByName(String name);
 
Example #18
Source File: SimpleRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("select s from Simple s where s.name = ?1 order by s.counter desc")
public abstract QueryResult<Simple> findByQueryWithOrderBy(String name);
 
Example #19
Source File: DeltaSpikeTransactionalRepositoryAbstract.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(lock = PESSIMISTIC_READ)
public abstract Simple findByName(String name);
 
Example #20
Source File: ExtendedRepositoryInterface.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Modifying @Query("delete from Simple")
int deleteAll();
 
Example #21
Source File: MemberRepository.java    From tutorials with MIT License 4 votes vote down vote up
@Query("from Member m order by m.name")
public abstract List<Member> findAllOrderedByName();
 
Example #22
Source File: SimpleStringIdRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("SELECT s FROM Simple s WHERE s.name = ?1")
List<Simple> findByName2(String name);
 
Example #23
Source File: JtaTransactionalRepositoryInterface.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(named = Simple.BY_NAME_LIKE)
Simple findByNameNoLock(String name);
 
Example #24
Source File: JtaTransactionalRepositoryInterface.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(lock = PESSIMISTIC_READ)
Simple findByName(String name);
 
Example #25
Source File: SimpleRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(named = SimpleStringId.FIND_ALL_ORDER_BY_ID)
public abstract QueryResult<SimpleStringId> findAllOrderByIdPaginate(@FirstResult int start, @MaxResults int pageSize);
 
Example #26
Source File: HouseRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("select h from House h where h.name = ?1")
@EntityGraph(paths = {"flats.tenants", "garages"})
House fetchByNameWithFlatTenants(String name);
 
Example #27
Source File: HouseRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("select h from House h where h.name = ?1")
@EntityGraph(paths = {"flats", "garages"})
House fetchByNameWithDynamicGraph(String name);
 
Example #28
Source File: HouseRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("select h from House h where h.name = ?1")
@EntityGraph("none")
House fetchByNameWithInvalidGraph(String name);
 
Example #29
Source File: HouseRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query("select h from House h where h.name = ?1")
@EntityGraph("withFlats")
House fetchByName(String name);
 
Example #30
Source File: DepositorRepository.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
@Query("SELECT d FROM Depositor d WHERE d.name=:name")
List<Depositor> findByName(@QueryParam("name") String name);