|
16 | 16 |
|
17 | 17 | package org.springframework.orm.jdo; |
18 | 18 |
|
19 | | -import java.lang.reflect.Method; |
20 | 19 | import java.sql.Connection; |
21 | 20 | import java.sql.SQLException; |
22 | 21 | import javax.jdo.Constants; |
23 | 22 | import javax.jdo.JDOException; |
24 | 23 | import javax.jdo.PersistenceManager; |
25 | | -import javax.jdo.Query; |
26 | 24 | import javax.jdo.Transaction; |
27 | 25 |
|
28 | | -import org.apache.commons.logging.Log; |
29 | | -import org.apache.commons.logging.LogFactory; |
30 | | - |
31 | 26 | import org.springframework.dao.DataAccessException; |
32 | 27 | import org.springframework.dao.support.PersistenceExceptionTranslator; |
33 | 28 | import org.springframework.jdbc.datasource.ConnectionHandle; |
34 | 29 | import org.springframework.jdbc.support.JdbcUtils; |
35 | 30 | import org.springframework.jdbc.support.SQLExceptionTranslator; |
36 | 31 | import org.springframework.transaction.TransactionDefinition; |
37 | 32 | import org.springframework.transaction.TransactionException; |
38 | | -import org.springframework.util.ClassUtils; |
39 | | -import org.springframework.util.ReflectionUtils; |
40 | 33 |
|
41 | 34 | /** |
42 | 35 | * Default implementation of the {@link JdoDialect} interface. |
43 | | - * Requires JDO 2.0; explicitly supports JDO API features up until 3.0. |
44 | | - * Used as default dialect by {@link JdoAccessor} and {@link JdoTransactionManager}. |
| 36 | + * As of Spring 4.0, designed for JDO 3.0 (or rather, semantics beyond JDO 3.0). |
| 37 | + * Used as default dialect by {@link JdoTransactionManager}. |
45 | 38 | * |
46 | 39 | * <p>Simply begins a standard JDO transaction in {@code beginTransaction}. |
47 | | - * Returns a handle for a JDO2 DataStoreConnection on {@code getJdbcConnection}. |
48 | | - * Calls the corresponding JDO2 PersistenceManager operation on {@code flush} |
49 | | - * Translates {@code applyQueryTimeout} to JDO 3.0's {@code setTimeoutMillis}. |
| 40 | + * Returns a handle for a JDO DataStoreConnection on {@code getJdbcConnection}. |
| 41 | + * Calls the corresponding JDO PersistenceManager operation on {@code flush} |
50 | 42 | * Uses a Spring SQLExceptionTranslator for exception translation, if applicable. |
51 | 43 | * |
52 | | - * <p>Note that, even with JDO2, vendor-specific subclasses are still necessary |
| 44 | + * <p>Note that, even with JDO 3.0, vendor-specific subclasses are still necessary |
53 | 45 | * for special transaction semantics and more sophisticated exception translation. |
54 | 46 | * Furthermore, vendor-specific subclasses are encouraged to expose the native JDBC |
55 | | - * Connection on {@code getJdbcConnection}, rather than JDO2's wrapper handle. |
| 47 | + * Connection on {@code getJdbcConnection}, rather than JDO 3.0's wrapper handle. |
56 | 48 | * |
57 | 49 | * <p>This class also implements the PersistenceExceptionTranslator interface, |
58 | 50 | * as autodetected by Spring's PersistenceExceptionTranslationPostProcessor, |
|
63 | 55 | * @author Juergen Hoeller |
64 | 56 | * @since 1.1 |
65 | 57 | * @see #setJdbcExceptionTranslator |
66 | | - * @see JdoAccessor#setJdoDialect |
67 | 58 | * @see JdoTransactionManager#setJdoDialect |
68 | 59 | * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor |
69 | 60 | */ |
70 | 61 | public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTranslator { |
71 | 62 |
|
72 | | - // JDO 3.0 setTimeoutMillis method available? |
73 | | - private static final Method setTimeoutMillisMethod = |
74 | | - ClassUtils.getMethodIfAvailable(Query.class, "setTimeoutMillis", Integer.class); |
75 | | - |
76 | | - protected final Log logger = LogFactory.getLog(getClass()); |
77 | | - |
78 | 63 | private SQLExceptionTranslator jdbcExceptionTranslator; |
79 | 64 |
|
80 | 65 |
|
@@ -174,18 +159,14 @@ public void cleanupTransaction(Object transactionData) { |
174 | 159 | } |
175 | 160 |
|
176 | 161 | /** |
177 | | - * This implementation returns a DataStoreConnectionHandle for JDO2, |
178 | | - * which will also work on JDO1 until actually accessing the JDBC Connection. |
179 | | - * <p>For pre-JDO2 implementations, override this method to return the |
180 | | - * Connection through the corresponding vendor-specific mechanism, or {@code null} |
181 | | - * if the Connection is not retrievable. |
182 | | - * <p><b>NOTE:</b> A JDO2 DataStoreConnection is always a wrapper, |
| 162 | + * This implementation returns a DataStoreConnectionHandle for JDO. |
| 163 | + * <p><b>NOTE:</b> A JDO DataStoreConnection is always a wrapper, |
183 | 164 | * never the native JDBC Connection. If you need access to the native JDBC |
184 | 165 | * Connection (or the connection pool handle, to be unwrapped via a Spring |
185 | 166 | * NativeJdbcExtractor), override this method to return the native |
186 | 167 | * Connection through the corresponding vendor-specific mechanism. |
187 | | - * <p>A JDO2 DataStoreConnection is only "borrowed" from the PersistenceManager: |
188 | | - * it needs to be returned as early as possible. Effectively, JDO2 requires the |
| 168 | + * <p>A JDO DataStoreConnection is only "borrowed" from the PersistenceManager: |
| 169 | + * it needs to be returned as early as possible. Effectively, JDO requires the |
189 | 170 | * fetched Connection to be closed before continuing PersistenceManager work. |
190 | 171 | * For this reason, the exposed ConnectionHandle eagerly releases its JDBC |
191 | 172 | * Connection at the end of each JDBC data access operation (that is, on |
@@ -212,25 +193,9 @@ public void releaseJdbcConnection(ConnectionHandle conHandle, PersistenceManager |
212 | 193 | throws JDOException, SQLException { |
213 | 194 | } |
214 | 195 |
|
215 | | - /** |
216 | | - * This implementation applies a JDO 3.0 query timeout, if available. Otherwise, |
217 | | - * it sets the JPA 2.0 query hints "javax.persistence.lock.timeout" and |
218 | | - * "javax.persistence.query.timeout", assuming that JDO providers are often |
219 | | - * JPA providers as well. |
220 | | - */ |
221 | | - public void applyQueryTimeout(Query query, int remainingTimeInSeconds) throws JDOException { |
222 | | - if (setTimeoutMillisMethod != null) { |
223 | | - ReflectionUtils.invokeMethod(setTimeoutMillisMethod, query, remainingTimeInSeconds); |
224 | | - } |
225 | | - else { |
226 | | - query.addExtension("javax.persistence.lock.timeout", remainingTimeInSeconds); |
227 | | - query.addExtension("javax.persistence.query.timeout", remainingTimeInSeconds); |
228 | | - } |
229 | | - } |
230 | | - |
231 | 196 |
|
232 | 197 | //----------------------------------------------------------------------------------- |
233 | | - // Hook for exception translation (used by JdoTransactionManager and JdoTemplate) |
| 198 | + // Hook for exception translation (used by JdoTransactionManager) |
234 | 199 | //----------------------------------------------------------------------------------- |
235 | 200 |
|
236 | 201 | /** |
@@ -273,9 +238,9 @@ protected String extractSqlStringFromException(JDOException ex) { |
273 | 238 |
|
274 | 239 |
|
275 | 240 | /** |
276 | | - * ConnectionHandle implementation that fetches a new JDO2 DataStoreConnection |
| 241 | + * ConnectionHandle implementation that fetches a new JDO DataStoreConnection |
277 | 242 | * for every {@code getConnection} call and closes the Connection on |
278 | | - * {@code releaseConnection}. This is necessary because JDO2 requires the |
| 243 | + * {@code releaseConnection}. This is necessary because JDO requires the |
279 | 244 | * fetched Connection to be closed before continuing PersistenceManager work. |
280 | 245 | * @see javax.jdo.PersistenceManager#getDataStoreConnection() |
281 | 246 | */ |
|