List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.court.controller.OldLoansFxmlController.java
private void deleteLoan(Integer id) { 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 delete the selected loan ?"); Optional<ButtonType> rs = alert_confirm.showAndWait(); if (rs.get() == ButtonType.OK) { Session s = HibernateUtil.getSessionFactory().openSession(); s.beginTransaction();//from w w w. j a va 2s . com MemberLoan ml = (MemberLoan) s.load(MemberLoan.class, id); //==================CHECK IF ANY LOAN PAYMENTS EXIST BEFORE DELETE if (ml.getLoanPayments().isEmpty()) { s.delete(ml); s.getTransaction().commit(); //================================================ Criteria c = s.createCriteria(MemberLoan.class); c.createAlias("member", "m"); c.add(Restrictions.eq("oldLoan", true)); c.add(Restrictions.eq("oldLoan", true)); c.add(Restrictions.eq("m.memberId", searchMbr.getMemberId())); List<MemberLoan> list = c.list(); s.close(); initOldLoanTable(list); } 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(); } //================================================ } }
From source file:com.court.controller.ProfileFxmlController.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 ww w .j av a 2 s. c om return; } if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); User user = (User) session.load(User.class, loggedSession.loggedUser().getId()); user.setUserName(usr_name_txt.getText()); user.setFullName(fullname_txt.getText()); user.setTel(tel_text.getText()); user.setAddress(adrs_txt.getText()); user.setEmail(email_txt.getText()); user.setImgPath(imgString == null ? "" : imgString.getImg_path().toString()); session.save(user); session.getTransaction().commit(); session.close(); Alert success = new Alert(Alert.AlertType.INFORMATION); success.setTitle("Success"); success.setHeaderText("Successfully Updated !"); success.setContentText("You have successfully updated your information !"); Optional<ButtonType> result = success.showAndWait(); if (result.get() == ButtonType.OK) { loadLoggedUserToForm(user); loggedSession.updateLoggedUser(user); DashBoardFxmlController.controller.setLoggedSession(loggedSession.getUrole()); } } }
From source file:com.court.controller.ProfileFxmlController.java
@FXML private void onChangePassBtnAction(ActionEvent event) throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/court/view/ResetPassFxml.fxml")); VBox node = (VBox) loader.load();//from w w w . ja va2 s. c o m ResetPassFxmlController controller = (ResetPassFxmlController) loader.getController(); Alert alert_custom = new Alert(Alert.AlertType.NONE); alert_custom.setTitle("Change Password"); alert_custom.getDialogPane().setContent(node); ButtonType buttonTypeCancel = new ButtonType("", ButtonBar.ButtonData.CANCEL_CLOSE); alert_custom.getButtonTypes().add(buttonTypeCancel); alert_custom.getDialogPane().lookupButton(buttonTypeCancel).setVisible(false); alert_custom.show(); validateResetPassAlertFields(controller); controller.getCancel_btn().setOnAction(e -> { alert_custom.hide(); }); controller.getRest_btn().setOnAction(e -> { //Reset Command here..... if (va1.validationResultProperty().get().getErrors().isEmpty()) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); int userId = getUserIdByUserName(session, usr_name_txt.getText()); User uLoaded = (User) session.load(User.class, userId); uLoaded.setPassword(PasswordHandler.encryptPassword(controller.getPass_again_field().getText())); session.update(uLoaded); session.getTransaction().commit(); session.close(); controller.getError_label().setStyle("-fx-text-fill: #349a46;"); controller.getError_label().setText("Successfully saved the password."); } else { Collection<ValidationMessage> e_messages = va1.validationResultProperty().get().getMessages(); String error_txt = ""; for (ValidationMessage e_msg : e_messages) { error_txt += e_msg.getText() + "\n"; } controller.getError_label().setText(error_txt); } }); }
From source file:com.court.controller.UserManageFxmlController.java
@FXML private void saveBtnAction(ActionEvent event) throws IOException { //user save validation problem :(--------- Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();// w w w. j a v a 2s. com UserHasUserRole uhur; int id = getUHasRoleIdByUserName(session, user_name_txt.getText()); if (id != 0) { uhur = (UserHasUserRole) session.load(UserHasUserRole.class, id); // ValidationSupport.setRequired(user_name_txt, true); } else { uhur = new UserHasUserRole(); } 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(); return; } if (validationSupport.validationResultProperty().get().getErrors().isEmpty()) { User u = new User(); u.setFullName(full_name_txt.getText()); u.setUserName(user_name_txt.getText()); u.setEmail(email_txt.getText()); u.setAddress(address_txt.getText()); u.setTel(tele_txt.getText()); u.setImgPath(imgString == null ? "" : imgString.getImg_path().toString()); u.setStatus(true); uhur.setUser(u); uhur.setUserRole(getUserRoleFrom(usr_role_combo.getSelectionModel().getSelectedItem(), session)); session.saveOrUpdate(uhur); session.getTransaction().commit(); session.close(); Alert alert_success = new Alert(Alert.AlertType.INFORMATION); alert_success.setTitle("Success"); alert_success.setHeaderText("Successfully Saved !"); alert_success.setContentText("You have successfully saved" + " \"" + full_name_txt.getText() + "\"."); Optional<ButtonType> result = alert_success.showAndWait(); if (result.get() == ButtonType.OK) { initUserRoleTable(getAllUserRoles()); //if logged user changes his own details...... if (loggedSession.getUrole().getId() == id) { loggedSession.setUrole(uhur); DashBoardFxmlController.controller.setLoggedSession(loggedSession.getUrole()); } } } }
From source file:com.court.controller.UserManageFxmlController.java
@FXML private void onSaveRoleBtnAction(ActionEvent event) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*from ww w. j a va2 s . com*/ UserRole uuRole; int id = getIdByUserRole(session, usr_role_name_txt.getText().trim().toLowerCase()); if (id != 0) { uuRole = (UserRole) session.load(UserRole.class, id); } else { uuRole = new UserRole(); } uuRole.setRoleName(usr_role_name_txt.getText().trim().toLowerCase()); uuRole.setStatus(true); if (checkedItems != null) { //first have to delete already exist privileges deleteAllDBExitsPrivilages(session, uuRole.getId()); Set<PrivCat> pCats = new HashSet<>(); checkedItems.forEach(e -> { PrivCat pc = new PrivCat(); pc.setUserRole(uuRole); pc.setUsrRolePrivilage(getPrivilegeByPrivId(session, e.getValue().getId())); pCats.add(pc); }); uuRole.setPrivCats(pCats); } session.saveOrUpdate(uuRole); session.getTransaction().commit(); session.close(); Alert alert_success = new Alert(Alert.AlertType.INFORMATION); alert_success.setTitle("Success"); alert_success.setHeaderText("Successfully Saved !"); alert_success .setContentText("You have successfully save the \"" + usr_role_name_txt.getText() + " user Role\""); Optional<ButtonType> showAndWait = alert_success.showAndWait(); if (showAndWait.get() == ButtonType.OK) { initUserRoleTable(getAllUserRoles()); FxUtilsHandler.clearFields(main_grid); imgString = null; usr_img_view.setImage(new Image(getClass().getResourceAsStream(FileHandler.MEMBER_DEFAULT_IMG))); FxUtilsHandler.activeDeactiveChildrenControls(true, main_grid); } }
From source file:com.court.controller.UserManageFxmlController.java
@FXML private void resetPassAction(ActionEvent event) throws IOException { boolean flag = isPassAlreadyExist(user_name_txt.getText()); if (flag) {/* w ww . j av a2 s.co m*/ FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/court/view/NewPassFxml.fxml")); VBox node = (VBox) loader.load(); NewPassFxmlController controller = (NewPassFxmlController) loader.getController(); Alert alert_custom = new Alert(Alert.AlertType.NONE); alert_custom.setTitle("New Password"); alert_custom.getDialogPane().setContent(node); ButtonType buttonTypeCancel = new ButtonType("", ButtonBar.ButtonData.CANCEL_CLOSE); alert_custom.getButtonTypes().add(buttonTypeCancel); alert_custom.getDialogPane().lookupButton(buttonTypeCancel).setVisible(false); alert_custom.show(); validateNewPassAlertFields(controller); controller.getCancel_btn().setOnAction(e -> { alert_custom.hide(); }); controller.getSave_btn().setOnAction(e -> { //Save command here....... if (va1.validationResultProperty().get().getErrors().isEmpty()) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); int userId = getUserIdByUserName(session, user_name_txt.getText()); User uLoaded = (User) session.load(User.class, userId); uLoaded.setPassword( PasswordHandler.encryptPassword(controller.getPass_again_field().getText())); session.update(uLoaded); session.getTransaction().commit(); session.close(); controller.getError_label().setStyle("-fx-text-fill: #349a46;"); controller.getError_label().setText("Successfully saved the password."); } else { Collection<ValidationMessage> e_messages = va1.validationResultProperty().get().getMessages(); String error_txt = ""; for (ValidationMessage e_msg : e_messages) { error_txt += e_msg.getText() + "\n"; } controller.getError_label().setText(error_txt); } }); } else { FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/court/view/ResetPassFxml.fxml")); VBox node = (VBox) loader.load(); ResetPassFxmlController controller = (ResetPassFxmlController) loader.getController(); Alert alert_custom = new Alert(Alert.AlertType.NONE); alert_custom.setTitle("Reset Password"); alert_custom.getDialogPane().setContent(node); ButtonType buttonTypeCancel = new ButtonType("", ButtonBar.ButtonData.CANCEL_CLOSE); alert_custom.getButtonTypes().add(buttonTypeCancel); alert_custom.getDialogPane().lookupButton(buttonTypeCancel).setVisible(false); alert_custom.show(); validateResetPassAlertFields(controller); controller.getCancel_btn().setOnAction(e -> { alert_custom.hide(); }); controller.getRest_btn().setOnAction(e -> { //Reset Command here..... if (va2.validationResultProperty().get().getErrors().isEmpty()) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); int userId = getUserIdByUserName(session, user_name_txt.getText()); User uLoaded = (User) session.load(User.class, userId); uLoaded.setPassword( PasswordHandler.encryptPassword(controller.getPass_again_field().getText())); session.update(uLoaded); session.getTransaction().commit(); session.close(); controller.getError_label().setStyle("-fx-text-fill: #349a46;"); controller.getError_label().setText("Successfully saved the password."); } else { Collection<ValidationMessage> e_messages = va2.validationResultProperty().get().getMessages(); String error_txt = ""; for (ValidationMessage e_msg : e_messages) { error_txt += e_msg.getText() + "\n"; } controller.getError_label().setText(error_txt); } }); } }
From source file:com.court.controller.UserManageFxmlController.java
private void getUserHasRoleById(Integer id) throws MalformedURLException { imgString = new ImageWithString(); Session session = HibernateUtil.getSessionFactory().openSession(); UserHasUserRole lu = (UserHasUserRole) session.load(UserHasUserRole.class, id); full_name_txt.setText(lu.getUser().getFullName()); user_name_txt.setText(lu.getUser().getUserName()); email_txt.setText(lu.getUser().getEmail()); address_txt.setText(lu.getUser().getAddress()); tele_txt.setText(lu.getUser().getTel()); usr_role_combo.getSelectionModel().select(lu.getUserRole().getRoleName()); if (!lu.getUser().getImgPath().trim().isEmpty()) { imgString.setImg_path(new File(lu.getUser().getImgPath()).toPath()); usr_img_view.setImage(new Image(new File(lu.getUser().getImgPath()).toURI().toURL().toString())); }// w w w. j av a 2 s .c o m session.close(); }
From source file:com.court.main.MainClass.java
private Company loadCompany() { Session session = HibernateUtil.getSessionFactory().openSession(); Company com = (Company) session.load(Company.class, 1); session.close();// w ww .j av a2 s . c o m return com; }
From source file:com.dao.InpatientDao.java
public void addInpatient(String patientName, int pAge, String gender, int pPhoneNumber, String pAddress, int doctors, String admitDate, String dischargeDate, int roomNum) { System.out.println("in addpatient"); Session session = HibernateUtil.getSession(); try {//from w w w .j a v a 2 s. c om Transaction tx = session.beginTransaction(); Doctor d1 = (Doctor) session.load(Doctor.class, doctors); Room r1 = (Room) session.load(Room.class, roomNum); Patient p1 = new Patient(); InPatient p2 = new InPatient(); //Room r1 = new Room(); p2.setName(patientName); p2.setAge(pAge); p2.setGender(gender); p2.setPhoneNumber(pPhoneNumber); p2.setAddress(pAddress); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); p2.setAdmitDate(format.parse(admitDate)); p2.setDischargeDate(format.parse(dischargeDate)); //p2.setRoomNumber(roomNum); //r1.setRoomType(roomType); p2.setDoctor(d1); //p2.setPatient(p1); p2.setRoom(r1); //session.save(r1); //session.save(p1); session.save(p2); tx.commit(); } catch (Exception e) { System.out.println(e.getMessage()); } finally { // Actual contact insertion will happen at this step session.close(); } }
From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java
License:GNU General Public License
/** * Returns a entity t (clazz type) that it corresponds to the id passed. * Made a searching by id.//from w w w. j a va2 s . c o m * * @param id * @return T Data type of entity * @throws PersistenceException */ @Override @SuppressWarnings("unchecked") public T getById(Long id) throws PersistenceException { Session session = this.getCurrentSession(); if (id == null) { logger.error("Persistence layer error: Illegal Argument in getById method, Id is null (" + PersistenceError.ARGUMENT_NULL.getMessage() + ")"); throw new PersistenceException(PersistenceError.ARGUMENT_NULL); } T t = (T) session.load(clazz, id.longValue()); if (loggerInfoEnabled) logger.debug("Persistence layer info: " + clazz.getSimpleName() + " loaded successfully, details=" + t); return t; }