01: package org.apache.ojb.broker.cache;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.PersistenceBroker;
19: import org.apache.ojb.broker.util.logging.Logger;
20: import org.apache.ojb.broker.util.logging.LoggerFactory;
21:
22: /**
23: * Factory for {@link ObjectCache} implementation classes.
24: * Each given {@link org.apache.ojb.broker.PersistenceBroker}
25: * was associated with its own <code>ObjectCache</code> instance
26: * and vice versa.
27: *
28: * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
29: * @version $Id: ObjectCacheFactory.java,v 1.17.2.3 2005/12/21 22:24:15 tomdz Exp $
30: */
31:
32: public class ObjectCacheFactory {
33: private Logger log = LoggerFactory
34: .getLogger(ObjectCacheFactory.class);
35:
36: private static ObjectCacheFactory singleton = new ObjectCacheFactory();
37:
38: /**
39: * Get the ObjectCacheFactory instance.
40: */
41: public static ObjectCacheFactory getInstance() {
42: return singleton;
43: }
44:
45: private ObjectCacheFactory() {
46: }
47:
48: /**
49: * Creates a new {@link ObjectCacheInternal} instance. Each <tt>ObjectCache</tt>
50: * implementation was wrapped by a {@link CacheDistributor} and the distributor
51: * was wrapped by {@link MaterializationCache}.
52: *
53: * @param broker The PB instance to associate with the cache instance
54: */
55: public MaterializationCache createObjectCache(
56: PersistenceBroker broker) {
57: CacheDistributor cache = null;
58: try {
59: log.info("Start creating new ObjectCache instance");
60: /*
61: 1.
62: if default cache was not found,
63: create an new instance of the default cache specified in the
64: configuration.
65: 2.
66: Then instantiate AllocatorObjectCache to handle
67: per connection/ per class caching instances.
68: 3.
69: To support intern operations we wrap ObjectCache with an
70: InternalObjectCache implementation
71: */
72: cache = new CacheDistributor(broker);
73: log.info("Instantiate new " + cache.getClass().getName()
74: + " for PB instance " + broker);
75: } catch (Exception e) {
76: log
77: .error(
78: "Error while initiation, please check your configuration"
79: + " files and the used implementation class",
80: e);
81: }
82: log.info("New ObjectCache instance was created");
83: return new MaterializationCache(cache);
84: }
85: }
|