List of usage examples for org.hibernate CacheMode IGNORE
CacheMode IGNORE
To view the source code for org.hibernate CacheMode IGNORE.
Click Source Link
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);//from www. ja va2s. c om System.out.println("Nova sesso criada"); } return (Session) sessionThread.get(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public void indexarTudo(Aguarde aguarde) throws Exception { System.out.println("Indexando documentos..."); long inicio = new Date().getTime(); try {//from w w w. j av a 2 s . co m FullTextSession fullTextSession = Search.getFullTextSession(getSessao()); Transaction deleteTx = fullTextSession.beginTransaction(); fullTextSession.purgeAll(ExDocumento.class); deleteTx.commit(); fullTextSession.clear(); getSessao().clear(); } catch (Throwable t) { // No havia documentos a excluir } final Criteria crit = getSessao().createCriteria(ExDocumento.class); int index = 0; FullTextSession fullTextSession = Search.getFullTextSession(getSessao()); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); crit.setMaxResults(30); crit.addOrder(Order.desc("idDoc")); List<ExDocumento> list; do { crit.setFirstResult(index); list = crit.list(); Transaction tx = fullTextSession.beginTransaction(); for (ExDocumento doc : list) { index++; // if (aguarde != null) // aguarde.setMensagem(String.valueOf(index) // + " documentos j indexados."); if (doc.isIndexavel()) fullTextSession.index(doc); if (index % 100 == 0) { //System.gc(); // fullTextSession.flush(); // fullTextSession.clear(); } } tx.commit(); fullTextSession.clear(); getSessao().clear(); System.out.print(String.valueOf(index) + " documentos j indexados. -- -- "); } while (list.size() > 0); //System.gc(); // fullTextSession.close(); System.out.println("Durao da indexao de documentos: " + (new Date().getTime() - inicio)); if (aguarde != null) aguarde.setMensagem(String.valueOf(index)); }
From source file:ca.ualberta.physics.cssdp.catalogue.dao.UrlDataProductDao.java
License:Apache License
public void process(UrlDataProductUpdateMap urlDataProductUpdateMap) { if (urlDataProductUpdateMap.getUrls().size() == 0) { return;/*w w w .ja v a 2 s . com*/ } /* * The size of scannedUrlDataProducts should be <= jdbc batch size * configured. */ // we have to resort to hibernate directly because JPA does not have // scrolling capability Session session = emp.get().unwrap(Session.class).getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); // "in" clause limit is 2^16 on Postgresql, it might be different on // other dbs String hqlString = "from UrlDataProduct urldp where urldp.url in (:urls)"; // the fastest way to scroll through the existing data Query q = session.createQuery(hqlString); q.setParameterList("urls", urlDataProductUpdateMap.getUrls()); q.setCacheMode(CacheMode.IGNORE); ScrollableResults existingData = q.scroll(ScrollMode.FORWARD_ONLY); while (existingData.next()) { UrlDataProduct existing = (UrlDataProduct) existingData.get(0); UrlDataProduct updated = urlDataProductUpdateMap.get(existing.getUrl()); if (updated != null) { /* * Only bother to update the record if it's actually changed. * Note that the scan timestamp is ignored in the check because * that isn't something the provider changed. A change can also * mean the url was deleted, and now it's back. */ if (existing.hasChanged(updated)) { // existing.setDataProduct(updated.getDataProduct()); existing.setUrl(updated.getUrl()); existing.setStartTimestamp(updated.getStartTimestamp()); existing.setEndTimestamp(updated.getEndTimestamp()); existing.setScanTimestamp(updated.getScanTimestamp()); existing.setDeleted(false); urlDataProductUpdateMap.remove(updated.getUrl()); session.update(existing); } else { // remove it so it's not duplicated urlDataProductUpdateMap.remove(existing.getUrl()); } } else { // if we get here it means the existing url has been removed // from the server, set "delete" it from the catalogue existing.setDeleted(true); existing.setScanTimestamp(new LocalDateTime()); } } // persist the new url mappings for (String newUrl : urlDataProductUpdateMap.getUrls()) { UrlDataProduct newUrlDataProduct = urlDataProductUpdateMap.get(newUrl); session.save(newUrlDataProduct); logger.debug("saved a mapping: " + newUrlDataProduct.getUrl()); } session.flush(); session.clear(); tx.commit(); session.close(); }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AuthorizationDAOFactory.java
License:Apache License
public void disableSecondLevelCacheForSession() { SessionFactory sessionFactory = persistencyResources.getSessionFactoryOrNull(); sessionFactory.getCurrentSession().setCacheMode(CacheMode.IGNORE); }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.DefaultFullTextIndexer.java
License:Apache License
public final <T> void doFullTextIndex(final Session hibernateSession, final Class<T> clazz) throws DataAccessException { operationLog.info(String.format("Indexing '%s'...", clazz.getSimpleName())); final FullTextSession fullTextSession = Search.getFullTextSession(hibernateSession); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); // we index entities in batches loading them in groups restricted by id: // [ ids[index], ids[min(index+batchSize, maxIndex))] ) final Transaction transaction = hibernateSession.beginTransaction(); final List<Long> ids = getAllIds(fullTextSession, clazz); final int idsSize = ids.size(); operationLog.info(String.format("... got %d '%s' ids...", idsSize, clazz.getSimpleName())); int index = 0; final int maxIndex = idsSize - 1; // need to increment last id because we use 'lt' condition if (maxIndex > -1) { ids.set(maxIndex, ids.get(maxIndex) + 1); }/*from w w w . j ava 2 s . c om*/ while (index < maxIndex) { final int nextIndex = getNextIndex(index, maxIndex); final long minId = ids.get(index); final long maxId = ids.get(nextIndex); final List<?> results = createCriteriaWithRestrictedId(fullTextSession, clazz, minId, maxId).list(); for (Object object : results) { indexEntity(hibernateSession, fullTextSession, object); index++; } operationLog.info(String.format("%d '%s' have been indexed...", index, clazz.getSimpleName())); fullTextSession.flushToIndexes(); hibernateSession.clear(); } fullTextSession.getSearchFactory().optimize(clazz); transaction.commit(); operationLog.info( String.format("'%s' index complete. %d entities have been indexed.", clazz.getSimpleName(), index)); }
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 ww w. j a va2 s. c o m*/ }); 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 www.j a v a 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. ja v a2 s . 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 a v a2 s.c o 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 a 2s . co 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; } }