KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > tx > GroupImpl


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package test.tx;
10
11 import org.apache.log4j.Category;
12 import org.ozoneDB.DxLib.DxHashMap;
13 import org.ozoneDB.DxLib.DxIterator;
14 import org.ozoneDB.OzoneObject;
15
16 public class GroupImpl extends OzoneObject implements Group {
17
18     /**
19      * log4j logger
20      */

21     private static Category fLog = Category.getInstance(GroupImpl.class);
22
23     protected final static long serialVersionUID = 1;
24
25     protected String JavaDoc name;
26
27     protected DxHashMap users;
28
29
30     public GroupImpl() {
31         name = "Group";
32         users = new DxHashMap();
33     }
34
35
36     public void setName(String JavaDoc _name) {
37         name = _name;
38     }
39
40
41     public String JavaDoc name() {
42         return name;
43     }
44
45
46     public User[] getAll() {
47         fLog.debug("*** getAll():");
48
49         User[] result = new User[users.count()];
50         DxIterator it = users.iterator();
51         for (int i = 0; it.next() != null; i++) {
52             result[i] = (User) it.object();
53         }
54         return result;
55
56         // return (User[])users.toArray();
57
}
58
59
60     public void addUser(User user) throws Exception JavaDoc {
61         users.addForKey(user, user.name());
62     }
63
64
65     public void populate(int n) throws Exception JavaDoc {
66         for (int i = 0; i < n; i++) {
67             User user = (User) database().createObject(UserImpl.class.getName());
68             users.addForKey(user, user.name());
69         }
70     }
71
72
73     public void crash() {
74         throw new NullPointerException JavaDoc();
75     }
76
77
78     public String JavaDoc toString() {
79         return "Group: name=" + name + ", userCount=" + users.count();
80     }
81
82
83     public void done() throws Exception JavaDoc {
84         DxIterator it = users.iterator();
85         while (it.next() != null) {
86             database().deleteObject((User) it.object());
87         }
88     }
89 }
90
Popular Tags