Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

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

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:com.cmweb.orm.hibernate.SimpleHibernateDao.java

License:Apache License

public Criteria distinct(Criteria criteria) {
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria;
}

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

private ObservableList<Loan> getAllLoans() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(Loan.class);
    c.add(Restrictions.eq("status", true));
    c.setProjection(Projections.projectionList().add(Projections.property("loanId"), "loanId")
            .add(Projections.property("loanName"), "loanName"));
    c.setResultTransformer(Transformers.aliasToBean(Loan.class));
    List<Loan> lList = c.list();
    ObservableList<Loan> loans = FXCollections.observableArrayList(lList);
    session.close();/*from w  w  w.j a va  2 s  .  co  m*/
    return loans;
}

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

private Set<Member> getAvailableGuarantors() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c1 = session.createCriteria(MemberLoan.class);
    c1.setProjection(Projections.projectionList().add(Projections.property("isComplete"), "isComplete")
            .add(Projections.property("guarantors"), "guarantors")
            .add(Projections.property("member"), "member"));
    c1.setResultTransformer(Transformers.aliasToBean(MemberLoan.class));
    List<MemberLoan> ml = c1.list();
    //GET ALL GUARANTORS OF ONGOING LOANS
    List<String> guarantors = ml.stream().filter(p -> !p.isIsComplete())
            .map(m -> m.getGuarantors() + "-" + m.getMember().getMemberId()).collect(Collectors.toList());

    Set<String> lkm = new HashSet<>(guarantors);
    List<String> guarantor_filtered = lkm.stream().map(r -> r = r.split("-")[0]).collect(Collectors.toList());

    //GET ALREADY GUARANTED MEMBERS OF THE GARNTOR
    List<String> alreadyGurantedMembers = ml.stream().filter(p -> !p.isIsComplete())
            .filter(p -> p.getMember().getMemberId().equalsIgnoreCase(getMember().getMemberId()))
            .map(MemberLoan::getGuarantors).collect(Collectors.toList());

    //========================
    Set<Member> set = new HashSet<>();
    //========================

    //GET ALL MEMBERS EXCEPT THE LOAN GRANTOR
    Criteria c2 = session.createCriteria(Member.class);
    c2.add(Restrictions.ne("memberId", getMember().getMemberId()));
    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));

    //IF NO GURANTORS FOUND THEN ALL MEMBERS CAN GUARANT FOR THE LOAN EXCEPT THE LOAN GRANTOR
    if (getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY).isEmpty()) {
        List<Member> list = c2.list();
        set.addAll(list);//from  w w  w.ja  va 2  s . co  m
        //
    } else {
        List<Member> list = c2.add(Restrictions
                .not(Restrictions.in("memberId", getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY))))
                .list();
        set.addAll(list);
    }

    //IF NO GUARANTORS AVAILABLE THEY CAN GURANT THE GRANTOR ULTIMATELY UNTIL ALL GUARANTED LOANS END
    if (!alreadyGurantedMembers.isEmpty()) {
        Set<Member> arlm = getAlreadyGurantedMembers(alreadyGurantedMembers, session);
        set.addAll(arlm);
    }

    session.close();
    return set;
}

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

private Set<Member> getAlreadyGurantedMembers(List<String> agm, Session s) {
    Set<String> ug = new HashSet<>();
    for (String string : agm) {
        Type type = new TypeToken<List<String>>() {
        }.getType();//  w w w .  ja va2s  .  c o m
        List<String> yourList = new Gson().fromJson(string, type);
        for (String yl : yourList) {
            ug.add(yl);
        }
    }
    Criteria cc2 = s.createCriteria(Member.class);
    cc2.add(Restrictions.in("memberId", ug));
    cc2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId")
            .add(Projections.property("fullName"), "fullName"));
    cc2.setResultTransformer(Transformers.aliasToBean(Member.class));
    List<Member> list = cc2.list();
    Set<Member> mbrs = new HashSet(list);
    return mbrs;
}

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);
    }/*w  ww .  ja va2  s. c om*/
    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  ww .j a  v  a 2  s. c o  m
    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 w  w w .  j ava 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.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();/*from  w w w .  j  a v  a 2 s  .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();/*w  w  w . j a  v  a 2  s  . c  o m*/
    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  w  w . j  a v a 2 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();
    }
}