Source Code Cross Referenced for ClientServerExample.java in  » Database-DBMS » db4o-6.4 » com » db4o » f1 » chapter5 » 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 » db4o 6.4 » com.db4o.f1.chapter5 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.db4o.f1.chapter5;
002:
003:        import java.io.*;
004:        import com.db4o.*;
005:        import com.db4o.f1.*;
006:
007:        public class ClientServerExample extends Util {
008:            private final static int PORT = 0xdb40;
009:            private final static String USER = "user";
010:            private final static String PASSWORD = "password";
011:
012:            public static void main(String[] args) throws IOException {
013:                new File(Util.DB4OFILENAME).delete();
014:                accessLocalServer();
015:                new File(Util.DB4OFILENAME).delete();
016:                ObjectContainer db = Db4o.openFile(Util.DB4OFILENAME);
017:                try {
018:                    setFirstCar(db);
019:                    setSecondCar(db);
020:                } finally {
021:                    db.close();
022:                }
023:                configureDb4o();
024:                ObjectServer server = Db4o.openServer(Util.DB4OFILENAME, 0);
025:                try {
026:                    queryLocalServer(server);
027:                    demonstrateLocalReadCommitted(server);
028:                    demonstrateLocalRollback(server);
029:                } finally {
030:                    server.close();
031:                }
032:                accessRemoteServer();
033:                server = Db4o.openServer(Util.DB4OFILENAME, PORT);
034:                server.grantAccess(USER, PASSWORD);
035:                try {
036:                    queryRemoteServer(PORT, USER, PASSWORD);
037:                    demonstrateRemoteReadCommitted(PORT, USER, PASSWORD);
038:                    demonstrateRemoteRollback(PORT, USER, PASSWORD);
039:                } finally {
040:                    server.close();
041:                }
042:            }
043:
044:            public static void setFirstCar(ObjectContainer db) {
045:                Pilot pilot = new Pilot("Rubens Barrichello", 99);
046:                Car car = new Car("BMW");
047:                car.setPilot(pilot);
048:                db.set(car);
049:            }
050:
051:            public static void setSecondCar(ObjectContainer db) {
052:                Pilot pilot = new Pilot("Michael Schumacher", 100);
053:                Car car = new Car("Ferrari");
054:                car.setPilot(pilot);
055:                db.set(car);
056:            }
057:
058:            public static void accessLocalServer() {
059:                ObjectServer server = Db4o.openServer(Util.DB4OFILENAME, 0);
060:                try {
061:                    ObjectContainer client = server.openClient();
062:                    // Do something with this client, or open more clients
063:                    client.close();
064:                } finally {
065:                    server.close();
066:                }
067:            }
068:
069:            public static void queryLocalServer(ObjectServer server) {
070:                ObjectContainer client = server.openClient();
071:                listResult(client.get(new Car(null)));
072:                client.close();
073:            }
074:
075:            public static void configureDb4o() {
076:                Db4o.configure().objectClass(Car.class).updateDepth(3);
077:            }
078:
079:            public static void demonstrateLocalReadCommitted(ObjectServer server) {
080:                ObjectContainer client1 = server.openClient();
081:                ObjectContainer client2 = server.openClient();
082:                Pilot pilot = new Pilot("David Coulthard", 98);
083:                ObjectSet result = client1.get(new Car("BMW"));
084:                Car car = (Car) result.next();
085:                car.setPilot(pilot);
086:                client1.set(car);
087:                listResult(client1.get(new Car(null)));
088:                listResult(client2.get(new Car(null)));
089:                client1.commit();
090:                listResult(client1.get(Car.class));
091:                listRefreshedResult(client2, client2.get(Car.class), 2);
092:                client1.close();
093:                client2.close();
094:            }
095:
096:            public static void demonstrateLocalRollback(ObjectServer server) {
097:                ObjectContainer client1 = server.openClient();
098:                ObjectContainer client2 = server.openClient();
099:                ObjectSet result = client1.get(new Car("BMW"));
100:                Car car = (Car) result.next();
101:                car.setPilot(new Pilot("Someone else", 0));
102:                client1.set(car);
103:                listResult(client1.get(new Car(null)));
104:                listResult(client2.get(new Car(null)));
105:                client1.rollback();
106:                client1.ext().refresh(car, 2);
107:                listResult(client1.get(new Car(null)));
108:                listResult(client2.get(new Car(null)));
109:                client1.close();
110:                client2.close();
111:            }
112:
113:            public static void accessRemoteServer() throws IOException {
114:                ObjectServer server = Db4o.openServer(Util.DB4OFILENAME, PORT);
115:                server.grantAccess(USER, PASSWORD);
116:                try {
117:                    ObjectContainer client = Db4o.openClient("localhost", PORT,
118:                            USER, PASSWORD);
119:                    // Do something with this client, or open more clients
120:                    client.close();
121:                } finally {
122:                    server.close();
123:                }
124:            }
125:
126:            public static void queryRemoteServer(int port, String user,
127:                    String password) throws IOException {
128:                ObjectContainer client = Db4o.openClient("localhost", port,
129:                        user, password);
130:                listResult(client.get(new Car(null)));
131:                client.close();
132:            }
133:
134:            public static void demonstrateRemoteReadCommitted(int port,
135:                    String user, String password) throws IOException {
136:                ObjectContainer client1 = Db4o.openClient("localhost", port,
137:                        user, password);
138:                ObjectContainer client2 = Db4o.openClient("localhost", port,
139:                        user, password);
140:                Pilot pilot = new Pilot("Jenson Button", 97);
141:                ObjectSet result = client1.get(new Car(null));
142:                Car car = (Car) result.next();
143:                car.setPilot(pilot);
144:                client1.set(car);
145:                listResult(client1.get(new Car(null)));
146:                listResult(client2.get(new Car(null)));
147:                client1.commit();
148:                listResult(client1.get(new Car(null)));
149:                listRefreshedResult(client2, client2.get(Car.class), 2);
150:                client1.close();
151:                client2.close();
152:            }
153:
154:            public static void demonstrateRemoteRollback(int port, String user,
155:                    String password) throws IOException {
156:                ObjectContainer client1 = Db4o.openClient("localhost", port,
157:                        user, password);
158:                ObjectContainer client2 = Db4o.openClient("localhost", port,
159:                        user, password);
160:                ObjectSet result = client1.get(new Car(null));
161:                Car car = (Car) result.next();
162:                car.setPilot(new Pilot("Someone else", 0));
163:                client1.set(car);
164:                listResult(client1.get(new Car(null)));
165:                listResult(client2.get(new Car(null)));
166:                client1.rollback();
167:                client1.ext().refresh(car, 2);
168:                listResult(client1.get(new Car(null)));
169:                listResult(client2.get(new Car(null)));
170:                client1.close();
171:                client2.close();
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.