1 package org.apache.ojb.broker.util.sequence; 2 3 17 18 import org.apache.ojb.broker.PersistenceBroker; 19 import org.apache.ojb.broker.PersistenceBrokerException; 20 import org.apache.ojb.broker.metadata.SequenceDescriptor; 21 import org.apache.ojb.broker.util.ClassHelper; 22 import org.apache.ojb.broker.util.logging.Logger; 23 import org.apache.ojb.broker.util.logging.LoggerFactory; 24 25 29 public class SequenceManagerFactory 30 { 31 private static Logger log = LoggerFactory.getLogger(SequenceManagerFactory.class); 32 private static SequenceManagerFactory singleton; 33 34 private Class defaultSeqManagerClass; 35 36 public SequenceManagerFactory() 37 { 38 defaultSeqManagerClass = SequenceManagerHighLowImpl.class; 39 if(log.isDebugEnabled()) log.debug("Default sequence manager class was " + defaultSeqManagerClass.getName()); 40 } 41 42 public synchronized static SequenceManager getSequenceManager(PersistenceBroker broker) 43 { 44 if (singleton == null) 45 { 46 singleton = new SequenceManagerFactory(); 47 } 48 return singleton.createNewSequenceManager(broker); 49 } 50 51 private SequenceManager createNewSequenceManager(PersistenceBroker broker) 52 { 53 synchronized (singleton) 54 { 55 if (log.isDebugEnabled()) log.debug("create new sequence manager for broker " + broker); 56 try 57 { 58 Class seqManClass = defaultSeqManagerClass; 60 SequenceDescriptor sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor(); 61 if (sd != null && sd.getSequenceManagerClass() != null) 62 { 63 seqManClass = sd.getSequenceManagerClass(); 65 if (log.isDebugEnabled()) 66 { 67 log.debug("Jdbc-Connection-Descriptor '" + 68 broker.serviceConnectionManager().getConnectionDescriptor().getJcdAlias() + 69 "' use sequence manager: " + seqManClass); 70 } 71 } 72 return (SequenceManager) ClassHelper.newInstance(seqManClass, PersistenceBroker.class, broker); 73 } 74 catch (Exception ex) 75 { 76 log.error("Could not create sequence manager for broker " + broker, ex); 77 throw new PersistenceBrokerException(ex); 78 } 79 } 80 } 81 } 82 | Popular Tags |