Example usage for javax.persistence CacheStoreMode REFRESH

List of usage examples for javax.persistence CacheStoreMode REFRESH

Introduction

In this page you can find the example usage for javax.persistence CacheStoreMode REFRESH.

Prototype

CacheStoreMode REFRESH

To view the source code for javax.persistence CacheStoreMode REFRESH.

Click Source Link

Document

Insert/update entity data into cache when read from database and when committed into database.

Usage

From source file:com.hiperium.dao.common.generic.GenericDAO.java

/**
 * /*  w  ww.  ja  v  a  2s .co  m*/
 * @param id
 * @param lock
 * @param bypassCache
 * @return
 */
protected T findById(ID id, boolean lock, boolean bypassCache) {
    this.logger.debug("findById - START");
    T entity = null;
    if (bypassCache) {
        this.entityManager.setProperty(RETRIEVE_MODE, CacheRetrieveMode.BYPASS);
        this.entityManager.setProperty(STORE_MODE, CacheStoreMode.REFRESH);
        entity = this.entityManager.find(this.entityClass, id);
    } else {
        entity = this.entityManager.find(this.entityClass, id);
    }
    if (lock) {
        this.entityManager.lock(entity, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
    }
    this.logger.debug("findById - END");
    return entity;
}

From source file:com.hiperium.dao.common.generic.GenericDAO.java

/**
 * /*from w w w.  j  av  a2s .  com*/
 * @param query
 */
private void setBypassCahe(Query query) {
    query.setHint(RETRIEVE_MODE, CacheRetrieveMode.BYPASS);
    query.setHint(STORE_MODE, CacheStoreMode.REFRESH);
}