Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

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

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:com.court.controller.HomeFXMLController.java

private void updateMemberCountTile(Label label) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(Member.class);
    int count = ((Long) c.setProjection(Projections.rowCount()).uniqueResult()).intValue();
    label.setText(String.valueOf(count));
    session.close();/*from w ww .  ja  v a2s  . co m*/
}

From source file:com.court.controller.HomeFXMLController.java

private void updateMonthlyCollection(Label label) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(LoanPayment.class);
    c.add(filterByMonthCriterion("paymentDate"));
    Object ob = c.setProjection(Projections.sum("paidAmt")).uniqueResult();

    Criteria c1 = session.createCriteria(SubscriptionPay.class);
    c1.add(filterByMonthCriterion("addedDate"));
    List<SubscriptionPay> spay = c1.list();

    Accumlator sp = spay.stream().filter(p -> p != null)
            .collect(Collector.of(Accumlator::new, Accumlator::accumlate, Accumlator::combine));
    double spayTot = sp.getAci() + sp.getHoi() + sp.getAdmission() + sp.getMembership() + sp.getMembership()
            + sp.getSavings();//from   w w  w.j  a  va  2  s . c om
    Double sum = ob != null ? (Double) ob : 0.0 + spayTot;
    label.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(sum));
    session.close();
}

From source file:com.court.controller.HomeFXMLController.java

private void updateLoanAmtCollectionCurrentMonth(Label label) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(MemberLoan.class);
    c.add(Restrictions.eq("status", true));
    c.add(filterByMonthCriterion("grantedDate"));
    Object ob = c.setProjection(Projections.sum("loanAmount")).uniqueResult();

    Double sum = ob != null ? (Double) ob : 0.0;
    label.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(sum));
}

From source file:com.court.controller.HomeFXMLController.java

private Map<String, Number> getLoanReleasedData() {
    LocalDate now = LocalDate.now();
    Map<String, Number> map = new HashMap<>();
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(MemberLoan.class);

    ProjectionList pList = Projections.projectionList();
    ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(MemberLoan.class);
    pList.add(Projections.property(lpMeta.getIdentifierPropertyName()));
    for (String prop : lpMeta.getPropertyNames()) {
        pList.add(Projections.property(prop), prop);
    }//from w  w w  . j av  a  2 s. c o m
    c.add(Restrictions.eq("status", true));
    c.add(Restrictions.between("grantedDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())),
            FxUtilsHandler.getDateFrom(now.with(lastDayOfYear()))));
    c.setProjection(pList
            .add(Projections.sqlGroupProjection("DATE_FORMAT(granted_date, '%Y-%m-01') AS groupPro", "groupPro",
                    new String[] { "groupPro" }, new Type[] { StringType.INSTANCE }))
            .add(Projections.sqlProjection("SUM(loan_amount) AS lSum", new String[] { "lSum" },
                    new Type[] { DoubleType.INSTANCE })));

    c.addOrder(Order.asc("grantedDate"));
    c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class));
    List<MemberLoan> list = (List<MemberLoan>) c.list();
    for (MemberLoan ml : list) {
        map.put(ml.getGroupPro(), ml.getlSum());
    }
    s.close();
    return map;
}

From source file:com.court.controller.HomeFXMLController.java

