Example #1
0
 //		public User getUserById(String userId)
 //		   {
 //		      User user=null;
 //		      session = HibernateUtil.getSessionFactory().getCurrentSession();
 //		      String hql = "FROM USER WHERE USER_ID= :userId";
 //		      try
 //		      {
 //		         Query query = session.createQuery(hql);
 //		         query.setParameter("userId", userId);
 //		         user = (query.list() != null)? (User)query.list().get(0):null;
 //		      }
 //		      catch(Exception e)
 //		      {
 //		         e.printStackTrace();
 //		      }
 //		      return user;
 //		   }
 public void initializeTransaction() {
   try {
     session = HibernateUtil.getSessionFactory().getCurrentSession();
     transaction = session.beginTransaction();
   } catch (Exception e) {
     if (transaction != null) {
       transaction.rollback();
     }
     e.printStackTrace();
   }
 }
Example #2
0
 public void addDoctor(Doctor doctor) {
   try {
     session = HibernateUtil.getSessionFactory().getCurrentSession();
     transaction = session.beginTransaction();
     session.save(doctor);
     System.out.println("Doctor with User is saved..");
   } catch (Exception e) {
     if (transaction != null) {
       transaction.rollback();
     }
     e.printStackTrace();
   }
   transaction.commit();
 }
Example #3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public List<Appointment> getAppointments(User user) {
    // List obj
    // Get all active appointments
    List<Appointment> appointmentList = new ArrayList();
    session = HibernateUtil.getSessionFactory().getCurrentSession();
    String hql;
    hql = "FROM APPOINTMENT WHERE ACTIVE = :active and user_id = :userId";
    try {
      Query query = session.createQuery(hql);
      query.setParameter(":active", true);
      query.setParameter(":userId", user.getUserId());
      appointmentList = (query.list() != null) ? (List<Appointment>) query.list() : null;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return appointmentList;
  }