Source Code Cross Referenced for ColumnRefCache.java in  » Content-Management-System » harmonise » org » openharmonise » rm » dsi » 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 » Content Management System » harmonise » org.openharmonise.rm.dsi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.rm.dsi;
020:
021:        import java.util.logging.*;
022:
023:        import org.openharmonise.commons.cache.*;
024:        import org.openharmonise.commons.dsi.*;
025:        import org.openharmonise.rm.metadata.Profile;
026:
027:        /**
028:         * Cache of <code>ColumnRef</code> objects used within Harmonise. 
029:         * Column references are stored with a cache key composed of the class 
030:         * name, column name and a boolean of whether the column referfence refers 
031:         * to a historical table or not.
032:         * 
033:         * <p>Note: Care should be used in dealing with <code>ColumnRef</code> objects 
034:         * taken from this cache as they are mutable and therefore there is a risk 
035:         * associated to any changes you might make to an object taken from 
036:         * the cache. For example, it is possible to reset the table name associated 
037:         * to the column reference to accomodate an alias in a select statement 
038:         * maybe, however this could possibly break further use.</p>
039:         * 
040:         * @author mike
041:         * @version $Revision: 1.2 $
042:         *
043:         */
044:        public class ColumnRefCache extends AbstractCache {
045:
046:            /**
047:             * Name of this cache
048:             */
049:            private static final String CACHE_NAME = "columnref";
050:
051:            /**
052:             * Singleton instance of this cache
053:             */
054:            private static ColumnRefCache m_instance = null;
055:
056:            /**
057:             * Logger for this class
058:             */
059:            private static final Logger m_logger = Logger
060:                    .getLogger(ColumnRefCache.class.getName());
061:
062:            /**
063:             * Creates new instance of a column reference cache
064:             * 
065:             * @throws CacheException if an error occurs creating the cache
066:             */
067:            private ColumnRefCache() throws CacheException {
068:                super (CACHE_NAME);
069:            }
070:
071:            /**
072:             * Returns the singleton instance of the cache
073:             * 
074:             * @return
075:             * @throws CacheException
076:             */
077:            static public ColumnRefCache getInstance() throws CacheException {
078:                if (m_instance == null) {
079:                    m_instance = new ColumnRefCache();
080:                }
081:
082:                return m_instance;
083:            }
084:
085:            /**
086:             * Returns a cached <code>ColumnRef</code> for the given column associated
087:             * to the given <code>DataStoreObject</code>. If the <code>ColumnRef</code>
088:             * is not in the cache it is retrieved from the object's <code>getInstanceColumnRef</code>
089:             * method.
090:             * 
091:             * <p>Note: this method calls the <code>getInstanceColumnRef</code> and
092:             * therefore should not be used in the <code>getInstanceColumnRef</code> 
093:             * method of a <code>DataStoreObject</code> in order to avoid an 
094:             * ininite loop.</p>
095:             * 
096:             * @param dsObj the data store object
097:             * @param sColumn the database column name
098:             * @param bIsHist <code>true</code> of the column is in the historical 
099:             * table, otherwise <code>false</code>
100:             * @return the <code>ColumnRef</code> associated with the specified 
101:             * database column
102:             * @throws CacheException if an error occurs obtaining the 
103:             * <code>ColumnRef</code>
104:             */
105:            public ColumnRef getColumnRef(DataStoreObject dsObj,
106:                    String sColumn, boolean bIsHist) throws CacheException {
107:                String sCacheKey = null;
108:
109:                //need to differentiate between profiles, i.e. document profiles, section profiles, etc..
110:                if (dsObj instanceof  Profile) {
111:                    sCacheKey = getCacheKey(dsObj.getDBTableName(), sColumn,
112:                            bIsHist);
113:                } else {
114:                    sCacheKey = getCacheKey(dsObj.getClass(), sColumn, bIsHist);
115:                }
116:
117:                ColumnRef colref = (ColumnRef) getObject(sCacheKey);
118:
119:                if (colref == null) {
120:                    try {
121:                        colref = dsObj.getInstanceColumnRef(sColumn, bIsHist);
122:                    } catch (DataStoreException e) {
123:                        throw new CacheException(
124:                                "Error occured getting column ref", e);
125:                    }
126:
127:                    super .addToCache(sCacheKey, colref);
128:                }
129:
130:                return colref;
131:
132:            }
133:
134:            /* (non-Javadoc)
135:             * @see org.openharmonise.commons.cache.AbstractCache#getObject(java.lang.Object)
136:             */
137:            public Object getObject(final Object key) {
138:
139:                Object cached_object = null;
140:                try {
141:                    cached_object = super .getObject(key);
142:                } catch (CacheException e) {
143:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
144:                }
145:                return cached_object;
146:            }
147:
148:            /**
149:             * Returns a cached <code>ColumnRef</code> for the given column associated
150:             * to the given class if there is one in the cache, otherwise a null is returned.
151:             * 
152:             * @param clss the <code>Class</code> of a <code>DataStoreObject</code>
153:             * @param sColumn the database column name
154:             * @param bIsHist <code>true</code> of the column is in the historical 
155:             * table, otherwise <code>false</code>
156:             * @return a cached <code>ColumnRef</code> for the specified database column
157:             * @throws CacheException if any errors occur
158:             */
159:            public ColumnRef getColumnRef(Class clss, String sColumn,
160:                    boolean bIsHist) throws CacheException {
161:
162:                String sCacheKey = getCacheKey(clss, sColumn, bIsHist);
163:                ColumnRef colref = (ColumnRef) getObject(sCacheKey);
164:
165:                return colref;
166:            }
167:
168:            /**
169:             * Adds the given <code>ColumnRef</code> to this cache for the given
170:             * column associated to the given class.
171:             * 
172:             * @param clss the class of the data store object associated to given the <code>ColumnRef</code>
173:             * @param sColumn the database column name
174:             * @param bIsHist <code>true</code> of the column is in the historical 
175:             * table, otherwise <code>false</code>
176:             * @param colref the column reference to cache
177:             */
178:            public void addToCache(Class clss, String sColumn, boolean bIsHist,
179:                    ColumnRef colref) {
180:                String sCacheKey = getCacheKey(clss, sColumn, bIsHist);
181:                super .addToCache(sCacheKey, colref);
182:            }
183:
184:            /* (non-Javadoc)
185:             * @see org.openharmonise.commons.cache.AbstractCache#getCacheableObject(java.lang.Object)
186:             */
187:            protected Object getCacheableObject(Object key) throws Exception {
188:
189:                return null;
190:            }
191:
192:            /**
193:             * Returns a unique key to be used in the cache composed of the 
194:             * combination of class, column and historical boolean.
195:             * 
196:             * @param clss the class name
197:             * @param sColumn the column name
198:             * @param bIsHist <code>true</code> if the column is in the historical table, otherwise <code>false</code>
199:             * @return a unique key for the column reference
200:             */
201:            protected String getCacheKey(Class clss, String sColumn,
202:                    boolean bIsHist) {
203:                StringBuffer strbuf = new StringBuffer();
204:                strbuf.append(clss.getName()).append(sColumn).append(
205:                        String.valueOf(bIsHist));
206:                return strbuf.toString();
207:            }
208:
209:            /**
210:             * Returns a unique key to be used in the cache composed the combination 
211:             * of class, column and historical boolean.
212:             * 
213:             * @param clss the class name
214:             * @param sColumn the column name
215:             * @param bIsHist <code>true</code> if the column is in the historical table, otherwise <code>false</code>
216:             * @return a unique key for the column reference
217:             */
218:            protected String getCacheKey(String sTable, String sColumn,
219:                    boolean bIsHist) {
220:                StringBuffer strbuf = new StringBuffer();
221:                strbuf.append(sTable).append(sColumn).append(
222:                        String.valueOf(bIsHist));
223:                return strbuf.toString();
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.