Source Code Cross Referenced for SampleDatabase.java in  » JMX » je » collections » ship » factory » 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 » JMX » je » collections.ship.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: SampleDatabase.java,v 1.25.2.2 2008/01/07 15:14:01 cwl Exp $
007:         */
008:
009:        package collections.ship.factory;
010:
011:        import java.io.File;
012:        import java.io.FileNotFoundException;
013:
014:        import com.sleepycat.bind.serial.StoredClassCatalog;
015:        import com.sleepycat.collections.TupleSerialFactory;
016:        import com.sleepycat.je.Database;
017:        import com.sleepycat.je.DatabaseConfig;
018:        import com.sleepycat.je.DatabaseException;
019:        import com.sleepycat.je.Environment;
020:        import com.sleepycat.je.EnvironmentConfig;
021:        import com.sleepycat.je.ForeignKeyDeleteAction;
022:        import com.sleepycat.je.SecondaryConfig;
023:        import com.sleepycat.je.SecondaryDatabase;
024:
025:        /**
026:         * SampleDatabase defines the storage containers, indices and foreign keys
027:         * for the sample database.
028:         *
029:         * @author Mark Hayes
030:         */
031:        public class SampleDatabase {
032:
033:            private static final String CLASS_CATALOG = "java_class_catalog";
034:            private static final String SUPPLIER_STORE = "supplier_store";
035:            private static final String PART_STORE = "part_store";
036:            private static final String SHIPMENT_STORE = "shipment_store";
037:            private static final String SHIPMENT_PART_INDEX = "shipment_part_index";
038:            private static final String SHIPMENT_SUPPLIER_INDEX = "shipment_supplier_index";
039:            private static final String SUPPLIER_CITY_INDEX = "supplier_city_index";
040:
041:            private Environment env;
042:            private Database partDb;
043:            private Database supplierDb;
044:            private Database shipmentDb;
045:            private SecondaryDatabase supplierByCityDb;
046:            private SecondaryDatabase shipmentByPartDb;
047:            private SecondaryDatabase shipmentBySupplierDb;
048:            private StoredClassCatalog javaCatalog;
049:            private TupleSerialFactory factory;
050:
051:            /**
052:             * Open all storage containers, indices, and catalogs.
053:             */
054:            public SampleDatabase(String homeDirectory)
055:                    throws DatabaseException, FileNotFoundException {
056:
057:                // Open the Berkeley DB environment in transactional mode.
058:                //
059:                System.out.println("Opening environment in: " + homeDirectory);
060:                EnvironmentConfig envConfig = new EnvironmentConfig();
061:                envConfig.setTransactional(true);
062:                envConfig.setAllowCreate(true);
063:                env = new Environment(new File(homeDirectory), envConfig);
064:
065:                // Set the Berkeley DB config for opening all stores.
066:                //
067:                DatabaseConfig dbConfig = new DatabaseConfig();
068:                dbConfig.setTransactional(true);
069:                dbConfig.setAllowCreate(true);
070:
071:                // Create the Serial class catalog.  This holds the serialized class
072:                // format for all database records of serial format.
073:                //
074:                Database catalogDb = env.openDatabase(null, CLASS_CATALOG,
075:                        dbConfig);
076:                javaCatalog = new StoredClassCatalog(catalogDb);
077:
078:                // Use the TupleSerialDbFactory for a Serial/Tuple-based database
079:                // where marshalling interfaces are used.
080:                //
081:                factory = new TupleSerialFactory(javaCatalog);
082:
083:                // Open the Berkeley DB database for the part, supplier and shipment
084:                // stores.  The stores are opened with no duplicate keys allowed.
085:                //
086:                partDb = env.openDatabase(null, PART_STORE, dbConfig);
087:
088:                supplierDb = env.openDatabase(null, SUPPLIER_STORE, dbConfig);
089:
090:                shipmentDb = env.openDatabase(null, SHIPMENT_STORE, dbConfig);
091:
092:                // Open the SecondaryDatabase for the city index of the supplier store,
093:                // and for the part and supplier indices of the shipment store.
094:                // Duplicate keys are allowed since more than one supplier may be in
095:                // the same city, and more than one shipment may exist for the same
096:                // supplier or part.  A foreign key constraint is defined for the
097:                // supplier and part indices to ensure that a shipment only refers to
098:                // existing part and supplier keys.  The CASCADE delete action means
099:                // that shipments will be deleted if their associated part or supplier
100:                // is deleted.
101:                //
102:                SecondaryConfig secConfig = new SecondaryConfig();
103:                secConfig.setTransactional(true);
104:                secConfig.setAllowCreate(true);
105:                secConfig.setSortedDuplicates(true);
106:
107:                secConfig.setKeyCreator(factory.getKeyCreator(Supplier.class,
108:                        Supplier.CITY_KEY));
109:                supplierByCityDb = env.openSecondaryDatabase(null,
110:                        SUPPLIER_CITY_INDEX, supplierDb, secConfig);
111:
112:                secConfig.setForeignKeyDatabase(partDb);
113:                secConfig
114:                        .setForeignKeyDeleteAction(ForeignKeyDeleteAction.CASCADE);
115:                secConfig.setKeyCreator(factory.getKeyCreator(Shipment.class,
116:                        Shipment.PART_KEY));
117:                shipmentByPartDb = env.openSecondaryDatabase(null,
118:                        SHIPMENT_PART_INDEX, shipmentDb, secConfig);
119:
120:                secConfig.setForeignKeyDatabase(supplierDb);
121:                secConfig
122:                        .setForeignKeyDeleteAction(ForeignKeyDeleteAction.CASCADE);
123:                secConfig.setKeyCreator(factory.getKeyCreator(Shipment.class,
124:                        Shipment.SUPPLIER_KEY));
125:                shipmentBySupplierDb = env.openSecondaryDatabase(null,
126:                        SHIPMENT_SUPPLIER_INDEX, shipmentDb, secConfig);
127:            }
128:
129:            /**
130:             * Return the tuple-serial factory.
131:             */
132:            public final TupleSerialFactory getFactory() {
133:
134:                return factory;
135:            }
136:
137:            /**
138:             * Return the storage environment for the database.
139:             */
140:            public final Environment getEnvironment() {
141:
142:                return env;
143:            }
144:
145:            /**
146:             * Return the class catalog.
147:             */
148:            public final StoredClassCatalog getClassCatalog() {
149:
150:                return javaCatalog;
151:            }
152:
153:            /**
154:             * Return the part storage container.
155:             */
156:            public final Database getPartDatabase() {
157:
158:                return partDb;
159:            }
160:
161:            /**
162:             * Return the supplier storage container.
163:             */
164:            public final Database getSupplierDatabase() {
165:
166:                return supplierDb;
167:            }
168:
169:            /**
170:             * Return the shipment storage container.
171:             */
172:            public final Database getShipmentDatabase() {
173:
174:                return shipmentDb;
175:            }
176:
177:            /**
178:             * Return the shipment-by-part index.
179:             */
180:            public final SecondaryDatabase getShipmentByPartDatabase() {
181:
182:                return shipmentByPartDb;
183:            }
184:
185:            /**
186:             * Return the shipment-by-supplier index.
187:             */
188:            public final SecondaryDatabase getShipmentBySupplierDatabase() {
189:
190:                return shipmentBySupplierDb;
191:            }
192:
193:            /**
194:             * Return the supplier-by-city index.
195:             */
196:            public final SecondaryDatabase getSupplierByCityDatabase() {
197:
198:                return supplierByCityDb;
199:            }
200:
201:            /**
202:             * Close all databases and the environment.
203:             */
204:            public void close() throws DatabaseException {
205:
206:                // Close secondary databases, then primary databases.
207:                supplierByCityDb.close();
208:                shipmentByPartDb.close();
209:                shipmentBySupplierDb.close();
210:                partDb.close();
211:                supplierDb.close();
212:                shipmentDb.close();
213:                // And don't forget to close the catalog and the environment.
214:                javaCatalog.close();
215:                env.close();
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.