diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java b/spring-orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java
index 9d058158b91..a7fd9651457 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java
@@ -16,18 +16,13 @@
package org.springframework.orm.jdo;
-import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import javax.jdo.Constants;
import javax.jdo.JDOException;
import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
import javax.jdo.Transaction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.jdbc.datasource.ConnectionHandle;
@@ -35,24 +30,21 @@ import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.SQLExceptionTranslator;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
-import org.springframework.util.ClassUtils;
-import org.springframework.util.ReflectionUtils;
/**
* Default implementation of the {@link JdoDialect} interface.
- * Requires JDO 2.0; explicitly supports JDO API features up until 3.0.
- * Used as default dialect by {@link JdoAccessor} and {@link JdoTransactionManager}.
+ * As of Spring 4.0, designed for JDO 3.0 (or rather, semantics beyond JDO 3.0).
+ * Used as default dialect by {@link JdoTransactionManager}.
*
*
Simply begins a standard JDO transaction in {@code beginTransaction}.
- * Returns a handle for a JDO2 DataStoreConnection on {@code getJdbcConnection}.
- * Calls the corresponding JDO2 PersistenceManager operation on {@code flush}
- * Translates {@code applyQueryTimeout} to JDO 3.0's {@code setTimeoutMillis}.
+ * Returns a handle for a JDO DataStoreConnection on {@code getJdbcConnection}.
+ * Calls the corresponding JDO PersistenceManager operation on {@code flush}
* Uses a Spring SQLExceptionTranslator for exception translation, if applicable.
*
- *
Note that, even with JDO2, vendor-specific subclasses are still necessary
+ *
Note that, even with JDO 3.0, vendor-specific subclasses are still necessary
* for special transaction semantics and more sophisticated exception translation.
* Furthermore, vendor-specific subclasses are encouraged to expose the native JDBC
- * Connection on {@code getJdbcConnection}, rather than JDO2's wrapper handle.
+ * Connection on {@code getJdbcConnection}, rather than JDO 3.0's wrapper handle.
*
*
This class also implements the PersistenceExceptionTranslator interface,
* as autodetected by Spring's PersistenceExceptionTranslationPostProcessor,
@@ -63,18 +55,11 @@ import org.springframework.util.ReflectionUtils;
* @author Juergen Hoeller
* @since 1.1
* @see #setJdbcExceptionTranslator
- * @see JdoAccessor#setJdoDialect
* @see JdoTransactionManager#setJdoDialect
* @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
*/
public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTranslator {
- // JDO 3.0 setTimeoutMillis method available?
- private static final Method setTimeoutMillisMethod =
- ClassUtils.getMethodIfAvailable(Query.class, "setTimeoutMillis", Integer.class);
-
- protected final Log logger = LogFactory.getLog(getClass());
-
private SQLExceptionTranslator jdbcExceptionTranslator;
@@ -174,18 +159,14 @@ public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTransl
}
/**
- * This implementation returns a DataStoreConnectionHandle for JDO2,
- * which will also work on JDO1 until actually accessing the JDBC Connection.
- *
For pre-JDO2 implementations, override this method to return the
- * Connection through the corresponding vendor-specific mechanism, or {@code null}
- * if the Connection is not retrievable.
- *
NOTE: A JDO2 DataStoreConnection is always a wrapper,
+ * This implementation returns a DataStoreConnectionHandle for JDO.
+ *
NOTE: A JDO DataStoreConnection is always a wrapper,
* never the native JDBC Connection. If you need access to the native JDBC
* Connection (or the connection pool handle, to be unwrapped via a Spring
* NativeJdbcExtractor), override this method to return the native
* Connection through the corresponding vendor-specific mechanism.
- *
A JDO2 DataStoreConnection is only "borrowed" from the PersistenceManager:
- * it needs to be returned as early as possible. Effectively, JDO2 requires the
+ *
A JDO DataStoreConnection is only "borrowed" from the PersistenceManager:
+ * it needs to be returned as early as possible. Effectively, JDO requires the
* fetched Connection to be closed before continuing PersistenceManager work.
* For this reason, the exposed ConnectionHandle eagerly releases its JDBC
* Connection at the end of each JDBC data access operation (that is, on
@@ -212,25 +193,9 @@ public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTransl
throws JDOException, SQLException {
}
- /**
- * This implementation applies a JDO 3.0 query timeout, if available. Otherwise,
- * it sets the JPA 2.0 query hints "javax.persistence.lock.timeout" and
- * "javax.persistence.query.timeout", assuming that JDO providers are often
- * JPA providers as well.
- */
- public void applyQueryTimeout(Query query, int remainingTimeInSeconds) throws JDOException {
- if (setTimeoutMillisMethod != null) {
- ReflectionUtils.invokeMethod(setTimeoutMillisMethod, query, remainingTimeInSeconds);
- }
- else {
- query.addExtension("javax.persistence.lock.timeout", remainingTimeInSeconds);
- query.addExtension("javax.persistence.query.timeout", remainingTimeInSeconds);
- }
- }
-
//-----------------------------------------------------------------------------------
- // Hook for exception translation (used by JdoTransactionManager and JdoTemplate)
+ // Hook for exception translation (used by JdoTransactionManager)
//-----------------------------------------------------------------------------------
/**
@@ -273,9 +238,9 @@ public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTransl
/**
- * ConnectionHandle implementation that fetches a new JDO2 DataStoreConnection
+ * ConnectionHandle implementation that fetches a new JDO DataStoreConnection
* for every {@code getConnection} call and closes the Connection on
- * {@code releaseConnection}. This is necessary because JDO2 requires the
+ * {@code releaseConnection}. This is necessary because JDO requires the
* fetched Connection to be closed before continuing PersistenceManager work.
* @see javax.jdo.PersistenceManager#getDataStoreConnection()
*/
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java
deleted file mode 100644
index 25d466f612b..00000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.orm.jdo;
-
-import javax.jdo.JDOException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.dao.DataAccessException;
-
-/**
- * Base class for JdoTemplate and JdoInterceptor, defining common
- * properties such as PersistenceManagerFactory and flushing behavior.
- *
- *
Note: With JDO, modifications to persistent objects are just possible
- * within a transaction (in contrast to Hibernate). Therefore, eager flushing
- * will just get applied when in a transaction. Furthermore, there is no
- * explicit notion of flushing never, as this would not imply a performance
- * gain due to JDO's field interception mechanism (which doesn't involve
- * the overhead of snapshot comparisons).
- *
- *
Eager flushing is just available for specific JDO providers.
- * You need to a corresponding JdoDialect to make eager flushing work.
- *
- *
Not intended to be used directly. See JdoTemplate and JdoInterceptor.
- *
- * @author Juergen Hoeller
- * @since 02.11.2003
- * @see JdoTemplate
- * @see JdoInterceptor
- * @see #setFlushEager
- * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
- * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
- * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
- */
-@Deprecated
-public abstract class JdoAccessor implements InitializingBean {
-
- /** Logger available to subclasses */
- protected final Log logger = LogFactory.getLog(getClass());
-
- private PersistenceManagerFactory persistenceManagerFactory;
-
- private JdoDialect jdoDialect;
-
- private boolean flushEager = false;
-
-
- /**
- * Set the JDO PersistenceManagerFactory that should be used to create
- * PersistenceManagers.
- */
- public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) {
- this.persistenceManagerFactory = pmf;
- }
-
- /**
- * Return the JDO PersistenceManagerFactory that should be used to create
- * PersistenceManagers.
- */
- public PersistenceManagerFactory getPersistenceManagerFactory() {
- return this.persistenceManagerFactory;
- }
-
- /**
- * Set the JDO dialect to use for this accessor.
- *
The dialect object can be used to retrieve the underlying JDBC
- * connection and to eagerly flush changes to the database.
- *
Default is a DefaultJdoDialect based on the PersistenceManagerFactory's
- * underlying DataSource, if any.
- */
- public void setJdoDialect(JdoDialect jdoDialect) {
- this.jdoDialect = jdoDialect;
- }
-
- /**
- * Return the JDO dialect to use for this accessor.
- *
Creates a default one for the specified PersistenceManagerFactory if none set.
- */
- public JdoDialect getJdoDialect() {
- if (this.jdoDialect == null) {
- this.jdoDialect = new DefaultJdoDialect();
- }
- return this.jdoDialect;
- }
-
- /**
- * Set if this accessor should flush changes to the database eagerly.
- *
Eager flushing leads to immediate synchronization with the database,
- * even if in a transaction. This causes inconsistencies to show up and throw
- * a respective exception immediately, and JDBC access code that participates
- * in the same transaction will see the changes as the database is already
- * aware of them then. But the drawbacks are:
- *
- *
additional communication roundtrips with the database, instead of a
- * single batch at transaction commit;
- *
the fact that an actual database rollback is needed if the JDO
- * transaction rolls back (due to already submitted SQL statements).
- *
- */
- public void setFlushEager(boolean flushEager) {
- this.flushEager = flushEager;
- }
-
- /**
- * Return if this accessor should flush changes to the database eagerly.
- */
- public boolean isFlushEager() {
- return this.flushEager;
- }
-
- /**
- * Eagerly initialize the JDO dialect, creating a default one
- * for the specified PersistenceManagerFactory if none set.
- */
- public void afterPropertiesSet() {
- if (getPersistenceManagerFactory() == null) {
- throw new IllegalArgumentException("Property 'persistenceManagerFactory' is required");
- }
- // Build default JdoDialect if none explicitly specified.
- if (this.jdoDialect == null) {
- this.jdoDialect = new DefaultJdoDialect(getPersistenceManagerFactory().getConnectionFactory());
- }
- }
-
-
- /**
- * Flush the given JDO persistence manager if necessary.
- * @param pm the current JDO PersistenceManager
- * @param existingTransaction if executing within an existing transaction
- * (within an existing JDO PersistenceManager that won't be closed immediately)
- * @throws JDOException in case of JDO flushing errors
- */
- protected void flushIfNecessary(PersistenceManager pm, boolean existingTransaction) throws JDOException {
- if (isFlushEager()) {
- logger.debug("Eagerly flushing JDO persistence manager");
- pm.flush();
- }
- }
-
- /**
- * Convert the given JDOException to an appropriate exception from the
- * {@code org.springframework.dao} hierarchy.
- *
Default implementation delegates to the JdoDialect.
- * May be overridden in subclasses.
- * @param ex JDOException that occured
- * @return the corresponding DataAccessException instance
- * @see JdoDialect#translateException
- */
- public DataAccessException convertJdoAccessException(JDOException ex) {
- return getJdoDialect().translateException(ex);
- }
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java
deleted file mode 100644
index 9a217332086..00000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.orm.jdo;
-
-import javax.jdo.JDOException;
-import javax.jdo.PersistenceManager;
-
-/**
- * Callback interface for JDO code. To be used with {@link JdoTemplate}'s
- * execution methods, often as anonymous classes within a method implementation.
- * A typical implementation will call PersistenceManager CRUD to perform
- * some operations on persistent objects.
- *
- *
Note that JDO works on bytecode-modified Java objects, to be able to
- * perform dirty detection on each modification of a persistent instance field.
- * In contrast to Hibernate, using returned objects outside of an active
- * PersistenceManager poses a problem: To be able to read and modify fields
- * e.g. in a web GUI, one has to explicitly make the instances "transient".
- * Reassociation with a new PersistenceManager, e.g. for updates when coming
- * back from the GUI, isn't possible, as the JDO instances have lost their
- * identity when turned transient. This means that either value objects have
- * to be used as parameters, or the contents of the outside-modified instance
- * have to be copied to a freshly loaded active instance on reassociation.
- *
- * @author Juergen Hoeller
- * @since 03.06.2003
- * @see JdoTemplate
- * @see JdoTransactionManager
- * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
- * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
- * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
- */
-@Deprecated
-public interface JdoCallback {
-
- /**
- * Gets called by {@code JdoTemplate.execute} with an active JDO
- * {@code PersistenceManager}. Does not need to care about activating
- * or closing the {@code PersistenceManager}, or handling transactions.
- *
- *
Note that JDO callback code will not flush any modifications to the
- * database if not executed within a transaction. Thus, you need to make
- * sure that JdoTransactionManager has initiated a JDO transaction when
- * the callback gets called, at least if you want to write to the database.
- *
- *
Allows for returning a result object created within the callback,
- * i.e. a domain object or a collection of domain objects.
- * A thrown custom RuntimeException is treated as an application exception:
- * It gets propagated to the caller of the template.
- *
- * @param pm active PersistenceManager
- * @return a result object, or {@code null} if none
- * @throws JDOException if thrown by the JDO API
- * @see JdoTemplate#execute
- * @see JdoTemplate#executeFind
- */
- T doInJdo(PersistenceManager pm) throws JDOException;
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoDialect.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoDialect.java
index 464b011e128..d5d76ef2bdc 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoDialect.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoDialect.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.orm.jdo;
import java.sql.SQLException;
import javax.jdo.JDOException;
import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
import javax.jdo.Transaction;
import org.springframework.dao.DataAccessException;
@@ -32,8 +31,8 @@ import org.springframework.transaction.TransactionException;
* in particular regarding transaction management and exception translation. To be
* implemented for specific JDO providers such as JPOX, Kodo, Lido, Versant Open Access.
*
- *
JDO 2.0 defines standard ways for most of the functionality covered here.
- * Hence, Spring's {@link DefaultJdoDialect} uses the corresponding JDO 2.0 methods
+ *
JDO 3.0 defines standard ways for most of the functionality covered here.
+ * Hence, Spring's {@link DefaultJdoDialect} uses the corresponding JDO 3.0 methods
* by default, to be overridden in a vendor-specific fashion if necessary.
* Vendor-specific subclasses of {@link DefaultJdoDialect} are still required for special
* transaction semantics and more sophisticated exception translation (if needed).
@@ -46,7 +45,6 @@ import org.springframework.transaction.TransactionException;
* @author Juergen Hoeller
* @since 02.11.2003
* @see JdoTransactionManager#setJdoDialect
- * @see JdoAccessor#setJdoDialect
* @see DefaultJdoDialect
*/
public interface JdoDialect {
@@ -144,19 +142,9 @@ public interface JdoDialect {
void releaseJdbcConnection(ConnectionHandle conHandle, PersistenceManager pm)
throws JDOException, SQLException;
- /**
- * Apply the given timeout to the given JDO query object.
- *
Invoked with the remaining time of a specified transaction timeout, if any.
- * @param query the JDO query object to apply the timeout to
- * @param timeout the timeout value (seconds) to apply
- * @throws JDOException if thrown by JDO methods
- * @see JdoTemplate#prepareQuery
- */
- void applyQueryTimeout(Query query, int timeout) throws JDOException;
-
//-----------------------------------------------------------------------------------
- // Hook for exception translation (used by JdoTransactionManager and JdoTemplate)
+ // Hook for exception translation (used by JdoTransactionManager)
//-----------------------------------------------------------------------------------
/**
@@ -171,7 +159,6 @@ public interface JdoDialect {
* in a database-specific fashion.
* @param ex the JDOException thrown
* @return the corresponding DataAccessException (must not be {@code null})
- * @see JdoAccessor#convertJdoAccessException
* @see JdoTransactionManager#convertJdoAccessException
* @see PersistenceManagerFactoryUtils#convertJdoAccessException
* @see org.springframework.dao.DataIntegrityViolationException
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java
deleted file mode 100644
index ff105e48ab9..00000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.orm.jdo;
-
-import javax.jdo.JDOException;
-import javax.jdo.PersistenceManager;
-
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import org.springframework.transaction.support.TransactionSynchronizationManager;
-
-/**
- * This interceptor binds a new JDO PersistenceManager to the thread before a method
- * call, closing and removing it afterwards in case of any method outcome.
- * If there already is a pre-bound PersistenceManager (e.g. from JdoTransactionManager,
- * or from a surrounding JDO-intercepted method), the interceptor simply participates in it.
- *
- *
Application code must retrieve a JDO PersistenceManager via the
- * {@code PersistenceManagerFactoryUtils.getPersistenceManager} method,
- * to be able to detect a thread-bound PersistenceManager. It is preferable to use
- * {@code getPersistenceManager} with allowCreate=false, if the code relies on
- * the interceptor to provide proper PersistenceManager handling. Typically, the code
- * will look like as follows:
- *
- *
Note that this interceptor automatically translates JDOExceptions, via
- * delegating to the {@code PersistenceManagerFactoryUtils.convertJdoAccessException}
- * method that converts them to exceptions that are compatible with the
- * {@code org.springframework.dao} exception hierarchy (like JdoTemplate does).
- * This can be turned off if the raw exceptions are preferred.
- *
- *
This class can be considered a declarative alternative to JdoTemplate's
- * callback approach. The advantages are:
- *
- *
no anonymous classes necessary for callback implementations;
- *
the possibility to throw any application exceptions from within data access code.
- *
- *
- *
The drawback is the dependency on interceptor configuration. However, note
- * that this interceptor is usually not necessary in scenarios where the
- * data access code always executes within transactions. A transaction will always
- * have a thread-bound PersistenceManager in the first place, so adding this interceptor
- * to the configuration just adds value when fine-tuning PersistenceManager settings
- * like the flush mode - or when relying on exception translation.
- *
- * @author Juergen Hoeller
- * @since 13.06.2003
- * @see PersistenceManagerFactoryUtils#getPersistenceManager
- * @see JdoTransactionManager
- * @see JdoTemplate
- * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
- * and AOP-driven exception translation through
- * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}
- */
-@Deprecated
-public class JdoInterceptor extends JdoAccessor implements MethodInterceptor {
-
- private boolean exceptionConversionEnabled = true;
-
-
- /**
- * Set whether to convert any JDOException raised to a Spring DataAccessException,
- * compatible with the {@code org.springframework.dao} exception hierarchy.
- *
Default is "true". Turn this flag off to let the caller receive raw exceptions
- * as-is, without any wrapping.
- * @see org.springframework.dao.DataAccessException
- */
- public void setExceptionConversionEnabled(boolean exceptionConversionEnabled) {
- this.exceptionConversionEnabled = exceptionConversionEnabled;
- }
-
-
- public Object invoke(MethodInvocation methodInvocation) throws Throwable {
- boolean existingTransaction = false;
- PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(getPersistenceManagerFactory(), true);
- if (TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory())) {
- logger.debug("Found thread-bound PersistenceManager for JDO interceptor");
- existingTransaction = true;
- }
- else {
- logger.debug("Using new PersistenceManager for JDO interceptor");
- TransactionSynchronizationManager.bindResource(getPersistenceManagerFactory(), new PersistenceManagerHolder(pm));
- }
- try {
- Object retVal = methodInvocation.proceed();
- flushIfNecessary(pm, existingTransaction);
- return retVal;
- }
- catch (JDOException ex) {
- if (this.exceptionConversionEnabled) {
- throw convertJdoAccessException(ex);
- }
- else {
- throw ex;
- }
- }
- finally {
- if (existingTransaction) {
- logger.debug("Not closing pre-bound JDO PersistenceManager after interceptor");
- }
- else {
- TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
- PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
- }
- }
- }
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java
deleted file mode 100644
index d2b4a67baf1..00000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.orm.jdo;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.springframework.dao.DataAccessException;
-
-/**
- * Interface that specifies a basic set of JDO operations,
- * implemented by {@link JdoTemplate}. Not often used, but a useful
- * option to enhance testability, as it can easily be mocked or stubbed.
- *
- *
Defines {@code JdoTemplate}'s data access methods that mirror
- * various JDO {@link javax.jdo.PersistenceManager} methods. Users are
- * strongly encouraged to read the JDO {@code PersistenceManager}
- * javadocs for details on the semantics of those methods.
- *
- *
Note that lazy loading will just work with an open JDO
- * {@code PersistenceManager}, either within a managed transaction or within
- * {@link org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter}/
- * {@link org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor}.
- * Furthermore, some operations just make sense within transactions,
- * for example: {@code evict}, {@code evictAll}, {@code flush}.
- *
- *
Updated to build on JDO 2.0 or higher, as of Spring 2.5.
- *
- * @author Juergen Hoeller
- * @since 1.1
- * @see JdoTemplate
- * @see javax.jdo.PersistenceManager
- * @see JdoTransactionManager
- * @see JdoDialect
- * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
- * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor
- * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
- * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
- * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
- */
-@Deprecated
-public interface JdoOperations {
-
- /**
- * Execute the action specified by the given action object within a
- * PersistenceManager. Application exceptions thrown by the action object
- * get propagated to the caller (can only be unchecked). JDO exceptions
- * are transformed into appropriate DAO ones. Allows for returning a
- * result object, i.e. a domain object or a collection of domain objects.
- *
Note: Callback code is not supposed to handle transactions itself!
- * Use an appropriate transaction manager like JdoTransactionManager.
- * @param action callback object that specifies the JDO action
- * @return a result object returned by the action, or {@code null}
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see JdoTransactionManager
- * @see javax.jdo.PersistenceManager
- */
- T execute(JdoCallback action) throws DataAccessException;
-
- /**
- * Execute the specified action assuming that the result object is a
- * Collection. This is a convenience method for executing JDO queries
- * within an action.
- * @param action callback object that specifies the JDO action
- * @return a Collection result returned by the action, or {@code null}
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- */
- Collection executeFind(JdoCallback> action) throws DataAccessException;
-
-
- //-------------------------------------------------------------------------
- // Convenience methods for load, save, delete
- //-------------------------------------------------------------------------
-
- /**
- * Return the persistent instance with the given JDO object id,
- * throwing an exception if not found.
- *
A JDO object id identifies both the persistent class and the id
- * within the namespace of that class.
- * @param objectId a JDO object id of the persistent instance
- * @return the persistent instance
- * @throws org.springframework.orm.ObjectRetrievalFailureException if not found
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#getObjectById(Object, boolean)
- */
- Object getObjectById(Object objectId) throws DataAccessException;
-
- /**
- * Return the persistent instance of the given entity class
- * with the given id value, throwing an exception if not found.
- *
The given id value is typically just unique within the namespace
- * of the persistent class. Its toString value must correspond to the
- * toString value of the corresponding JDO object id.
- *
Usually, the passed-in value will have originated from the primary
- * key field of a persistent object that uses JDO's application identity.
- * @param entityClass a persistent class
- * @param idValue an id value of the persistent instance
- * @return the persistent instance
- * @throws org.springframework.orm.ObjectRetrievalFailureException if not found
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#getObjectById(Object, boolean)
- * @see javax.jdo.PersistenceManager#getObjectById(Class, Object)
- */
- T getObjectById(Class entityClass, Object idValue) throws DataAccessException;
-
- /**
- * Remove the given object from the PersistenceManager cache.
- * @param entity the persistent instance to evict
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#evict(Object)
- */
- void evict(Object entity) throws DataAccessException;
-
- /**
- * Remove all given objects from the PersistenceManager cache.
- * @param entities the persistent instances to evict
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#evictAll(java.util.Collection)
- */
- void evictAll(Collection entities) throws DataAccessException;
-
- /**
- * Remove all objects from the PersistenceManager cache.
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#evictAll()
- */
- void evictAll() throws DataAccessException;
-
- /**
- * Re-read the state of the given persistent instance.
- * @param entity the persistent instance to re-read
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#refresh(Object)
- */
- void refresh(Object entity) throws DataAccessException;
-
- /**
- * Re-read the state of all given persistent instances.
- * @param entities the persistent instances to re-read
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#refreshAll(java.util.Collection)
- */
- void refreshAll(Collection entities) throws DataAccessException;
-
- /**
- * Re-read the state of all persistent instances.
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#refreshAll()
- */
- void refreshAll() throws DataAccessException;
-
- /**
- * Make the given transient instance persistent.
- * Attach the given entity if the instance is detached.
- * @param entity the transient instance to make persistent
- * @return the persistent instance
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#makePersistent(Object)
- */
- T makePersistent(T entity) throws DataAccessException;
-
- /**
- * Make the given transient instances persistent.
- * Attach the given entities if the instances are detached.
- * @param entities the transient instances to make persistent
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#makePersistentAll(java.util.Collection)
- */
- Collection makePersistentAll(Collection entities) throws DataAccessException;
-
- /**
- * Delete the given persistent instance.
- * @param entity the persistent instance to delete
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#deletePersistent(Object)
- */
- void deletePersistent(Object entity) throws DataAccessException;
-
- /**
- * Delete all given persistent instances.
- *
This can be combined with any of the find methods to delete by query
- * in two lines of code.
- * @param entities the persistent instances to delete
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#deletePersistentAll(java.util.Collection)
- */
- void deletePersistentAll(Collection entities) throws DataAccessException;
-
- /**
- * Detach a copy of the given persistent instance from the current JDO transaction,
- * for use outside a JDO transaction (for example, as web form object).
- * @param entity the persistent instance to detach
- * @return the corresponding detached instance
- * @see javax.jdo.PersistenceManager#detachCopy(Object)
- */
- T detachCopy(T entity);
-
- /**
- * Detach copies of the given persistent instances from the current JDO transaction,
- * for use outside a JDO transaction (for example, as web form objects).
- * @param entities the persistent instances to detach
- * @return the corresponding detached instances
- * @see javax.jdo.PersistenceManager#detachCopyAll(Collection)
- */
- Collection detachCopyAll(Collection entities);
-
- /**
- * Flush all transactional modifications to the database.
- *
Only invoke this for selective eager flushing, for example when JDBC code
- * needs to see certain changes within the same transaction. Else, it's preferable
- * to rely on auto-flushing at transaction completion.
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#flush()
- */
- void flush() throws DataAccessException;
-
-
- //-------------------------------------------------------------------------
- // Convenience finder methods
- //-------------------------------------------------------------------------
-
- /**
- * Find all persistent instances of the given class.
- * @param entityClass a persistent class
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class)
- */
- Collection find(Class entityClass) throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match (or {@code null} if none)
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- */
- Collection find(Class entityClass, String filter) throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter, with the given result ordering.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match (or {@code null} if none)
- * @param ordering the ordering of the result (or {@code null} if none)
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- * @see javax.jdo.Query#setOrdering
- */
- Collection find(Class entityClass, String filter, String ordering) throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter, using the given parameter declarations and parameter values.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match
- * @param parameters the JDOQL parameter declarations
- * @param values the corresponding parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- * @see javax.jdo.Query#declareParameters
- * @see javax.jdo.Query#executeWithArray
- */
- Collection find(Class entityClass, String filter, String parameters, Object... values)
- throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter, using the given parameter declarations and parameter values,
- * with the given result ordering.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match
- * @param parameters the JDOQL parameter declarations
- * @param values the corresponding parameter values
- * @param ordering the ordering of the result (or {@code null} if none)
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- * @see javax.jdo.Query#declareParameters
- * @see javax.jdo.Query#executeWithArray
- * @see javax.jdo.Query#setOrdering
- */
- Collection find(
- Class entityClass, String filter, String parameters, Object[] values, String ordering)
- throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter, using the given parameter declarations and parameter values.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match
- * @param parameters the JDOQL parameter declarations
- * @param values a Map with parameter names as keys and parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- * @see javax.jdo.Query#declareParameters
- * @see javax.jdo.Query#executeWithMap
- */
- Collection find(Class entityClass, String filter, String parameters, Map values)
- throws DataAccessException;
-
- /**
- * Find all persistent instances of the given class that match the given
- * JDOQL filter, using the given parameter declarations and parameter values,
- * with the given result ordering.
- * @param entityClass a persistent class
- * @param filter the JDOQL filter to match
- * @param parameters the JDOQL parameter declarations
- * @param values a Map with parameter names as keys and parameter values
- * @param ordering the ordering of the result (or {@code null} if none)
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(Class, String)
- * @see javax.jdo.Query#declareParameters
- * @see javax.jdo.Query#executeWithMap
- * @see javax.jdo.Query#setOrdering
- */
- Collection find(
- Class entityClass, String filter, String parameters, Map values, String ordering)
- throws DataAccessException;
-
- /**
- * Find persistent instances through the given query object
- * in the specified query language.
- * @param language the query language ({@code javax.jdo.Query#JDOQL}
- * or {@code javax.jdo.Query#SQL}, for example)
- * @param queryObject the query object for the specified language
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(String, Object)
- * @see javax.jdo.Query#JDOQL
- * @see javax.jdo.Query#SQL
- */
- Collection find(String language, Object queryObject) throws DataAccessException;
-
- /**
- * Find persistent instances through the given single-string JDOQL query.
- * @param queryString the single-string JDOQL query
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(String)
- */
- Collection find(String queryString) throws DataAccessException;
-
- /**
- * Find persistent instances through the given single-string JDOQL query.
- * @param queryString the single-string JDOQL query
- * @param values the corresponding parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(String)
- */
- Collection find(String queryString, Object... values) throws DataAccessException;
-
- /**
- * Find persistent instances through the given single-string JDOQL query.
- * @param queryString the single-string JDOQL query
- * @param values a Map with parameter names as keys and parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newQuery(String)
- */
- Collection find(String queryString, Map values) throws DataAccessException;
-
- /**
- * Find persistent instances through the given named query.
- * @param entityClass a persistent class
- * @param queryName the name of the query
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newNamedQuery(Class, String)
- */
- Collection findByNamedQuery(Class entityClass, String queryName)
- throws DataAccessException;
-
- /**
- * Find persistent instances through the given named query.
- * @param entityClass a persistent class
- * @param queryName the name of the query
- * @param values the corresponding parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newNamedQuery(Class, String)
- */
- Collection findByNamedQuery(Class entityClass, String queryName, Object... values)
- throws DataAccessException;
-
- /**
- * Find persistent instances through the given named query.
- * @param entityClass a persistent class
- * @param queryName the name of the query
- * @param values a Map with parameter names as keys and parameter values
- * @return the persistent instances
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- * @see javax.jdo.PersistenceManager#newNamedQuery(Class, String)
- */
- Collection findByNamedQuery(Class entityClass, String queryName, Map values)
- throws DataAccessException;
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java b/spring-orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java
deleted file mode 100644
index 6ed2028384f..00000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java
+++ /dev/null
@@ -1,618 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.orm.jdo;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Collection;
-import java.util.Map;
-import javax.jdo.JDOException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
-import javax.jdo.Query;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.dao.InvalidDataAccessApiUsageException;
-import org.springframework.transaction.support.TransactionSynchronizationManager;
-import org.springframework.util.Assert;
-import org.springframework.util.ClassUtils;
-
-/**
- * Helper class that simplifies JDO data access code, and converts
- * JDOExceptions into Spring DataAccessExceptions, following the
- * {@code org.springframework.dao} exception hierarchy.
- *
- *
The central method is {@code execute}, supporting JDO access code
- * implementing the {@link JdoCallback} interface. It provides JDO PersistenceManager
- * handling such that neither the JdoCallback implementation nor the calling
- * code needs to explicitly care about retrieving/closing PersistenceManagers,
- * or handling JDO lifecycle exceptions.
- *
- *
Typically used to implement data access or business logic services that
- * use JDO within their implementation but are JDO-agnostic in their interface.
- * The latter or code calling the latter only have to deal with business
- * objects, query objects, and {@code org.springframework.dao} exceptions.
- *
- *
Can be used within a service implementation via direct instantiation
- * with a PersistenceManagerFactory reference, or get prepared in an
- * application context and given to services as bean reference.
- * Note: The PersistenceManagerFactory should always be configured as bean in
- * the application context, in the first case given to the service directly,
- * in the second case to the prepared template.
- *
- *
This class can be considered as direct alternative to working with the
- * raw JDO PersistenceManager API (through
- * {@code PersistenceManagerFactoryUtils.getPersistenceManager()}).
- * The major advantage is its automatic conversion to DataAccessExceptions, the
- * major disadvantage that no checked application exceptions can get thrown from
- * within data access code. Corresponding checks and the actual throwing of such
- * exceptions can often be deferred to after callback execution, though.
- *
- *
{@link LocalPersistenceManagerFactoryBean} is the preferred way of obtaining
- * a reference to a specific PersistenceManagerFactory, at least in a non-EJB
- * environment. The Spring application context will manage its lifecycle,
- * initializing and shutting down the factory as part of the application.
- *
- *
Note that lazy loading will just work with an open JDO PersistenceManager,
- * either within a Spring-driven transaction (with JdoTransactionManager or
- * JtaTransactionManager) or within OpenPersistenceManagerInViewFilter/Interceptor.
- * Furthermore, some operations just make sense within transactions,
- * for example: {@code evict}, {@code evictAll}, {@code flush}.
- *
- *
NOTE: This class requires JDO 2.0 or higher, as of Spring 2.5.
- * As of Spring 3.0, it follows JDO 2.1 conventions in terms of generic
- * parameter and return types, which still remaining compatible with JDO 2.0.
- *
- * @author Juergen Hoeller
- * @since 03.06.2003
- * @see #setPersistenceManagerFactory
- * @see JdoCallback
- * @see javax.jdo.PersistenceManager
- * @see LocalPersistenceManagerFactoryBean
- * @see JdoTransactionManager
- * @see org.springframework.transaction.jta.JtaTransactionManager
- * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
- * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor
- * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
- * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
- * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
- */
-@Deprecated
-public class JdoTemplate extends JdoAccessor implements JdoOperations {
-
- private boolean allowCreate = true;
-
- private boolean exposeNativePersistenceManager = false;
-
-
- /**
- * Create a new JdoTemplate instance.
- */
- public JdoTemplate() {
- }
-
- /**
- * Create a new JdoTemplate instance.
- * @param pmf PersistenceManagerFactory to create PersistenceManagers
- */
- public JdoTemplate(PersistenceManagerFactory pmf) {
- setPersistenceManagerFactory(pmf);
- afterPropertiesSet();
- }
-
- /**
- * Create a new JdoTemplate instance.
- * @param pmf PersistenceManagerFactory to create PersistenceManagers
- * @param allowCreate if a non-transactional PersistenceManager should be created
- * when no transactional PersistenceManager can be found for the current thread
- */
- public JdoTemplate(PersistenceManagerFactory pmf, boolean allowCreate) {
- setPersistenceManagerFactory(pmf);
- setAllowCreate(allowCreate);
- afterPropertiesSet();
- }
-
- /**
- * Set if a new PersistenceManager should be created when no transactional
- * PersistenceManager can be found for the current thread.
- *
JdoTemplate is aware of a corresponding PersistenceManager bound to the
- * current thread, for example when using JdoTransactionManager.
- * If allowCreate is true, a new non-transactional PersistenceManager will be
- * created if none found, which needs to be closed at the end of the operation.
- * If false, an IllegalStateException will get thrown in this case.
- * @see PersistenceManagerFactoryUtils#getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
- */
- public void setAllowCreate(boolean allowCreate) {
- this.allowCreate = allowCreate;
- }
-
- /**
- * Return if a new PersistenceManager should be created if no thread-bound found.
- */
- public boolean isAllowCreate() {
- return this.allowCreate;
- }
-
- /**
- * Set whether to expose the native JDO PersistenceManager to JdoCallback
- * code. Default is "false": a PersistenceManager proxy will be returned,
- * suppressing {@code close} calls and automatically applying transaction
- * timeouts (if any).
- *
As there is often a need to cast to a provider-specific PersistenceManager
- * class in DAOs that use provider-specific functionality, the exposed proxy
- * implements all interfaces implemented by the original PersistenceManager.
- * If this is not sufficient, turn this flag to "true".
- * @see JdoCallback
- * @see javax.jdo.PersistenceManager
- * @see #prepareQuery
- */
- public void setExposeNativePersistenceManager(boolean exposeNativePersistenceManager) {
- this.exposeNativePersistenceManager = exposeNativePersistenceManager;
- }
-
- /**
- * Return whether to expose the native JDO PersistenceManager to JdoCallback
- * code, or rather a PersistenceManager proxy.
- */
- public boolean isExposeNativePersistenceManager() {
- return this.exposeNativePersistenceManager;
- }
-
-
- public T execute(JdoCallback action) throws DataAccessException {
- return execute(action, isExposeNativePersistenceManager());
- }
-
- public Collection executeFind(JdoCallback> action) throws DataAccessException {
- Object result = execute(action, isExposeNativePersistenceManager());
- if (result != null && !(result instanceof Collection)) {
- throw new InvalidDataAccessApiUsageException(
- "Result object returned from JdoCallback isn't a Collection: [" + result + "]");
- }
- return (Collection) result;
- }
-
- /**
- * Execute the action specified by the given action object within a
- * PersistenceManager.
- * @param action callback object that specifies the JDO action
- * @param exposeNativePersistenceManager whether to expose the native
- * JDO persistence manager to callback code
- * @return a result object returned by the action, or {@code null}
- * @throws org.springframework.dao.DataAccessException in case of JDO errors
- */
- public T execute(JdoCallback action, boolean exposeNativePersistenceManager) throws DataAccessException {
- Assert.notNull(action, "Callback object must not be null");
-
- PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(
- getPersistenceManagerFactory(), isAllowCreate());
- boolean existingTransaction =
- TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory());
- try {
- PersistenceManager pmToExpose = (exposeNativePersistenceManager ? pm : createPersistenceManagerProxy(pm));
- T result = action.doInJdo(pmToExpose);
- flushIfNecessary(pm, existingTransaction);
- return postProcessResult(result, pm, existingTransaction);
- }
- catch (JDOException ex) {
- throw convertJdoAccessException(ex);
- }
- catch (RuntimeException ex) {
- // callback code threw application exception
- throw ex;
- }
- finally {
- PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
- }
- }
-
- /**
- * Create a close-suppressing proxy for the given JDO PersistenceManager.
- * Called by the {@code execute} method.
- *
The proxy also prepares returned JDO Query objects.
- * @param pm the JDO PersistenceManager to create a proxy for
- * @return the PersistenceManager proxy, implementing all interfaces
- * implemented by the passed-in PersistenceManager object (that is,
- * also implementing all provider-specific extension interfaces)
- * @see javax.jdo.PersistenceManager#close()
- * @see #execute(JdoCallback, boolean)
- * @see #prepareQuery
- */
- protected PersistenceManager createPersistenceManagerProxy(PersistenceManager pm) {
- Class[] ifcs = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader());
- return (PersistenceManager) Proxy.newProxyInstance(
- pm.getClass().getClassLoader(), ifcs, new CloseSuppressingInvocationHandler(pm));
- }
-
- /**
- * Post-process the given result object, which might be a Collection.
- * Called by the {@code execute} method.
- *
Default implementation always returns the passed-in Object as-is.
- * Subclasses might override this to automatically detach result
- * collections or even single result objects.
- * @param pm the current JDO PersistenceManager
- * @param result the result object (might be a Collection)
- * @param existingTransaction if executing within an existing transaction
- * (within an existing JDO PersistenceManager that won't be closed immediately)
- * @return the post-processed result object (can be simply be the passed-in object)
- * @see #execute(JdoCallback, boolean)
- */
- protected T postProcessResult(T result, PersistenceManager pm, boolean existingTransaction) {
- return result;
- }
-
-
- //-------------------------------------------------------------------------
- // Convenience methods for load, save, delete
- //-------------------------------------------------------------------------
-
- public Object getObjectById(final Object objectId) throws DataAccessException {
- return execute(new JdoCallback