Example usage for org.hibernate Session setCacheMode

List of usage examples for org.hibernate Session setCacheMode

Introduction

In this page you can find the example usage for org.hibernate Session setCacheMode.

Prototype

void setCacheMode(CacheMode cacheMode);

Source Link

Document

Set the cache mode.

Usage

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;// w  w  w .  j ava  2  s . com

    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;//from  ww w. j ava 2  s. c  o m

    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  av  a2 s  . com*/

    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;/*  w w  w .j  a va2  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.openkm.dao.LanguageDAO.java

License:Open Source License

/**
 * Find all languages//from w ww .  j a  v  a  2  s  . com
 *
 * @param cacheMode Execute language query with the designed cache mode.
 */
@SuppressWarnings("unchecked")
private static List<Language> findAll(CacheMode cacheMode) throws DatabaseException {
    log.debug("findAll({})", cacheMode);
    String qs = "from Language lg order by lg.name asc";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.setCacheMode(cacheMode);
        Query q = session.createQuery(qs).setCacheable(true);
        List<Language> ret = q.list();
        log.debug("findAll: {}", ret);
        return ret;
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.rdsic.pcm.common.HibernateUtil.java

public static Session currentSession() {
    initSessionFactory("hibernate.cfg.xml");
    Session s = (Session) session.get();
    if ((s == null) || (!s.isConnected())) {
        s = sessionFactory.openSession();
        s.setFlushMode(FlushMode.COMMIT);
        s.setCacheMode(CacheMode.IGNORE);
        session.set(s);//  w  ww .jav a2 s.  co m
    }
    return s;
}

From source file:com.rdsic.pcm.common.HibernateUtil.java

public static Session currentSession(String cfgFile) {
    initSessionFactory(cfgFile);// ww w. j a v  a  2  s  .  c o  m
    Session s = (Session) session.get();
    if ((s == null) || (!s.isConnected())) {
        s = sessionFactory.openSession();
        s.setFlushMode(FlushMode.COMMIT);
        s.setCacheMode(CacheMode.IGNORE);
        session.set(s);
    }
    return s;
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public List<BapiDD03LPojo> select() throws NotFoundException {
    List<BapiDD03LPojo> list = null;
    Session session = null;
    try {//from   w  ww .  java  2 s. c o  m
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LPojo").addOrder(Order.asc("id.TABNAME"))
                .addOrder(Order.asc("id.FIELDNAME")).addOrder(Order.asc("id.AS4LOCAL"))
                .addOrder(Order.asc("id.AS4VERS")).addOrder(Order.asc("id.POSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public List<BapiDD03LPojo> selectTabFields(String tabName) throws NotFoundException {
    List<BapiDD03LPojo> list = null;
    Session session = null;
    try {/* w w  w. j  av  a  2s.  c om*/
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LPojo").add(Restrictions.eq("id.TABNAME", tabName))
                .addOrder(Order.asc("id.POSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiDD03LDMDao.java

public List<BapiDD03LDMPojo> selectKeyFields(String tabName) throws NotFoundException {
    List<BapiDD03LDMPojo> list = null;
    Session session = null;
    try {/*  w  w  w.  ja  v  a  2s .c  o  m*/
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LDMPojo").add(Restrictions.eq("id.TABNAME", tabName))
                .add(Restrictions.eq("DM_KEYFLAG", "X")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}