1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.jta; |
17 | |
|
18 | |
import javax.naming.NamingException; |
19 | |
import javax.transaction.UserTransaction; |
20 | |
|
21 | |
import org.apache.commons.lang.StringUtils; |
22 | |
import org.kuali.rice.core.config.Config; |
23 | |
import org.kuali.rice.core.config.ConfigContext; |
24 | |
import org.kuali.rice.core.config.ConfigurationException; |
25 | |
import org.kuali.rice.core.util.RiceConstants; |
26 | |
import org.springframework.beans.factory.FactoryBean; |
27 | |
import org.springframework.jndi.JndiTemplate; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class UserTransactionFactoryBean implements FactoryBean { |
39 | |
|
40 | |
private UserTransaction defaultUserTransaction; |
41 | |
private JndiTemplate jndiTemplate; |
42 | |
|
43 | |
public Object getObject() throws Exception { |
44 | |
|
45 | 0 | if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null) { |
46 | 0 | return null; |
47 | |
} |
48 | |
|
49 | 0 | UserTransaction userTransaction = (UserTransaction)ConfigContext.getCurrentContextConfig().getObject(RiceConstants.USER_TRANSACTION_OBJ); |
50 | 0 | if (userTransaction == null) { |
51 | 0 | String userTransactionJndiName = ConfigContext.getCurrentContextConfig().getProperty(RiceConstants.USER_TRANSACTION_JNDI); |
52 | 0 | if (!StringUtils.isEmpty(userTransactionJndiName)) { |
53 | 0 | if (this.jndiTemplate == null) { |
54 | 0 | this.jndiTemplate = new JndiTemplate(); |
55 | |
} |
56 | |
try { |
57 | 0 | userTransaction = (UserTransaction)this.jndiTemplate.lookup(userTransactionJndiName, UserTransaction.class); |
58 | 0 | } catch (NamingException e) { |
59 | 0 | throw new ConfigurationException("Could not locate the UserTransaction at the given JNDI location: '" + userTransactionJndiName + "'", e); |
60 | 0 | } |
61 | |
} |
62 | |
|
63 | |
} |
64 | 0 | if (userTransaction != null) { |
65 | 0 | return userTransaction; |
66 | |
} |
67 | 0 | return this.defaultUserTransaction; |
68 | |
} |
69 | |
|
70 | |
public Class getObjectType() { |
71 | 0 | return UserTransaction.class; |
72 | |
} |
73 | |
|
74 | |
public boolean isSingleton() { |
75 | 0 | return true; |
76 | |
} |
77 | |
|
78 | |
public void setDefaultUserTransaction(UserTransaction userTransaction) { |
79 | 0 | this.defaultUserTransaction = userTransaction; |
80 | 0 | } |
81 | |
|
82 | |
public JndiTemplate getJndiTemplate() { |
83 | 0 | return this.jndiTemplate; |
84 | |
} |
85 | |
|
86 | |
public void setJndiTemplate(JndiTemplate jndiTemplate) { |
87 | 0 | this.jndiTemplate = jndiTemplate; |
88 | 0 | } |
89 | |
|
90 | |
|
91 | |
|
92 | |
} |