1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.transaction.constraints.ConstraintFilter; |
15 | |
import org.mule.umo.UMOTransactionConfig; |
16 | |
import org.mule.umo.UMOTransactionFactory; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class MuleTransactionConfig implements UMOTransactionConfig |
26 | |
{ |
27 | |
|
28 | |
|
29 | |
|
30 | 4 | protected static final Log logger = LogFactory.getLog(MuleTransactionConfig.class); |
31 | |
|
32 | |
public static final String ACTION_NONE_STRING = "NONE"; |
33 | |
public static final String ACTION_ALWAYS_BEGIN_STRING = "ALWAYS_BEGIN"; |
34 | |
public static final String ACTION_BEGIN_OR_JOIN_STRING = "BEGIN_OR_JOIN"; |
35 | |
public static final String ACTION_ALWAYS_JOIN_STRING = "ALWAYS_JOIN"; |
36 | |
public static final String ACTION_JOIN_IF_POSSIBLE_STRING = "JOIN_IF_POSSIBLE"; |
37 | |
|
38 | |
private UMOTransactionFactory factory; |
39 | |
|
40 | 828 | private byte action = ACTION_NONE; |
41 | |
|
42 | 828 | private ConstraintFilter constraint = null; |
43 | |
|
44 | |
private int timeout; |
45 | |
|
46 | |
public MuleTransactionConfig() |
47 | 828 | { |
48 | 828 | timeout = MuleManager.getConfiguration().getTransactionTimeout(); |
49 | 828 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public UMOTransactionFactory getFactory() |
57 | |
{ |
58 | 0 | return factory; |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setFactory(UMOTransactionFactory factory) |
67 | |
{ |
68 | 0 | if (factory == null) |
69 | |
{ |
70 | 0 | throw new IllegalArgumentException("Transaction Factory cannot be null"); |
71 | |
} |
72 | 0 | this.factory = factory; |
73 | 0 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public byte getAction() |
81 | |
{ |
82 | 0 | return action; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public void setAction(byte action) |
91 | |
{ |
92 | 10 | this.action = action; |
93 | |
|
94 | 10 | } |
95 | |
|
96 | |
public void setActionAsString(String action) |
97 | |
{ |
98 | 0 | if (ACTION_ALWAYS_BEGIN_STRING.equals(action)) |
99 | |
{ |
100 | 0 | this.action = ACTION_ALWAYS_BEGIN; |
101 | |
} |
102 | 0 | else if (ACTION_BEGIN_OR_JOIN_STRING.equals(action)) |
103 | |
{ |
104 | 0 | this.action = ACTION_BEGIN_OR_JOIN; |
105 | |
} |
106 | 0 | else if (ACTION_ALWAYS_JOIN_STRING.equals(action)) |
107 | |
{ |
108 | 0 | this.action = ACTION_ALWAYS_JOIN; |
109 | |
} |
110 | 0 | else if (ACTION_JOIN_IF_POSSIBLE_STRING.equals(action)) |
111 | |
{ |
112 | 0 | this.action = ACTION_JOIN_IF_POSSIBLE; |
113 | |
} |
114 | 0 | else if (ACTION_NONE_STRING.equals(action)) |
115 | |
{ |
116 | 0 | this.action = ACTION_NONE; |
117 | |
} |
118 | |
else |
119 | |
{ |
120 | 0 | throw new IllegalArgumentException("Action " + action + " is not recognised as a begin action."); |
121 | |
} |
122 | 0 | } |
123 | |
|
124 | |
public String getActionAsString() |
125 | |
{ |
126 | 66 | switch (action) |
127 | |
{ |
128 | |
case ACTION_ALWAYS_BEGIN : |
129 | 2 | return ACTION_ALWAYS_BEGIN_STRING; |
130 | |
case ACTION_BEGIN_OR_JOIN : |
131 | 2 | return ACTION_BEGIN_OR_JOIN_STRING; |
132 | |
case ACTION_ALWAYS_JOIN : |
133 | 2 | return ACTION_ALWAYS_JOIN_STRING; |
134 | |
case ACTION_JOIN_IF_POSSIBLE : |
135 | 2 | return ACTION_JOIN_IF_POSSIBLE_STRING; |
136 | |
default : |
137 | 58 | return ACTION_NONE_STRING; |
138 | |
} |
139 | |
} |
140 | |
|
141 | |
public boolean isTransacted() |
142 | |
{ |
143 | 0 | return isConfigured() && factory.isTransacted() && action != ACTION_NONE; |
144 | |
} |
145 | |
|
146 | |
public boolean isConfigured() |
147 | |
{ |
148 | 106 | return factory != null; |
149 | |
} |
150 | |
|
151 | |
public ConstraintFilter getConstraint() |
152 | |
{ |
153 | 0 | if (constraint == null) |
154 | |
{ |
155 | 0 | return null; |
156 | |
} |
157 | |
try |
158 | |
{ |
159 | 0 | return (ConstraintFilter) constraint.clone(); |
160 | |
} |
161 | 0 | catch (CloneNotSupportedException e) |
162 | |
{ |
163 | 0 | logger.fatal("Failed to clone ContraintFilter: " + e.getMessage(), e); |
164 | 0 | return constraint; |
165 | |
} |
166 | |
} |
167 | |
|
168 | |
public void setConstraint(ConstraintFilter constraint) |
169 | |
{ |
170 | 0 | this.constraint = constraint; |
171 | 0 | } |
172 | |
|
173 | |
public int getTimeout() |
174 | |
{ |
175 | 0 | return timeout; |
176 | |
} |
177 | |
|
178 | |
public void setTimeout(int timeout) |
179 | |
{ |
180 | 0 | this.timeout = timeout; |
181 | 0 | } |
182 | |
|
183 | |
public String toString() |
184 | |
{ |
185 | 56 | StringBuffer buf = new StringBuffer(); |
186 | 56 | buf.append("Transaction{factory=") |
187 | |
.append(factory) |
188 | |
.append(", action=") |
189 | |
.append(getActionAsString()) |
190 | |
.append(", timeout=") |
191 | |
.append(timeout) |
192 | |
.append("}"); |
193 | 56 | return buf.toString(); |
194 | |
} |
195 | |
} |