01: /*
02: * Copyright (c) 2006 Your Corporation. All Rights Reserved.
03: */
04:
05: /*
06: * Created by IntelliJ IDEA.
07: * User: Jacques
08: * Date: Jan 3, 2006
09: * Time: 5:32:09 AM
10: */
11: package com.technoetic.xplanner.tx;
12:
13: import net.sf.hibernate.SessionFactory;
14: import org.springframework.transaction.support.TransactionCallback;
15: import org.springframework.transaction.support.TransactionTemplate;
16: import org.springframework.transaction.TransactionStatus;
17: import org.apache.axis.utils.SessionUtils;
18:
19: import com.technoetic.xplanner.util.Callable;
20: import com.technoetic.xplanner.db.hibernate.ThreadSession;
21:
22: public class CheckedExceptionHandlingTransactionTemplate {
23: private TransactionTemplate springTransactionTemplate;
24:
25: public void setSpringTransactionTemplate(
26: TransactionTemplate springTransactionTemplate) {
27: this .springTransactionTemplate = springTransactionTemplate;
28: }
29:
30: public Object execute(final Callable callable) throws Exception {
31: try {
32: return springTransactionTemplate
33: .execute(new TransactionCallback() {
34: public Object doInTransaction(
35: TransactionStatus status) {
36: try {
37: Object res = callable.run();
38: ThreadSession.get().flush();
39: return res;
40: } catch (Throwable e) {
41: throw new RuntimeException(e);
42: }
43: }
44: });
45: // DEBT(SPRING) Remove all this exception handling by doing spring declarative transaction demarkation
46: // DEBT(SPRING) Convert all xplanner exception to Runtime so we can remove this crap!
47: } catch (RuntimeException re) {
48: Throwable e = re.getCause();
49: if (e instanceof RuntimeException)
50: throw (RuntimeException) e;
51: if (e instanceof Error)
52: throw (Error) e;
53: if (e instanceof Exception)
54: throw (Exception) e;
55: return null;
56: }
57: }
58:
59: }
|