List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
From source file:com.court.controller.MemberfxmlController.java
private List<MemberLoan> getAllMemberLoans(String mCode) { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class); c.createAlias("member", "m").add(Restrictions.disjunction().add(Restrictions.eq("m.memberId", mCode))); List<MemberLoan> mList = c.list(); session.close();//from w w w . j ava 2 s.c o m return mList; }
From source file:com.court.controller.MemberfxmlController.java
private boolean anyIncompleteLoansOfMember(String memberCode) { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class); List<MemberLoan> lns = c.createAlias("member", "m").add(Restrictions.eq("m.memberId", memberCode)) .add(Restrictions.eq("isComplete", false)).list(); return !lns.isEmpty(); }
From source file:com.court.controller.MemberfxmlController.java
private int getSubscriptionsByMemberAndSubscription(Session session, String fee_name, Integer id) { System.out.println("===============QUERY START============="); Criteria c = session.createCriteria(MemberSubscriptions.class); MemberSubscriptions ms = (MemberSubscriptions) c.createAlias("member", "m") .createAlias("memberSubscription", "ms").add(Restrictions.eq("m.id", id)) .add(Restrictions.eq("ms.feeName", fee_name)).uniqueResult(); System.out.println("===============QUERY END============="); if (ms != null) { return ms.getId(); } else {//from ww w . j a va2s . c o m return 0; } }
From source file:com.court.controller.MemberfxmlController.java
private MemberSubscriptions getMemberSubscriptionsFromMember(String member_code, Session s) { Criteria c = s.createCriteria(MemberSubscriptions.class, "ms"); c.createAlias("ms.member", "m").add(Restrictions.eq("m.memberId", member_code)).setMaxResults(1); MemberSubscriptions ms = (MemberSubscriptions) c.uniqueResult(); return ms;/*from w w w. j a va 2 s .c om*/ }
From source file:com.court.controller.MemberfxmlController.java
private double getContinuingBalance(String mbrCode) { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(MemberLoan.class, "ml"); c.createAlias("ml.member", "m"); c.add(Restrictions.eq("m.memberId", mbrCode)); List<MemberLoan> list = c.list(); double sum = list.stream().mapToDouble(MemberLoan::getKotaLeft).sum(); s.close();/*ww w . j a v a 2 s. c o m*/ return sum; }
From source file:com.court.controller.MemberfxmlController.java
@FXML private void onMbrStatHistoryBtnAction(ActionEvent event) { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(StatJob.class, "sj"); c.createAlias("sj.member", "m"); c.add(Restrictions.eq("m.memberId", member_code_txt.getText().trim())); List<StatJob> stat_hst = c.list(); s.close();/* w w w .j a v a 2 s . co m*/ createJobStatHistoryTable(stat_hst); }
From source file:com.court.controller.OldLoansFxmlController.java
public void loadOldLoans() { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(MemberLoan.class, "ml"); c.createAlias("ml.member", "m"); c.add(Restrictions.eq("ml.oldLoan", true)); c.add(Restrictions.eq("m.memberId", searchMbr.getMemberId())); List<MemberLoan> list = c.list(); s.close();//w w w.j a v a2 s . co m initOldLoanTable(list); }
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 ww . j a v a 2 s . co m*/ 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.ReportFormFxmlController.java
@FXML private void onLoanAction(ActionEvent event) { Dialog<AllLoansReport> dialog = new Dialog<>(); dialog.setTitle("Loans"); dialog.setHeaderText("Select Office"); ButtonType viewBtn = new ButtonType("View Report", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(viewBtn, ButtonType.CANCEL); GridPane grid = new GridPane(); grid.setHgap(10);//from ww w . j av a 2 s . co m grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); TextField bField = new TextField(); TextFields.bindAutoCompletion(bField, getBranches(true)); DatePicker fDate = new DatePicker(); DatePicker tDate = new DatePicker(); FxUtilsHandler.setDatePickerTimeFormat(fDate, tDate); grid.add(new Label("Office:"), 0, 0); grid.add(bField, 1, 0); grid.add(new Label("Start Date:"), 0, 1); grid.add(fDate, 1, 1); grid.add(new Label("End Date:"), 0, 2); grid.add(tDate, 1, 2); dialog.getDialogPane().setContent(grid); fDate.setValue(LocalDate.now()); tDate.setValue(LocalDate.now()); dialog.setResultConverter(db -> { if (db == viewBtn) { return new AllLoansReport(bField.getText().split("-")[0], fDate.getValue(), tDate.getValue()); } return null; }); Optional<AllLoansReport> result = dialog.showAndWait(); result.ifPresent(b -> { // String reportPath = "com/court/reports/LoansReport.jasper"; String reportPath = null; try { reportPath = PropHandler.getStringProperty("report_path") + "LoansReport.jasper"; } catch (IOException ex) { Logger.getLogger(ReportFormFxmlController.class.getName()).log(Level.SEVERE, null, ex); } Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class, "ml"); c.createAlias("ml.member", "m"); c.createAlias("m.branch", "b"); if (!b.getBranch().equalsIgnoreCase("All")) { c.add(Restrictions.eq("b.branchCode", b.getBranch())); } c.add(Restrictions.between("ml.grantedDate", FxUtilsHandler.getDateFrom(b.getFd()), FxUtilsHandler.getDateFrom(b.getTd()))); c.addOrder(Order.asc("b.branchName")); List<MemberLoan> list = (List<MemberLoan>) c.list(); JRBeanCollectionDataSource memberLoanBeanCollection = new JRBeanCollectionDataSource(list); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); Map<String, Object> map = new HashMap<>(); map.put("companyName", ReportHandler.COMPANY_NAME); map.put("companyAddress", ReportHandler.ADDRESS); map.put("reportTitle", "Welfare Loan List Granted From " + sdf.format(FxUtilsHandler.getDateFrom(b.getFd())) + " To " + sdf.format(FxUtilsHandler.getDateFrom(b.getTd()))); ReportHandler rh = new ReportHandler(reportPath, map, memberLoanBeanCollection); // rh.genarateReport(); boolean blah = rh.genReport(); if (blah) { rh.viewReport(); } session.close(); }); }
From source file:com.court.controller.ReportFormFxmlController.java
@FXML private void onMemberAction(ActionEvent event) { Dialog<Pair<String, Integer>> dialog = new Dialog<>(); dialog.setTitle("Member List"); dialog.setHeaderText("Select Working Office"); ButtonType viewBtn = new ButtonType("View Report", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(viewBtn, ButtonType.CANCEL); GridPane grid = new GridPane(); grid.setHgap(10);/*from www . j a v a 2s .c om*/ grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); TextField bField = new TextField(); ComboBox<String> cbox = new ComboBox<>(FXCollections.observableArrayList("All", "Active", "Deactivated")); cbox.getSelectionModel().select(0); TextFields.bindAutoCompletion(bField, getBranches(true)); grid.add(new Label("Office:"), 0, 0); grid.add(bField, 1, 0); grid.add(new Label("Member Status:"), 0, 1); grid.add(cbox, 1, 1); dialog.getDialogPane().setContent(grid); dialog.setResultConverter(db -> { if (db == viewBtn) { return new Pair<>(bField.getText(), cbox.getSelectionModel().getSelectedIndex()); } return null; }); Optional<Pair<String, Integer>> result = dialog.showAndWait(); result.ifPresent(b -> { //String reportPath = "com/court/reports/MemberReport.jasper"; String reportPath = null; try { reportPath = PropHandler.getStringProperty("report_path") + "MemberReport.jasper"; } catch (IOException ex) { Logger.getLogger(ReportFormFxmlController.class.getName()).log(Level.SEVERE, null, ex); } Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(Member.class, "m"); c.createAlias("m.branch", "b"); if (!b.getKey().equalsIgnoreCase("All")) { c.add(Restrictions.eq("b.branchCode", b.getKey().split("-")[0])); } switch (b.getValue()) { case 1: c.add(Restrictions.eq("m.status", true)); break; case 2: c.add(Restrictions.eq("m.status", false)); break; } List<Member> list = (List<Member>) c.list(); List<Member> orderedList = list.stream() .sorted(Comparator.comparing(p -> p.getBranch().getBranchCode())).collect(Collectors.toList()); JRBeanCollectionDataSource memberBeanCollection = new JRBeanCollectionDataSource(orderedList); Map<String, Object> map = new HashMap<>(); map.put("companyName", ReportHandler.COMPANY_NAME); map.put("companyAddress", ReportHandler.ADDRESS); map.put("reportTitle", "Welfare Member List Of Working Office - " + b.getKey().split("-")[1]); ReportHandler rh = new ReportHandler(reportPath, map, memberBeanCollection); // rh.genarateReport(); boolean blah = rh.genReport(); if (blah) { rh.viewReport(); } session.close(); }); }