/**
   * Updates given object in the database. Returns true if update is successful, otherwise returns
   * false.
   *
   * @param object
   * @return
   */
  public synchronized boolean update(Object object) {

    Transaction transaction = null;
    Session session = null;
    boolean errorResult = false;

    try {
      session = HibernateUtil.getCurrentSession();
      transaction = session.beginTransaction();
      session.update(object);
      transaction.commit();

      return true;
    } catch (HibernateException exception) {
      rollback(transaction);
      BookingLogger.getDefault()
          .severe(this, Messages.METHOD_UPDATE, Messages.HIBERNATE_FAILED, exception);
      return errorResult;
    } catch (RuntimeException exception) {
      rollback(transaction);
      BookingLogger.getDefault()
          .severe(this, Messages.METHOD_UPDATE, Messages.GENERIC_FAILED, exception);
      return errorResult;
    } finally {
      closeSession();
    }
  }
  /**
   * Deletes all database entries based on the class where method is called.
   *
   * @return
   */
  public synchronized boolean deleteAll() {

    Session session = null;
    Transaction transaction = null;
    boolean errorResult = false;

    try {
      session = HibernateUtil.getCurrentSession();
      transaction = session.beginTransaction();
      SQLQuery query = session.createSQLQuery(DELETE_ALL + getTableName());
      query.executeUpdate();
      transaction.commit();
      return true;
    } catch (HibernateException exception) {
      rollback(transaction);
      BookingLogger.getDefault()
          .severe(this, Messages.METHOD_DELETE_ALL, Messages.HIBERNATE_FAILED, exception);
      return errorResult;
    } catch (RuntimeException exception) {
      rollback(transaction);
      BookingLogger.getDefault()
          .severe(this, Messages.METHOD_DELETE_ALL, Messages.GENERIC_FAILED, exception);
      return errorResult;
    } finally {
      closeSession();
    }
  }
  /**
   * Rolls back given transaction and logs it to the log file.
   *
   * @param transaction
   */
  protected void rollback(Transaction transaction) {

    try {
      if (transaction != null) transaction.rollback();
    } catch (HibernateException exception) {
      BookingLogger.getDefault()
          .severe(this, Messages.METHOD_ROLLBACK, Messages.HIBERNATE_FAILED, exception);
    }
  }