KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > sequence > SequenceManagerHandle


1 package org.apache.ojb.broker.sequence;
2
3 import org.apache.ojb.broker.PersistenceBroker;
4 import org.apache.ojb.broker.PersistenceBrokerException;
5 import org.apache.ojb.broker.metadata.FieldDescriptor;
6 import org.apache.ojb.broker.util.sequence.SequenceManager;
7 import org.apache.ojb.broker.util.sequence.SequenceManagerFactory;
8 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12
13 /**
14  * Simple class, obtains sequence numbers from a SequenceManager
15  * (in multi-threaded tests).
16  *
17  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
18  * @version $Id: SequenceManagerHandle.java,v 1.6 2003/11/06 01:38:16 arminw Exp $
19  */

20 public class SequenceManagerHandle implements Runnable JavaDoc
21 {
22     private PersistenceBroker broker;
23     private int loops;
24     private Class JavaDoc targetClass;
25     private FieldDescriptor field;
26     private List JavaDoc resultList;
27
28     public SequenceManagerHandle(PersistenceBroker broker, Class JavaDoc targetClass, int loops)
29     {
30         this.broker = broker;
31         this.targetClass = targetClass;
32         this.field = broker.getClassDescriptor(targetClass).getAutoIncrementFields()[0];
33         if(field == null)
34         {
35             String JavaDoc error = "No autoincrement field found for class "+targetClass+
36             " using class descriptor from given broker: "+broker.getClassDescriptor(targetClass);
37             throw new PersistenceBrokerException(error);
38         }
39         this.loops = loops;
40         resultList = new ArrayList JavaDoc();
41     }
42
43     public void run()
44     {
45         SequenceManager sm = SequenceManagerFactory.getSequenceManager(broker);
46         Object JavaDoc result;
47         for (int i = 0; i < loops; i++)
48         {
49             try
50             {
51                 result = sm.getUniqueValue(field);
52                 //System.err.println("result "+result);
53
resultList.add(result);
54                 SequenceManagerTest.countKey();
55             }
56             catch (SequenceManagerException e)
57             {
58                 // ignore
59
}
60         }
61         SequenceManagerTest.addResultList(resultList);
62     }
63 }
64
Popular Tags