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.BranchFxmlController.java

@FXML
private void onBranchSaveBtnAction(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. ja va2 s.  c  o m
        return;
    }
    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Branch branch;
        int id = getIdByBranchCode(session, br_id_txt.getText().trim());
        if (id != 0) {
            branch = (Branch) session.load(Branch.class, id);
            parent_id = branch.getParentId();
        } else {
            branch = new Branch();
        }

        branch.setBranchCode(br_id_txt.getText().trim());
        branch.setBranchName(branch_name_txt.getText().trim());
        branch.setAddress(branch_adrs_txt.getText());
        branch.setBranchType(branch_type_combo.getSelectionModel().getSelectedItem());
        branch.setContactNo(branch_tel_txt.getText());
        branch.setDescription(branch_des_txt.getText().isEmpty() ? "No Description" : branch_des_txt.getText());
        branch.setStatus(true);
        branch.setParentId(parent_id);
        session.saveOrUpdate(branch);
        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 the \"" + branch_name_txt.getText() + "\" \n " + "branch.");
        Optional<ButtonType> result = alert_info.showAndWait();
        if (result.get() == ButtonType.OK) {
            FxUtilsHandler.clearFields(branch_grid_pane);
            fillBranchCodeTxt(br_id_txt);

            ObservableList<Branch> allBranches = getAllBranches();
            initBranchTable(allBranches, false);
            List<String> branchCodes = allBranches.stream().map(Branch::getBranchCode)
                    .collect(Collectors.toList());
            List<String> branchNames = allBranches.stream().map(Branch::getBranchName)
                    .collect(Collectors.toList());
            TextFields.bindAutoCompletion(branch_search_id, branchCodes);
            TextFields.bindAutoCompletion(branch_search_name, branchNames);
            btitle_pane.setContent(branch_search_grid_pane);
            parent_id = 0;

        }

    } 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.BranchFxmlController.java

@FXML
private void onBranchDeactiveBtnAction(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  ww  w. ja  va 2 s  . c  om
        return;
    }
    if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Branch prfm_action = (Branch) session.load(Branch.class,
                getIdByBranchCode(session, br_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 " + branch_name_txt.getText() + " branch !");
        Optional<ButtonType> result = alert_inf.showAndWait();
        if (result.get() == ButtonType.OK) {
            //deactivation proccess----------
            ObservableList<Branch> allBranches = getAllBranches();
            initBranchTable(allBranches, false);
            FxUtilsHandler.activeDeactiveChildrenControls(set_status, branch_grid_pane);
            FxUtilsHandler.activeBtnAppearanceChange(branch_actv_deactv_btn, set_status, false);
            parent_id = 0;
        }
    } 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 branch and try again.");
        alert_inf.show();
    }
}

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

private void move_branch(int draggedIndex, int dropIndex) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//ww  w  .  ja  v a  2s  . co m
    Branch movingBranch = (Branch) session.load(Branch.class, draggedIndex);
    movingBranch.setParentId(dropIndex);
    session.update(movingBranch);
    updateMbrPayOfficeOfWorkOffice(draggedIndex, dropIndex == 0 ? draggedIndex : dropIndex, session);
    session.getTransaction().commit();
    session.close();
}

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

private void updatePreviousInstallmentsOfMemberLoan(Session session, LoanPayment lp) {

    int getLastUpdated = lp.getId();
    LoanPayment lastPayment = (LoanPayment) session.load(LoanPayment.class, getLastUpdated);
    lastPayment.setIsLast(false);//from   w  w  w . j a  v a 2s.  c om
    session.update(lastPayment);

}

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

private void endLoan(Session session, MemberLoan ml) {
    int getEndingLoan = ml.getId();
    MemberLoan mml = (MemberLoan) session.load(MemberLoan.class, getEndingLoan);
    mml.setIsComplete(true);/*  www  .  jav a2s  .com*/
    session.update(mml);
}

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

private double updateMemberLoan(MemberLoan ml, double paidAmt, double again_kota_left, Session session,
        boolean isKotaPay, java.util.Date payUntil) {
    boolean kotaKotaPay = (again_kota_left == 0) && isKotaPay;
    MemberLoan mll = (MemberLoan) session.load(MemberLoan.class, ml.getId());
    mll.setPaidUntil(payUntil);/*from  ww w .j a  v a  2 s.  com*/

    /**
     * paidSoFar calculation removed because paidSoFar column is only for
     * old loans if there are already paid amount(installment amt * previous
     * paid installment count)
     *
     */
    // updating paidSoFar column
    //mll.setPaidSofar(mll.getPaidSofar() + paidAmt);
    // end updating paidSoFar column
    mll.setKotaLeft(kotaKotaPay ? 0.0 : (mll.getKotaLeft() + again_kota_left));
    mll.setLastInstall(mll.getLastInstall() + 1);
    session.update(mll);
    //Return Current kota amount=====================
    return mll.getKotaLeft();
}

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

private Double getListedPayFrom(MemberLoan ml, Session s, boolean isKotaPay) {
    MemberLoan mml = (MemberLoan) s.load(MemberLoan.class, ml.getId());
    return isKotaPay ? mml.getKotaLeft() : mml.getLoanInstallment();
}

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

private void updateMemberOverPay(Member m, Session session) {
    Member mm = (Member) session.load(Member.class, m.getId());
    //   mm.setOverpay(mm.getOverpay() + m.getOverpay());
    mm.setOverpay(mm.getOverpay() + m.getZeroOverpay());
    session.update(mm);/*from www  . j a v a  2 s. c o  m*/
}

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

@FXML
private void onDsplySetSaveBtnAction(ActionEvent event) throws IOException {
    if (v1.validationResultProperty().get().getErrors().isEmpty()) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();/* w  w w  . j  a v a  2  s  . c  o m*/
        Company c = (Company) session.load(Company.class, 1);
        c.setCompanyName(dis_name_txt.getText());
        c.setTitleName(title_txt.getText());
        session.update(c);
        session.getTransaction().commit();
        session.close();

        Alert alert_sucess = new Alert(Alert.AlertType.INFORMATION);
        alert_sucess.setTitle("Success");
        alert_sucess.setHeaderText("Successfully Saved !");
        alert_sucess.setContentText("You have successfully Saved the display settings.");
        Optional<ButtonType> result = alert_sucess.showAndWait();
        if (result.get() == ButtonType.OK) {
            loadDisplaySettings();
        }

    }
}

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

private Company getCompany() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Company c = (Company) session.load(Company.class, 1);
    session.close();// ww  w .j  a v  a  2s  .c  o m
    return c;
}