From fb004027ad861c1c0b00c0470bf3248d16f54c15 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Thu, 11 Feb 2010 16:18:46 +0000 Subject: [PATCH] OPENJPA-1334: Emulate 1.2 versions IncludedTypes/ExcludedTypes functionality via new distribution policy mechanics git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@909054 13f79535-47bb-0310-9956-ffa450edef68 --- .../TypeBasedCacheDistributionPolicy.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/TypeBasedCacheDistributionPolicy.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/TypeBasedCacheDistributionPolicy.java index 3e5f9d6c4..e797a8153 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/TypeBasedCacheDistributionPolicy.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/TypeBasedCacheDistributionPolicy.java @@ -35,8 +35,8 @@ import serp.util.Strings; *
* The policy checks for the given instance by its type whether the class name appears in * exclusion or inclusion lists. If the class name appears in exclusion list then the - * instance is not cached. Otherwise If the class name appears in inclusion list but not in - * exclusion list, then the instance is cached. + * instance is not cached. Otherwise, if an inclusion list exists and the class name appears in inclusion list + * or @DataCache annotation is specified on the class meta data, then the instance is cached. * * @author Pinaki Poddar * @@ -85,36 +85,20 @@ public class TypeBasedCacheDistributionPolicy extends DefaultCacheDistributionPo return Collections.unmodifiableSet(set); } - /** - * Is the given type cacheable by excludeTypes/includeTypes plug-in properties. - * - * @param meta the given type - * @return TRUE or FALSE if the type has appeared in the plug-in property. - * null otherwise. - */ - private Boolean isCacheableByPlugin(ClassMetaData meta) { - String className = meta.getDescribedType().getName(); - if (_excludedTypes != null && _excludedTypes.contains(className)) { - return Boolean.FALSE; - } - if (_includedTypes != null && _includedTypes.contains(className)) { - return Boolean.TRUE; - } - return null; - } - - - - @Override public String selectCache(OpenJPAStateManager sm, Object context) { - Boolean result = isCacheableByPlugin(sm.getMetaData()); - if (result == null) { // this policy does not know, ask the super class - return super.selectCache(sm, context); - } else if (Boolean.FALSE.equals(result)) { // must be excluded + ClassMetaData meta = sm.getMetaData(); + String className = meta.getDescribedType().getName(); + if (_excludedTypes != null && _excludedTypes.contains(className)) { return null; } - String name = sm.getMetaData().getDataCacheName(); - return name == null ? DataCache.NAME_DEFAULT : name; + if (_includedTypes != null && !_includedTypes.isEmpty()) { + if (_includedTypes.contains(className)) + return meta.getDataCacheName(); + return (meta.getDataCacheEnabled()) ? meta.getDataCacheName() : null; + + } else { + return super.selectCache(sm, context); + } } }