01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: Statistics.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
08:
09: package org.ozoneDB.tools;
10:
11: import java.io.*;
12: import org.ozoneDB.DxLib.*;
13: import org.ozoneDB.core.*;
14:
15: public class Statistics extends Object {
16: static String dir = File.separator + "stats";
17: public static String clusp = new String("clusp");
18:
19: public static void main(String[] args) {
20: try {
21: String odbdir = args[0].toString();
22: System.out.println("ODB3X statistics");
23: System.out.println("----------------");
24: printLastOID(odbdir);
25: printStats(odbdir);
26: } catch (Exception e) {
27: System.out.println("\nusage: java Statistics <dir>");
28: System.exit(1);
29: }
30: }
31:
32: public static void printLastOID(String odbdir) {
33: // FIXME:
34: // try {
35: // File f = new File (odbdir, Env.OID_FILE);
36: // RandomAccessFile rf = new RandomAccessFile (f, "rw");
37: // long id = rf.readLong ();
38: // System.out.println ("DatabaseID : " + (id>>40));
39: // System.out.println ("ObjectID count : " + (id & 0xFFFFF));
40: // System.out.println ("ClusterID count : " + (rf.readLong() & 0xFFFFF));
41: // System.out.println ("TransactionID count : " + (rf.readLong() & 0xFFFFF));
42: // rf.close ();
43: // } catch (IOException e) {
44: // System.err.println (e);
45: // }
46: }
47:
48: public static void printStats(String odbdir) {
49: System.out.print("\nClusterSpace stats:");
50: System.out.println(readClusterStats(odbdir));
51: }
52:
53: public static void writeStats(DxObject cs, String path, String file) {
54: try {
55: File f = new File(path + dir);
56: if (!f.exists()) {
57: f.mkdir();
58: }
59: f = new File(path + dir, file);
60: FileOutputStream fo = new FileOutputStream(f);
61: ObjectOutputStream os = new ObjectOutputStream(fo);
62: os.writeObject(cs);
63: os.close();
64: } catch (Exception e) {
65: System.out.println(e);
66: }
67: }
68:
69: public static DxObject readStats(String path, String file) {
70: try {
71: File f = new File(path + dir, file);
72: FileInputStream fi = new FileInputStream(f);
73: ObjectInputStream is = new ObjectInputStream(fi);
74: DxObject obj = (DxObject) is.readObject();
75: fi.close();
76: return obj;
77: } catch (FileNotFoundException e) {
78: // nichts tun, wenn file nicht da, wird spaeter angelegt
79: } catch (Exception e) {
80: System.out.println(e);
81: }
82: return null;
83: }
84:
85: public static void writeClusterStats(ClusterStats cs, String path) {
86: writeStats(cs, path, clusp);
87: }
88:
89: public static ClusterStats readClusterStats(String path) {
90: ClusterStats cs = (ClusterStats) Statistics.readStats(path,
91: clusp);
92: if (cs == null) {
93: cs = new ClusterStats();
94: writeClusterStats(cs, path);
95: }
96: return cs;
97: }
98: }
|