Example usage for org.hibernate Criteria setMaxResults

List of usage examples for org.hibernate Criteria setMaxResults

Introduction

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

Prototype

public Criteria setMaxResults(int maxResults);

Source Link

Document

Set a limit upon the number of objects to be retrieved.

Usage

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

private void fillLoanCodeTxt(TextField branchCodeField) {
    DocSeqHandler seqHandler = new DocSeqHandler();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(Loan.class);
    c.addOrder(Order.desc("id"));
    c.setMaxResults(1);
    Loan ln = (Loan) c.uniqueResult();/*from   w w  w  .  j  a  va2 s  . co  m*/
    session.close();
    if (ln != null) {
        seqHandler.reqTable(TABLE_NAME, Integer.parseInt(ln.getLoanId().replaceAll("\\D+", "")) + 1);
        branchCodeField.setText(seqHandler.getSeq_code());
    } else {
        seqHandler.reqTable(TABLE_NAME, 0);
        branchCodeField.setText(seqHandler.getSeq_code());
    }

}

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

private void getMemberLoanByCode(String mlCode, int childId) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {// w w w  .  j ava 2  s . c o  m
        Criteria c = session.createCriteria(MemberLoan.class);
        c.add(Restrictions.eq("memberLoanCode", mlCode));
        c.add(Restrictions.eq("childId", childId));
        c.setMaxResults(1);
        MemberLoan ml = (MemberLoan) c.uniqueResult();
        if (ml != null) {
            double prins_plus_ins = ml.getLoanInstallment() * ml.getNoOfRepay();
            gurantors_lstview.getItems().clear();
            loan_id_txt.setText(ml.getMemberLoanCode());
            g_date_txt.setText(new SimpleDateFormat("yyyy-MM-dd").format(ml.getGrantedDate()));
            r_date_txt.setText(
                    ml.getlRequested() != null ? new SimpleDateFormat("yyyy-MM-dd").format(ml.getlRequested())
                            : "");
            l_type_txt.setText(ml.getInterestMethod());
            l_amount_txt.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(ml.getLoanAmount()));
            l_int_txt.setText(TextFormatHandler.PRECENTAGE_DECIMAL_FORMAT.format(ml.getLoanInterest() / 100)
                    + " " + ml.getInterestPer());
            l_du_txt.setText(ml.getLoanDuration() + " " + ml.getDurationPer());
            int_pls_prin_txt.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(prins_plus_ins));
            bal_cont_txt.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(ml.getKotaLeft()));
            loan_nm_txt.setText(ml.getLoanName());
            List<Member> signedGuarantors = getSignedGuarantors(ml.getGuarantors(), session);
            if (signedGuarantors != null) {
                gurantors_lstview.getItems().addAll(signedGuarantors);
            }

            double ins_only = prins_plus_ins - ml.getLoanAmount();
            l_repay_txt.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(ml.getLoanInstallment()) + "( "
                    + TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format((ml.getLoanInstallment()
                            - FxUtilsHandler.roundNumber((ins_only / ml.getLoanDuration()), 0)))
                    + " + " + TextFormatHandler.CURRENCY_DECIMAL_FORMAT
                            .format(FxUtilsHandler.roundNumber((ins_only / ml.getLoanDuration()), 0))
                    + " )");

            Criteria cl = session.createCriteria(LoanPayment.class);
            cl.createAlias("memberLoan", "ml");
            // cl.add(Restrictions.eq("ml.memberLoanCode", ml.getMemberLoanCode()));
            cl.add(Restrictions.eq("ml.id", ml.getId()));
            List<LoanPayment> filteredList = cl.list();

            if (!filteredList.isEmpty()) {
                List<LoanPayment> collect = filteredList.stream()
                        .filter(FxUtilsHandler.distinctByKey(p -> p.getInstallmentNo()))
                        .collect(Collectors.toList());

                double tot_pay_lo = (ml.getLoanInstallment() * ml.getNoOfRepay());

                Double paymentDue = tot_pay_lo - collect.stream().mapToDouble(LoanPayment::getPaidAmt).sum();

                // System.out.println("ESTIMATE - " + paymentDue);
                double loanComplete = ml.isClosedLoan() ? 1.0 : (paymentDue / tot_pay_lo) * 100;
                ReadOnlyDoubleWrapper workDone = new ReadOnlyDoubleWrapper();
                ProgressIndicatorBar bar = new ProgressIndicatorBar(workDone, loanComplete);
                bar.createProgressIndicatorBar(progress_box, workDone);

                initLoanPayTable(FXCollections.observableArrayList(collect));
            } else {

                initLoanPayTable(FXCollections.observableArrayList());
                ReadOnlyDoubleWrapper workDone = new ReadOnlyDoubleWrapper();
                ProgressIndicatorBar bar = new ProgressIndicatorBar(workDone, 0);
                bar.createProgressIndicatorBar(progress_box, workDone);
            }
        }

    } finally {
        if (session != null) {
            session.close();
        }
    }
}

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

