001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.performance;
025:
026: public class AbcClient {
027: public static int PORT = 54321;
028: public static String USERNAME = "admin";
029: public static String PASSWORD = "admin";
030:
031: public static void main(String args[]) throws Exception {
032: StreamProtocolClient.register(); // use optimized object protocol definitions
033:
034: org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open(
035: "tcp://localhost:" + PORT, USERNAME, PASSWORD);
036:
037: org.myoodb.collectable.AbcObject abcObject = null;
038: org.myoodb.collectable.AbcStore root = (org.myoodb.collectable.AbcStore) db
039: .getRoot("AbcStore");
040: if (root == null) {
041: root = (org.myoodb.collectable.AbcStore) db
042: .createRoot("AbcStore",
043: "org.myoodb.collectable.AbcStoreDbImpl");
044: //root = (org.myoodb.collectable.AbcStore) db.createRoot("AbcStore", org.myoodb.collectable.AbcStoreDbImpl.class);
045:
046: System.out.println("\nTiming abc create/add/find: 1250");
047: long start = System.currentTimeMillis();
048: for (int i = 0; i < 1250; i++) {
049: abcObject = (org.myoodb.collectable.AbcObject) db
050: .createObject("org.myoodb.collectable.AbcObjectDbImpl");
051: //abcObject = (org.myoodb.collectable.AbcObject) db.createObject(org.myoodb.collectable.AbcObjectDbImpl.class);
052:
053: abcObject.setString(String.valueOf(i));
054:
055: // XXX: AbcObject.setAbcStore is not in side AbcStore.addAbcObject so that
056: // if the AbcObject is locked, it does not lock the AbcStore.
057: abcObject.setAbcStore(root);
058: root.addAbcObject(abcObject);
059:
060: System.out.print(".");
061: System.out.flush();
062:
063: if (abcObject.equals(root.getAbcObject(abcObject
064: .getString())) == false) {
065: System.out.println("\nAbcObject not found: "
066: + abcObject.getString());
067: }
068: }
069: long stop = System.currentTimeMillis();
070: System.out.println("Total time(ms): " + (stop - start)
071: + ", " + root);
072: } else {
073: System.out
074: .println("\nTiming abc access/find ( in one big get ): "
075: + root);
076:
077: long start = System.currentTimeMillis();
078:
079: java.util.ArrayList<org.myoodb.collectable.AbcObject> abcs = root
080: .getAbcObjects();
081:
082: long stop = System.currentTimeMillis();
083:
084: System.out.println("Total time(ms): " + (stop - start));
085:
086: java.util.Iterator iter = abcs.iterator();
087: for (int i = 0; iter.hasNext(); i++) {
088: abcObject = (org.myoodb.collectable.AbcObject) iter
089: .next();
090:
091: System.out.print(i + ":" + abcObject.getString() + ",");
092: System.out.flush();
093:
094: if (abcObject.equals(root.getAbcObject(abcObject
095: .getString())) == false) {
096: System.out.println("AbcObject not found: "
097: + abcObject.getString());
098: }
099: }
100: }
101: }
102: }
|