Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ObjectCacheFactory |
|
| 1.3333333333333333;1.333 |
1 | package org.apache.ojb.broker.cache; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * 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.1 2007-08-24 22:17:29 ewestfal Exp $ | |
30 | */ | |
31 | ||
32 | public class ObjectCacheFactory | |
33 | { | |
34 | private Logger log = LoggerFactory.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 | { | |
43 | return singleton; | |
44 | } | |
45 | ||
46 | private ObjectCacheFactory() | |
47 | { | |
48 | } | |
49 | ||
50 | /** | |
51 | * Creates a new {@link ObjectCacheInternal} instance. Each <tt>ObjectCache</tt> | |
52 | * implementation was wrapped by a {@link CacheDistributor} and the distributor | |
53 | * was wrapped by {@link MaterializationCache}. | |
54 | * | |
55 | * @param broker The PB instance to associate with the cache instance | |
56 | */ | |
57 | public MaterializationCache createObjectCache(PersistenceBroker broker) | |
58 | { | |
59 | CacheDistributor cache = null; | |
60 | try | |
61 | { | |
62 | log.info("Start creating new ObjectCache instance"); | |
63 | /* | |
64 | 1. | |
65 | if default cache was not found, | |
66 | create an new instance of the default cache specified in the | |
67 | configuration. | |
68 | 2. | |
69 | Then instantiate AllocatorObjectCache to handle | |
70 | per connection/ per class caching instances. | |
71 | 3. | |
72 | To support intern operations we wrap ObjectCache with an | |
73 | InternalObjectCache implementation | |
74 | */ | |
75 | cache = new CacheDistributor(broker); | |
76 | log.info("Instantiate new " + cache.getClass().getName() + " for PB instance " + broker); | |
77 | } | |
78 | catch(Exception e) | |
79 | { | |
80 | log.error("Error while initiation, please check your configuration" + | |
81 | " files and the used implementation class", e); | |
82 | } | |
83 | log.info("New ObjectCache instance was created"); | |
84 | return new MaterializationCache(cache); | |
85 | } | |
86 | } |