01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.oldboss.framework.bo.impl;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19:
20: import com.metaboss.enterprise.bo.BOException;
21: import com.metaboss.enterprise.bo.BOIllegalArgumentException;
22: import com.oldboss.framework.bo.BOEntityDomain;
23: import com.oldboss.framework.bo.BOObject;
24:
25: /* Base class for the bo domain object. This object has the object cache for all other objects */
26: public class BOEntityDomainImpl implements BOEntityDomain {
27: private static Map sTypeCache = new HashMap();
28:
29: /** Return existing instance for the object or null if none exists in the cache */
30: public BOObject retrieveExistingBOInstance(Class pInstanceType,
31: String pInstancePrimaryKey) throws BOException {
32: synchronized (sTypeCache) {
33: Map lInstanceMap = (Map) sTypeCache.get(pInstanceType
34: .getName());
35: if (lInstanceMap == null)
36: return null;
37: return (BOObject) lInstanceMap.get(pInstancePrimaryKey);
38: }
39: }
40:
41: /** Removes existing instance for the object.
42: * @return Removed instance or null if none exists in the cache */
43: public BOObject removeExistingBOInstance(Class pInstanceType,
44: String pInstancePrimaryKey) throws BOException {
45: synchronized (sTypeCache) {
46: Map lInstanceMap = (Map) sTypeCache.get(pInstanceType
47: .getName());
48: if (lInstanceMap == null)
49: return null;
50: return (BOObject) lInstanceMap.remove(pInstancePrimaryKey);
51: }
52: }
53:
54: /** Saves new instance of the object into the cache */
55: public void saveNewBOInstance(Class pInstanceType,
56: String pInstancePrimaryKey, BOObject pInstance)
57: throws BOException {
58: synchronized (sTypeCache) {
59: Map lInstanceMap = (Map) sTypeCache.get(pInstanceType
60: .getName());
61: if (lInstanceMap == null)
62: sTypeCache.put(pInstanceType.getName(),
63: lInstanceMap = new HashMap());
64: if (lInstanceMap.containsKey(pInstancePrimaryKey))
65: throw new BOIllegalArgumentException(
66: "Inatance already exists in the cache. Type: "
67: + pInstanceType + " Primay Key: "
68: + pInstancePrimaryKey);
69: lInstanceMap.put(pInstancePrimaryKey, pInstance);
70: }
71: }
72: }
|