private Map<String, Number> getLoanCollectionData() {
    LocalDate now = LocalDate.now();
    Map<String, Number> map = new HashMap<>();
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(LoanPayment.class);

    ProjectionList pList = Projections.projectionList();
    ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(LoanPayment.class);
    pList.add(Projections.property(lpMeta.getIdentifierPropertyName()));
    for (String prop : lpMeta.getPropertyNames()) {
        pList.add(Projections.property(prop), prop);
    }//from   w  w w  .  ja v a  2  s . c  om
    c.add(Restrictions.between("paymentDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())),
            FxUtilsHandler.getDateFrom(now.with(lastDayOfYear()))));
    c.setProjection(pList
            .add(Projections.sqlGroupProjection("DATE_FORMAT(payment_date, '%Y-%m-01') AS groupPro", "groupPro",
                    new String[] { "groupPro" }, new Type[] { StringType.INSTANCE }))
            .add(Projections.sqlProjection("SUM(paid_amt) AS lSum", new String[] { "lSum" },
                    new Type[] { DoubleType.INSTANCE })));

    c.addOrder(Order.asc("paymentDate"));
    c.setResultTransformer(Transformers.aliasToBean(LoanPayment.class));
    List<LoanPayment> list = (List<LoanPayment>) c.list();
    for (LoanPayment lp : list) {
        map.put(lp.getGroupPro(), lp.getlSum());
    }
    s.close();
    return map;
}

From source file:com.court.controller.MemberfxmlController.java

private ObservableList<Member> getAllMembers() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from  www  .  j  a v a 2s .  c  o  m*/
        Criteria c = session.createCriteria(Member.class);
        c.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId")
                .add(Projections.property("fullName"), "fullName")
                .add(Projections.property("jobTitle"), "jobTitle"));
        c.setResultTransformer(Transformers.aliasToBean(Member.class));
        List<Member> mList = c.list();
        ObservableList<Member> members = FXCollections.observableArrayList(mList);
        return members;
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:com.court.controller.MemberfxmlController.java

private ObservableList<String> getAllBranches() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from ww  w.  ja  v a2s .  co  m
        Criteria c = session.createCriteria(Branch.class);
        c.add(Restrictions.eq("status", true));
        c.setProjection(Projections.property("branchName"));
        List<String> bList = c.list();
        ObservableList<String> branches = FXCollections.observableArrayList(bList);
        return branches;
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:com.court.controller.OldLoansFxmlController.java

private List<Member> getMembers() {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(Member.class);
    c.add(Restrictions.eq("status", true));
    ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(Member.class);
    c.setProjection(Projections.projectionList().add(Projections.property(lpMeta.getIdentifierPropertyName()))
            .add(Projections.property("memberId"), "memberId")
            .add(Projections.property("fullName"), "fullName"));
    c.setResultTransformer(Transformers.aliasToBean(Member.class));
    List<Member> list = c.list();
    s.close();/*ww w . ja  v a 2s .c o  m*/
    return list;
}

From source file:com.court.controller.OldLoansFxmlController.java

private Set<Member> getAvailableGuarantors() {
    String mbrId = mbr_search_txt.getText().split("-")[0].trim();
    //GET ALL MEMBERS EXPECT GRANTOR======
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c2 = session.createCriteria(Member.class);
    c2.add(Restrictions.ne("memberId", mbrId));
    c2.add(Restrictions.eq("status", true));
    c2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId")
            .add(Projections.property("fullName"), "fullName"));
    c2.setResultTransformer(Transformers.aliasToBean(Member.class));
    List<Member> list = c2.list();
    session.close();//from   w  w w . j a  v  a2  s .  c om
    return new HashSet<>(list);
}

From source file:com.court.controller.OldLoansFxmlController.java

public String fillMemberLoanCodeTxt() {
    DocSeqHandler seqHandler = new DocSeqHandler();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(MemberLoan.class);
    c.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("memberLoanCode"), "memberLoanCode"));
    c.addOrder(Order.desc("id"));
    c.setMaxResults(1);/*from   w  ww.  j  a v  a2  s. c  o m*/
    c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class));
    MemberLoan ln = (MemberLoan) c.uniqueResult();
    session.close();
    if (ln != null) {
        seqHandler.reqTable(TABLE_NAME, Integer.parseInt(ln.getMemberLoanCode().replaceAll("\\D+", "")) + 1);
        return seqHandler.getSeq_code();
    } else {
        seqHandler.reqTable(TABLE_NAME, 0);
        return seqHandler.getSeq_code();
    }
}