Source Code Cross Referenced for ExampleInventoryRead.java in  » JMX » je » persist » gettingStarted » 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 » persist.gettingStarted 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package persist.gettingStarted;
002:
003:        import java.io.File;
004:
005:        import com.sleepycat.je.DatabaseException;
006:        import com.sleepycat.persist.EntityCursor;
007:
008:        public class ExampleInventoryRead {
009:
010:            private static File myDbEnvPath = new File("/tmp/JEDB");
011:
012:            private DataAccessor da;
013:
014:            // Encapsulates the database environment.
015:            private static MyDbEnv myDbEnv = new MyDbEnv();
016:
017:            // The item to locate if the -s switch is used
018:            private static String locateItem;
019:
020:            private static void usage() {
021:                System.out.println("ExampleInventoryRead [-h <env directory>]"
022:                        + "[-s <item to locate>]");
023:                System.exit(-1);
024:            }
025:
026:            public static void main(String args[]) {
027:                ExampleInventoryRead eir = new ExampleInventoryRead();
028:                try {
029:                    eir.run(args);
030:                } catch (DatabaseException dbe) {
031:                    System.err.println("ExampleInventoryRead: "
032:                            + dbe.toString());
033:                    dbe.printStackTrace();
034:                } finally {
035:                    myDbEnv.close();
036:                }
037:                System.out.println("All done.");
038:            }
039:
040:            private void run(String args[]) throws DatabaseException {
041:                // Parse the arguments list
042:                parseArgs(args);
043:
044:                myDbEnv.setup(myDbEnvPath, // path to the environment home
045:                        true); // is this environment read-only?
046:
047:                // Open the data accessor. This is used to retrieve
048:                // persistent objects.
049:                da = new DataAccessor(myDbEnv.getEntityStore());
050:
051:                // If a item to locate is provided on the command line,
052:                // show just the inventory items using the provided name.
053:                // Otherwise, show everything in the inventory.
054:                if (locateItem != null) {
055:                    showItem();
056:                } else {
057:                    showAllInventory();
058:                }
059:            }
060:
061:            // Shows all the inventory items that exist for a given
062:            // inventory name.
063:            private void showItem() throws DatabaseException {
064:
065:                // Use the inventory name secondary key to retrieve
066:                // these objects.
067:                EntityCursor<Inventory> items = da.inventoryByName.subIndex(
068:                        locateItem).entities();
069:                try {
070:                    for (Inventory item : items) {
071:                        displayInventoryRecord(item);
072:                    }
073:                } finally {
074:                    items.close();
075:                }
076:            }
077:
078:            // Displays all the inventory items in the store
079:            private void showAllInventory() throws DatabaseException {
080:
081:                // Get a cursor that will walk every
082:                // inventory object in the store.
083:                EntityCursor<Inventory> items = da.inventoryBySku.entities();
084:
085:                try {
086:                    for (Inventory item : items) {
087:                        displayInventoryRecord(item);
088:                    }
089:                } finally {
090:                    items.close();
091:                }
092:            }
093:
094:            private void displayInventoryRecord(Inventory theInventory)
095:                    throws DatabaseException {
096:
097:                System.out.println(theInventory.getSku() + ":");
098:                System.out.println("\t " + theInventory.getItemName());
099:                System.out.println("\t " + theInventory.getCategory());
100:                System.out.println("\t " + theInventory.getVendor());
101:                System.out.println("\t\tNumber in stock: "
102:                        + theInventory.getVendorInventory());
103:                System.out.println("\t\tPrice per unit:  "
104:                        + theInventory.getVendorPrice());
105:                System.out.println("\t\tContact: ");
106:
107:                Vendor theVendor = da.vendorByName
108:                        .get(theInventory.getVendor());
109:                assert theVendor != null;
110:
111:                System.out.println("\t\t " + theVendor.getAddress());
112:                System.out.println("\t\t " + theVendor.getCity() + ", "
113:                        + theVendor.getState() + " " + theVendor.getZipcode());
114:                System.out.println("\t\t Business Phone: "
115:                        + theVendor.getBusinessPhoneNumber());
116:                System.out.println("\t\t Sales Rep: " + theVendor.getRepName());
117:                System.out.println("\t\t            "
118:                        + theVendor.getRepPhoneNumber());
119:            }
120:
121:            protected ExampleInventoryRead() {
122:            }
123:
124:            private static void parseArgs(String args[]) {
125:                for (int i = 0; i < args.length; ++i) {
126:                    if (args[i].startsWith("-")) {
127:                        switch (args[i].charAt(1)) {
128:                        case 'h':
129:                            myDbEnvPath = new File(args[++i]);
130:                            break;
131:                        case 's':
132:                            locateItem = args[++i];
133:                            break;
134:                        default:
135:                            usage();
136:                        }
137:                    }
138:                }
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.