From: Erik Brakkee Date: Mon, 5 Jul 2010 14:17:51 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~367 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=f9ccadb956bac942258d9892c66e481ac2aec446;p=utils --- diff --git a/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java b/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java index 1679942b..b6fd991b 100644 --- a/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java +++ b/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java @@ -42,7 +42,7 @@ public class EclipselinkJpaCustomizer implements JpaCustomizer { Map aJpaProperties) { // DDL generation - aJpaProperties.put("eclipselink.ddl-generation", "create-tables"); + aJpaProperties.put("eclipselink.ddl-generation", "drop-and-create-tables"); // DDL generation FileSystemUtils.createDir(new File("target/sql")); diff --git a/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java b/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java index e47c037a..02668cdc 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java +++ b/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java @@ -71,6 +71,14 @@ public class ThreadSpecificProxyFactory { public void set(T aService) { svc.set(aService); } + + /** + * Gets the current thread-specific service. + * @return Service. + */ + public T get() { + return svc.get(); + } /** * Gets the proxy that delegates to the thread-specific instance set by diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/PersistenceUnitDescription.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/PersistenceUnitDescription.java index b6dc28bb..4cd06d04 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/persistence/PersistenceUnitDescription.java +++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/PersistenceUnitDescription.java @@ -17,12 +17,23 @@ package org.wamblee.support.persistence; import org.dbunit.dataset.filter.ITableFilterSimple; +/** + * Describes a persistence unit. + * + * @author Erik Brakkee + */ public class PersistenceUnitDescription { private String jndiName; private String unitName; private ITableFilterSimple tables; + /** + * Constructs the description. + * @param aJndiName Jndi name. + * @param aUnitName Persistence unit name. + * @param aTables Tables to delete. + */ public PersistenceUnitDescription(String aJndiName, String aUnitName, ITableFilterSimple aTables) { jndiName = aJndiName; @@ -30,14 +41,24 @@ public class PersistenceUnitDescription { tables = aTables; } + /** + * @return JNDI name. + */ public String getJndiName() { return jndiName; } + /** + * Persistence unit name. + */ public String getUnitName() { return unitName; } + /** + * Tables to delete. + * @return Tables. + */ public ITableFilterSimple getTables() { return tables; } diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java index e56d34fa..548a3cda 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java +++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java @@ -15,6 +15,7 @@ */ package org.wamblee.support.persistence; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,11 +28,25 @@ import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork; /** * This utility makes sure that each invocation on a certain interface is - * carried out within a JPA unit of work. + * carried out within a JPA unit of work. Note that this is equivalent + * to the sementics of a requiresNew transaction attribute. * * Use {@link #getTransactionScopedEntityManager()} to get the transaction * scoped entity manager to pass to services. * + * + * For example: + *
+ *     JpaBuilder builder = ...
+ *     TransactionProxyFactory factory = new TransactionProxyFactory(
+ *           builder, Service.class);
+ *     Service service = new JpaService(factory.getTransactionScopedEntityManager());
+ *     Service proxy = factory.getProxy(service);
+ *     proxy.executeMethod(...); 
+ * 
+ * The above example executes the executeMethod() call on the service object within an active transaction. + * In the constructor of the service a transaction scoped entity manager is passed. + * * @param T * Type of interface to proxy. * @@ -39,6 +54,13 @@ import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork; */ public class TransactionProxyFactory { + /** + * Executes the call on the service within a new transaction. + * + * @author Erik Brakkee + * + * @param Type of the service interface. + */ private class UnitOfWorkInvocationHandler implements InvocationHandler { private T service; @@ -54,6 +76,7 @@ public class TransactionProxyFactory { .execute(new JpaUnitOfWork() { @Override public Object execute(EntityManager aEm) throws Exception { + EntityManager oldEm = ENTITY_MANAGER.get(); try { ENTITY_MANAGER.set(aEm); return aMethod.invoke(service, aArgs); @@ -67,7 +90,7 @@ public class TransactionProxyFactory { // last resort. throw new RuntimeException(e); } finally { - ENTITY_MANAGER.set(null); + ENTITY_MANAGER.set(oldEm); } } }); diff --git a/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java b/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java index 71bbb18c..923d0c22 100644 --- a/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java +++ b/test/hibernate/src/main/java/org/wamblee/support/persistence/hibernate/HibernateJpaCustomizer.java @@ -51,7 +51,7 @@ public class HibernateJpaCustomizer implements JpaCustomizer { System.setProperty("hibernate.connection.password", aJpaProperties.get("javax.persistence.jdbc.password")); // Hibernate schema generation - aJpaProperties.put("hibernate.hbm2ddl.auto", "create"); + aJpaProperties.put("hibernate.hbm2ddl.auto", "create-drop"); } @Override diff --git a/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java b/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java index 1b3808f0..da40441c 100644 --- a/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java +++ b/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java @@ -46,7 +46,7 @@ public class ToplinkJpaCustomizer implements JpaCustomizer { aJpaProperties.put("toplink.jdbc.password", aJpaProperties.get("javax.persistence.jdbc.password")); // DDL generation for toplink - aJpaProperties.put("toplink.ddl-generation", "create-tables"); + aJpaProperties.put("toplink.ddl-generation", "drop-and-create-tables"); // DDL generation FileSystemUtils.createDir(new File("target/sql"));