From: Juergen H. <jho...@us...> - 2006-04-19 21:23:25
|
Update of /cvsroot/springframework/spring/tiger/src/org/springframework/orm/jpa/support In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31443/tiger/src/org/springframework/orm/jpa/support Modified Files: SharedEntityManagerAdapter.java Log Message: added "entityManagerInterface" property, for exposing a vendor-extended interface Index: SharedEntityManagerAdapter.java =================================================================== RCS file: /cvsroot/springframework/spring/tiger/src/org/springframework/orm/jpa/support/SharedEntityManagerAdapter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SharedEntityManagerAdapter.java 10 Apr 2006 13:17:52 -0000 1.5 --- SharedEntityManagerAdapter.java 19 Apr 2006 21:23:21 -0000 1.6 *************** *** 29,33 **** --- 29,35 ---- import org.springframework.beans.factory.FactoryBean; + import org.springframework.beans.factory.InitializingBean; import org.springframework.orm.jpa.EntityManagerFactoryUtils; + import org.springframework.util.Assert; /** *************** *** 37,45 **** * JndiObjectFactoryBean definition for a Java EE 5 server's EntityManager. * ! * <p>The shared EntityManager will behave just like an EntityManager ! * fetched from an application server's JNDI environment, as defined ! * by the JPA specification. It will delegate all calls to the current ! * transactional EntityManager, if any; else, it will fall back to ! * a newly created EntityManager per operation. * * <p>Can be passed to DAOs that expect a shared EntityManager reference --- 39,47 ---- * JndiObjectFactoryBean definition for a Java EE 5 server's EntityManager. * ! * <p>The shared EntityManager will behave just like an EntityManager fetched ! * from an application server's JNDI environment, as defined by the JPA ! * specification. It will delegate all calls to the current transactional ! * EntityManager, if any; else, it will fall back to a newly created ! * EntityManager per operation. * * <p>Can be passed to DAOs that expect a shared EntityManager reference *************** *** 48,59 **** * to be able to create new transactional EntityManager instances. * * @author Juergen Hoeller * @since 2.0 * @see org.springframework.orm.jpa.LocalEntityManagerFactoryBean * @see org.springframework.orm.jpa.JpaTransactionManager */ ! public class SharedEntityManagerAdapter implements FactoryBean { ! private EntityManager entityManager; --- 50,72 ---- * to be able to create new transactional EntityManager instances. * + * <p>This adapter is also able to expose a vendor-extended EntityManager + * interface: Simply specify the extended interface as "entityManagerInterface". + * By default, only the standard <code>javax.persistence.EntityManager</code> + * interface will be exposed. + * * @author Juergen Hoeller * @since 2.0 + * @see #setEntityManagerFactory + * @see #setEntityManagerInterface * @see org.springframework.orm.jpa.LocalEntityManagerFactoryBean * @see org.springframework.orm.jpa.JpaTransactionManager */ ! public class SharedEntityManagerAdapter implements FactoryBean, InitializingBean { ! private EntityManagerFactory target; ! ! private Class entityManagerInterface = EntityManager.class; ! ! private EntityManager shared; *************** *** 64,77 **** * @see org.springframework.orm.jpa.JpaTransactionManager */ ! public void setEntityManagerFactory(EntityManagerFactory emf) { ! this.entityManager = (EntityManager) Proxy.newProxyInstance( getClass().getClassLoader(), ! new Class[] {EntityManager.class}, ! new SharedEntityManagerInvocationHandler(emf)); } public Object getObject() { ! return this.entityManager; } --- 77,111 ---- * @see org.springframework.orm.jpa.JpaTransactionManager */ ! public void setEntityManagerFactory(EntityManagerFactory target) { ! this.target = target; ! } ! ! /** ! * Specify the EntityManager interface to expose. ! * <p>Default is the standard <code>javax.persistence.EntityManager</code> ! * interface. This can be overridden to make the proxy expose a ! * vendor-extended EntityManager interface. ! * @see javax.persistence.EntityManager ! */ ! public void setEntityManagerInterface(Class entityManagerInterface) { ! Assert.notNull(entityManagerInterface, "entityManagerInterface must not be null"); ! Assert.isAssignableFrom(EntityManager.class, entityManagerInterface); ! this.entityManagerInterface = entityManagerInterface; ! } ! ! ! public void afterPropertiesSet() { ! if (this.target == null) { ! throw new IllegalArgumentException("entityManagerFactory is required"); ! } ! this.shared = (EntityManager) Proxy.newProxyInstance( getClass().getClassLoader(), ! new Class[] {this.entityManagerInterface}, ! new SharedEntityManagerInvocationHandler(this.target)); } public Object getObject() { ! return this.shared; } |