private void fillMemberDocCodeTxt(TextField doc_id_txt) {

    DocSeqHandler seqHandler = new DocSeqHandler();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(Document.class);
    c.addOrder(Order.desc("id"));
    c.setMaxResults(1);
    Document doc = (Document) c.uniqueResult();
    session.close();//from  w w w.  jav  a 2  s  .co m
    if (doc != null) {
        seqHandler.reqTable(TABLE_NAME_DOC, Integer.parseInt(doc.getDocCode().replaceAll("\\D+", "")) + 1);
        doc_id_txt.setText(seqHandler.getSeq_code());
    } else {
        seqHandler.reqTable(TABLE_NAME_DOC, 0);
        doc_id_txt.setText(seqHandler.getSeq_code());
    }
}

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

public String fillMemberLoanCodeTxt() {
    DocSeqHandler seqHandler = new DocSeqHandler();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(MemberLoan.class);
    c.addOrder(Order.desc("id"));
    c.setMaxResults(1);
    MemberLoan ln = (MemberLoan) c.uniqueResult();
    session.close();//from   w ww  .jav a  2 s  .c om
    if (ln != null) {
        seqHandler.reqTable("member_loan", Integer.parseInt(ln.getMemberLoanCode().replaceAll("\\D+", "")) + 1);
        return seqHandler.getSeq_code();
    } else {
        seqHandler.reqTable("member_loan", 0);
        return seqHandler.getSeq_code();
    }
}

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

private Loan getGurantorTransLoan(Session s) {
    Criteria c = s.createCriteria(Loan.class);
    c.add(Restrictions.like("loanName", "GUARANTOR", MatchMode.START));
    c.setMaxResults(1);
    Loan gl = (Loan) c.uniqueResult();//w ww . j a  va 2s.  c  o m
    System.out.println("LOAN - " + gl.getLoanName());
    return gl;
}

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);
    c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class));
    MemberLoan ln = (MemberLoan) c.uniqueResult();
    session.close();/*from   w w  w .  java 2 s  . c  om*/
    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();
    }
}

From source file:com.cristian.tareask.daoImpl.EmailFolderDaoImpl.java

@Override
public EmailFolder getIdFolderByName(String nameFolder) {
    s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(EmailFolder.class);
    c.add(Restrictions.eq("folder", nameFolder));
    c.setMaxResults(1);
    EmailFolder emailFolder = (EmailFolder) c.uniqueResult();

    return emailFolder;
}

From source file:com.cristian.tareask.daoImpl.EmailMessageDaoImpl.java

@Override
public EmailMessage getLastEmailMessageByConversation(Integer conversation) {
    s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(EmailMessage.class);
    //c.add(Restrictions.eq("emailConversation.id", conversation));
    c.addOrder(Order.desc("date"));
    c.setMaxResults(1);
    EmailMessage email = (EmailMessage) c.uniqueResult();
    return email;
}

From source file:com.cubeia.backoffice.accounting.core.dao.AccountingDAOImpl.java

License:Open Source License

private Criteria createFindEntriesCriteria(Long accountId, int offset, int limit, Boolean ascending) {
    Session hbSession = getHibernateSession();
    Criteria c = hbSession.createCriteria(Entry.class);

    if (accountId != null) {
        c.add(Restrictions.eq("account.id", accountId));
    }/*  w w w.  ja  va 2  s . com*/

    if (ascending != null) {
        if (ascending) {
            c.addOrder(Order.asc("id"));
        } else {
            c.addOrder(Order.desc("id"));
        }
    }

    c.setFirstResult(offset);
    c.setMaxResults(limit);
    return c;
}

From source file:com.cubeia.backoffice.users.dao.UserDAOImpl.java

License:Open Source License

private Criteria createFindUserCriteria(Long userId, Long operatorId, String name,
        Collection<UserStatus> includeStatuses, int offset, int limit, UserOrder order, boolean ascending) {

    Session hbSession = getHibernateSession();
    Criteria c = hbSession.createCriteria(User.class);
    c.createAlias("information", "information", JoinType.LEFT_OUTER_JOIN);
    c.setFetchMode("attributes", FetchMode.SELECT);

    if (userId != null) {
        c.add(eq("id", userId));
    }//from w w w .j  a v a2  s . com

    if (operatorId != null) {
        c.add(eq("operatorId", operatorId));
    }

    if (name != null && !name.isEmpty()) {
        c.add(Restrictions.disjunction().add(like("userName", name)).add(like("information.firstName", name))
                .add(like("information.lastName", name)));
    }

    if (includeStatuses != null) {
        c.add(Restrictions.in("status", includeStatuses));
    }

    if (order != null) {
        if (ascending) {
            c.addOrder(Order.asc(order.getColumnName()));
        } else {
            c.addOrder(Order.desc(order.getColumnName()));
        }
    }

    c.setFirstResult(offset);
    c.setMaxResults(limit);
    return c;
}