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 DigitClient {
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.DigitObject digitObject = null;
038: org.myoodb.collectable.DigitStore root = (org.myoodb.collectable.DigitStore) db
039: .getRoot("DigitStore");
040: if (root == null) {
041: root = (org.myoodb.collectable.DigitStore) db.createRoot(
042: "DigitStore",
043: "org.myoodb.collectable.DigitStoreDbImpl");
044: //root = (org.myoodb.collectable.DigitStore) db.createRoot("DigitStore", org.myoodb.collectable.DigitStoreDbImpl.class);
045:
046: System.out.println("\nTiming digit create/add/find: 1250");
047: long start = System.currentTimeMillis();
048: for (int i = 0; i < 1250; i++) {
049: digitObject = (org.myoodb.collectable.DigitObject) db
050: .createObject("org.myoodb.collectable.DigitObjectDbImpl");
051: //digitObject = (org.myoodb.collectable.DigitObject) db.createObject(org.myoodb.collectable.DigitObjectDbImpl.class);
052:
053: digitObject.setNumber(i);
054:
055: // XXX: DigitObject.setDigitStore is not in side DigitStore.addDigitObject so that
056: // if the DigitObject is locked, it does not lock the DigitStore.
057: digitObject.setDigitStore(root);
058: root.addDigitObject(digitObject);
059:
060: System.out.print(".");
061: System.out.flush();
062:
063: if (digitObject.equals(root.getDigitObject(digitObject
064: .getNumber())) == false) {
065: System.out.println("\nDigitObject not found: "
066: + digitObject.getNumber());
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 digit access/find ( in one big get ): "
075: + root);
076:
077: long start = System.currentTimeMillis();
078:
079: java.util.ArrayList<org.myoodb.collectable.DigitObject> digits = root
080: .getDigitObjects();
081:
082: long stop = System.currentTimeMillis();
083:
084: System.out.println("Total time(ms): " + (stop - start));
085:
086: java.util.Iterator iter = digits.iterator();
087: for (int i = 0; iter.hasNext(); i++) {
088: digitObject = (org.myoodb.collectable.DigitObject) iter
089: .next();
090:
091: System.out.print(i + ":" + digitObject.getNumber()
092: + ",");
093: System.out.flush();
094:
095: if (digitObject.equals(root.getDigitObject(digitObject
096: .getNumber())) == false) {
097: System.out.println("DigitObject not found: "
098: + digitObject.getNumber());
099: }
100: }
101: }
102: }
103: }
|