X Tutup
Skip to content

Commit 96b9cf6

Browse files
committed
DefaultJdoDialect supports JDO 3.0 query timeout facility (as supported by DataNucleus 2.1)
1 parent 3918518 commit 96b9cf6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.orm.jdo;
1818

19+
import java.lang.reflect.Method;
1920
import java.sql.Connection;
2021
import java.sql.SQLException;
2122
import javax.jdo.JDOException;
@@ -34,6 +35,8 @@
3435
import org.springframework.transaction.InvalidIsolationLevelException;
3536
import org.springframework.transaction.TransactionDefinition;
3637
import org.springframework.transaction.TransactionException;
38+
import org.springframework.util.ClassUtils;
39+
import org.springframework.util.ReflectionUtils;
3740

3841
/**
3942
* Default implementation of the {@link JdoDialect} interface.
@@ -66,6 +69,10 @@
6669
*/
6770
public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTranslator {
6871

72+
// JDO 3.0 setTimeoutMillis method available?
73+
private static final Method setTimeoutMillisMethod =
74+
ClassUtils.getMethodIfAvailable(Query.class, "setTimeoutMillis", Integer.class);
75+
6976
protected final Log logger = LogFactory.getLog(getClass());
7077

7178
private SQLExceptionTranslator jdbcExceptionTranslator;
@@ -181,13 +188,19 @@ public void releaseJdbcConnection(ConnectionHandle conHandle, PersistenceManager
181188
}
182189

183190
/**
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
186194
* JPA providers as well.
187195
*/
188196
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+
}
191204
}
192205

193206

0 commit comments

Comments
 (0)
X Tutup