001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: GarageImpl.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
008:
009: package org.ozoneDB.test.simple;
010:
011: import java.io.*;
012: import org.ozoneDB.*;
013: import org.ozoneDB.DxLib.*;
014:
015: public class GarageImpl extends OzoneObject implements Garage {
016: String name = "Morris";
017: DxHashMap table = new DxHashMap();
018: DxBag list = new DxArrayBag();
019:
020: /** */
021: public GarageImpl() {
022: }
023:
024: /** */
025: public void print() {
026: System.out.println(toString());
027: }
028:
029: /** */
030: public void printAll() throws Exception {
031: DxIterator it = table.iterator();
032: Auto auto;
033: while ((auto = (Auto) it.next()) != null) {
034: auto.print();
035: }
036: }
037:
038: /** */
039: public Auto[] getAll() throws Exception {
040: Auto[] ans = new Auto[table.count()];
041: DxIterator it = table.iterator();
042: for (int c = 0; it.next() != null; c++) {
043: ans[c] = (Auto) it.object();
044: }
045: return ans;
046: }
047:
048: /** */
049: public int[] _setAll(Auto a0, int[] a1, Integer[] a2)
050: throws Exception {
051: System.out.println("Got " + a1.length + " ints...");
052: System.out.println("Got " + a2.length + " Integrs...");
053: return a1;
054: }
055:
056: /** */
057: public void setAll(Integer age) throws Exception {
058: DxIterator it = table.iterator();
059: Auto auto;
060: while ((auto = (Auto) it.next()) != null) {
061: auto.setAge(age);
062: }
063: }
064:
065: /** */
066: public void _addAuto(Auto auto) throws Exception {
067: table.addForKey(auto, auto.name());
068: }
069:
070: /** */
071: public void _newAuto(String name) throws Exception {
072: Auto auto = (Auto) database().createObject(
073: AutoImpl.class.getName());
074: auto.setName(name.toString());
075: table.addForKey(auto, name);
076: list.add(auto);
077: }
078:
079: /** */
080: public void _populate(Integer num) throws Exception {
081: for (int i = 0; i < num.intValue(); i++) {
082: String name = "Auto" + String.valueOf(i);
083: _newAuto(name);
084: }
085: }
086:
087: /** */
088: public Auto autoForName(String search) {
089: return (Auto) table.elementForKey(search);
090: }
091:
092: /** */
093: public void setAlter(DxInteger alter) throws Exception {
094: DxIterator it = table.iterator();
095: Auto auto;
096: while ((auto = (Auto) it.next()) != null) {
097: auto.setAge(new Integer(alter.toInt()));
098: }
099: }
100:
101: /** */
102: public void crunch(DxInteger num) throws Exception {
103: int n = num.toInt();
104: for (int i = 0; i < n; i++) {
105: _newAuto(String.valueOf(i));
106: }
107:
108: DxIterator it = table.iterator();
109: Auto auto;
110: while ((auto = (Auto) it.next()) != null) {
111: auto.age();
112: }
113: }
114:
115: /** */
116: public void _lockThis() throws Exception {
117: }
118:
119: /** */
120: public void _langeTA(Garage garage) throws Exception {
121: Thread.currentThread().sleep(10000);
122: if (garage != null) {
123: garage._lockThis();
124: }
125: }
126:
127: /**
128: * destructor fuer db-objekte
129: */
130: public void done() throws Exception {
131: System.out.println(toString() + " done.");
132: DxIterator it = table.iterator();
133: Auto auto;
134: while ((auto = (Auto) it.next()) != null) {
135: database().deleteObject(auto);
136: }
137: }
138:
139: /** */
140: public String toString() {
141: return "Garage:" + name;
142: }
143:
144: /*
145: * public Object invoke (String methodName, int argNum, Object arg1, Object arg2, Object arg3)
146: throws MethodNotFoundExc, IllegalAccessException, IllegalArgumentException, Throwable {
147: if (methodName.equals("toString"))
148: return toString();
149: else if (methodName.equals("print"))
150: print();
151: else if (methodName.equals("crunch"))
152: crunch ((DxInteger)arg1);
153: else if (methodName.equals("langeTA"))
154: langeTA ((Auto)arg1);
155: else if (methodName.equals("lockThis"))
156: lockThis();
157: else if (methodName.equals("printAll"))
158: printAll();
159: else
160: throw new MethodNotFoundExc();
161: return null;
162: }
163: */
164: protected void finalize() throws Throwable {
165: // System.out.println (toString() + " abgeraeumt...");
166: }
167: }
|