List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:com.Accenture.DAO.trainerDao.java
public List<markregister> findattendance(String email) { List<markregister> list = new ArrayList<>(); Session ses = null;// www .j a v a 2 s . com SessionFactory sf = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); ses = sf.openSession(); ses.beginTransaction(); String HQL_QUERY = "from markregister markregister where fname =:email"; org.hibernate.Query query = ses.createQuery(HQL_QUERY); query.setParameter("email", email); for (Iterator it = query.iterate(); it.hasNext();) { markregister b = (markregister) it.next(); b.getLname(); b.getStatus(); b.getDate(); list.add(b); } return list; }
From source file:com.Accenture.DAO.trainerDao.java
public List<trainerpojo> search0(String group, String loc) { List<trainerpojo> result = new ArrayList<>(); Session session = null;//from w w w .j a v a 2s. c om SessionFactory sessionfactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionfactory.openSession(); session.beginTransaction(); String HQL_QUERY = "from trainerpojo trainerpojo where groupID='" + group + "' AND location='" + loc + "'"; org.hibernate.Query query = session.createQuery(HQL_QUERY); for (Iterator it = query.iterate(); it.hasNext();) { trainerpojo l = (trainerpojo) it.next(); l.getEmail(); l.getContact(); l.getGender(); l.getIdNumber(); l.getLocation(); l.getName(); l.getQualification(); l.getSurname(); result.add(l); } return result; }
From source file:com.Accenture.Java.Viewlearner.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request// ww w. ja va 2 s . com * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); Session session; try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Viewlearner</title>"); out.println("</head>"); out.println("<body>"); SessionFactory sessionfactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionfactory.openSession(); session.beginTransaction(); String hgl = "from grouppojo groups"; org.hibernate.Query query = session.createQuery(hgl); //query.setParameter(hgl, out); System.out.println("Reading values"); for (Iterator it = query.iterate(); it.hasNext();) { grouppojo model = (grouppojo) it.next(); out.println("Reading the location table"); out.println("<h2>" + model.getGroupid() + "</h2>"); out.println("<h2>" + model.getGname() + "</h2>"); out.println("<h2>" + model.getStart() + "</h2>"); out.println("</br>"); } session.getTransaction().commit(); System.out.println("Done!"); out.println("<h1>Servlet Viewlearner at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:com.Accenture.Servlet.Viewlearner.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from w w w . j ava 2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); Session session; try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Viewlearner</title>"); out.println("</head>"); out.println("<body>"); SessionFactory sessionfactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionfactory.openSession(); session.beginTransaction(); String hgl = "from learnerspojo learner"; org.hibernate.Query query = session.createQuery(hgl); //query.setParameter(hgl, out); System.out.println("Reading values"); for (Iterator it = query.iterate(); it.hasNext();) { learnerspojo model = (learnerspojo) it.next(); out.println("Reading the location table"); out.println("<h2>" + model.getLID() + "</h2>"); out.println("<h2>" + model.getLName() + "</h2>"); out.println("<h2>" + model.getLSurname() + "</h2>"); out.println("</br>"); } session.getTransaction().commit(); System.out.println("Done!"); out.println("<h1>Servlet Viewlearner at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:com.addshare.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); int m = 0;/*from w ww. java 2 s. co m*/ HttpSession session = request.getSession(true); try { int comp = Integer.parseInt(request.getParameter("form1")); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file SessionFactory factory = cfg.buildSessionFactory(); Session session1 = factory.openSession(); Transaction t = session1.beginTransaction(); if (comp == 1) { String comp1 = request.getParameter("comp"); String rate = request.getParameter("rate"); String email = (String) session.getAttribute("email"); int rate1 = Integer.parseInt(rate); int opening = rate1; Date date = new Date(); ShareCom u = new ShareCom(rate1, opening, date, rate1, rate1, email, comp1); session1.persist(u); t.commit(); session1.close(); request.setAttribute("success", "suc"); RequestDispatcher rd = request.getRequestDispatcher("admindash.jsp"); rd.forward(request, response); } } catch (Exception e1) { request.setAttribute("success", "err"); RequestDispatcher rd = request.getRequestDispatcher("admindash.jsp"); rd.forward(request, response); } }
From source file:com.akatkar.hibernate3.Application.java
public static void main(String[] args) { System.out.println("running..."); AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.configure();// w w w .j av a 2s.c o m new SchemaExport(cfg).create(true, true); SessionFactory sessionFactory = cfg.buildSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); CustomerInfo ci = new CustomerInfo("Carrefour", "Erenky", "stanbul", "02163445366"); session.save(ci); session.getTransaction().commit(); session.close(); }
From source file:com.akatkar.winerydemoproject.Application.java
public static void main(String[] args) { System.out.println("running ..."); SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try {/*from w ww .j a va 2 s .co m*/ } finally { session.close(); sessionFactory.close(); } }
From source file:com.akursat.ws.UserServiceImpl.java
@Override public String find(String username) { Transaction trns = null;//from w w w . j av a 2s . com SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try { trns = session.beginTransaction(); Query query = session.createQuery("from Users where username=:username_param") .setParameter("username_param", username); List<Users> users = query.list(); if (users.isEmpty()) { return "Empty"; } else if (users.size() == 1) { return users.get(0).getEmail() + users.get(0).getBirthday() + users.get(0).getSex(); } session.getTransaction().commit(); sessionFactory.close(); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } return ""; }
From source file:com.akursat.ws.UserServiceImpl.java
@Override public void createUser(String username, String email, String password, Date birthday, Short sex) { Transaction trns = null;/*w w w. ja va2 s . c om*/ SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try { trns = session.beginTransaction(); if (find(username) != null) { System.out.println("User already exist!"); } else { Users u = new Users(); u.setUsername(username); u.setEmail(email); u.setBirthday(birthday); u.setPassword(password); u.setSex(sex); session.save(u); session.getTransaction().commit(); } } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } }
From source file:com.akursat.ws.UserServiceImpl.java
@Override public void deleteUser(String username) { Transaction trns = null;//from w ww . j a v a 2 s .c om SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try { trns = session.beginTransaction(); Query query = session.createQuery("delete Users where username = :username_param"); query.setParameter("username_param", username); int result = query.executeUpdate(); session.getTransaction().commit(); System.out.println((result == 1 ? "User deleted." : "Fail!")); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } }