1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ojb;
17
18 import org.apache.commons.beanutils.ConstructorUtils;
19 import org.apache.log4j.Logger;
20 import org.apache.ojb.broker.PersistenceBroker;
21 import org.apache.ojb.broker.accesslayer.JdbcAccess;
22 import org.apache.ojb.broker.metadata.ClassDescriptor;
23 import org.apache.ojb.broker.metadata.FieldDescriptor;
24 import org.apache.ojb.broker.util.sequence.SequenceManager;
25 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
26 import org.kuali.rice.core.api.config.ConfigurationException;
27 import org.kuali.rice.core.api.config.property.ConfigContext;
28
29
30
31
32
33 public class ConfigurableSequenceManager implements SequenceManager {
34 private static final Logger LOG = Logger.getLogger(ConfigurableSequenceManager.class);
35 private static final String SEQUENCE_MANAGER_CLASS_NAME_PROPERTY = "datasource.ojb.sequence.manager";
36 private SequenceManager sequenceManager;
37
38 public ConfigurableSequenceManager(PersistenceBroker broker) {
39 this.sequenceManager = createSequenceManager(broker);
40 }
41
42 protected SequenceManager createSequenceManager(PersistenceBroker broker) {
43 String sequenceManagerClassName = ConfigContext.getCurrentContextConfig().getProperty(SEQUENCE_MANAGER_CLASS_NAME_PROPERTY);
44 try {
45 Object sequenceManagerObject = ConstructorUtils.invokeConstructor(Class.forName(sequenceManagerClassName), broker);
46 if (!(sequenceManagerObject instanceof SequenceManager)) {
47 throw new ConfigurationException("The configured sequence manager ('" + sequenceManagerClassName + "') is not an instance of '" + SequenceManager.class.getName() + "'");
48 }
49 return (SequenceManager) sequenceManagerObject;
50 }
51 catch (Exception e) {
52 String message = "Unable to configure SequenceManager specified by " + SEQUENCE_MANAGER_CLASS_NAME_PROPERTY + " KualiConfigurationService property";
53 LOG.fatal(message, e);
54 throw new RuntimeException(message, e);
55 }
56 }
57
58 protected SequenceManager getConfiguredSequenceManager() {
59 return this.sequenceManager;
60 }
61
62 @Override
63 public void afterStore(JdbcAccess jdbcAccess, ClassDescriptor classDescriptor, Object object) throws SequenceManagerException {
64 sequenceManager.afterStore(jdbcAccess, classDescriptor, object);
65 }
66
67 @Override
68 public Object getUniqueValue(FieldDescriptor fieldDescriptor) throws SequenceManagerException {
69 return sequenceManager.getUniqueValue(fieldDescriptor);
70 }
71 }