List of usage examples for org.hibernate Session setCacheMode
void setCacheMode(CacheMode cacheMode);
From source file:at.molindo.esi4j.module.hibernate.HibernateEntityResolver.java
License:Apache License
public void openResolveSession() { Session session = _localSession.get(); if (session != null) { log.warn("session already open, now closing first"); closeResolveSession();//from www.j ava2 s . co m session = null; } session = getNewSession(getSessionFactory()); session.setDefaultReadOnly(true); session.setCacheMode(CacheMode.GET); session.setFlushMode(FlushMode.MANUAL); session.beginTransaction(); _localSession.set(session); }
From source file:br.com.hslife.catu.db.HibernateUtil.java
License:Open Source License
public static Session getSession() { if (sessionThread.get() == null) { Session session = sessionFactory.openSession(); session.setCacheMode(CacheMode.IGNORE); sessionThread.set(session);/*ww w . j a v a2 s . c o m*/ System.out.println("Nova sesso criada"); } return (Session) sessionThread.get(); }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
public List<AbstractEntity> insert(AbstractEntity obj) throws DAOException { List<AbstractEntity> lista = new ArrayList<AbstractEntity>(); try {/*from w ww.j av a 2 s. c om*/ Session session = currentSession(); session.setCacheMode(CacheMode.GET); session.save(obj); session.flush(); lista.add(obj); return lista; } catch (HibernateException e) { throw new DAOException(e); } }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
public List<AbstractEntity> insertOrUpdate(AbstractEntity obj) throws DAOException { List<AbstractEntity> lista = new ArrayList<AbstractEntity>(); try {//w w w. j a va 2 s .c om Session session = currentSession(); session.setCacheMode(CacheMode.GET); session.saveOrUpdate(obj); session.flush(); lista.add(obj); return lista; } catch (HibernateException e) { throw new DAOException(e); } }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
public List<AbstractEntity> update(AbstractEntity obj) throws DAOException { List<AbstractEntity> lista = new ArrayList<AbstractEntity>(); try {/*from w w w. j a v a2 s . c o m*/ Session session = currentSession(); session.setCacheMode(CacheMode.GET); session.update(obj); session.flush(); lista.add(obj); return lista; } catch (HibernateException e) { throw new DAOException(e); } }
From source file:com.adsapient.shared.dao.HibernateEntityDao.java
License:Open Source License
public int getCount(final String query) { Object obj = (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.setCacheMode(CacheMode.IGNORE); return session.createQuery(query).uniqueResult(); }/*from w w w . jav a2s. c om*/ }); Integer count = null; if (obj instanceof Integer) { count = (Integer) obj; } else if (obj instanceof Long) { Long l = (Long) obj; count = l.intValue(); } if (count == null) { return 0; } else { return count.intValue(); } }
From source file:com.adsapient.shared.dao.HibernateEntityDao.java
License:Open Source License
public List getObject(final String query) { List result = (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.setCacheMode(CacheMode.IGNORE); return session.createQuery(query).list(); }//from w ww . j a va 2 s .c o m }); return result; }
From source file:com.adsapient.shared.dao.HibernateEntityDao.java
License:Open Source License
public Object loadObject(final Class objClass, final String ObjectId) { return getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.setCacheMode(CacheMode.IGNORE); return session.load(objClass, ObjectId); }/*w w w . j a v a2s .c o m*/ }); }
From source file:com.adsapient.shared.dao.HibernateEntityDao.java
License:Open Source License
public Object loadObject(final Class objClass, final Integer ObjectId) { return getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.setCacheMode(CacheMode.IGNORE); return session.get(objClass, ObjectId); }// w w w . j ava 2 s . co m }); }
From source file:com.adsapient.shared.dao.HibernateEntityDao.java
License:Open Source License
public synchronized Object loadObjectWithCriteria(final Class hibernateObjectClass, final String criteriaName, final Object criteriaValue) { List collect = (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.setCacheMode(CacheMode.IGNORE); return session.createCriteria(hibernateObjectClass) .add(Expression.like(criteriaName, criteriaValue)).list(); }/*from w w w . j a v a2s.c o m*/ }); getHibernateTemplate().flush(); getHibernateTemplate().clear(); if ((collect != null) && (!collect.isEmpty())) { if (collect.size() != 1) { logger.warn(new StringBuffer("Waring thearis few instance of class ").append(hibernateObjectClass) .append("with field ").append(criteriaName).append("and value ").append(criteriaValue) .append("the count of instance is ").append(collect.size()).toString()); } return collect.iterator().next(); } else { return null; } }