Example usage for org.hibernate Criteria setComment

List of usage examples for org.hibernate Criteria setComment

Introduction

In this page you can find the example usage for org.hibernate Criteria setComment.

Prototype

public Criteria setComment(String comment);

Source Link

Document

Add a comment to the generated SQL.

Usage

From source file:com.sapienter.jbilling.server.invoice.db.InvoiceDAS.java

License:Open Source License

public BigDecimal findTotalBalanceByUser(Integer userId) {
    Criteria criteria = getSession().createCriteria(InvoiceDTO.class);

    addUserCriteria(criteria, userId);/*from ww w  .j a v  a 2  s  . c o m*/
    criteria.add(Restrictions.eq("isReview", 0));

    criteria.createAlias("invoiceStatus", "s").add(Restrictions.ne("s.id", Constants.INVOICE_STATUS_PAID));

    criteria.setProjection(Projections.sum("balance"));
    criteria.setComment("InvoiceDAS.findTotalBalanceByUser");

    Object ttlBal = criteria.uniqueResult();

    return (ttlBal == null ? BigDecimal.ZERO : (BigDecimal) ttlBal);
}

From source file:com.sapienter.jbilling.server.invoice.db.InvoiceDAS.java

License:Open Source License

/**
 * Returns the sum total balance of all unpaid invoices for the given user.
 *
 * @param userId user id//from w ww . j av a 2  s  .c  om
 * @return total balance of all unpaid invoices.
 */
public BigDecimal findTotalAmountOwed(Integer userId) {
    Criteria criteria = getSession().createCriteria(InvoiceDTO.class);
    addUserCriteria(criteria, userId);
    criteria.createAlias("invoiceStatus", "status");
    criteria.add(Restrictions.ne("status.id", Constants.INVOICE_STATUS_PAID));
    criteria.add(Restrictions.eq("isReview", 0));
    criteria.setProjection(Projections.sum("balance"));
    criteria.setComment("InvoiceDAS.findTotalAmountOwed");

    return (criteria.uniqueResult() == null ? BigDecimal.ZERO : (BigDecimal) criteria.uniqueResult());
}

From source file:com.sapienter.jbilling.server.item.db.ItemTypeDAS.java

License:Open Source License

/**
 * Returns true if the given item type ID is in use.
 *
 * @param typeId type id/*www . j a  v a 2  s .  co  m*/
 * @return true if in use, false if not
 */
public boolean isInUse(Integer typeId) {
    Criteria criteria = getSession().createCriteria(getPersistentClass()).add(Restrictions.eq("id", typeId))
            .createAlias("items", "item").add(Restrictions.eq("item.deleted", 0)) // item type contains non-deleted items
            .setProjection(Projections.count("item.id"));

    criteria.setComment("ItemTypeDTO.isInUse");

    return (criteria.uniqueResult() != null && ((Integer) criteria.uniqueResult()) > 0);
}

From source file:com.sapienter.jbilling.server.payment.db.PaymentDAS.java

License:Open Source License

public BigDecimal findTotalRevenueByUser(Integer userId) {
    Criteria criteria = getSession().createCriteria(PaymentDTO.class);
    criteria.add(Restrictions.eq("deleted", 0)).createAlias("baseUser", "u")
            .add(Restrictions.eq("u.id", userId)).createAlias("paymentResult", "pr")
            .add(Restrictions.ne("pr.id", CommonConstants.PAYMENT_RESULT_FAILED));
    criteria.add(Restrictions.eq("isRefund", 0));
    criteria.setProjection(Projections.sum("amount"));
    criteria.setComment("PaymentDAS.findTotalRevenueByUser-Gross Receipts");

    BigDecimal grossReceipts = criteria.uniqueResult() == null ? BigDecimal.ZERO
            : (BigDecimal) criteria.uniqueResult();

    Criteria criteria2 = getSession().createCriteria(PaymentDTO.class);
    criteria2.add(Restrictions.eq("deleted", 0)).createAlias("baseUser", "u")
            .add(Restrictions.eq("u.id", userId)).createAlias("paymentResult", "pr")
            .add(Restrictions.ne("pr.id", CommonConstants.PAYMENT_RESULT_FAILED));
    criteria2.add(Restrictions.eq("isRefund", 1));
    criteria2.setProjection(Projections.sum("amount"));
    criteria2.setComment("PaymentDAS.findTotalRevenueByUser-Gross Refunds");

    BigDecimal refunds = criteria2.uniqueResult() == null ? BigDecimal.ZERO
            : (BigDecimal) criteria2.uniqueResult();

    //net revenue = gross - all refunds
    return (grossReceipts.subtract(refunds));
}

From source file:com.sapienter.jbilling.server.payment.db.PaymentDAS.java

License:Open Source License

public BigDecimal findTotalBalanceByUser(Integer userId) {
    Criteria criteria = getSession().createCriteria(PaymentDTO.class);

    criteria.add(Restrictions.eq("deleted", 0)).createAlias("baseUser", "u")
            .add(Restrictions.eq("u.id", userId));

    criteria.setProjection(Projections.sum("balance"));
    criteria.setComment("PaymentDAS.findTotalBalanceByUser");

    return (criteria.uniqueResult() == null ? BigDecimal.ZERO : (BigDecimal) criteria.uniqueResult());
}

From source file:org.eurocarbdb.action.AbstractBrowseAction.java

License:Open Source License

/** 
*   Adds comments and offset/limit restrictions to the passed {@link Criteria} query. 
*   Note that offset ({@link #getOffset}) and limit ({@link #getMaxResults}) parameters
*   and their dependant values must be set <em>prior</em> to this method being called.
*//*from w  w w  .  ja v a 2s.c o m*/
protected void initQuery(Criteria q) {
    if (log.isDebugEnabled()) {
        log.debug(
                "initialising query: offset = " + this.getOffset() + ", max results = " + this.getMaxResults());
    }

    q.setComment(this.getClass().getName());
    q.setMaxResults(this.getMaxResults());
    q.setFirstResult(this.getOffset());
}