001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.ocache;
010:
011: /**
012: * Odal object cache
013: *
014: * @author Gennady Krizhevsky
015: */
016: public interface OdalCache {
017:
018: public static final NullOdalCache NULL_ODAL_CACHE = new NullOdalCache(
019: "NULL_ODAL_CACHE");
020:
021: /**
022: * Gets object from cache
023: *
024: * @param key key
025: * @return cached object or null if not found
026: */
027: Object get(Object key);
028:
029: /**
030: * Inserts object into chache with given key
031: *
032: * @param key key
033: * @param value value to cache
034: * @return Object - old object
035: */
036: Object put(Object key, Object value);
037:
038: /**
039: * Removes object with given key from the cache
040: *
041: * @param key key
042: * @return removed object
043: */
044: Object remove(Object key);
045:
046: /**
047: * Removes all the entries from the cache
048: */
049: void clear();
050:
051: /**
052: * Gets Cache name
053: *
054: * @return Cache name
055: */
056: String getName();
057:
058: /**
059: * Null implementation
060: */
061: public static class NullOdalCache implements OdalCache {
062:
063: private String name;
064:
065: public NullOdalCache(String name) {
066: this .name = name;
067: }
068:
069: public Object get(Object key) {
070: return null;
071: }
072:
073: public Object put(Object key, Object object) {
074: return object;
075: }
076:
077: public Object remove(Object key) {
078: return null;
079: }
080:
081: public String getName() {
082: return name;
083: }
084:
085: public void clear() {
086: }
087:
088: public boolean equals(Object value) {
089: if (this == value)
090: return true;
091: if (value == null || getClass() != value.getClass())
092: return false;
093:
094: final NullOdalCache that = (NullOdalCache) value;
095:
096: if (name != null ? !name.equals(that.name)
097: : that.name != null)
098: return false;
099:
100: return true;
101: }
102:
103: public int hashCode() {
104: return (name != null ? name.hashCode() : 0);
105: }
106: }
107:
108: }
|