View Javadoc

1   package org.apache.ojb.broker.util.collections;
2   
3   /* Copyright 2002-2005 The Apache Software Foundation
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  import org.apache.ojb.broker.ManageableCollection;
19  import org.apache.ojb.broker.PersistenceBroker;
20  import org.apache.ojb.broker.PersistenceBrokerException;
21  
22  import java.util.HashSet;
23  import java.util.Iterator;
24  
25  /**
26   * is a utility class. provides a HashSet that addionally implements
27   * the ManageableCollection interface. This class may be used
28   * as a type for collection attributes.
29   *
30   * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
31   * @version $Id: ManageableHashSet.java,v 1.1 2007-08-24 22:17:39 ewestfal Exp $
32   */
33  public class ManageableHashSet extends HashSet implements ManageableCollection
34  {
35      /**
36       * add a single Object to the Collection. This method is used during reading Collection elements
37       * from the database. Thus it is is save to cast anObject to the underlying element type of the
38       * collection.
39       */
40      public void ojbAdd(Object anObject)
41      {
42          super.add(anObject);
43      }
44  
45      /**
46       * adds a Collection to this collection. Used in reading Extents from the Database.
47       * Thus it is save to cast otherCollection to this.getClass().
48       */
49      public void ojbAddAll(ManageableCollection otherCollection)
50      {
51          super.addAll((ManageableHashSet) otherCollection);
52      }
53  
54      public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
55      {
56          //do nothing
57      }
58  
59      /**
60       * returns an Iterator over all elements in the collection. Used during store and delete Operations.
61       * If the implementor does not return an iterator over ALL elements, OJB cannot store and delete all elements properly.
62       *
63       */
64      public Iterator ojbIterator()
65      {
66          return super.iterator();
67      }
68  }