All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.cache.annotation.CacheRemoveEntry Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
/**
 *  Copyright (c) 2011 Terracotta, Inc.
 *  Copyright (c) 2011 Oracle and/or its affiliates.
 *
 *  All rights reserved. Use is subject to license terms.
 */


package javax.cache.annotation;

import javax.enterprise.util.Nonbinding;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
 * When a method annotated with {@link CacheRemoveEntry} is invoked a {@link CacheKey} will be generated and
 * {@link javax.cache.Cache#remove(Object)} will be invoked on the specified cache.
 * 

* The default behavior is to call {@link javax.cache.Cache#remove(Object)} after the annotated method is invoked, * this behavior can be changed by setting {@link #afterInvocation()} to false in which case {@link javax.cache.Cache#remove(Object)} * will be called before the annotated method is invoked. *

* Example of removing a specific Domain object from the "domainCache". A {@link CacheKey} will be generated * from the String and int parameters and used to call {@link javax.cache.Cache#remove(Object)} after * the deleteDomain method completes successfully. *

 * package my.app;
 * 
 * public class DomainDao {
 *   @CacheRemoveEntry(cacheName="domainCache")
 *   public void deleteDomain(String domainId, int index) {
 *     ...
 *   }
 * }
 * 

* Exception Handling, only used if {@link #afterInvocation()} is true. *
    *
  1. If {@link #evictFor()} and {@link #noEvictFor()} are both empty then all exceptions prevent the remove
  2. *
  3. If {@link #evictFor()} is specified and {@link #noEvictFor()} is not specified then only exceptions * which pass an instanceof check against the evictFor list result in a remove
  4. *
  5. If {@link #noEvictFor()} is specified and {@link #evictFor()} is not specified then all exceptions * which do not pass an instanceof check against the noEvictFor result in a remove
  6. *
  7. If {@link #evictFor()} and {@link #noEvictFor()} are both specified then exceptions which pass an * instanceof check against the evictFor list but do not pass an instanceof check against the noEvictFor * list result in a remove
  8. *
* * @author Eric Dalquist * @author Rick Hightower * @since 1.0 * @see CacheKeyParam */ @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface CacheRemoveEntry { /** * (Optional) name of the cache. *

* If not specified defaults first to {@link CacheDefaults#cacheName()}, if that is not set it * a {@link CacheAnnotationConfigurationException} will be thrown by the provider. */ @Nonbinding String cacheName() default ""; /** * (Optional) When {@link javax.cache.Cache#remove(Object)} should be called. If true it is called after the annotated method * invocation completes successfully. If false it is called before the annotated method is invoked. *

* Defaults to true. *

* If true and the annotated method throws an exception the put will not be executed. */ @Nonbinding boolean afterInvocation() default true; /** * (Optional) The {@link CacheResolverFactory} used to find the {@link CacheResolver} to use at runtime. *

* The default resolver pair will resolve the cache by name from the default {@link javax.cache.CacheManager} */ @Nonbinding Class cacheResolverFactory() default CacheResolverFactory.class; /** * (Optional) The {@link CacheKeyGenerator} to use to generate the {@link CacheKey} for interacting * with the specified Cache. *

* Defaults to a key generator that uses {@link java.util.Arrays#deepHashCode(Object[])} and * {@link java.util.Arrays#deepEquals(Object[], Object[])} with the array returned by * {@link CacheKeyInvocationContext#getKeyParameters()} * * @see CacheKeyParam */ @Nonbinding Class cacheKeyGenerator() default CacheKeyGenerator.class; /** * Defines zero (0) or more exception {@link Class classes}, which must be a * subclass of {@link Throwable}, indicating which exception types must cause * a cache evict. Only used if {@link #afterInvocation()} is true. */ Class[] evictFor() default { }; /** * Defines zero (0) or more exception {@link Class Classes}, which must be a * subclass of {@link Throwable}, indicating which exception types must not * cause a cache evict. Only used if {@link #afterInvocation()} is true. */ Class[] noEvictFor() default { }; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy