01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.datacache;
20:
21: import org.apache.openjpa.conf.OpenJPAConfiguration;
22: import org.apache.openjpa.lib.conf.ObjectValue;
23: import org.apache.openjpa.lib.util.Closeable;
24: import org.apache.openjpa.util.ImplHelper;
25:
26: /**
27: * Default data cache manager.
28: *
29: * @author Abe White
30: * @author Patrick Linskey
31: */
32: public class DataCacheManagerImpl implements Closeable,
33: DataCacheManager {
34:
35: private DataCache _cache = null;
36: private QueryCache _queryCache = null;
37: private DataCachePCDataGenerator _pcGenerator = null;
38: private DataCacheScheduler _scheduler = null;
39:
40: public void initialize(OpenJPAConfiguration conf,
41: ObjectValue dataCache, ObjectValue queryCache) {
42: _cache = (DataCache) dataCache.instantiate(DataCache.class,
43: conf);
44: if (_cache == null)
45: return;
46:
47: // create helpers before initializing caches
48: if (conf.getDynamicDataStructs())
49: _pcGenerator = new DataCachePCDataGenerator(conf);
50: _scheduler = new DataCacheScheduler(conf);
51:
52: _cache.initialize(this );
53: _queryCache = (QueryCache) queryCache.instantiate(
54: QueryCache.class, conf);
55: if (_queryCache != null)
56: _queryCache.initialize(this );
57: }
58:
59: public DataCache getSystemDataCache() {
60: return getDataCache(null, false);
61: }
62:
63: public DataCache getDataCache(String name) {
64: return getDataCache(name, false);
65: }
66:
67: public DataCache getDataCache(String name, boolean create) {
68: if (name == null
69: || (_cache != null && name.equals(_cache.getName())))
70: return _cache;
71: return null;
72: }
73:
74: public QueryCache getSystemQueryCache() {
75: return _queryCache;
76: }
77:
78: public DataCachePCDataGenerator getPCDataGenerator() {
79: return _pcGenerator;
80: }
81:
82: public DataCacheScheduler getDataCacheScheduler() {
83: return _scheduler;
84: }
85:
86: public void close() {
87: ImplHelper.close(_cache);
88: ImplHelper.close(_queryCache);
89: if (_scheduler != null)
90: _scheduler.stop();
91: }
92: }
|