Example usage for org.hibernate CacheMode IGNORE

List of usage examples for org.hibernate CacheMode IGNORE

Introduction

In this page you can find the example usage for org.hibernate CacheMode IGNORE.

Prototype

CacheMode IGNORE

To view the source code for org.hibernate CacheMode IGNORE.

Click Source Link

Document

The session will never interact with the cache, except to invalidate cache items when updates occur.

Usage

From source file:com.model.dao.EmployeeDao.java

public static Employee login(String email, String password) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;/*ww  w  . j a va 2 s . com*/

    Employee result = null;
    try {
        tx = session.beginTransaction();
        Query q = session.createQuery("FROM Employee where email = :email and password = :password");
        q.setParameter("email", email);
        q.setParameter("password", password);
        result = (Employee) q.list().get(0);
        tx.commit();
    } catch (Exception ex) {
        if (tx != null) {
            tx.rollback();
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }

    return result;
}

From source file:com.model.dao.VacationDao.java

public static boolean addVacation(Vacation v) {
    boolean result = false;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;/*from   w ww. j  a  v  a2s.  com*/

    try {
        tx = session.beginTransaction();
        session.save(v);
        tx.commit();
        result = true;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
            result = false;
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static List<Vacation> listMyVacations(long emp_id) {
    List<Vacation> result = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;//from  ww  w .  j av  a 2  s. c om

    try {
        tx = session.beginTransaction();
        Query q = session.createQuery("FROM Vacation  Where employee.id = :emp_id order by requestedAt DESC");
        q.setParameter("emp_id", emp_id);
        result = q.list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null)
            tx.rollback();
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static List<Vacation> listDepartmentVacations(long department_id) {
    List<Vacation> result = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;// w  w  w . jav  a 2s  .  co m

    try {
        tx = session.beginTransaction();
        Query q = session
                .createQuery("FROM Vacation  Where employee.department.id = :dep_id AND status = 'Pending'");
        q.setParameter("dep_id", department_id);
        result = q.list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null)
            tx.rollback();
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static boolean dmReject(Vacation v) {
    boolean result = false;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;//from  w  ww . j a  v a2s .  c  o  m

    try {
        tx = session.beginTransaction();
        v.setStatus(Vacation.VacationStatus.RejectedByDepartmentManager);
        session.update(v);
        tx.commit();
        result = true;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
            result = false;
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static boolean dmAccept(Vacation v) {
    boolean result = false;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;/*from ww  w . j av a 2 s . c  om*/

    try {
        tx = session.beginTransaction();
        v.setStatus(Vacation.VacationStatus.AcceptedByDepartmentManager);
        session.update(v);
        tx.commit();
        result = true;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
            result = false;
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static List<Vacation> listCompanyVacations() {
    List<Vacation> result = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;/*w  w  w .j a  v  a 2 s .c om*/

    try {
        tx = session.beginTransaction();
        result = session.createQuery("FROM Vacation  Where Status = 'AcceptedByDepartmentManager'").list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null)
            tx.rollback();
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static boolean gmReject(Vacation v) {
    boolean result = false;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;/*from  w  w w  .j  a  va 2s  .  c o  m*/

    try {
        tx = session.beginTransaction();
        v.setStatus(Vacation.VacationStatus.RejectedByCompanyManager);
        session.update(v);
        tx.commit();
        result = true;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
            result = false;
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.model.dao.VacationDao.java

public static boolean gmAccept(Vacation v) {
    boolean result = false;
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.setCacheMode(CacheMode.IGNORE);
    Transaction tx = null;//from  ww  w.j  av  a  2 s.c  o  m

    try {
        tx = session.beginTransaction();
        v.setStatus(Vacation.VacationStatus.Accepted);
        session.update(v);
        tx.commit();
        result = true;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
            result = false;
        }
        ex.printStackTrace();
    } finally {
        session.close();
    }
    return result;
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

License:Apache License

@Override
public ScrollableResults scrollableSearch(Long userId, DocumentState state, String queryString,
        SortOrder sortOrder, Date startDate, Date endDate) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w  w w .  ja v  a  2  s.c o m*/

    final FullTextQuery fullTextQuery = this.buildFullTextQuery(queryString, userId, startDate, endDate, false,
            state, FullTextQuery.THIS, FullTextQuery.SCORE);

    final Sort sort;
    switch (sortOrder) {
    case DATE_ASC:
        sort = new Sort(new SortField("id", SortField.LONG));
        break;
    case DATE_DESC:
        sort = new Sort(new SortField("id", SortField.LONG, true));
        break;
    case RELEVANCE:
        sort = new Sort(SortField.FIELD_SCORE, new SortField("id", SortField.LONG, true));
        break;
    default:
        throw new IllegalArgumentException("Unexpected SortOrder: " + sortOrder.name());
    }
    fullTextQuery.setSort(sort);

    fullTextQuery.setFetchSize(50);
    fullTextQuery.setReadOnly(true);
    fullTextQuery.setCacheable(false);
    fullTextQuery.setCacheMode(CacheMode.IGNORE);

    final ScrollableResults result = fullTextQuery.scroll(ScrollMode.FORWARD_ONLY);

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return result;
}