Source Code Cross Referenced for ObjectCacheJCSImpl.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » cache » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » db ojb » org.apache.ojb.broker.cache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.cache;
002:
003:        /* Copyright 2004-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import java.util.Properties;
019:
020:        import org.apache.commons.lang.builder.ToStringBuilder;
021:        import org.apache.commons.lang.builder.ToStringStyle;
022:        import org.apache.jcs.JCS;
023:        import org.apache.jcs.access.exception.CacheException;
024:        import org.apache.jcs.access.exception.ObjectExistsException;
025:        import org.apache.ojb.broker.Identity;
026:        import org.apache.ojb.broker.PersistenceBroker;
027:
028:        /**
029:         * This local {@link ObjectCache} implementation using
030:         * <a href="http://jakarta.apache.org/turbine/jcs/index.html">
031:         * turbine-JCS</a> to cache objects is primarily for intern use in
032:         * conjunction with {@link ObjectCacheJCSPerClassImpl} implementation. If
033:         * used as main <code>ObjectCache</code> all cached objects will be cached
034:         * under the same JCS region name (see {@link #DEFAULT_REGION}).
035:         * <p/>
036:         * <p/>
037:         * Implementation configuration properties:
038:         * </p>
039:         * <p/>
040:         * <table cellspacing="2" cellpadding="2" border="3" frame="box">
041:         * <tr>
042:         * <td><strong>Property Key</strong></td>
043:         * <td><strong>Property Values</strong></td>
044:         * </tr>
045:         * <tr>
046:         * <td> - </td>
047:         * <td>
048:         * -
049:         * </td>
050:         * </tr>
051:         * </table>
052:         *
053:         * @author Matthew Baird (mattbaird@yahoo.com);
054:         * @version $Id: ObjectCacheJCSImpl.java,v 1.11.2.2 2005/12/21 22:24:15 tomdz Exp $
055:         */
056:        public class ObjectCacheJCSImpl implements  ObjectCache {
057:            /**
058:             * The used default region name.
059:             */
060:            public static final String DEFAULT_REGION = "ojbDefaultJCSRegion";
061:
062:            private JCS jcsCache;
063:            /**
064:             * if no regionname is passed in, we use the default region.
065:             */
066:            private String regionName = DEFAULT_REGION;
067:
068:            public ObjectCacheJCSImpl(PersistenceBroker broker, Properties prop) {
069:                this (null);
070:            }
071:
072:            /**
073:             * Constructor used by the {@link ObjectCacheJCSPerClassImpl}
074:             */
075:            public ObjectCacheJCSImpl(String name) {
076:                regionName = (name != null ? name : DEFAULT_REGION);
077:                try {
078:                    jcsCache = JCS.getInstance(regionName);
079:                } catch (Exception e) {
080:                    throw new RuntimeCacheException(
081:                            "Can't instantiate JCS ObjectCacheImplementation",
082:                            e);
083:                }
084:            }
085:
086:            public String getRegionName() {
087:                return regionName;
088:            }
089:
090:            /**
091:             * makes object obj persistent to the Objectcache under the key oid.
092:             */
093:            public void cache(Identity oid, Object obj) {
094:                try {
095:                    jcsCache.put(oid.toString(), obj);
096:                } catch (CacheException e) {
097:                    throw new RuntimeCacheException(e);
098:                }
099:            }
100:
101:            public boolean cacheIfNew(Identity oid, Object obj) {
102:                boolean result = false;
103:                try {
104:                    jcsCache.putSafe(oid.toString(), obj);
105:                    result = true;
106:                } catch (ObjectExistsException e) {
107:                    // do nothing, object already in cache
108:                } catch (CacheException e) {
109:                    throw new RuntimeCacheException(e);
110:                }
111:                return result;
112:            }
113:
114:            /**
115:             * Lookup object with Identity oid in objectTable.
116:             * returns null if no matching id is found
117:             */
118:            public Object lookup(Identity oid) {
119:                return jcsCache.get(oid.toString());
120:            }
121:
122:            /**
123:             * removes an Object from the cache.
124:             *
125:             * @param oid the Identity of the object to be removed.
126:             */
127:            public void remove(Identity oid) {
128:                try {
129:                    jcsCache.remove(oid.toString());
130:                } catch (CacheException e) {
131:                    throw new RuntimeCacheException(e.getMessage());
132:                }
133:            }
134:
135:            /**
136:             * clear the ObjectCache.
137:             */
138:            public void clear() {
139:                if (jcsCache != null) {
140:                    try {
141:                        jcsCache.remove();
142:                    } catch (CacheException e) {
143:                        throw new RuntimeCacheException(e);
144:                    }
145:                }
146:            }
147:
148:            public String toString() {
149:                ToStringBuilder buf = new ToStringBuilder(this ,
150:                        ToStringStyle.DEFAULT_STYLE);
151:                buf.append("JCS region name", regionName);
152:                buf.append("JCS region", jcsCache);
153:                return buf.toString();
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.