use of org.hibernate.CacheMode in project hibernate-orm by hibernate.
the class DefaultDeleteEventListener method cascadeBeforeDelete.
protected void cascadeBeforeDelete(EventSource session, EntityPersister persister, Object entity, EntityEntry entityEntry, Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode(CacheMode.GET);
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to collections BEFORE the collection owner is deleted
Cascade.cascade(CascadingActions.DELETE, CascadePoint.AFTER_INSERT_BEFORE_DELETE, session, persister, entity, transientEntities);
} finally {
session.getPersistenceContext().decrementCascadeLevel();
session.setCacheMode(cacheMode);
}
}
use of org.hibernate.CacheMode in project hibernate-orm by hibernate.
the class AbstractProducedQuery method beforeQuery.
protected void beforeQuery() {
if (optionalId == null) {
getQueryParameterBindings().verifyParametersBound(isCallable());
}
assert sessionFlushMode == null;
assert sessionCacheMode == null;
if (flushMode != null) {
sessionFlushMode = getProducer().getHibernateFlushMode();
getProducer().setHibernateFlushMode(flushMode);
}
final CacheMode effectiveCacheMode = CacheModeHelper.effectiveCacheMode(cacheStoreMode, cacheRetrieveMode);
if (effectiveCacheMode != null) {
sessionCacheMode = getProducer().getCacheMode();
getProducer().setCacheMode(effectiveCacheMode);
}
}
use of org.hibernate.CacheMode in project openmrs-core by openmrs.
the class HibernateContextDAO method updateSearchIndexForType.
@Override
@Transactional
public void updateSearchIndexForType(Class<?> type) {
// From http://docs.jboss.org/hibernate/search/3.3/reference/en-US/html/manual-index-changes.html#search-batchindex-flushtoindexes
FullTextSession session = Search.getFullTextSession(sessionFactory.getCurrentSession());
session.purgeAll(type);
// Prepare session for batch work
session.flush();
session.clear();
FlushMode flushMode = session.getFlushMode();
CacheMode cacheMode = session.getCacheMode();
try {
session.setFlushMode(FlushMode.MANUAL);
session.setCacheMode(CacheMode.IGNORE);
// Scrollable results will avoid loading too many objects in memory
ScrollableResults results = session.createCriteria(type).setFetchSize(1000).scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
index++;
// index each element
session.index(results.get(0));
if (index % 1000 == 0) {
// apply changes to indexes
session.flushToIndexes();
// free memory since the queue is processed
session.clear();
}
}
session.flushToIndexes();
session.clear();
} finally {
session.setFlushMode(flushMode);
session.setCacheMode(cacheMode);
}
}
use of org.hibernate.CacheMode in project hibernate-orm by hibernate.
the class SessionImpl method refresh.
@Override
public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
checkOpen();
final CacheMode previousCacheMode = getCacheMode();
final CacheMode refreshCacheMode = determineAppropriateLocalCacheMode(properties);
LockOptions lockOptions = null;
try {
setCacheMode(refreshCacheMode);
if (!contains(entity)) {
throw exceptionConverter.convert(new IllegalArgumentException("Entity not managed"));
}
if (lockModeType != null) {
if (!LockModeType.NONE.equals(lockModeType)) {
checkTransactionNeeded();
}
lockOptions = buildLockOptions(lockModeType, properties);
refresh(entity, lockOptions);
} else {
refresh(entity);
}
} catch (MappingException e) {
throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
} catch (RuntimeException e) {
throw exceptionConverter.convert(e, lockOptions);
} finally {
setCacheMode(previousCacheMode);
}
}
use of org.hibernate.CacheMode in project hibernate-orm by hibernate.
the class DefaultDeleteEventListener method cascadeAfterDelete.
protected void cascadeAfterDelete(EventSource session, EntityPersister persister, Object entity, Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode(CacheMode.GET);
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to many-to-one AFTER the parent was deleted
Cascade.cascade(CascadingActions.DELETE, CascadePoint.BEFORE_INSERT_AFTER_DELETE, session, persister, entity, transientEntities);
} finally {
session.getPersistenceContext().decrementCascadeLevel();
session.setCacheMode(cacheMode);
}
}
Aggregations