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 ; 11 import java.util.List ; 12 13 20 public class SequenceManagerHandle implements Runnable 21 { 22 private PersistenceBroker broker; 23 private int loops; 24 private Class targetClass; 25 private FieldDescriptor field; 26 private List resultList; 27 28 public SequenceManagerHandle(PersistenceBroker broker, Class 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 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 (); 41 } 42 43 public void run() 44 { 45 SequenceManager sm = SequenceManagerFactory.getSequenceManager(broker); 46 Object result; 47 for (int i = 0; i < loops; i++) 48 { 49 try 50 { 51 result = sm.getUniqueValue(field); 52 resultList.add(result); 54 SequenceManagerTest.countKey(); 55 } 56 catch (SequenceManagerException e) 57 { 58 } 60 } 61 SequenceManagerTest.addResultList(resultList); 62 } 63 } 64 | Popular Tags |