Source Code Cross Referenced for OSCacheProvider.java in  » Cache » OSCache » com » opensymphony » oscache » hibernate » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.hibernate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.opensymphony.oscache.hibernate;
002:
003:        import java.util.Properties;
004:
005:        import org.apache.commons.logging.Log;
006:        import org.apache.commons.logging.LogFactory;
007:
008:        import org.hibernate.cache.Cache;
009:        import org.hibernate.cache.CacheException;
010:        import org.hibernate.cache.CacheProvider;
011:        import org.hibernate.cache.Timestamper;
012:        import org.hibernate.util.StringHelper;
013:
014:        import com.opensymphony.oscache.base.CacheEntry;
015:        import com.opensymphony.oscache.base.Config;
016:        import com.opensymphony.oscache.general.GeneralCacheAdministrator;
017:        import com.opensymphony.oscache.util.StringUtil;
018:
019:        /**
020:         * Cache provider plugin for Hibernate 3.2 and OpenSymphony OSCache 2.4.
021:         * <p/>
022:         * This implementation assumes that identifiers have well-behaved <tt>toString()</tt> methods.
023:         * <p/>
024:         * To enable OSCache for Hibernate's second level cache add the following line to Hibernate's configuration e.g. <code>hibernate.cfg.xml</code>):
025:         * <code>hibernate.cache.provider_class=com.opensymphony.oscache.hibernate.OSCacheProvider</code>
026:         * To configure a different configuration file use the following parameter in the Hibernate's configuration:
027:         * <code>com.opensymphony.oscache.configurationResourceName=[path to oscache-hibernate.properties]</code>
028:         * 
029:         * @version $Revision:$
030:         */
031:        public class OSCacheProvider implements  CacheProvider {
032:
033:            private static final Log LOG = LogFactory
034:                    .getLog(OSCacheProvider.class);
035:
036:            /** In the Hibernate system property you can specify the location of the oscache configuration file name. */
037:            public static final String OSCACHE_CONFIGURATION_RESOURCE_NAME = "com.opensymphony.oscache.configurationResourceName";
038:
039:            /** The <tt>OSCache</tt> refresh period property suffix. */
040:            public static final String OSCACHE_REFRESH_PERIOD = "refresh.period";
041:
042:            /** The <tt>OSCache</tt> CRON expression property suffix. */
043:            public static final String OSCACHE_CRON = "cron";
044:
045:            private static GeneralCacheAdministrator cache;
046:
047:            /**
048:             * Builds a new {@link Cache} instance, and gets it's properties from the 
049:             * GeneralCacheAdministrator {@link GeneralCacheAdministrator}
050:             * which reads the properties file (<code>oscache.properties</code>) in the start method: 
051:             * @see com.opensymphony.oscache.hibernate.OSCacheProvider#start(java.util.Properties)
052:             *
053:             * @param region the region of the cache
054:             * @param properties not used
055:             * @return the hibernate 2nd level cache
056:             * @throws CacheException
057:             * 
058:             * @see org.hibernate.cache.CacheProvider#buildCache(java.lang.String, java.util.Properties)
059:             */
060:            public Cache buildCache(String region, Properties properties)
061:                    throws CacheException {
062:                if (cache != null) {
063:                    LOG.debug("building cache in OSCacheProvider...");
064:
065:                    String refreshPeriodString = cache.getProperty(StringHelper
066:                            .qualify(region, OSCACHE_REFRESH_PERIOD));
067:                    int refreshPeriod = refreshPeriodString == null ? CacheEntry.INDEFINITE_EXPIRY
068:                            : Integer.parseInt(refreshPeriodString.trim());
069:
070:                    String cron = cache.getProperty(StringHelper.qualify(
071:                            region, OSCACHE_CRON));
072:
073:                    return new OSCache(cache, refreshPeriod, cron, region);
074:                }
075:                throw new CacheException(
076:                        "OSCache was stopped or wasn't configured via method start.");
077:            }
078:
079:            /**
080:             * @see org.hibernate.cache.CacheProvider#nextTimestamp()
081:             */
082:            public long nextTimestamp() {
083:                return Timestamper.next();
084:            }
085:
086:            /**
087:             * This method isn't documented in Hibernate:
088:             * @see org.hibernate.cache.CacheProvider#isMinimalPutsEnabledByDefault()
089:             */
090:            public boolean isMinimalPutsEnabledByDefault() {
091:                return false;
092:            }
093:
094:            /**
095:             * @see org.hibernate.cache.CacheProvider#stop()
096:             */
097:            public void stop() {
098:                if (cache != null) {
099:                    LOG.debug("Stopping OSCacheProvider...");
100:                    cache.destroy();
101:                    cache = null;
102:                    LOG.debug("OSCacheProvider stopped.");
103:                }
104:            }
105:
106:            /**
107:             * @see org.hibernate.cache.CacheProvider#start(java.util.Properties)
108:             */
109:            public void start(Properties hibernateSystemProperties)
110:                    throws CacheException {
111:                if (cache == null) {
112:                    // construct the cache
113:                    LOG.debug("Starting OSCacheProvider...");
114:                    String configResourceName = null;
115:                    if (hibernateSystemProperties != null) {
116:                        configResourceName = (String) hibernateSystemProperties
117:                                .get(OSCACHE_CONFIGURATION_RESOURCE_NAME);
118:                    }
119:                    if (StringUtil.isEmpty(configResourceName)) {
120:                        cache = new GeneralCacheAdministrator();
121:                    } else {
122:                        Properties propertiesOSCache = Config.loadProperties(
123:                                configResourceName, this .getClass().getName());
124:                        cache = new GeneralCacheAdministrator(propertiesOSCache);
125:                    }
126:                    LOG.debug("OSCacheProvider started.");
127:                } else {
128:                    LOG
129:                            .warn("Tried to restart OSCacheProvider, which is already running.");
130:                }
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.