01: package org.apache.ojb.broker.sequence;
02:
03: import org.apache.ojb.broker.PersistenceBroker;
04: import org.apache.ojb.broker.PersistenceBrokerException;
05: import org.apache.ojb.broker.metadata.FieldDescriptor;
06: import org.apache.ojb.broker.util.sequence.SequenceManager;
07: import org.apache.ojb.broker.util.sequence.SequenceManagerFactory;
08: import org.apache.ojb.broker.util.sequence.SequenceManagerException;
09:
10: import java.util.ArrayList;
11: import java.util.List;
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 {
21: private PersistenceBroker broker;
22: private int loops;
23: private Class targetClass;
24: private FieldDescriptor field;
25: private List resultList;
26:
27: public SequenceManagerHandle(PersistenceBroker broker,
28: Class targetClass, int loops) {
29: this .broker = broker;
30: this .targetClass = targetClass;
31: this .field = broker.getClassDescriptor(targetClass)
32: .getAutoIncrementFields()[0];
33: if (field == null) {
34: String error = "No autoincrement field found for class "
35: + targetClass
36: + " using class descriptor from given broker: "
37: + broker.getClassDescriptor(targetClass);
38: throw new PersistenceBrokerException(error);
39: }
40: this .loops = loops;
41: resultList = new ArrayList();
42: }
43:
44: public void run() {
45: SequenceManager sm = SequenceManagerFactory
46: .getSequenceManager(broker);
47: Object result;
48: for (int i = 0; i < loops; i++) {
49: try {
50: result = sm.getUniqueValue(field);
51: //System.err.println("result "+result);
52: resultList.add(result);
53: SequenceManagerTest.countKey();
54: } catch (SequenceManagerException e) {
55: // ignore
56: }
57: }
58: SequenceManagerTest.addResultList(resultList);
59: }
60: }
|