Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

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

@FXML
private void onSaveBtnAction(ActionEvent event) throws IOException {
    if (isValidationEmpty()) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Empty Fields !");
        alert_error.setContentText(PropHandler.getStringProperty("empty_fields"));
        alert_error.show();/*from   w w w  .jav  a2  s.c  om*/
        return;
    }
    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Loan loan;
        int id = getIdByLoanCode(session, loan_id_txt.getText().trim());
        if (id != 0) {
            loan = (Loan) session.load(Loan.class, id);
        } else {
            loan = new Loan();
        }

        autoDetectRepayCycle();
        loan.setLoanId(loan_id_txt.getText().trim());
        loan.setLoanName(loan_name_txt.getText());
        loan.setInterestMethod(int_method_combo.getSelectionModel().getSelectedItem());
        loan.setLoanInterest(TextFormatHandler.getPercentageFieldValue(loan_int_txt));
        loan.setInterestPer(loan_int_combo.getSelectionModel().getSelectedItem());
        loan.setLoanDuration(Integer.parseInt(loan_due_txt.getText().trim()));
        loan.setDurationPer(loan_due_combo.getSelectionModel().getSelectedItem());
        loan.setRepaymentCycle("Monthly");
        loan.setNoOfRepay(Integer.parseInt(repay_txt.getText().trim()));
        loan.setStatus(true);
        session.saveOrUpdate(loan);
        session.getTransaction().commit();
        session.close();

        Alert alert_info = new Alert(Alert.AlertType.INFORMATION);
        alert_info.setTitle("Information");
        alert_info.setHeaderText("Successfully Saved !");
        alert_info.setContentText("You have successfully saved \"" + loan_name_txt.getText() + "\"");
        Optional<ButtonType> result = alert_info.showAndWait();
        if (result.get() == ButtonType.OK) {
            FxUtilsHandler.clearFields(save_grid, loan_int_hbox, loan_due_hbox, loan_repay_hbox);
            fillLoanCodeTxt(loan_id_txt);

            ObservableList<Loan> allLoans = getAllLoans();
            initLoanTable(allLoans);
            List<String> loanCodes = allLoans.stream().map(Loan::getLoanId).collect(Collectors.toList());
            List<String> loanNames = allLoans.stream().map(Loan::getLoanName).collect(Collectors.toList());
            TextFields.bindAutoCompletion(loan_search_id_txt, loanCodes);
            TextFields.bindAutoCompletion(loan_search_name_txt, loanNames);
        }
    } else {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Missing Fields !");
        alert_error.setContentText("You have some missing fields left. Move the cursor to the red \"X\""
                + " sign and find the error.");
        alert_error.show();
    }
}

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

@FXML
private void onDeactiveBtnAction(ActionEvent event) throws IOException {
    if (isValidationEmpty()) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Empty Fields !");
        alert_error.setContentText(PropHandler.getStringProperty("empty_fields"));
        alert_error.show();/*from  www .  ja  v  a2s. co  m*/
        return;
    }
    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Loan prfm_action = (Loan) session.load(Loan.class, getIdByLoanCode(session, loan_id_txt.getText()));
        boolean set_status = !prfm_action.isStatus();
        prfm_action.setStatus(set_status);
        session.update(prfm_action);
        session.getTransaction().commit();
        session.close();

        Alert alert_inf = new Alert(Alert.AlertType.INFORMATION);
        alert_inf.setTitle("Information");
        String what_happened = set_status ? "Activated" : "Deactivated";
        alert_inf.setHeaderText("Successfully " + what_happened + "!");
        alert_inf.setContentText(
                "You have successfully " + what_happened + " the " + loan_name_txt.getText() + " !");
        Optional<ButtonType> result = alert_inf.showAndWait();
        if (result.get() == ButtonType.OK) {
            //deactivation proccess----------
            ObservableList<Loan> allLoans = getAllLoans();
            initLoanTable(allLoans);
            FxUtilsHandler.activeDeactiveChildrenControls(set_status, save_grid, loan_int_hbox, loan_due_hbox,
                    loan_repay_hbox);
            FxUtilsHandler.activeBtnAppearanceChange(deactive_btn, set_status, false);
        }
    } else {
        Alert alert_inf = new Alert(Alert.AlertType.INFORMATION);
        alert_inf.setTitle("Information");
        alert_inf.setHeaderText("Nothing to deactive !");
        alert_inf.setContentText(
                "You have not selected a valid branch to deactivate." + " Select a loan and try again.");
        alert_inf.show();
    }
}

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

