• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CachePut类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.cache.annotation.CachePut的典型用法代码示例。如果您正苦于以下问题:Java CachePut类的具体用法?Java CachePut怎么用?Java CachePut使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CachePut类属于javax.cache.annotation包,在下文中一共展示了CachePut类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: saveOrUpdate

import javax.cache.annotation.CachePut; //导入依赖的package包/类
/**
 * Save or update a setting and return the corresponding identifier.
 * 
 * @param name
 *            the configuration name.
 * @param value
 *            the new value.
 */
@POST
@PUT
@Path("{name}/{value}")
@CachePut(cacheName = "configuration")
public void saveOrUpdate(@CacheKey @PathParam("name") final String name, @CacheValue @PathParam("value") final String value) {
	final SystemConfiguration setting = repository.findByName(name);
	if (setting == null) {
		final SystemConfiguration entity = new SystemConfiguration();
		entity.setName(name);
		entity.setValue(cryptoHelper.encrypt(value));
		repository.saveAndFlush(entity);
	} else {
		setting.setValue(cryptoHelper.encrypt(value));
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:24,代码来源:ConfigurationResource.java


示例2: CachePutOperation

import javax.cache.annotation.CachePut; //导入依赖的package包/类
public CachePutOperation(
		CacheMethodDetails<CachePut> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) {

	super(methodDetails, cacheResolver, keyGenerator);
	CachePut ann = methodDetails.getCacheAnnotation();
	this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor());
	this.valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails);
	if (this.valueParameterDetail == null) {
		throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " +
				"" + methodDetails.getMethod());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:CachePutOperation.java


示例3: invoke

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
protected Object invoke(CacheOperationInvocationContext<CachePutOperation> context,
		CacheOperationInvoker invoker) {

	CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context);
	CachePutOperation operation = context.getOperation();

	boolean earlyPut = operation.isEarlyPut();
	Object value = invocationContext.getValueParameter().getValue();

	if (earlyPut) {
		cacheValue(context, value);
	}

	try {
		Object result = invoker.invoke();
		if (!earlyPut) {
			cacheValue(context, value);
		}
		return result;
	}
	catch (CacheOperationInvoker.ThrowableWrapper ex) {
		Throwable original = ex.getOriginal();
		if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) {
			cacheValue(context, value);
		}
		throw ex;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CachePutInterceptor.java


示例4: findCacheOperation

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
protected JCacheOperation<?> findCacheOperation(Method method, Class<?> targetType) {
	CacheResult cacheResult = method.getAnnotation(CacheResult.class);
	CachePut cachePut = method.getAnnotation(CachePut.class);
	CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
	CacheRemoveAll cacheRemoveAll = method.getAnnotation(CacheRemoveAll.class);

	int found = countNonNull(cacheResult, cachePut, cacheRemove, cacheRemoveAll);
	if (found == 0) {
		return null;
	}
	if (found > 1) {
		throw new IllegalStateException("More than one cache annotation found on '" + method + "'");
	}

	CacheDefaults defaults = getCacheDefaults(method, targetType);
	if (cacheResult != null) {
		return createCacheResultOperation(method, defaults, cacheResult);
	}
	else if (cachePut != null) {
		return createCachePutOperation(method, defaults, cachePut);
	}
	else if (cacheRemove != null) {
		return createCacheRemoveOperation(method, defaults, cacheRemove);
	}
	else {
		return createCacheRemoveAllOperation(method, defaults, cacheRemoveAll);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:AnnotationJCacheOperationSource.java


示例5: createCachePutOperation

import javax.cache.annotation.CachePut; //导入依赖的package包/类
protected CachePutOperation createCachePutOperation(Method method, CacheDefaults defaults, CachePut ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AnnotationJCacheOperationSource.java


示例6: noCacheValue

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Test
public void noCacheValue() {
	CacheMethodDetails<CachePut> methodDetails = create(CachePut.class,
			SampleObject.class, "noCacheValue", Long.class);

	thrown.expect(IllegalArgumentException.class);
	createDefaultOperation(methodDetails);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:CachePutOperationTests.java


示例7: multiCacheValues

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Test
public void multiCacheValues() {
	CacheMethodDetails<CachePut> methodDetails = create(CachePut.class,
			SampleObject.class, "multiCacheValues", Long.class, SampleObject.class, SampleObject.class);

	thrown.expect(IllegalArgumentException.class);
	createDefaultOperation(methodDetails);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:CachePutOperationTests.java


示例8: fullPutConfig

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Test
public void fullPutConfig() {
	CacheMethodDetails<CachePut> methodDetails = create(CachePut.class,
			SampleObject.class, "fullPutConfig", Long.class, SampleObject.class);
	CachePutOperation operation = createDefaultOperation(methodDetails);
	assertTrue(operation.isEarlyPut());
	assertNotNull(operation.getExceptionTypeFilter());
	assertTrue(operation.getExceptionTypeFilter().match(IOException.class));
	assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:CachePutOperationTests.java


示例9: earlyPut

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
@CachePut(afterInvocation = false)
public void earlyPut(String id, @CacheValue Object value) {
	Object key = SimpleKeyGenerator.generateKey(id);
	Cache.ValueWrapper valueWrapper = defaultCache.get(key);
	if (valueWrapper == null) {
		throw new AssertionError("Excepted value to be put in cache with key " + key);
	}
	Object actual = valueWrapper.get();
	if (value != actual) { // instance check on purpose
		throw new AssertionError("Wrong value set in cache with key " + key + ". " +
				"Expected=" + value + ", but got=" + actual);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:AnnotatedJCacheableService.java


示例10: invoke

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {

  final Method method = methodInvocation.getMethod();
  final CachePut annotation = method.getAnnotation(CachePut.class);
  checkNotNull(annotation);
  final CacheKeyInvocationContext<CachePut> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName());

  LOGGER.trace("Cache PUT {}", context.getMethod().getName());

  // get cache
  final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation);

  // get key
  final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator());
  final GeneratedCacheKey key = keyGenerator.generateCacheKey(context);

  // get value to cache
  final Object value = context.getValueParameter().getValue();

  if (!annotation.afterInvocation()) {
    cacheValue(key, value, cache);
  }

  final Object result = methodInvocation.proceed();

  if (annotation.afterInvocation()) {
    cacheValue(key, value, cache);
  }

  return result;
}
 
开发者ID:Wadpam,项目名称:guja,代码行数:33,代码来源:CachePutMethodInterceptor.java


示例11: save

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
@CachePut(cacheName = "conference" )
public Conference save(final Conference conference) {
	if (conference.isNew()) {
		entityManager.persist(conference);
		entityManager.flush();
		return conference;
	} else {
		Conference conf = entityManager.merge(conference);
		entityManager.flush();
		return conf;
	}
}
 
开发者ID:hantsy,项目名称:spring4-sandbox,代码行数:14,代码来源:JpaConferenceRepositoryImpl.java


示例12: simplePut

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@CachePut(cacheName = "simpleCache")
public void simplePut(Long id, @CacheValue SampleObject instance) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:SampleObject.java


示例13: noCacheValue

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@CachePut(cacheName = "simpleCache")
public void noCacheValue(Long id) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:SampleObject.java


示例14: multiCacheValues

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@CachePut(cacheName = "simpleCache")
public void multiCacheValues(Long id, @CacheValue SampleObject instance,
		@CacheValue SampleObject anotherInstance) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:SampleObject.java


示例15: fullPutConfig

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@CachePut(cacheName = "simpleCache", afterInvocation = false,
		cacheFor = Exception.class, noCacheFor = RuntimeException.class)
public void fullPutConfig(@CacheKey Long id, @CacheValue SampleObject instance) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:SampleObject.java


示例16: createSimpleOperation

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
protected CachePutOperation createSimpleOperation() {
	CacheMethodDetails<CachePut> methodDetails = create(CachePut.class,
			SampleObject.class, "simplePut", Long.class, SampleObject.class);
	return createDefaultOperation(methodDetails);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:7,代码来源:CachePutOperationTests.java


示例17: createDefaultOperation

import javax.cache.annotation.CachePut; //导入依赖的package包/类
private CachePutOperation createDefaultOperation(CacheMethodDetails<CachePut> methodDetails) {
	return new CachePutOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:CachePutOperationTests.java


示例18: put

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@CachePut
public void put(long id, @CacheValue Object object) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:JCacheErrorHandlerTests.java


示例19: put

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
@CachePut
public void put(String id, @CacheValue Object value) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:AnnotatedJCacheableService.java


示例20: putWithException

import javax.cache.annotation.CachePut; //导入依赖的package包/类
@Override
@CachePut(cacheFor = UnsupportedOperationException.class)
public void putWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:6,代码来源:AnnotatedJCacheableService.java



注:本文中的javax.cache.annotation.CachePut类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HelpBlock类代码示例发布时间:2022-05-23
下一篇:
Java IDrawHandler类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap