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.maven.plugins.ingester.PropertyLoadingFactoryBean;
27 import org.kuali.rice.core.config.ConfigurationException;
28
29
30
31
32 public class ConfigurableSequenceManager implements SequenceManager {
33 private static final Logger LOG = Logger.getLogger(ConfigurableSequenceManager.class);
34 private static final String SEQUENCE_MANAGER_CLASS_NAME_PROPERTY = "datasource.ojb.sequence.manager";
35 private SequenceManager sequenceManager;
36
37 public ConfigurableSequenceManager(PersistenceBroker broker) {
38 this.sequenceManager = createSequenceManager(broker);
39 }
40
41 protected SequenceManager createSequenceManager(PersistenceBroker broker) {
42 String sequenceManagerClassName = PropertyLoadingFactoryBean
43 .getBaseProperty(SEQUENCE_MANAGER_CLASS_NAME_PROPERTY);
44 try {
45 Object sequenceManagerObject = ConstructorUtils.invokeConstructor(Class.forName(sequenceManagerClassName),
46 broker);
47 if (!(sequenceManagerObject instanceof SequenceManager)) {
48 throw new ConfigurationException("The configured sequence manager ('" + sequenceManagerClassName
49 + "') is not an instance of '" + SequenceManager.class.getName() + "'");
50 }
51 return (SequenceManager) sequenceManagerObject;
52 } catch (Exception e) {
53 String message = "Unable to configure SequenceManager specified by " + SEQUENCE_MANAGER_CLASS_NAME_PROPERTY
54 + " KualiConfigurationService property";
55 LOG.fatal(message, e);
56 throw new RuntimeException(message, e);
57 }
58 }
59
60 protected SequenceManager getConfiguredSequenceManager() {
61 return this.sequenceManager;
62 }
63
64 @Override
65 public void afterStore(JdbcAccess jdbcAccess, ClassDescriptor classDescriptor, Object object)
66 throws SequenceManagerException {
67 sequenceManager.afterStore(jdbcAccess, classDescriptor, object);
68 }
69
70 @Override
71 public Object getUniqueValue(FieldDescriptor fieldDescriptor) throws SequenceManagerException {
72 return sequenceManager.getUniqueValue(fieldDescriptor);
73 }
74 }