Source Code Cross Referenced for HashtableTest.java in  » Database-DBMS » JDBM » jdbm » 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 DBMS » JDBM » jdbm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jdbm;
002:
003:        import jdbm.RecordManager;
004:        import jdbm.RecordManagerFactory;
005:        import jdbm.helper.FastIterator;
006:        import jdbm.htree.HTree;
007:        import java.io.IOException;
008:        import java.io.PrintStream;
009:
010:        /**
011:         * Test case provided by Daniel Herlemont to demonstrate a bug in
012:         * HashDirectory.  The returned Enumeration got into an infinite loop
013:         * on the same key/val pair.
014:         *
015:         * @version $Id: HashtableTest.java,v 1.6 2005/06/25 23:12:32 doomdark Exp $
016:         */
017:        public class HashtableTest {
018:
019:            private RecordManager recman;
020:            private HTree hashtable;
021:
022:            private boolean enumerate = false;
023:            private boolean populate = false;
024:            private boolean retrieve = false;
025:            private String jdbmName = "hashtest";
026:            private String name = "hashtable";
027:            private String onekey = "onekey";
028:
029:            /**
030:             * Initialize RecordManager and HTree
031:             */
032:            protected void init() throws IOException {
033:                recman = RecordManagerFactory.createRecordManager(jdbmName);
034:
035:                // create or reload HTree
036:                long recid = recman.getNamedObject(name);
037:                if (recid == 0) {
038:                    hashtable = HTree.createInstance(recman);
039:                    recman.setNamedObject(name, hashtable.getRecid());
040:                } else {
041:                    hashtable = HTree.load(recman, recid);
042:                }
043:
044:            }
045:
046:            /**
047:             * Populate HTree with some data
048:             */
049:            protected void populate() throws IOException {
050:                try {
051:                    int max = 1000;
052:                    for (int i = 0; i < max; i++) {
053:                        String key = "key" + i;
054:                        String val = "val" + i;
055:                        hashtable.put(key, val);
056:                        System.out.println("put key=" + key + " val=" + val);
057:                    }
058:
059:                    System.out.println("populate completed");
060:                } finally {
061:                    recman.close();
062:                }
063:            }
064:
065:            /**
066:             * Retrieve a given object based on key
067:             */
068:            protected Object retrieve(Object key) throws IOException {
069:                init();
070:
071:                try {
072:                    Object val = hashtable.get(key);
073:                    System.out.println("retrieve key=" + key + " val=" + val);
074:                    return val;
075:                } finally {
076:                    recman.close();
077:                }
078:            }
079:
080:            /**
081:             * Enumerate keys and objects found in HTree
082:             */
083:            protected void enumerate() throws IOException {
084:                init();
085:
086:                try {
087:                    FastIterator iter = hashtable.keys();
088:                    Object key = iter.next();
089:                    while (key != null) {
090:                        Object val = hashtable.get(key);
091:                        System.out.println("enum key=" + key + " val=" + val);
092:                    }
093:                } finally {
094:                    recman.close();
095:                }
096:            }
097:
098:            /**
099:             * Execute commands specified on command-line
100:             */
101:            protected void doCommands() throws IOException {
102:                if (enumerate) {
103:                    enumerate();
104:                }
105:
106:                if (populate) {
107:                    populate();
108:                }
109:
110:                if (retrieve) {
111:                    retrieve(onekey);
112:                }
113:            }
114:
115:            /**
116:             * Parse command-line arguments
117:             */
118:            protected void parseArgs(String args[]) {
119:                for (int argn = 0; argn < args.length; argn++) {
120:                    if (args[argn].equals("-enum")) {
121:                        enumerate = true;
122:                    } else if (args[argn].equals("-populate")) {
123:                        populate = true;
124:                    } else if (args[argn].equals("-retrieve")) {
125:                        retrieve = true;
126:                    } else if (args[argn].equals("-jdbmName")
127:                            && argn < args.length - 1) {
128:                        jdbmName = args[++argn];
129:                    } else if (args[argn].equals("-key")
130:                            && argn < args.length - 1) {
131:                        onekey = args[++argn];
132:                    } else if (args[argn].equals("-name")
133:                            && argn < args.length - 1) {
134:                        name = args[++argn];
135:                    } else {
136:                        System.err
137:                                .println("Unrecognized option: " + args[argn]);
138:                        usage(System.err);
139:                    }
140:                }
141:            }
142:
143:            /**
144:             * Display usage information
145:             */
146:            protected void usage(PrintStream ps) {
147:                ps.println("Usage: java " + getClass().getName() + " Options");
148:                ps.println();
149:                ps.println("Options (with default values):");
150:                ps.println("-help print this");
151:            }
152:
153:            /**
154:             * Static program entrypoint
155:             */
156:            public static void main(String[] args) {
157:                HashtableTest instance = new HashtableTest();
158:                instance.parseArgs(args);
159:                try {
160:                    instance.doCommands();
161:                } catch (IOException except) {
162:                    except.printStackTrace();
163:                }
164:            }
165:
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.