Source Code Cross Referenced for SimpleCache.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » db » impl » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.db.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         *  All rights reserved.
004:         *
005:         *
006:         */
007:
008:        //=======================================================================
009:        // Package
010:        package com.hp.hpl.jena.db.impl;
011:
012:        //=======================================================================
013:        // Imports
014:        import java.util.*;
015:
016:        import com.hp.hpl.jena.util.CollectionFactory;
017:
018:        //=======================================================================
019:        /**
020:         * Trivial implementation of the generic cache interface used to cache
021:         * literals and resources. This implementation simple flushes the cache
022:         * when the threshold limit is exceeded.
023:         *
024:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
025:         * @version $Revision: 1.8 $ on $Date: 2008/01/02 12:08:25 $
026:         */
027:
028:        public class SimpleCache implements  ICache {
029:
030:            /** The cache itself */
031:            protected Map cache = CollectionFactory.createHashedMap();
032:
033:            /** The current size limit */
034:            protected int threshold;
035:
036:            /** The current number of entries (probably redundant, just use cache.size) */
037:            protected int count = 0;
038:
039:            /**
040:             * Create an empty cache with the given threshold limit.
041:             *
042:             * @param threshold the cache size limit, use 0 for no cache, -1 for
043:             * unlimited cache growth; any other number indicates the number of cache entries
044:             */
045:            public SimpleCache(int threshold) {
046:                this .threshold = threshold;
047:            }
048:
049:            /**
050:             * Add an entry to the cache
051:             * @param id the database ID to be used as an index
052:             * @param val the literal or resources to be stored
053:             */
054:            public void put(IDBID id, Object val) {
055:                if (threshold == 0)
056:                    return;
057:                if (threshold > 0 && count >= threshold) {
058:                    cache = CollectionFactory.createHashedMap();
059:                    count = 0;
060:                }
061:                count++;
062:                cache.put(id, val);
063:            }
064:
065:            /**
066:             * Retreive an object from the cache
067:             * @param id the database ID of the object to be retrieved
068:             * @return the object or null if it is not in the cache
069:             */
070:            public Object get(IDBID id) {
071:                return cache.get(id);
072:            }
073:
074:            /**
075:             * Set a threshold for the cache size in terms of the count of cache entries.
076:             * For literals a storage limit rather than a count might be more useful but
077:             * counts are easier, more general and sufficient for the current use.
078:             *
079:             * @param threshold the cache size limit, use 0 for no cache, -1 for
080:             * unlimited cache growth; any other number indicates the number of cache entries
081:             */
082:            public void setLimit(int threshold) {
083:                this .threshold = threshold;
084:                if (threshold >= 0 && count > threshold) {
085:                    cache = CollectionFactory.createHashedMap();
086:                    count = 0;
087:                }
088:            }
089:
090:            /**
091:             * Return the current threshold limit for the cache size.
092:             */
093:            public int getLimit() {
094:                return threshold;
095:            }
096:        }
097:        /*
098:         *  (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
099:         *  All rights reserved.
100:         *
101:         * Redistribution and use in source and binary forms, with or without
102:         * modification, are permitted provided that the following conditions
103:         * are met:
104:         * 1. Redistributions of source code must retain the above copyright
105:         *    notice, this list of conditions and the following disclaimer.
106:         * 2. Redistributions in binary form must reproduce the above copyright
107:         *    notice, this list of conditions and the following disclaimer in the
108:         *    documentation and/or other materials provided with the distribution.
109:         * 3. The name of the author may not be used to endorse or promote products
110:         *    derived from this software without specific prior written permission.
111:         * 
112:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
113:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
114:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
115:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
116:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
117:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
118:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
119:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
120:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
121:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
122:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.