01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.simpleUdp;
25:
26: import org.myoodb.objects.*;
27:
28: public class Client {
29: public static int PORT = 54322;
30: public static String USERNAME = "admin";
31: public static String PASSWORD = "admin";
32:
33: public static void main(String args[]) throws Exception {
34: // XXX: set packet size large enough for running this test 1000 times
35: // ( since calling root.toArrayList() would max out at 400 persons )
36: org.myoodb.core.AbstractConnection.setBufferSize(1024 * 32);
37:
38: org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open(
39: "udp://localhost:" + PORT, USERNAME, PASSWORD);
40:
41: org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db
42: .getRoot("Persons");
43: if (root == null) {
44: root = (org.myoodb.collectable.LinkedList) db.createRoot(
45: "Persons",
46: "org.myoodb.collectable.LinkedListDbImpl");
47: //root = (org.myoodb.collectable.LinkedList) db.createRoot("Persons", org.myoodb.collectable.LinkedListDbImpl.class);
48: }
49:
50: Person person = (Person) db
51: .createObject("org.myoodb.objects.PersonDbImpl");
52: //Person person = (Person) db.createObject(PersonDbImpl.class);
53:
54: person.setName("John Smith the " + root.size());
55: root.add(person);
56:
57: System.out.println("New persons in database: " + person);
58:
59: java.util.Iterator iter = root.toArrayList().iterator();
60: while (iter.hasNext()) {
61: person = (Person) iter.next();
62:
63: long start = System.currentTimeMillis();
64: String name = person.getName();
65: long stop = System.currentTimeMillis();
66:
67: System.out.println(" - Existing persons in database: "
68: + name + " / getTime:" + (stop - start));
69: }
70: }
71: }
|