public void register(ActionEvent actionEvent) { CustomerDAO cdao = HibernateDAOFactory.instance().getCustomerDAO(); RequestContext context = RequestContext.getCurrentInstance(); FacesMessage msg = null; boolean loggedIn = false; FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); if (cdao.checklemail(email)) { Customer cs = new Customer(); cs.setEmail(email); cs.setPass(pass); cs.setFullName(fullName); cs.setAddress(address); cs.setPhone(phone); cs.setVip(vip); cdao.add(cs); loggedIn = true; msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registe succes! Welcome", email); String url = "index.xhtml"; try { ec.redirect(url); } catch (IOException ex) { } } else { loggedIn = false; msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Registe Error", "Invalid credentials"); } FacesContext.getCurrentInstance().addMessage(null, msg); context.addCallbackParam("loggedIn", loggedIn); }
public void ChangeData() { model.Customer c = customerdao.get(user.getCustomer().getCustomerid()); c.setCustomerfirstname(firstname); c.setCustomerlastname(lastname); c.setCustomeraddress(address); c.setCustomerphone(phone); customerdao.update(c); user.setCustomer(c); }
@Override public void addCustomer(String firstName, String lastName, Date dob, String address) { try { CustomerDAO dao = new RDBCustomerDAO(connection); Customer customer = new Customer(firstName, lastName, dob, address); dao.createCustomer(customer); } catch (Exception e) { System.out.println("Could not create cusomter."); e.printStackTrace(); } }
public void ChangePassword() { model.Account a = customerdao.getAccounts(user.getCustomer()).get(0); if (oldpassword.equals(a.getAccountpassword())) { a.setAccountpassword(newpassword); accountdao.update(a); } }
@Override public String readCustomer(int id) { String s; try { CustomerDAO dao = new RDBCustomerDAO(connection); // Employee employee = new Employee(id); // dao.createEmployee(employee); // return dao.readCustomer(id); // The Below worked before change back to this if things break. s = dao.readCustomer(id); return s; // return "TESTTTTTTTTTTTTTTTTTT"; } catch (Exception e) { System.out.println("Invalid Customer."); e.printStackTrace(); return e.toString(); } }
public String perform(HttpServletRequest request) { HttpSession session = request.getSession(); List<String> errors = new ArrayList<String>(); // authority judge if ((EmployeeBean) session.getAttribute("employee") == null) { return "employeelogin.do"; } request.setAttribute("errors", errors); EmployeeBean employee = (EmployeeBean) session.getAttribute("employee"); if (employee == null) { return "employeelogin.do"; } /* * Check the deposit form. */ DepositCheckForm depositcheckform = new DepositCheckForm(request); request.setAttribute("depositcheckform", depositcheckform); if (!depositcheckform.isPresent()) { return "employee_deposit_check.jsp"; } errors.addAll(depositcheckform.getValidationErrors()); if (errors.size() != 0) { return "employee_deposit_check.jsp"; } CustomerBean customer = (CustomerBean) session.getAttribute("modifyCustomer"); int id = customer.getCustomerId(); try { customer = customerDAO.read(id); } catch (RollbackException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } double amount = depositcheckform.getAmount(); ////////////////////// // Transaction START // ////////////////////// try { Transaction.begin(); TransactionBean transaction = new TransactionBean(); // what kind of transaction transaction.setTransactionType(TransactionType.DEPOSIT.toString()); // who request the deposit transaction.setCustomerId(customer.getCustomerId()); // how much money(in long) transaction.writeAmount(amount); // Create transaction transactionDAO.create(transaction); // update balance&available immediately. customer.writeCashBalance(amount); customerDAO.update(customer); Transaction.commit(); } catch (RollbackException e) { e.printStackTrace(); } //////////////////// // Transaction END// //////////////////// session.setAttribute("modifyCustomer", customer); // session.setAttribute("customer", customer); session.setAttribute( "message", "Thank you! You have successfully sent your deposit check request!"); return "success_employee.jsp"; }
// @Transactional public void loadData() { DataLoader dataLoader = new DataLoader(); try { Map<BigInteger, Supplier> suppliers = dataLoader.loadSuppliers("suppliers.xml"); System.out.println(suppliers.keySet()); logger.info("loadData : Persisting " + suppliers.size() + " suppliers"); for (Supplier s : suppliers.values()) { supplierDAO.create(s); } Map<String, Customer> customers = dataLoader.loadCustomers("customers.xml"); logger.info("loadData : Persisting " + customers.size() + " customers"); for (Customer c : customers.values()) { customerDAO.create(c); } Map<BigInteger, Category> categories = dataLoader.loadCategories("categories.xml"); logger.info("loadData : Persisting " + categories.size() + " categories"); for (Category c : categories.values()) { categoryDAO.create(c); } Map<BigInteger, Shipper> shippers = dataLoader.loadShippers("shippers.xml"); logger.info("loadData : Persisting " + shippers.size() + " shippers"); for (Shipper s : shippers.values()) { shipperDAO.create(s); } Map<BigInteger, Product> products = dataLoader.loadProducts("products.xml", suppliers, categories); logger.info("loadData : Persisting " + products.size() + " products"); for (Product p : products.values()) productDAO.create(p); Map<BigInteger, Employee> employees = dataLoader.loadEmployees("employees.xml"); logger.info("loadData : Persisting " + employees.size() + " employees"); for (Employee e : employees.values()) { try { employeeDAO.create(e); } catch (Exception es) { logger.warn(es.getMessage()); } } logger.info("Loading orders with details"); Map<BigInteger, Order> orders = dataLoader.loadOrders("orders_rand_10000.xml", customers, employees, shippers); orders.putAll(dataLoader.loadOrders("orders_rand_20000.xml", customers, employees, shippers)); Map<Integer, OrderDetails> orderDetails = dataLoader.loadOrderDetails("orderdetails_rand_10000.xml", orders, products); orderDetails.putAll( dataLoader.loadOrderDetails("orderdetails_rand_20000.xml", orders, products)); Map<Order, List<OrderDetails>> orderToOrderDetails = buildOrderToOrderDetailsMap(orderDetails); for (OrderDetails od : orderDetails.values()) { od.getOrderID().addOrderDetails(od); } List<Order> orderList = new ArrayList<Order>(orders.values()); logger.info("Orders persisting:"); int size = orderList.size(); int i = 0; long start, stop = 0; StringBuilder builder = new StringBuilder(); for (int j = 1000; j < size; j += 1000) { start = System.currentTimeMillis(); entityManager.getTransaction().begin(); while (i < j) { // entityManager.persist(orderList.get(i)); orderDAO.create(orderList.get(i)); i++; } entityManager.getTransaction().commit(); stop = System.currentTimeMillis(); builder.append((j / 1000) + " : " + (stop - start) + "\n"); logger.info("Orders round: " + j / 1000 + " : " + (stop - start)); } System.out.println(builder.toString()); } catch (Exception e) { e.printStackTrace(); } }