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