KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > xml > Client


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// 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.xml;
25
26 public class Client
27 {
28     public static int PORT = 54321;
29     public static String JavaDoc USERNAME = "admin";
30     public static String JavaDoc PASSWORD = "admin";
31
32     public static void main(String JavaDoc args[]) throws Exception JavaDoc
33     {
34         org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoodb://localhost:" + PORT, USERNAME, PASSWORD);
35
36         org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db.getRoot("Persons");
37
38         if (root == null)
39         {
40             root = (org.myoodb.collectable.LinkedList) db.createRoot(org.myoodb.collectable.LinkedListDbImpl.class, "Persons");
41             //root = (org.myoodb.collectable.LinkedList) db.createRoot("org.myoodb.collectable.LinkedListDbImpl", "Persons");
42
}
43
44         Person person = (Person) db.createObject(PersonDbImpl.class);
45         //Person person = (Person) db.createObject("org.myoodb.bean.PersonDbImpl");
46
person.setName("John: " + root.size());
47
48         String JavaDoc personXML = (String JavaDoc) person.getXML();
49         System.out.println("XML:\n" + personXML);
50         personXML = personXML.replace("John:", "Sue");
51         person.setXML(personXML);
52
53         root.add(person);
54
55         System.out.println("New persons in database: " + person);
56
57         java.util.Iterator JavaDoc iter = root.toArrayList().iterator();
58         while (iter.hasNext())
59         {
60             person = (Person) iter.next();
61
62             long start = System.currentTimeMillis();
63             String JavaDoc name = person.getName();
64             long stop = System.currentTimeMillis();
65
66             System.out.println(" - Existing persons in database: " + name + " / getTime:" + (stop-start));
67         }
68     }
69 }
70
Popular Tags