|
1 | 1 | /* |
2 | | - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.orm.jdo; |
18 | 18 |
|
| 19 | +import java.lang.reflect.Method; |
19 | 20 | import java.sql.Connection; |
20 | 21 | import java.sql.SQLException; |
21 | 22 | import javax.jdo.JDOException; |
|
34 | 35 | import org.springframework.transaction.InvalidIsolationLevelException; |
35 | 36 | import org.springframework.transaction.TransactionDefinition; |
36 | 37 | import org.springframework.transaction.TransactionException; |
| 38 | +import org.springframework.util.ClassUtils; |
| 39 | +import org.springframework.util.ReflectionUtils; |
37 | 40 |
|
38 | 41 | /** |
39 | 42 | * Default implementation of the {@link JdoDialect} interface. |
|
66 | 69 | */ |
67 | 70 | public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTranslator { |
68 | 71 |
|
| 72 | + // JDO 3.0 setTimeoutMillis method available? |
| 73 | + private static final Method setTimeoutMillisMethod = |
| 74 | + ClassUtils.getMethodIfAvailable(Query.class, "setTimeoutMillis", Integer.class); |
| 75 | + |
69 | 76 | protected final Log logger = LogFactory.getLog(getClass()); |
70 | 77 |
|
71 | 78 | private SQLExceptionTranslator jdbcExceptionTranslator; |
@@ -181,13 +188,19 @@ public void releaseJdbcConnection(ConnectionHandle conHandle, PersistenceManager |
181 | 188 | } |
182 | 189 |
|
183 | 190 | /** |
184 | | - * This implementation sets the JPA 2.0 query hints "javax.persistence.lock.timeout" |
185 | | - * and "javax.persistence.query.timeout", assuming that JDO 2.1 providers are often |
| 191 | + * This implementation applies a JDO 3.0 query timeout, if available. Otherwise, |
| 192 | + * it sets the JPA 2.0 query hints "javax.persistence.lock.timeout" and |
| 193 | + * "javax.persistence.query.timeout", assuming that JDO providers are often |
186 | 194 | * JPA providers as well. |
187 | 195 | */ |
188 | 196 | public void applyQueryTimeout(Query query, int remainingTimeInSeconds) throws JDOException { |
189 | | - query.addExtension("javax.persistence.lock.timeout", remainingTimeInSeconds); |
190 | | - query.addExtension("javax.persistence.query.timeout", remainingTimeInSeconds); |
| 197 | + if (setTimeoutMillisMethod != null) { |
| 198 | + ReflectionUtils.invokeMethod(setTimeoutMillisMethod, query, remainingTimeInSeconds); |
| 199 | + } |
| 200 | + else { |
| 201 | + query.addExtension("javax.persistence.lock.timeout", remainingTimeInSeconds); |
| 202 | + query.addExtension("javax.persistence.query.timeout", remainingTimeInSeconds); |
| 203 | + } |
191 | 204 | } |
192 | 205 |
|
193 | 206 |
|
|
0 commit comments