diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
index b9b4704f95..d7c8270a1c 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
@@ -110,8 +110,6 @@ public abstract class AbstractEntityManagerFactoryBean implements
/** Raw EntityManagerFactory as returned by the PersistenceProvider */
public EntityManagerFactory nativeEntityManagerFactory;
- private EntityManagerFactoryPlusOperations plusOperations;
-
private EntityManagerFactory entityManagerFactory;
@@ -339,10 +337,6 @@ public abstract class AbstractEntityManagerFactoryBean implements
ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(emf.getClass(), this.beanClassLoader));
}
ifcs.add(EntityManagerFactoryInfo.class);
- if (getJpaDialect() != null && getJpaDialect().supportsEntityManagerFactoryPlusOperations()) {
- this.plusOperations = getJpaDialect().getEntityManagerFactoryPlusOperations(emf);
- ifcs.add(EntityManagerFactoryPlusOperations.class);
- }
try {
return (EntityManagerFactory) Proxy.newProxyInstance(
this.beanClassLoader, ifcs.toArray(new Class[ifcs.size()]),
@@ -363,16 +357,13 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
/**
- * Delegate an incoming invocation from the proxy, dispatching to EntityManagerFactoryInfo /
- * EntityManagerFactoryPlusOperations / the native EntityManagerFactory accordingly.
+ * Delegate an incoming invocation from the proxy, dispatching to EntityManagerFactoryInfo
+ * or the native EntityManagerFactory accordingly.
*/
Object invokeProxyMethod(Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass().isAssignableFrom(EntityManagerFactoryInfo.class)) {
return method.invoke(this, args);
}
- else if (method.getDeclaringClass().equals(EntityManagerFactoryPlusOperations.class)) {
- return method.invoke(this.plusOperations, args);
- }
else if (method.getName().equals("createEntityManager") && args != null && args.length > 0 &&
args[0] != null && args[0].getClass().isEnum() && "SYNCHRONIZED".equals(args[0].toString())) {
// JPA 2.1's createEntityManager(SynchronizationType, Map)
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java
index 63df63e531..1a8f691915 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.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.
@@ -18,9 +18,7 @@ package org.springframework.orm.jpa;
import java.io.Serializable;
import java.sql.SQLException;
-
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.springframework.dao.DataAccessException;
@@ -31,23 +29,20 @@ import org.springframework.transaction.TransactionException;
/**
* Default implementation of the {@link JpaDialect} interface.
- * Used as default dialect by {@link JpaAccessor} and {@link JpaTransactionManager}.
+ * Used as default dialect by {@link JpaTransactionManager}.
*
*
Simply begins a standard JPA transaction in {@link #beginTransaction}
* and performs standard exception translation through {@link EntityManagerFactoryUtils}.
*
+ *
NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0.
+ *
* @author Juergen Hoeller
* @since 2.0
- * @see JpaAccessor#setJpaDialect
* @see JpaTransactionManager#setJpaDialect
*/
@SuppressWarnings("serial")
public class DefaultJpaDialect implements JpaDialect, Serializable {
- //-------------------------------------------------------------------------
- // Hooks for transaction management (used by JpaTransactionManager)
- //-------------------------------------------------------------------------
-
/**
* This implementation invokes the standard JPA {@code Transaction.begin}
* method. Throws an InvalidIsolationLevelException if a non-default isolation
@@ -110,7 +105,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
//-----------------------------------------------------------------------------------
- // Hook for exception translation (used by JpaTransactionManager and JpaTemplate)
+ // Hook for exception translation (used by JpaTransactionManager)
//-----------------------------------------------------------------------------------
/**
@@ -121,21 +116,4 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}
-
- public boolean supportsEntityManagerFactoryPlusOperations() {
- return false;
- }
-
- public boolean supportsEntityManagerPlusOperations() {
- return false;
- }
-
- public EntityManagerFactoryPlusOperations getEntityManagerFactoryPlusOperations(EntityManagerFactory rawEntityManager) {
- throw new UnsupportedOperationException(getClass().getName() + " does not support EntityManagerFactoryPlusOperations");
- }
-
- public EntityManagerPlusOperations getEntityManagerPlusOperations(EntityManager rawEntityManager) {
- throw new UnsupportedOperationException(getClass().getName() + " does not support EntityManagerPlusOperations");
- }
-
}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java
index 3d7c0041be..e5463d6d27 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.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.
@@ -36,11 +36,8 @@ import org.springframework.util.CollectionUtils;
* Base class for any class that needs to access an EntityManagerFactory,
* usually in order to obtain an EntityManager. Defines common properties.
*
- *
Not intended to be used directly. See {@link JpaAccessor}.
- *
* @author Juergen Hoeller
* @since 2.0
- * @see JpaAccessor
* @see EntityManagerFactoryUtils
*/
public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware {
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlus.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlus.java
deleted file mode 100644
index 9af3079dfe..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlus.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2002-2006 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.jpa;
-
-import javax.persistence.EntityManagerFactory;
-
-/**
- * Extension of the standard JPA EntityManagerFactory interface, linking in
- * Spring's EntityManagerFactoryPlusOperations interface which defines
- * additional operations (beyond JPA 1.0) in a vendor-independent fashion.
- *
- * @author Rod Johnson
- * @since 2.0
- * @see javax.persistence.EntityManager
- */
-public interface EntityManagerFactoryPlus extends EntityManagerFactory, EntityManagerFactoryPlusOperations {
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlusOperations.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlusOperations.java
deleted file mode 100644
index a895fe169b..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryPlusOperations.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2002-2006 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.jpa;
-
-/**
- * Interface that defines common operations beyond the standard
- * JPA EntityManagerFactory interface, in a vendor-independent fashion.
- * To be adapted to specific JPA providers through a JpaDialect.
- *
- *
As of Spring 2.0, this interface does not define any operations yet.
- * The pass-through mechanism to the underlying JpaDialect is already in
- * place. Concrete operations may be added in future releases.
- *
- * @author Rod Johnson
- * @since 2.0
- * @see JpaDialect#getEntityManagerPlusOperations
- * @see javax.persistence.EntityManagerFactory
- */
-public interface EntityManagerFactoryPlusOperations {
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlus.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlus.java
deleted file mode 100644
index b1c44058e9..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlus.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2002-2006 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.jpa;
-
-import javax.persistence.EntityManager;
-
-/**
- * Extension of the standard JPA EntityManager interface, linking in
- * Spring's EntityManagerPlusOperations interface which defines additional
- * operations (beyond JPA 1.0) in a vendor-independent fashion.
- *
- * @author Rod Johnson
- * @since 2.0
- * @see javax.persistence.EntityManager
- */
-public interface EntityManagerPlus extends EntityManager, EntityManagerPlusOperations {
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlusOperations.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlusOperations.java
deleted file mode 100644
index bf0e9065b3..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerPlusOperations.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2002-2006 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.jpa;
-
-/**
- * Interface that defines common operations beyond the standard
- * JPA EntityManager interface, in a vendor-independent fashion.
- * To be adapted to specific JPA providers through a JpaDialect.
- *
- *
As of Spring 2.0, this interface does not define any operations yet.
- * The pass-through mechanism to the underlying JpaDialect is already in
- * place. Concrete operations may be added in future releases.
- *
- * @author Rod Johnson
- * @since 2.0
- * @see JpaDialect#getEntityManagerPlusOperations
- * @see javax.persistence.EntityManager
- */
-public interface EntityManagerPlusOperations {
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java
index a94b6bd249..475fcd8ad3 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java
@@ -59,48 +59,11 @@ import org.springframework.util.CollectionUtils;
public abstract class ExtendedEntityManagerCreator {
/**
- * Create an EntityManager that can join transactions with the
- * {@code joinTransaction()} method, but is not automatically
- * managed by the container.
+ * Create an EntityManager that can join transactions with the {@code joinTransaction()}
+ * method, but is not automatically managed by the container.
* @param rawEntityManager raw EntityManager
- * @param plusOperations an implementation of the EntityManagerPlusOperations
- * interface, if those operations should be exposed (may be {@code null})
- * @return an application-managed EntityManager that can join transactions
- * but does not participate in them automatically
- */
- public static EntityManager createApplicationManagedEntityManager(
- EntityManager rawEntityManager, EntityManagerPlusOperations plusOperations) {
-
- return createProxy(rawEntityManager, null, null, plusOperations, null, null, false, false);
- }
-
- /**
- * Create an EntityManager that can join transactions with the
- * {@code joinTransaction()} method, but is not automatically
- * managed by the container.
- * @param rawEntityManager raw EntityManager
- * @param plusOperations an implementation of the EntityManagerPlusOperations
- * interface, if those operations should be exposed (may be {@code null})
- * @param exceptionTranslator the exception translator to use for translating
- * JPA commit/rollback exceptions during transaction synchronization
- * (may be {@code null})
- * @return an application-managed EntityManager that can join transactions
- * but does not participate in them automatically
- */
- public static EntityManager createApplicationManagedEntityManager(
- EntityManager rawEntityManager, EntityManagerPlusOperations plusOperations,
- PersistenceExceptionTranslator exceptionTranslator) {
-
- return createProxy(rawEntityManager, null, null, plusOperations, exceptionTranslator, null, false, false);
- }
-
- /**
- * Create an EntityManager that can join transactions with the
- * {@code joinTransaction()} method, but is not automatically
- * managed by the container.
- * @param rawEntityManager raw EntityManager
- * @param emfInfo the EntityManagerFactoryInfo to obtain the
- * EntityManagerPlusOperations and PersistenceUnitInfo from
+ * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect
+ * and PersistenceUnitInfo from
* @return an application-managed EntityManager that can join transactions
* but does not participate in them automatically
*/
@@ -111,12 +74,11 @@ public abstract class ExtendedEntityManagerCreator {
}
/**
- * Create an EntityManager that can join transactions with the
- * {@code joinTransaction()} method, but is not automatically
- * managed by the container.
+ * Create an EntityManager that can join transactions with the {@code joinTransaction()}
+ * method, but is not automatically managed by the container.
* @param rawEntityManager raw EntityManager
- * @param emfInfo the EntityManagerFactoryInfo to obtain the
- * EntityManagerPlusOperations and PersistenceUnitInfo from
+ * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect
+ * and PersistenceUnitInfo from
* @param synchronizedWithTransaction whether to automatically join ongoing
* transactions (according to the JPA 2.1 SynchronizationType rules)
* @return an application-managed EntityManager that can join transactions
@@ -128,47 +90,12 @@ public abstract class ExtendedEntityManagerCreator {
return createProxy(rawEntityManager, emfInfo, false, synchronizedWithTransaction);
}
-
/**
* Create an EntityManager whose lifecycle is managed by the container and which
* automatically joins a transaction when being invoked within its scope.
* @param rawEntityManager raw EntityManager
- * @param plusOperations an implementation of the EntityManagerPlusOperations
- * interface, if those operations should be exposed (may be {@code null})
- * @return a container-managed EntityManager that will automatically participate
- * in any managed transaction
- */
- public static EntityManager createContainerManagedEntityManager(
- EntityManager rawEntityManager, EntityManagerPlusOperations plusOperations) {
-
- return createProxy(rawEntityManager, null, null, plusOperations, null, null, true, true);
- }
-
- /**
- * Create an EntityManager whose lifecycle is managed by the container and which
- * automatically joins a transaction when being invoked within its scope.
- * @param rawEntityManager raw EntityManager
- * @param plusOperations an implementation of the EntityManagerPlusOperations
- * interface, if those operations should be exposed (may be {@code null})
- * @param exceptionTranslator the exception translator to use for translating
- * JPA commit/rollback exceptions during transaction synchronization
- * (may be {@code null})
- * @return a container-managed EntityManager that will automatically participate
- * in any managed transaction
- */
- public static EntityManager createContainerManagedEntityManager(
- EntityManager rawEntityManager, EntityManagerPlusOperations plusOperations,
- PersistenceExceptionTranslator exceptionTranslator) {
-
- return createProxy(rawEntityManager, null, null, plusOperations, exceptionTranslator, null, true, true);
- }
-
- /**
- * Create an EntityManager whose lifecycle is managed by the container and which
- * automatically joins a transaction when being invoked within its scope.
- * @param rawEntityManager raw EntityManager
- * @param emfInfo the EntityManagerFactoryInfo to obtain the
- * EntityManagerPlusOperations and PersistenceUnitInfo from
+ * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect
+ * and PersistenceUnitInfo from
* @return a container-managed EntityManager that will automatically participate
* in any managed transaction
*/
@@ -182,9 +109,8 @@ public abstract class ExtendedEntityManagerCreator {
* Create an EntityManager whose lifecycle is managed by the container and which
* automatically joins a transaction when being invoked within its scope.
* @param emf the EntityManagerFactory to create the EntityManager with.
- * If this implements the EntityManagerFactoryInfo interface, appropriate handling
- * of the native EntityManagerFactory and available EntityManagerPlusOperations
- * will automatically apply.
+ * If this implements the EntityManagerFactoryInfo interface, the corresponding
+ * JpaDialect and PersistenceUnitInfo will be detected accordingly.
* @return a container-managed EntityManager that will automatically participate
* in any managed transaction
* @see javax.persistence.EntityManagerFactory#createEntityManager()
@@ -197,9 +123,8 @@ public abstract class ExtendedEntityManagerCreator {
* Create an EntityManager whose lifecycle is managed by the container and which
* automatically joins a transaction when being invoked within its scope.
* @param emf the EntityManagerFactory to create the EntityManager with.
- * If this implements the EntityManagerFactoryInfo interface, appropriate handling
- * of the native EntityManagerFactory and available EntityManagerPlusOperations
- * will automatically apply.
+ * If this implements the EntityManagerFactoryInfo interface, the corresponding
+ * JpaDialect and PersistenceUnitInfo will be detected accordingly.
* @param properties the properties to be passed into the {@code createEntityManager}
* call (may be {@code null})
* @return a container-managed EntityManager that will automatically participate
@@ -214,9 +139,8 @@ public abstract class ExtendedEntityManagerCreator {
* Create an EntityManager whose lifecycle is managed by the container and which
* may automatically join a transaction when being invoked within its scope.
* @param emf the EntityManagerFactory to create the EntityManager with.
- * If this implements the EntityManagerFactoryInfo interface, appropriate handling
- * of the native EntityManagerFactory and available EntityManagerPlusOperations
- * will automatically apply.
+ * If this implements the EntityManagerFactoryInfo interface, the corresponding
+ * JpaDialect and PersistenceUnitInfo will be detected accordingly.
* @param properties the properties to be passed into the {@code createEntityManager}
* call (may be {@code null})
* @param synchronizedWithTransaction whether to automatically join ongoing
@@ -239,7 +163,7 @@ public abstract class ExtendedEntityManagerCreator {
else {
EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ?
emf.createEntityManager(properties) : emf.createEntityManager());
- return createProxy(rawEntityManager, null, null, null, null, null, true, synchronizedWithTransaction);
+ return createProxy(rawEntityManager, null, null, null, null, true, synchronizedWithTransaction);
}
}
@@ -247,8 +171,8 @@ public abstract class ExtendedEntityManagerCreator {
/**
* Actually create the EntityManager proxy.
* @param rawEntityManager raw EntityManager
- * @param emfInfo the EntityManagerFactoryInfo to obtain the
- * EntityManagerPlusOperations and PersistenceUnitInfo from
+ * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect
+ * and PersistenceUnitInfo from
* @param containerManaged whether to follow container-managed EntityManager
* or application-managed EntityManager semantics
* @param synchronizedWithTransaction whether to automatically join ongoing
@@ -260,14 +184,10 @@ public abstract class ExtendedEntityManagerCreator {
Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null");
JpaDialect jpaDialect = emfInfo.getJpaDialect();
- EntityManagerPlusOperations plusOperations = null;
- if (jpaDialect != null && jpaDialect.supportsEntityManagerPlusOperations()) {
- plusOperations = jpaDialect.getEntityManagerPlusOperations(rawEntityManager);
- }
PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo();
Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null);
return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(),
- emfInfo.getBeanClassLoader(), plusOperations, jpaDialect, jta, containerManaged, synchronizedWithTransaction);
+ emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction);
}
/**
@@ -275,8 +195,7 @@ public abstract class ExtendedEntityManagerCreator {
* @param rawEm raw EntityManager
* @param emIfc the (potentially vendor-specific) EntityManager
* interface to proxy, or {@code null} for default detection of all interfaces
- * @param plusOperations an implementation of the EntityManagerPlusOperations
- * interface, if those operations should be exposed (may be {@code null})
+ * @param cl the ClassLoader to use for proxy creation (maybe {@code null})
* @param exceptionTranslator the PersistenceException translator to use
* @param jta whether to create a JTA-aware EntityManager
* (or {@code null} if not known in advance)
@@ -288,8 +207,8 @@ public abstract class ExtendedEntityManagerCreator {
*/
private static EntityManager createProxy(
EntityManager rawEm, Class extends EntityManager> emIfc, ClassLoader cl,
- EntityManagerPlusOperations plusOperations, PersistenceExceptionTranslator exceptionTranslator,
- Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) {
+ PersistenceExceptionTranslator exceptionTranslator, Boolean jta,
+ boolean containerManaged, boolean synchronizedWithTransaction) {
Assert.notNull(rawEm, "EntityManager must not be null");
Set ifcs = new LinkedHashSet();
@@ -300,14 +219,11 @@ public abstract class ExtendedEntityManagerCreator {
ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(rawEm.getClass(), cl));
}
ifcs.add(EntityManagerProxy.class);
- if (plusOperations != null) {
- ifcs.add(EntityManagerPlusOperations.class);
- }
return (EntityManager) Proxy.newProxyInstance(
(cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()),
ifcs.toArray(new Class[ifcs.size()]),
new ExtendedEntityManagerInvocationHandler(
- rawEm, plusOperations, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction));
+ rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction));
}
@@ -321,8 +237,6 @@ public abstract class ExtendedEntityManagerCreator {
private final EntityManager target;
- private final EntityManagerPlusOperations plusOperations;
-
private final PersistenceExceptionTranslator exceptionTranslator;
private final boolean jta;
@@ -331,13 +245,11 @@ public abstract class ExtendedEntityManagerCreator {
private final boolean synchronizedWithTransaction;
- private ExtendedEntityManagerInvocationHandler(
- EntityManager target, EntityManagerPlusOperations plusOperations,
+ private ExtendedEntityManagerInvocationHandler(EntityManager target,
PersistenceExceptionTranslator exceptionTranslator, Boolean jta,
boolean containerManaged, boolean synchronizedWithTransaction) {
this.target = target;
- this.plusOperations = plusOperations;
this.exceptionTranslator = exceptionTranslator;
this.jta = (jta != null ? jta : isJtaEntityManager());
this.containerManaged = containerManaged;
@@ -418,12 +330,7 @@ public abstract class ExtendedEntityManagerCreator {
// Invoke method on current EntityManager.
try {
- if (method.getDeclaringClass().equals(EntityManagerPlusOperations.class)) {
- return method.invoke(this.plusOperations, args);
- }
- else {
- return method.invoke(this.target, args);
- }
+ return method.invoke(this.target, args);
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaAccessor.java
deleted file mode 100644
index cb4b282a84..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaAccessor.java
+++ /dev/null
@@ -1,158 +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.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
-
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.dao.support.DataAccessUtils;
-
-/**
- * Base class for JpaTemplate and JpaInterceptor, defining common
- * properties such as EntityManagerFactory and flushing behavior.
- *
- *
Not intended to be used directly.
- * See {@link JpaTemplate} and {@link JpaInterceptor}.
- *
- * @author Juergen Hoeller
- * @since 2.0
- * @see #setEntityManagerFactory
- * @see #setEntityManager
- * @see #setJpaDialect
- * @see #setFlushEager
- * @see JpaTemplate
- * @see JpaInterceptor
- * @see JpaDialect
- * @deprecated as of Spring 3.1, in favor of native EntityManager usage
- * (typically obtained through {@code @PersistenceContext})
- */
-@Deprecated
-public abstract class JpaAccessor extends EntityManagerFactoryAccessor implements InitializingBean {
-
- private EntityManager entityManager;
-
- private JpaDialect jpaDialect = new DefaultJpaDialect();
-
- private boolean flushEager = false;
-
-
- /**
- * Set the JPA EntityManager to use.
- */
- public void setEntityManager(EntityManager entityManager) {
- this.entityManager = entityManager;
- }
-
- /**
- * Return the JPA EntityManager to use.
- */
- public EntityManager getEntityManager() {
- return entityManager;
- }
-
- /**
- * Set the JPA dialect to use for this accessor.
- *
The dialect object can be used to retrieve the underlying JDBC
- * connection, for example.
- */
- public void setJpaDialect(JpaDialect jpaDialect) {
- this.jpaDialect = (jpaDialect != null ? jpaDialect : new DefaultJpaDialect());
- }
-
- /**
- * Return the JPA dialect to use for this accessor.
- *
Creates a default one for the specified EntityManagerFactory if none set.
- */
- public JpaDialect getJpaDialect() {
- return this.jpaDialect;
- }
-
- /**
- * 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 JPA
- * 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 JPA dialect, creating a default one
- * for the specified EntityManagerFactory if none set.
- */
- public void afterPropertiesSet() {
- EntityManagerFactory emf = getEntityManagerFactory();
- if (emf == null && getEntityManager() == null) {
- throw new IllegalArgumentException("'entityManagerFactory' or 'entityManager' is required");
- }
- if (emf instanceof EntityManagerFactoryInfo) {
- JpaDialect jpaDialect = ((EntityManagerFactoryInfo) emf).getJpaDialect();
- if (jpaDialect != null) {
- setJpaDialect(jpaDialect);
- }
- }
- }
-
-
- /**
- * Flush the given JPA entity manager if necessary.
- * @param em the current JPA PersistenceManage
- * @param existingTransaction if executing within an existing transaction
- * @throws javax.persistence.PersistenceException in case of JPA flushing errors
- */
- protected void flushIfNecessary(EntityManager em, boolean existingTransaction) throws PersistenceException {
- if (isFlushEager()) {
- logger.debug("Eagerly flushing JPA entity manager");
- em.flush();
- }
- }
-
- /**
- * Convert the given runtime exception to an appropriate exception from the
- * {@code org.springframework.dao} hierarchy if necessary, or
- * return the exception itself if it is not persistence related
- *
Default implementation delegates to the JpaDialect.
- * May be overridden in subclasses.
- * @param ex runtime exception that occured, which may or may not
- * be JPA-related
- * @return the corresponding DataAccessException instance if
- * wrapping should occur, otherwise the raw exception
- * @see org.springframework.dao.support.DataAccessUtils#translateIfNecessary
- */
- public RuntimeException translateIfNecessary(RuntimeException ex) {
- return DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
- }
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaCallback.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaCallback.java
deleted file mode 100644
index 4606c6258a..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaCallback.java
+++ /dev/null
@@ -1,61 +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.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
-
-/**
- * Callback interface for JPA code. To be used with {@link JpaTemplate}'s
- * execution method, often as anonymous classes within a method implementation.
- * A typical implementation will call {@code EntityManager.find/merge}
- * to perform some operations on persistent objects.
- *
- * @author Juergen Hoeller
- * @since 2.0
- * @see JpaTemplate
- * @see JpaTransactionManager
- * @deprecated as of Spring 3.1, in favor of native EntityManager usage
- * (typically obtained through {@code @PersistenceContext})
- */
-@Deprecated
-public interface JpaCallback {
-
- /**
- * Gets called by {@code JpaTemplate.execute} with an active
- * JPA {@code EntityManager}. Does not need to care about activating
- * or closing the {@code EntityManager}, or handling transactions.
- *
- *
Note that JPA callback code will not flush any modifications to the
- * database if not executed within a transaction. Thus, you need to make
- * sure that JpaTransactionManager has initiated a JPA 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 em active EntityManager
- * @return a result object, or {@code null} if none
- * @throws PersistenceException if thrown by the JPA API
- * @see JpaTemplate#execute
- * @see JpaTemplate#executeFind
- */
- T doInJpa(EntityManager em) throws PersistenceException;
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java
index 882fa83523..11529655b6 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.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.
@@ -18,7 +18,6 @@ package org.springframework.orm.jpa;
import java.sql.SQLException;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
@@ -27,7 +26,7 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
/**
- * SPI strategy that encapsulates certain functionality that standard JPA 1.0
+ * SPI strategy that encapsulates certain functionality that standard JPA 2.0
* does not offer, such as access to the underlying JDBC Connection. This
* strategy is mainly intended for standalone usage of a JPA provider; most
* of its functionality is not relevant when running with JTA transactions.
@@ -45,7 +44,6 @@ import org.springframework.transaction.TransactionException;
* @author Rod Johnson
* @since 2.0
* @see DefaultJpaDialect
- * @see JpaAccessor#setJpaDialect
* @see JpaTransactionManager#setJpaDialect
* @see JpaVendorAdapter#getJpaDialect()
* @see AbstractEntityManagerFactoryBean#setJpaDialect
@@ -53,51 +51,6 @@ import org.springframework.transaction.TransactionException;
*/
public interface JpaDialect extends PersistenceExceptionTranslator {
- //-----------------------------------------------------------------------------------
- // Hooks for non-standard persistence operations (used by EntityManagerFactory beans)
- //-----------------------------------------------------------------------------------
-
- /**
- * Return whether the EntityManagerFactoryPlus(Operations) interface is
- * supported by this provider.
- * @see EntityManagerFactoryPlusOperations
- * @see EntityManagerFactoryPlus
- */
- boolean supportsEntityManagerFactoryPlusOperations();
-
- /**
- * Return whether the EntityManagerPlus(Operations) interface is
- * supported by this provider.
- * @see EntityManagerPlusOperations
- * @see EntityManagerPlus
- */
- boolean supportsEntityManagerPlusOperations();
-
- /**
- * Return an EntityManagerFactoryPlusOperations implementation for
- * the given raw EntityManagerFactory. This operations object can be
- * used to serve the additional operations behind a proxy that
- * implements the EntityManagerFactoryPlus interface.
- * @param rawEntityManager the raw provider-specific EntityManagerFactory
- * @return the EntityManagerFactoryPlusOperations implementation
- */
- EntityManagerFactoryPlusOperations getEntityManagerFactoryPlusOperations(EntityManagerFactory rawEntityManager);
-
- /**
- * Return an EntityManagerPlusOperations implementation for
- * the given raw EntityManager. This operations object can be
- * used to serve the additional operations behind a proxy that
- * implements the EntityManagerPlus interface.
- * @param rawEntityManager the raw provider-specific EntityManagerFactory
- * @return the EntityManagerFactoryPlusOperations implementation
- */
- EntityManagerPlusOperations getEntityManagerPlusOperations(EntityManager rawEntityManager);
-
-
- //-------------------------------------------------------------------------
- // Hooks for transaction management (used by JpaTransactionManager)
- //-------------------------------------------------------------------------
-
/**
* Begin the given JPA transaction, applying the semantics specified by the
* given Spring transaction definition (in particular, an isolation level
@@ -173,7 +126,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator {
* needing access to the underlying JDBC Connection, usually within an active JPA
* transaction (for example, by JpaTransactionManager). The returned handle will
* be passed into the {@code releaseJdbcConnection} method when not needed anymore.
- *
This strategy is necessary as JPA 1.0 does not provide a standard way to retrieve
+ *
This strategy is necessary as JPA does not provide a standard way to retrieve
* the underlying JDBC Connection (due to the fact that a JPA implementation might not
* work with a relational database at all).
*
Implementations are encouraged to return an unwrapped Connection object, i.e.
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaInterceptor.java
deleted file mode 100644
index cdb4830d3d..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaInterceptor.java
+++ /dev/null
@@ -1,123 +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.jpa;
-
-import javax.persistence.EntityManager;
-
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import org.springframework.transaction.support.TransactionSynchronizationManager;
-
-/**
- * This interceptor binds a new JPA EntityManager 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 EntityManager (e.g. from JpaTransactionManager,
- * or from a surrounding JPA-intercepted method), the interceptor simply participates in it.
- *
- *
Application code must retrieve a JPA EntityManager via the
- * {@code EntityManagerFactoryUtils.getEntityManager} method or - preferably -
- * via a shared {@code EntityManager} reference, to be able to detect a
- * thread-bound EntityManager. Typically, the code will look like as follows:
- *
- *
Note that this interceptor automatically translates PersistenceExceptions,
- * via delegating to the {@code EntityManagerFactoryUtils.convertJpaAccessException}
- * method that converts them to exceptions that are compatible with the
- * {@code org.springframework.dao} exception hierarchy (like JpaTemplate does).
- *
- *
This class can be considered a declarative alternative to JpaTemplate'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 EntityManager in the first place, so adding this interceptor
- * to the configuration just adds value when fine-tuning EntityManager settings
- * like the flush mode - or when relying on exception translation.
- *
- * @author Juergen Hoeller
- * @since 2.0
- * @see JpaTransactionManager
- * @see JpaTemplate
- * @deprecated as of Spring 3.1, in favor of native EntityManager usage
- * (typically obtained through {@code @PersistenceContext}) and
- * AOP-driven exception translation through
- * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}
- */
-@Deprecated
-public class JpaInterceptor extends JpaAccessor implements MethodInterceptor {
-
- private boolean exceptionConversionEnabled = true;
-
-
- /**
- * Set whether to convert any PersistenceException 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 {
- // Determine current EntityManager: either the transactional one
- // managed by the factory or a temporary one for the given invocation.
- EntityManager em = getTransactionalEntityManager();
- boolean isNewEm = false;
- if (em == null) {
- logger.debug("Creating new EntityManager for JpaInterceptor invocation");
- em = createEntityManager();
- isNewEm = true;
- TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), new EntityManagerHolder(em));
- }
-
- try {
- Object retVal = methodInvocation.proceed();
- flushIfNecessary(em, !isNewEm);
- return retVal;
- }
- catch (RuntimeException rawException) {
- if (this.exceptionConversionEnabled) {
- // Translation enabled. Translate if we understand the exception.
- throw translateIfNecessary(rawException);
- }
- else {
- // Translation not enabled. Don't try to translate.
- throw rawException;
- }
- }
- finally {
- if (isNewEm) {
- TransactionSynchronizationManager.unbindResource(getEntityManagerFactory());
- EntityManagerFactoryUtils.closeEntityManager(em);
- }
- }
- }
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaOperations.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaOperations.java
deleted file mode 100644
index b3355da5ec..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaOperations.java
+++ /dev/null
@@ -1,88 +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.jpa;
-
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.dao.DataAccessException;
-
-/**
- * Interface that specifies a basic set of JPA operations,
- * implemented by {@link JpaTemplate}. Not often used, but a useful
- * option to enhance testability, as it can easily be mocked or stubbed.
- *
- *
Defines {@code JpaTemplate}'s data access methods that mirror
- * various {@link javax.persistence.EntityManager} methods. Users are
- * strongly encouraged to read the JPA {@code EntityManager}
- * javadocs for details on the semantics of those methods.
- *
- *
Note that lazy loading will just work with an open JPA
- * {@code EntityManager}, either within a managed transaction or within
- * {@link org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter}/
- * {@link org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor}.
- * Furthermore, some operations just make sense within transactions,
- * for example: {@code flush}, {@code clear}.
- *
- * @author Juergen Hoeller
- * @since 2.0
- * @see JpaTemplate
- * @see javax.persistence.EntityManager
- * @see JpaTransactionManager
- * @see JpaDialect
- * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
- * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
- * @deprecated as of Spring 3.1, in favor of native EntityManager usage
- * (typically obtained through {@code @PersistenceContext}).
- * Note that this interface did not get upgraded to JPA 2.0 and never will.
- */
-@Deprecated
-public interface JpaOperations {
-
- T execute(JpaCallback action) throws DataAccessException;
-
- List executeFind(JpaCallback> action) throws DataAccessException;
-
- T find(Class entityClass, Object id) throws DataAccessException;
-
- T getReference(Class entityClass, Object id) throws DataAccessException;
-
- boolean contains(Object entity) throws DataAccessException;
-
- void refresh(Object entity) throws DataAccessException;
-
- void persist(Object entity) throws DataAccessException;
-
- T merge(T entity) throws DataAccessException;
-
- void remove(Object entity) throws DataAccessException;
-
- void flush() throws DataAccessException;
-
- List find(String queryString) throws DataAccessException;
-
- List find(String queryString, Object... values) throws DataAccessException;
-
- List findByNamedParams(String queryString, Map params) throws DataAccessException;
-
- List findByNamedQuery(String queryName) throws DataAccessException;
-
- List findByNamedQuery(String queryName, Object... values) throws DataAccessException;
-
- List findByNamedQueryAndNamedParams(String queryName, Map params) throws DataAccessException;
-
-}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTemplate.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTemplate.java
deleted file mode 100644
index 1b039f6573..0000000000
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTemplate.java
+++ /dev/null
@@ -1,442 +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.jpa;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.List;
-import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
-import javax.persistence.Query;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.dao.InvalidDataAccessApiUsageException;
-import org.springframework.util.Assert;
-import org.springframework.util.ClassUtils;
-
-/**
- * Helper class that allows for writing JPA data access code in the same style
- * as with Spring's well-known JdoTemplate and HibernateTemplate classes.
- * Automatically converts PersistenceExceptions into Spring DataAccessExceptions,
- * following the {@code org.springframework.dao} exception hierarchy.
- *
- *
The central method is of this template is "execute", supporting JPA access code
- * implementing the {@link JpaCallback} interface. It provides JPA EntityManager
- * handling such that neither the JpaCallback implementation nor the calling code
- * needs to explicitly care about retrieving/closing EntityManagers, or handling
- * JPA lifecycle exceptions.
- *
- *
Can be used within a service implementation via direct instantiation with
- * a EntityManagerFactory reference, or get prepared in an application context
- * and given to services as bean reference. Note: The EntityManagerFactory 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.
- *
- *
NOTE: JpaTemplate mainly exists as a sibling of JdoTemplate and
- * HibernateTemplate, offering the same style for people used to it. For newly
- * started projects, consider adopting the standard JPA style of coding data
- * access objects instead, based on a "shared EntityManager" reference injected
- * via a Spring bean definition or the JPA PersistenceContext annotation.
- * (Using Spring's SharedEntityManagerBean / PersistenceAnnotationBeanPostProcessor,
- * or using a direct JNDI lookup for an EntityManager on a Java EE 5 server.)
- *
- *
JpaTemplate can be considered as direct alternative to working with the
- * native JPA EntityManager API (through a shared EntityManager reference,
- * as outlined above). The major advantage is its automatic conversion to
- * DataAccessExceptions; the major disadvantage is that it introduces
- * another thin layer on top of the native JPA API. Note that exception
- * translation can also be achieved through AOP advice; check out
- * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}.
- *
- *
{@link LocalContainerEntityManagerFactoryBean} is the preferred way of
- * obtaining a reference to an EntityManagerFactory, at least outside of a full
- * Java EE 5 environment. The Spring application context will manage its lifecycle,
- * initializing and shutting down the factory as part of the application.
- * Within a Java EE 5 environment, you will typically work with a server-managed
- * EntityManagerFactory that is exposed via JNDI, obtained through Spring's
- * {@link org.springframework.jndi.JndiObjectFactoryBean}.
- *
- * @author Juergen Hoeller
- * @since 2.0
- * @see #setEntityManagerFactory
- * @see JpaCallback
- * @see javax.persistence.EntityManager
- * @see LocalEntityManagerFactoryBean
- * @see LocalContainerEntityManagerFactoryBean
- * @see JpaTransactionManager
- * @see org.springframework.transaction.jta.JtaTransactionManager
- * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
- * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
- * @deprecated as of Spring 3.1, in favor of native EntityManager usage
- * (typically obtained through {@code @PersistenceContext})
- * Note that this class did not get upgraded to JPA 2.0 and never will.
- */
-@Deprecated
-public class JpaTemplate extends JpaAccessor implements JpaOperations {
-
- private boolean exposeNativeEntityManager = false;
-
-
- /**
- * Create a new JpaTemplate instance.
- */
- public JpaTemplate() {
- }
-
- /**
- * Create a new JpaTemplate instance.
- * @param emf EntityManagerFactory to create EntityManagers
- */
- public JpaTemplate(EntityManagerFactory emf) {
- setEntityManagerFactory(emf);
- afterPropertiesSet();
- }
-
- /**
- * Create a new JpaTemplate instance.
- * @param em EntityManager to use
- */
- public JpaTemplate(EntityManager em) {
- setEntityManager(em);
- afterPropertiesSet();
- }
-
-
- /**
- * Set whether to expose the native JPA EntityManager to JpaCallback
- * code. Default is "false": a EntityManager 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 EntityManager
- * class in DAOs that use the JPA 1.0 API, for JPA 2.0 previews and other
- * provider-specific functionality, the exposed proxy implements all interfaces
- * implemented by the original EntityManager. If this is not sufficient,
- * turn this flag to "true".
- * @see JpaCallback
- * @see javax.persistence.EntityManager
- */
- public void setExposeNativeEntityManager(boolean exposeNativeEntityManager) {
- this.exposeNativeEntityManager = exposeNativeEntityManager;
- }
-
- /**
- * Return whether to expose the native JPA EntityManager to JpaCallback
- * code, or rather an EntityManager proxy.
- */
- public boolean isExposeNativeEntityManager() {
- return this.exposeNativeEntityManager;
- }
-
-
- public T execute(JpaCallback action) throws DataAccessException {
- return execute(action, isExposeNativeEntityManager());
- }
-
- public List executeFind(JpaCallback> action) throws DataAccessException {
- Object result = execute(action, isExposeNativeEntityManager());
- if (!(result instanceof List)) {
- throw new InvalidDataAccessApiUsageException(
- "Result object returned from JpaCallback isn't a List: [" + result + "]");
- }
- return (List) result;
- }
-
- /**
- * Execute the action specified by the given action object within a
- * EntityManager.
- * @param action callback object that specifies the JPA action
- * @param exposeNativeEntityManager whether to expose the native
- * JPA entity manager to callback code
- * @return a result object returned by the action, or {@code null}
- * @throws org.springframework.dao.DataAccessException in case of JPA errors
- */
- public T execute(JpaCallback action, boolean exposeNativeEntityManager) throws DataAccessException {
- Assert.notNull(action, "Callback object must not be null");
-
- EntityManager em = getEntityManager();
- boolean isNewEm = false;
- if (em == null) {
- em = getTransactionalEntityManager();
- if (em == null) {
- logger.debug("Creating new EntityManager for JpaTemplate execution");
- em = createEntityManager();
- isNewEm = true;
- }
- }
-
- try {
- EntityManager emToExpose = (exposeNativeEntityManager ? em : createEntityManagerProxy(em));
- T result = action.doInJpa(emToExpose);
- flushIfNecessary(em, !isNewEm);
- return result;
- }
- catch (RuntimeException ex) {
- throw translateIfNecessary(ex);
- }
- finally {
- if (isNewEm) {
- logger.debug("Closing new EntityManager after JPA template execution");
- EntityManagerFactoryUtils.closeEntityManager(em);
- }
- }
- }
-
- /**
- * Create a close-suppressing proxy for the given JPA EntityManager.
- * The proxy also prepares returned JPA Query objects.
- * @param em the JPA EntityManager to create a proxy for
- * @return the EntityManager proxy, implementing all interfaces
- * implemented by the passed-in EntityManager object (that is,
- * also implementing all provider-specific extension interfaces)
- * @see javax.persistence.EntityManager#close
- */
- protected EntityManager createEntityManagerProxy(EntityManager em) {
- Class[] ifcs = null;
- EntityManagerFactory emf = getEntityManagerFactory();
- if (emf instanceof EntityManagerFactoryInfo) {
- Class entityManagerInterface = ((EntityManagerFactoryInfo) emf).getEntityManagerInterface();
- if (entityManagerInterface != null) {
- ifcs = new Class[] {entityManagerInterface};
- }
- }
- if (ifcs == null) {
- ifcs = ClassUtils.getAllInterfacesForClass(em.getClass());
- }
- return (EntityManager) Proxy.newProxyInstance(
- em.getClass().getClassLoader(), ifcs, new CloseSuppressingInvocationHandler(em));
- }
-
-
- //-------------------------------------------------------------------------
- // Convenience methods for load, save, delete
- //-------------------------------------------------------------------------
-
- public T find(final Class entityClass, final Object id) throws DataAccessException {
- return execute(new JpaCallback() {
- public T doInJpa(EntityManager em) throws PersistenceException {
- return em.find(entityClass, id);
- }
- }, true);
- }
-
- public T getReference(final Class entityClass, final Object id) throws DataAccessException {
- return execute(new JpaCallback() {
- public T doInJpa(EntityManager em) throws PersistenceException {
- return em.getReference(entityClass, id);
- }
- }, true);
- }
-
- public boolean contains(final Object entity) throws DataAccessException {
- return execute(new JpaCallback() {
- public Boolean doInJpa(EntityManager em) throws PersistenceException {
- return em.contains(entity);
- }
- }, true);
- }
-
- public void refresh(final Object entity) throws DataAccessException {
- execute(new JpaCallback