@FXML
private void onMemberSaveBtnAction(ActionEvent event) throws IOException {
    if (isValidationEmpty(validationSupport)) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Empty Fields !");
        alert_error.setContentText(PropHandler.getStringProperty("empty_fields"));
        alert_error.show();/*  w w  w.  ja v a2 s .co m*/
        return;
    }

    Predicate<String> predicate = (t) -> {
        return memberCodes.contains(t);
    };

    if (!isSearch && predicate.test(member_code_txt.getText())) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Member already exist.");
        alert_error.setContentText("You have already saved this member " + member_code_txt.getText());
        alert_error.show();
        return;
    }

    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Member member;
            int id = getIdByMemberCode(session, member_code_txt.getText().trim());
            if (id != 0) {
                member = (Member) session.load(Member.class, id);
                updateMemberStatus(member_status_combo.getSelectionModel().getSelectedItem(), member,
                        hndler.loggedUser(), session);
            } else {
                member = new Member();
                member.setMemberId(member_code_txt.getText().trim());
                member.setNic(nic_no.getText());
            }

            member.setEmpId(emp_id_txt.getText());
            member.setJobStatus(job_status_combo.getSelectionModel().getSelectedItem());
            //member.setPaymentOfficer(payment_officer_txt.getText());
            member.setFullName(member_full_name_txt.getText());
            member.setNameWithIns(member_namins_txt.getText());
            member.setAddress(member_adrs_txt.getText());
            member.setJobTitle(member_job_txt.getText());
            member.setBranch(getBranchByName(session, member_brch_txt.getText().trim()));
            member.setTel1(member_tel1_txt.getText());
            member.setTel2(member_tel2_txt.getText());
            member.setEmail(member_email_txt.getText());
            member.setSex(member_sex_combo.getSelectionModel().getSelectedItem());
            member.setCurStatus(member_status_combo.getSelectionModel().getSelectedItem());
            member.setMaritalStatus(member_maritial_combo.getSelectionModel().getSelectedItem());
            member.setDob(FxUtilsHandler.getDateFrom(member_bday_chooser.getValue()));
            member.setAppintedDate(Date.valueOf(member_apo_chooser.getValue()));
            member.setJoinedDate(FxUtilsHandler.getDateFrom(member_join_chooser.getValue()));
            member.setOverpay(0.0);
            member.setZeroOverpay(0.0);
            member.setStatus(member.getCurStatus().equalsIgnoreCase("Active"));
            member.setDescription(
                    member_des_txt.getText().isEmpty() ? "No Description" : member_des_txt.getText());
            //  member.setImgPath(imgString == null ? "" : imgString.getImg_path().toString());
            //   member.setStatus(true);
            if (payBranch != null) {
                member.setPayOffice(payBranch);
            }
            session.saveOrUpdate(member);
            session.getTransaction().commit();
        } catch (Exception e) {
            if (session.getTransaction() != null) {
                session.getTransaction().rollback();
            }
        } finally {
            if (session != null) {
                session.close();
            }
        }

        Alert alert_info = new Alert(Alert.AlertType.INFORMATION);
        alert_info.setTitle("Information");
        alert_info.setHeaderText("Successfully Saved !");
        alert_info.setContentText("You have successfully saved member \"" + member_namins_txt.getText() + "\"");
        Optional<ButtonType> result = alert_info.showAndWait();
        if (result.get() == ButtonType.OK) {
            FxUtilsHandler.clearFields(main_grid_pane, date_hbox, tel_hbox, nic_col_id, working_box,
                    job_title_box);
            fillMemberCodeTxt(member_code_txt);
            imgString = null;
            member_img.setImage(new Image(getClass().getResourceAsStream(FileHandler.MEMBER_DEFAULT_IMG)));

            ObservableList<Member> allMembers = getAllMembers();
            List<String> memberCodes = allMembers.stream().map(Member::getMemberId)
                    .collect(Collectors.toList());
            List<String> memberNames = allMembers.stream().map(Member::getFullName)
                    .collect(Collectors.toList());
            List<String> memberJobs = allMembers.stream()
                    .filter(FxUtilsHandler.distinctByKey(p -> p.getJobTitle())).map(Member::getJobTitle)
                    .collect(Collectors.toList());
            p1.clearSuggestions();
            p1.addPossibleSuggestions(memberCodes);
            p2.clearSuggestions();
            p2.addPossibleSuggestions(memberNames);
            p3.clearSuggestions();
            p3.addPossibleSuggestions(memberJobs);
            identifyCodesEditable(true);
            isSearch = false;
            disableTabs(true);
            FxUtilsHandler.activeDeactiveChildrenControls(true, main_grid_pane, date_hbox, tel_hbox);
            FxUtilsHandler.activeBtnAppearanceChange(member_deactive_btn, true, true);
            deactive_label.setText("");

        }
    } else {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Missing Fields !");
        alert_error.setContentText(PropHandler.getStringProperty("missing_fields"));
        alert_error.show();
    }
}

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

