1 | |
package org.apache.ojb.odmg; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.OJBRuntimeException; |
19 | |
import org.apache.ojb.broker.util.configuration.ConfigurationException; |
20 | |
import org.apache.ojb.broker.util.logging.Logger; |
21 | |
import org.apache.ojb.broker.util.logging.LoggerFactory; |
22 | |
import org.apache.ojb.odmg.oql.EnhancedOQLQuery; |
23 | |
import org.odmg.DArray; |
24 | |
import org.odmg.DBag; |
25 | |
import org.odmg.DList; |
26 | |
import org.odmg.DMap; |
27 | |
import org.odmg.DSet; |
28 | |
import org.odmg.Database; |
29 | |
import org.odmg.Implementation; |
30 | |
import org.odmg.Transaction; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class ImplementationJTAImpl extends ImplementationImpl |
39 | |
{ |
40 | |
private Logger log = LoggerFactory.getLogger(ImplementationJTAImpl.class); |
41 | |
|
42 | |
protected ImplementationJTAImpl() |
43 | |
{ |
44 | |
super(); |
45 | |
} |
46 | |
|
47 | |
public Database getDatabase(Object obj) |
48 | |
{ |
49 | |
beginInternTransaction(); |
50 | |
return this.getCurrentDatabase(); |
51 | |
} |
52 | |
|
53 | |
public Transaction currentTransaction() |
54 | |
{ |
55 | |
beginInternTransaction(); |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
return new NarrowTransaction((TransactionImpl) super.currentTransaction()); |
62 | |
} |
63 | |
|
64 | |
public EnhancedOQLQuery newOQLQuery() |
65 | |
{ |
66 | |
beginInternTransaction(); |
67 | |
return super.newOQLQuery(); |
68 | |
} |
69 | |
|
70 | |
public DList newDList() |
71 | |
{ |
72 | |
beginInternTransaction(); |
73 | |
return super.newDList(); |
74 | |
} |
75 | |
|
76 | |
public DBag newDBag() |
77 | |
{ |
78 | |
beginInternTransaction(); |
79 | |
return super.newDBag(); |
80 | |
} |
81 | |
|
82 | |
public DSet newDSet() |
83 | |
{ |
84 | |
beginInternTransaction(); |
85 | |
return super.newDSet(); |
86 | |
} |
87 | |
|
88 | |
public DArray newDArray() |
89 | |
{ |
90 | |
beginInternTransaction(); |
91 | |
return super.newDArray(); |
92 | |
} |
93 | |
|
94 | |
public DMap newDMap() |
95 | |
{ |
96 | |
beginInternTransaction(); |
97 | |
return super.newDMap(); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
private void beginInternTransaction() |
106 | |
{ |
107 | |
if (log.isDebugEnabled()) log.debug("beginInternTransaction was called"); |
108 | |
J2EETransactionImpl tx = (J2EETransactionImpl) super.currentTransaction(); |
109 | |
if (tx == null) tx = newInternTransaction(); |
110 | |
if (!tx.isOpen()) |
111 | |
{ |
112 | |
|
113 | |
tx.begin(); |
114 | |
tx.setInExternTransaction(true); |
115 | |
} |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
private J2EETransactionImpl newInternTransaction() |
122 | |
{ |
123 | |
if (log.isDebugEnabled()) log.debug("obtain new intern odmg-transaction"); |
124 | |
J2EETransactionImpl tx = new J2EETransactionImpl(this); |
125 | |
try |
126 | |
{ |
127 | |
getConfigurator().configure(tx); |
128 | |
} |
129 | |
catch (ConfigurationException e) |
130 | |
{ |
131 | |
throw new OJBRuntimeException("Cannot create new intern odmg transaction", e); |
132 | |
} |
133 | |
return tx; |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public Transaction newTransaction() |
140 | |
{ |
141 | |
throw new UnsupportedOperationException("Not supported in managed environment"); |
142 | |
} |
143 | |
} |