javax.persistence.CacheRetrieveMode Java Examples

The following examples show how to use javax.persistence.CacheRetrieveMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private CacheMode determineAppropriateLocalCacheMode(Map<String, Object> localProperties) {
	CacheRetrieveMode retrieveMode = null;
	CacheStoreMode storeMode = null;
	if ( localProperties != null ) {
		retrieveMode = determineCacheRetrieveMode( localProperties );
		storeMode = determineCacheStoreMode( localProperties );
	}
	if ( retrieveMode == null ) {
		// use the EM setting
		retrieveMode = determineCacheRetrieveMode( this.properties );
	}
	if ( storeMode == null ) {
		// use the EM setting
		storeMode = determineCacheStoreMode( this.properties );
	}
	return CacheModeHelper.interpretCacheMode( storeMode, retrieveMode );
}
 
Example #2
Source File: CacheModeHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a JPA {@link CacheStoreMode} and {@link CacheRetrieveMode}, determine the corresponding
 * legacy Hibernate {@link CacheMode}.
 *
 * @param storeMode The JPA shared-cache store mode.
 * @param retrieveMode The JPA shared-cache retrieve mode.
 *
 * @return Corresponding {@link CacheMode}.
 */
public static CacheMode interpretCacheMode(CacheStoreMode storeMode, CacheRetrieveMode retrieveMode) {
	if ( storeMode == null ) {
		storeMode = DEFAULT_STORE_MODE;
	}
	if ( retrieveMode == null ) {
		retrieveMode = DEFAULT_RETRIEVE_MODE;
	}

	final boolean get = ( CacheRetrieveMode.USE == retrieveMode );

	switch ( storeMode ) {
		case USE: {
			return get ? CacheMode.NORMAL : CacheMode.PUT;
		}
		case REFRESH: {
			// really (get == true) here is a bit of an invalid combo...
			return CacheMode.REFRESH;
		}
		case BYPASS: {
			return get ? CacheMode.GET : CacheMode.IGNORE;
		}
		default: {
			throw new IllegalStateException( "huh? :)" );
		}
	}
}
 
Example #3
Source File: CacheModeHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a JPA {@link CacheStoreMode} and {@link CacheRetrieveMode}, determine the corresponding
 * legacy Hibernate {@link CacheMode}.
 *
 * @param storeMode The JPA shared-cache store mode.
 * @param retrieveMode The JPA shared-cache retrieve mode.
 *
 * @return Corresponding {@link CacheMode}.
 */
public static CacheMode effectiveCacheMode(CacheStoreMode storeMode, CacheRetrieveMode retrieveMode) {
	if ( storeMode == null && retrieveMode == null ) {
		return null;
	}

	if ( storeMode == null ) {
		storeMode = DEFAULT_STORE_MODE;
	}
	if ( retrieveMode == null ) {
		retrieveMode = DEFAULT_RETRIEVE_MODE;
	}

	final boolean get = ( CacheRetrieveMode.USE == retrieveMode );

	switch ( storeMode ) {
		case USE: {
			return get ? CacheMode.NORMAL : CacheMode.PUT;
		}
		case REFRESH: {
			// really (get == true) here is a bit of an invalid combo...
			return CacheMode.REFRESH;
		}
		case BYPASS: {
			return get ? CacheMode.GET : CacheMode.IGNORE;
		}
		default: {
			throw new IllegalStateException( "huh? :)" );
		}
	}
}
 
Example #4
Source File: CacheModeHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static CacheRetrieveMode interpretCacheRetrieveMode(CacheMode cacheMode) {
	if ( cacheMode == null ) {
		cacheMode = DEFAULT_LEGACY_MODE;
	}

	return ( CacheMode.NORMAL == cacheMode || CacheMode.GET == cacheMode )
			? CacheRetrieveMode.USE
			: CacheRetrieveMode.BYPASS;
}
 
Example #5
Source File: AbstractProducedQuery.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected boolean applyJpaCacheRetrieveMode(CacheRetrieveMode mode) {
	this.cacheRetrieveMode = mode;
	return true;
}
 
Example #6
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private CacheRetrieveMode currentCacheRetrieveMode() {
	return determineCacheRetrieveMode( properties );
}
 
Example #7
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private CacheRetrieveMode determineCacheRetrieveMode(Map<String, Object> settings) {
	return ( CacheRetrieveMode ) settings.get( JPA_SHARED_CACHE_RETRIEVE_MODE );
}
 
Example #8
Source File: CleanupCacheIT.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
@Before
public void configureEntityManager() {
    // These are defaults but put here for documentation purposes
    manager.setProperty("javax.persistence.cache.storeMode", CacheStoreMode.USE);
    manager.setProperty("javax.persistence.cache.retrieveMode", CacheRetrieveMode.USE);
}
 
Example #9
Source File: AbstractCleanupCacheTest.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
@Before
public void configureEntityManager() {
    // These are defaults but put here for documentation purposes
    manager.setProperty("javax.persistence.cache.storeMode", CacheStoreMode.USE);
    manager.setProperty("javax.persistence.cache.retrieveMode", CacheRetrieveMode.USE);
}
 
Example #10
Source File: CleanupCacheIT.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
@Before
public void configureEntityManager() {
    // These are defaults but put here for documentation purposes
    manager.setProperty("javax.persistence.cache.storeMode", CacheStoreMode.USE);
    manager.setProperty("javax.persistence.cache.retrieveMode", CacheRetrieveMode.USE);
}
 
Example #11
Source File: CacheConfig.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
private CacheConfig(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode) {
    this.retrieveMode = retrieveMode;
    this.storeMode = storeMode;
}
 
Example #12
Source File: CacheConfig.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
public CacheRetrieveMode getRetrieveMode() {
    return retrieveMode;
}
 
Example #13
Source File: CacheConfig.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
/**
 * get entities from cache
 */
public static CacheConfig get() {
    return new CacheConfig(CacheRetrieveMode.USE, CacheStoreMode.USE);
}
 
Example #14
Source File: CacheConfig.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
/**
 * get entities from db and refresh cache
 */
public static CacheConfig refresh() {
    return new CacheConfig(CacheRetrieveMode.USE, CacheStoreMode.REFRESH);
}
 
Example #15
Source File: CacheConfig.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
/**
 * bypass cache
 */
public static CacheConfig bypass() {
    return new CacheConfig(CacheRetrieveMode.BYPASS, CacheStoreMode.BYPASS);
}
 
Example #16
Source File: CacheHelper.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
public static void cacheable(Query query) {
    query.setHint(CACHEBLE, true);
    query.setHint(RETRIEVE_MODE, CacheRetrieveMode.USE);
    query.setHint(STORE_MODE, CacheStoreMode.USE);
}