@FXML
private void onMemberDeactiveBtnAction(ActionEvent event) throws IOException {
    if (isValidationEmpty(validationSupport)) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Invalid Entries !");
        alert_error.setContentText(PropHandler.getStringProperty("empty_fields"));
        alert_error.show();//from ww w . ja  va 2  s.  com
        return;
    }
    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Member prfm_action = (Member) session.load(Member.class,
                getIdByMemberCode(session, member_code_txt.getText()));
        boolean set_status = !prfm_action.isStatus();
        boolean cur_job_stat = !prfm_action.getCurStatus().equalsIgnoreCase("Active");
        prfm_action.setStatus(set_status);
        if (set_status && cur_job_stat) {
            prfm_action.setCurStatus("Active");
        }
        session.update(prfm_action);
        session.getTransaction().commit();
        session.close();

        Alert alert_inf = new Alert(Alert.AlertType.INFORMATION);
        alert_inf.setTitle("Information");
        String what_happened = set_status ? "Activated" : "Deactivated";
        alert_inf.setHeaderText("Successfully " + what_happened + "!");
        alert_inf.setContentText(
                "You have successfully " + what_happened + " the member " + member_namins_txt.getText() + "!");
        Optional<ButtonType> result = alert_inf.showAndWait();
        if (result.get() == ButtonType.OK) {
            //deactivation proccess----------
            FxUtilsHandler.activeDeactiveChildrenControls(set_status, main_grid_pane, date_hbox, tel_hbox);
            FxUtilsHandler.activeBtnAppearanceChange(member_deactive_btn, set_status, true);
            if (set_status && cur_job_stat) {
                member_status_combo.getSelectionModel().select("Active");
                deactive_label.setText("");
            }
            if (!set_status) {
                deactive_label.setText("Member Deactivated .");
            }
            if (set_status
                    && !member_status_combo.getSelectionModel().getSelectedItem().equalsIgnoreCase("Active")) {
                deactive_label
                        .setText("Member " + member_status_combo.getSelectionModel().getSelectedItem() + " .");
            }

        }
    }
}

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

@FXML
private void onRemoveLoanBtnAction(ActionEvent event) {

    MemberLoan selectedLoan = l_taken_tbl.getSelectionModel().getSelectedItem();
    if (selectedLoan != null) {
        Alert alert_confirm = new Alert(Alert.AlertType.CONFIRMATION);
        alert_confirm.setTitle("Warning");
        alert_confirm.setHeaderText("Confirm ?");
        alert_confirm.setContentText("Are you sure you want to remove the selected loan ?");
        Optional<ButtonType> rs = alert_confirm.showAndWait();
        if (rs.get() == ButtonType.OK) {
            Session ses = HibernateUtil.getSessionFactory().openSession();
            MemberLoan ml = (MemberLoan) ses.load(MemberLoan.class, selectedLoan.getId());
            if (ml.getLoanPayments().isEmpty()) {
                ses.beginTransaction();//  w w w.  j  a  v a 2s .c  o m
                ses.delete(ml);
                ses.getTransaction().commit();
                Alert alert_success = new Alert(Alert.AlertType.INFORMATION);
                alert_success.setTitle("Success");
                alert_success.setHeaderText("Successfully Removed !");
                alert_success.setContentText("You have successfully removed the member loan.");
                Optional<ButtonType> result = alert_success.showAndWait();
                if (result.get() == ButtonType.OK) {
                    FxUtilsHandler.clearFields(loan_name_hbox, loan_info_grid);
                    clearProgressBar();
                    buildMemberLoanTable();
                }
            } else {
                Alert error_alert = new Alert(Alert.AlertType.INFORMATION);
                error_alert.setTitle("Error");
                error_alert.setHeaderText("Error Occured !");
                error_alert.setContentText("There are already assigned payments for this loan.");
                error_alert.show();
            }
            ses.close();
        }

    } else {
        Alert error_alert = new Alert(Alert.AlertType.INFORMATION);
        error_alert.setTitle("Error");
        error_alert.setHeaderText("Error Occured !");
        error_alert.setContentText("You have to select a member loan to proceed.");
        error_alert.show();
    }
}

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

