Source code: ojb/broker/cache/ObjectCache.java
1 /*
2 * ObJectRelationalBridge - Bridging Java Objects and Relational Databases
3 * http://objectbridge.sourceforge.net
4 * Copyright (C) 2000, 2001 Thomas Mahler, et al.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 package ojb.broker.cache;
21
22 import ojb.broker.Identity;
23 import ojb.broker.metadata.ClassNotPersistenceCapableException;
24
25 /**
26 * The ObjectCache stores all Objects loaded by the PersistenceBroker from a DB.
27 * When the PersistenceBroker tries to get an Object by its Primary key values
28 * it first lookups the cache if the object has been already loaded and cached.
29 *
30 * Using an ObjectCache has several advantages:
31 * - it increases performance as it reduces DB lookups.
32 * - it allows to perform circular lookups (as by crossreferenced objects)
33 * that would result in non-terminating loops without such a cache.
34 * - it maintains the uniqueness of objects as any Db row will be mapped to
35 * exactly one object.
36 *
37 * This interface allows to have userdefined Cache implementations.
38 * The ObjectCacheFactory is responsible for generating cache instances.
39 * by default it uses the OJB ObjectCacheDefaultImpl.
40 *
41 * @author <a href="mailto:thomas.mahler@itellium.com">Thomas Mahler<a>
42 */
43 public interface ObjectCache
44 {
45
46 /**
47 * Make object obj persistent to Objectcache.
48 * compute objects identity and use it as key for the hashmap
49 */
50 public void cache(Object obj) throws ClassNotPersistenceCapableException;
51
52
53 /**
54 * makes object obj persistent to the Objectcache under the key oid.
55 */
56 public void cache(Identity oid, Object obj);
57
58
59 /**
60 * Lookup object with Identity oid in objectTable.
61 * returns null if no matching id is found
62 */
63 public Object lookup(Identity oid);
64
65
66 /**
67 * removes an Object from the cache.
68 * @param obj the Object (or the Identity of the object) to be removed.
69 */
70 public void remove(Object obj);
71
72 /**
73 * clear the ObjectCache.
74 */
75 public void clear();
76
77
78 }