1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.jcs.jcache.openjpa;
20
21 import org.apache.openjpa.conf.OpenJPAConfiguration;
22 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
23 import org.apache.openjpa.event.SingleJVMRemoteCommitProvider;
24 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
25 import org.apache.openjpa.lib.conf.Configuration;
26 import org.apache.openjpa.lib.conf.ConfigurationProvider;
27 import org.apache.openjpa.lib.conf.Configurations;
28
29 import java.util.Map;
30
31 public class OpenJPAJCacheDerivation extends AbstractProductDerivation
32 {
33 private static final String JCACHE_NAME = "jcache";
34
35 @Override
36 public boolean beforeConfigurationLoad(final Configuration conf)
37 {
38 if (OpenJPAConfiguration.class.isInstance(conf)) {
39 final OpenJPAConfigurationImpl oconf = OpenJPAConfigurationImpl.class.cast(conf);
40 oconf.dataCacheManagerPlugin.setAlias(JCACHE_NAME, OpenJPAJCacheDataCacheManager.class.getName());
41 oconf.dataCachePlugin.setAlias(JCACHE_NAME, OpenJPAJCacheDataCache.class.getName());
42 oconf.queryCachePlugin.setAlias(JCACHE_NAME, OpenJPAJCacheQueryCache.class.getName());
43 }
44 return super.beforeConfigurationLoad(conf);
45 }
46
47 @Override
48 public boolean beforeConfigurationConstruct(final ConfigurationProvider cp)
49 {
50 final Map<?, ?> props = cp.getProperties();
51 final Object dcm = Configurations.getProperty("DataCacheManager", props);
52 if (dcm != null && JCACHE_NAME.equals(dcm))
53 {
54 if (Configurations.getProperty("DataCache", props) == null)
55 {
56 cp.addProperty("openjpa.DataCache", JCACHE_NAME);
57 }
58 if (Configurations.getProperty("QueryCache", props) == null)
59 {
60 cp.addProperty("openjpa.QueryCache", JCACHE_NAME);
61 }
62 if (Configurations.getProperty("RemoteCommitProvider", props) == null)
63 {
64 cp.addProperty("openjpa.RemoteCommitProvider", SingleJVMRemoteCommitProvider.class.getName());
65 }
66 }
67 return super.beforeConfigurationConstruct(cp);
68 }
69
70 @Override
71 public int getType()
72 {
73 return TYPE_FEATURE;
74 }
75 }