@FXML
private void onOtherDetailsSaveBtnAction(ActionEvent event) throws IOException {

    if (isValidationEmpty(va)) {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Invalid Entries !");
        alert_error.setContentText(PropHandler.getStringProperty("empty_fields"));
        alert_error.show();//from w ww.  j a  v  a 2 s . c  o m
        return;
    }
    if (va.validationResultProperty().get().getErrors().isEmpty()) {
        Spouse s = new Spouse();
        s.setSpouse(spouse_name_txt.getText());
        s.setHoi(s_hoi_check.isSelected());
        s.setAci(s_aci_check.isSelected());

        Benifits mb = new Benifits();
        mb.setName(mb_ben_name.getText());
        mb.setRelation(mem_ben_rel.getText());

        Benifits ab = new Benifits();
        ab.setName(ac_ben_name.getText());
        ab.setRelation(ac_ben_rel.getText());

        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Criteria c = session.createCriteria(Member.class);
            Member member = (Member) c.add(Restrictions.eq("memberId", member_code_txt.getText()))
                    .uniqueResult();
            member.setFather(father_txt.getText());
            member.setMother(mother_txt.getText());
            member.setSpouse(s.getSpouse() == null || s.getSpouse().isEmpty() ? "" : new Gson().toJson(s));
            member.setMemBenifits(mb.getName() == null || mb.getName().isEmpty() ? "" : new Gson().toJson(mb));
            member.setAccBenifits(ab.getName() == null || mb.getName().isEmpty() ? "" : new Gson().toJson(ab));
            session.beginTransaction();
            session.update(member);

            Set<MemberSubscriptions> mss = member.getMemberSubscriptions();
            List<MemberSubscription> msList = session.createCriteria(MemberSubscription.class).list();
            if (mss.isEmpty()) {

                for (MemberSubscription ms : msList) {
                    MemberSubscriptions mm = new MemberSubscriptions();
                    hibernateSaveMemberSubscriptions(ms, mm, session, member);
                }
            } else {
                for (MemberSubscription ms : msList) {
                    int id = getSubscriptionsByMemberAndSubscription(session, ms.getFeeName(), member.getId());
                    MemberSubscriptions msm;
                    if (id != 0) {
                        msm = (MemberSubscriptions) session.load(MemberSubscriptions.class, id);
                    } else {
                        msm = new MemberSubscriptions();
                    }
                    hibernateSaveMemberSubscriptions(ms, msm, session, member);
                }
            }
            session.getTransaction().commit();
        } catch (Exception e) {
            if (session.getTransaction() != null) {
                session.getTransaction().rollback();
            }
        } finally {
            if (session != null) {
                session.close();
            }
        }

        Alert alert_success = new Alert(Alert.AlertType.INFORMATION);
        alert_success.setTitle("Information");
        alert_success.setHeaderText("Successfully Saved !");
        alert_success.setContentText("You have successfully saved the family information.");
        alert_success.show();
    } else {
        Alert alert_error = new Alert(Alert.AlertType.ERROR);
        alert_error.setTitle("Error");
        alert_error.setHeaderText("Missing Fields !");
        alert_error.setContentText(PropHandler.getStringProperty("missing_fields"));
        alert_error.show();
    }
}

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

private void deleteChildFromMember(MemChild mchild) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();// w  w w  .  j a  v  a  2  s  .  c  o m
    MemChild dc = (MemChild) session.load(MemChild.class, mchild.getId());
    session.delete(dc);
    session.getTransaction().commit();
    session.close();
}

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

private void endLoan(Session s, MemberLoan ml) {
    int getEndingLoan = ml.getId();
    MemberLoan mml = (MemberLoan) s.load(MemberLoan.class, getEndingLoan);
    mml.setIsComplete((mml.getKotaLeft() <= 0));
    s.update(mml);//w  ww.j  av  a2s. c  o m
}

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

private void assignToGuarantors(Session s, MemberLoan ml) {
    int asgGurLoan = ml.getId();
    MemberLoan mml = (MemberLoan) s.load(MemberLoan.class, asgGurLoan);
    mml.setIsComplete(true);/*w  ww . j  a va 2s  .c  om*/
    mml.setAssigntoGurs(true);
    s.update(mml);
}

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

private void updateMemberLoan(MemberLoan ml, int inst_count, Session s, java.util.Date payUntil) {
    int getLoan = ml.getId();
    MemberLoan mml = (MemberLoan) s.load(MemberLoan.class, getLoan);
    mml.setPaidUntil(payUntil);/*  w ww  .j  a  v a  2  s. com*/
    mml.setLastInstall(mml.getLastInstall() + inst_count);
    s.update(mml);
}