Now working with both hibernate and eclipselink
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 2 May 2010 20:57:06 +0000 (20:57 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 2 May 2010 20:57:06 +0000 (20:57 +0000)
19 files changed:
README.txt
pom.xml
security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java
security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java
security/impl/src/main/java/org/wamblee/security/authorization/UrlAuthorizationRule.java
security/impl/src/main/java/org/wamblee/security/authorization/jpa/JpaAuthorizationService.java
security/impl/src/main/java/org/wamblee/usermgt/User.java
security/impl/src/main/java/org/wamblee/usermgt/UserAdministrationImpl.java
security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java
security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaUserSet.java
security/impl/src/test/java/org/wamblee/security/authorization/AuthorizationServiceTest.java
security/jpatest/pom.xml
security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java
security/jpatest/src/test/java/org/wamblee/usermgt/jpa/JpaUserAdministrationTest.java
test/eclipselink/pom.xml
test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java
test/enterprise/src/main/java/org/wamblee/support/jndi/StubInitialContext.java
test/enterprise/src/main/java/org/wamblee/support/persistence/JpaBuilder.java
test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java

index a41ba43712340249866fc48241f48af6da1ca00e..26f0a2ffc33711c9c2e9ff0cc35a7cea3ba9fffd 100644 (file)
@@ -28,6 +28,10 @@ Building
 
 You need maven2 and java 6 
 
+By default eclipselink is used as persistence provider. 
+Use mvn -Phibernate,!eclipselink (escape the ! if needed) to build with hibernate as
+persistence provider. 
+
 Releasing
 =========
 
diff --git a/pom.xml b/pom.xml
index 34cde99070ec0ec23f5abfa58ec4360332741135..a5a9652c9cab86098af72545ecdf0329793f57fa 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <dependency>
                 <groupId>org.eclipse.persistence</groupId>
                 <artifactId>eclipselink</artifactId>
-                <version>2.0.0</version>
+                <version>2.0.2</version>
                 <scope>compile</scope>
             </dependency>
 
index d8c1e527ca6f2a7cf8acad7a0122808e970a83fc..8d79a95ec9ec8598d5fae2c66376c85c6219fb29 100644 (file)
@@ -55,12 +55,26 @@ public abstract class AbstractAuthorizationService implements AuthorizationServi
     @Version
     private int version;
     
+    /**
+     * Name for this instance of the authorization service.
+     */
+    private String name; 
+    
     public AbstractAuthorizationService() { 
         // Empty. 
     }
     
+    public AbstractAuthorizationService(String aName) { 
+        name = aName; 
+    }
+    
     public AbstractAuthorizationService(AbstractAuthorizationService aSvc) { 
         primaryKey = aSvc.primaryKey;
         version = aSvc.version;
+        name = aSvc.name;
+    }
+    
+    public String getName() {
+        return name;
     }
 }
index 8ee411780d9fb0726776e14b2246999600f58701..1e5abb99c0e28cf9cc95b67e7187f0215c98efd6 100644 (file)
@@ -57,11 +57,6 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
     @Transient
     private UserAccessor userAccessor;
 
-    /**
-     * Name for this instance of the authorization service.
-     */
-    private String name;
-
     /**
      * Constructs the service.
      * 
@@ -71,9 +66,9 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
      *            Name of this instance of the service.
      */
     public DefaultAuthorizationService(UserAccessor aAccessor, String aName) {
+        super(aName);
         rules = new ArrayList<AuthorizationRule>();
         userAccessor = aAccessor;
-        name = aName;
     }
 
     /**
@@ -82,7 +77,6 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
     public DefaultAuthorizationService() {
         rules = new ArrayList<AuthorizationRule>();
         userAccessor = null;
-        name = null;
     }
 
     /**
@@ -133,14 +127,6 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
         return aResource;
     }
 
-    protected String getName() {
-        return name;
-    }
-
-    public void setName(String aName) {
-        name = aName;
-    }
-
     /*
      * (non-Javadoc)
      * 
index 17bdc348ae8263b97c7ca000d6da2b0414ebe476..e782a18e5c3c09485c6cc606be9aa1b6d3d885ec 100644 (file)
@@ -26,6 +26,7 @@ import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
 import javax.persistence.Transient;
 
 import org.apache.log4j.Logger;
@@ -264,7 +265,7 @@ public abstract class UrlAuthorizationRule extends AbstractAuthorizationRule {
      * 
      * @return Returns the operationCondition.
      */
-    @ManyToOne(cascade = CascadeType.ALL, targetEntity = AbstractOperationCondition.class)
+    @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractOperationCondition.class, orphanRemoval = true)
     @JoinColumn(name = "OPER_COND_PK")
     public OperationCondition getOperationCondition() {
         return operationCondition;
@@ -283,7 +284,7 @@ public abstract class UrlAuthorizationRule extends AbstractAuthorizationRule {
      * 
      * @return Returns the pathCondition.
      */
-    @ManyToOne(cascade = CascadeType.ALL, targetEntity = AbstractPathCondition.class)
+    @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractPathCondition.class, orphanRemoval = true)
     @JoinColumn(name = "PATH_COND_PK")
     public PathCondition getPathCondition() {
         return pathCondition;
@@ -302,7 +303,7 @@ public abstract class UrlAuthorizationRule extends AbstractAuthorizationRule {
      * 
      * @return Returns the userCondition.
      */
-    @ManyToOne(cascade = CascadeType.ALL, targetEntity = AbstractUserCondition.class)
+    @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractUserCondition.class, orphanRemoval = true)
     @JoinColumn(name = "USER_COND_PK")
     public UserCondition getUserCondition() {
         return userCondition;
index e1b71d7dd177c8a940f8c9119630294871dcfb50..57d29636c06cb261cb4d2e5e175b7706a37d4add 100644 (file)
@@ -100,16 +100,17 @@ public class JpaAuthorizationService implements AuthorizationService {
      */
     private void initialize() {
         if (service == null) {
-            refreshByReload();
+            service = refreshByReload();
         }
     }
 
-    private void refreshByReload() {
+    private AuthorizationService refreshByReload() {
+        AuthorizationService service; 
         try {
             service = entityManager.createNamedQuery(
                 AbstractAuthorizationService.QUERY_FIND_BY_NAME,
                 AbstractAuthorizationService.class).setParameter(
-                    AbstractAuthorizationService.NAME_PARAM, name).getSingleResult();
+                    DefaultAuthorizationService.NAME_PARAM, name).getSingleResult();
             service.setUserAccessor(userAccessor);
         } catch (NonUniqueResultException e) {
             throw new IllegalArgumentException(
@@ -118,6 +119,7 @@ public class JpaAuthorizationService implements AuthorizationService {
             service = new DefaultAuthorizationService(userAccessor, name);
             entityManager.persist(service);
         }
+        return service;
     }
 
     /*
@@ -170,7 +172,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.appendRule(aRule);
-        save();
+        save(); // service might still be detached as service is cached. 
     }
 
     /*
@@ -183,7 +185,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.removeRule(aIndex);
-        save();
+        save(); // service might still be detached as service is cached. 
     }
 
     /*
@@ -197,7 +199,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.insertRuleAfter(aIndex, aRule);
-        save();
+        save(); // service might still be detached as service is cached.
     }
 
     /**
@@ -207,7 +209,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         long time = System.currentTimeMillis();
 
         if ((time - lastRefreshTime) > refreshInterval) {
-            refreshByReload();
+            service = refreshByReload();
             lastRefreshTime = time;
         }
     }
index 7462507a149bf9531926dcfb16f9ecba29b6a3d0..0e1c545394a7d0031c067c8f8fcf92d9a7a7f9eb 100644 (file)
@@ -47,7 +47,7 @@ import org.wamblee.usermgt.UserMgtException.Reason;
         User.NAME_PARAM),
     @NamedQuery(name = User.QUERY_FIND_BY_GROUP_NAME, query = "select user from User user join user.groups grp where grp.name = :name"),
     @NamedQuery(name = User.QUERY_COUNT_USERS, query = "select count(u) from User u"),
-    @NamedQuery(name = User.QUERY_ALL_USERS, query = "select u from User u")})
+    @NamedQuery(name = User.QUERY_ALL_USERS, query = "select u from User u") })
 public class User implements Serializable, Comparable {
 
     public static final String QUERY_FIND_BY_NAME = "User.findByName";
@@ -119,7 +119,7 @@ public class User implements Serializable, Comparable {
      * 
      */
     public User(User aUser) {
-        primaryKey  = aUser.primaryKey;
+        primaryKey = aUser.primaryKey;
         version = aUser.version;
         name = aUser.name;
         password = aUser.password;
@@ -356,6 +356,9 @@ public class User implements Serializable, Comparable {
      */
     @Override
     public boolean equals(Object aUser) {
+        if (aUser == null) {
+            return false;
+        }
         if (!(aUser instanceof User)) {
             return false;
         }
index 6866d45416a6e93f9eb4b9abfff262d62ff14d66..3dc00e06838e709b36a2e7af914d31d24aadda87 100644 (file)
@@ -12,7 +12,7 @@
  * 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.wamblee.usermgt;
 
 import static org.wamblee.usermgt.UserMgtException.Reason.DUPLICATE_GROUP;
@@ -22,6 +22,7 @@ import static org.wamblee.usermgt.UserMgtException.Reason.TRIVIAL_RENAME;
 import static org.wamblee.usermgt.UserMgtException.Reason.UNKNOWN_GROUP;
 import static org.wamblee.usermgt.UserMgtException.Reason.UNKNOWN_USER;
 
+import java.util.HashSet;
 import java.util.Set;
 
 /**
@@ -125,7 +126,11 @@ public class UserAdministrationImpl implements UserAdministration {
      * @see org.wamblee.usermgt.UserAdministration#getUser(java.lang.String)
      */
     public User getUser(String aName) {
-        return users.find(aName);
+        User user = users.find(aName);
+        if (user == null) {
+            return user;
+        }
+        return new User(user);
     }
 
     /*
@@ -134,7 +139,11 @@ public class UserAdministrationImpl implements UserAdministration {
      * @see org.wamblee.usermgt.UserAdministration#getGroup(java.lang.String)
      */
     public Group getGroup(String aName) {
-        return groups.find(aName);
+        Group group = groups.find(aName);
+        if ( group == null ) {
+            return group;
+        }
+        return new Group(group);
     }
 
     /*
@@ -143,7 +152,11 @@ public class UserAdministrationImpl implements UserAdministration {
      * @see org.wamblee.usermgt.UserAdministration#getUsers()
      */
     public Set<User> getUsers() {
-        return users.list();
+        Set<User> res = new HashSet<User>(); 
+        for (User user: users.list()) { 
+            res.add(new User(user));
+        }
+        return res; 
     }
 
     /*
@@ -154,7 +167,11 @@ public class UserAdministrationImpl implements UserAdministration {
      * )
      */
     public Set<User> getUsers(Group aGroup) {
-        return users.list(aGroup);
+        Set<User> res = new HashSet<User>(); 
+        for (User user: users.list(aGroup)) { 
+            res.add(new User(user));
+        }
+        return res;
     }
 
     /*
@@ -163,7 +180,11 @@ public class UserAdministrationImpl implements UserAdministration {
      * @see org.wamblee.usermgt.UserAdministration#getGroups()
      */
     public Set<Group> getGroups() {
-        return groups.list();
+        Set<Group> res = new HashSet<Group>(); 
+        for (Group group: groups.list()) { 
+            res.add(new Group(group));
+        }
+        return res; 
     }
 
     /*
@@ -215,7 +236,7 @@ public class UserAdministrationImpl implements UserAdministration {
         }
 
         userValidator.validate(aUserName);
-  
+
         aUser.setName(aUserName);
         users.userModified(aUser);
     }
@@ -240,7 +261,7 @@ public class UserAdministrationImpl implements UserAdministration {
         }
 
         groupValidator.validate(aGroupName);
-      
+
         aGroup.setName(aGroupName);
         groups.groupModified(aGroup);
     }
index 2150b43a653f05d2ad5cc5946ed7af2ea3407432..a9d579e2b89a76561a319058cb9f168e780124bd 100644 (file)
@@ -46,6 +46,7 @@ public class JpaGroupSet implements GroupSet {
             return false;
         }
         em.persist(aGroup);
+        em.flush(); // to make sure the version is updated. 
         return true;
     }
 
index 045eda00623141e7d7489b7ed32cd8f1f6cc3dee..12a5dabfa17692bc85ca115722b7e92af60a9456 100644 (file)
@@ -124,6 +124,7 @@ public class JpaUserSet extends AbstractUserSet {
         }
 
         entityManager.persist(aUser);
+        entityManager.flush(); // to make sure the version is updated. 
         setPasswordInfo(aUser);
         cache.put(aUser.getName(), aUser);
 
@@ -159,7 +160,7 @@ public class JpaUserSet extends AbstractUserSet {
 
         for (User user : list) {
             setPasswordInfo(user);
-            users.add(new User(user));
+            users.add(user);
         }
 
         return users;
@@ -177,10 +178,9 @@ public class JpaUserSet extends AbstractUserSet {
         query.setParameter(User.NAME_PARAM, aGroup.getName());
         
         List<User> list = query.getResultList();
-
-        for (User user : list) {
+        users.addAll(list);
+        for (User user : users) {
             setPasswordInfo(user);
-            users.add(new User(user));
         }
 
         return users;
index 8be34f9da74d5204f4c5275984f5be6a77161f8d..8b1f1e1521b216e0b8db1697921b28fd463757fa 100644 (file)
@@ -56,6 +56,7 @@ public class AuthorizationServiceTest extends TestCase {
         service.appendRule(rule1);
         service.appendRule(rule2);
         service.appendRule(rule3);
+        checkRuleCount(3);
     }
 
     protected void resetTestRules() {
index 83b96e8f16914036364e0ba3d1738cd6bc8e9319..6fc29ff0550e9308b2b1809cf4451c9de86f1571 100644 (file)
@@ -1,64 +1,87 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-  <parent>
+    <parent>
+        <groupId>org.wamblee</groupId>
+        <artifactId>wamblee-utils</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
     <groupId>org.wamblee</groupId>
-    <artifactId>wamblee-utils</artifactId>
-    <version>0.2.3-SNAPSHOT</version>
-  </parent>
+    <artifactId>wamblee-security-jpatest</artifactId>
+    <packaging>jar</packaging>
+    <name>/security/jpatest</name>
+    <url>http://wamblee.org</url>
+    <dependencies>
 
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.wamblee</groupId>
-  <artifactId>wamblee-security-jpatest</artifactId>
-  <packaging>jar</packaging>
-  <name>/security/jpatest</name>
-  <url>http://wamblee.org</url>
-  <dependencies>
+        <dependency>
+            <groupId>org.wamblee</groupId>
+            <artifactId>wamblee-security-impl</artifactId>
+            <version>0.2.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wamblee</groupId>
+            <artifactId>wamblee-security-impl</artifactId>
+            <version>0.2.3-SNAPSHOT</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
 
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-entitymanager</artifactId>
-      <version>3.5.0-Final</version>
-      <exclusions>
-        <exclusion>
-          <groupId>javax.transaction</groupId>
-          <artifactId>jta</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-security-impl</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-security-impl</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-      <type>test-jar</type>
-      <scope>test</scope>
-    </dependency>
-   
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-test-enterprise</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-test-hibernate</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-      <scope>test</scope>
-    </dependency>
-  
-  </dependencies>
+        <dependency>
+            <groupId>org.wamblee</groupId>
+            <artifactId>wamblee-test-enterprise</artifactId>
+            <version>0.2.3-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
 
-  <repositories>
-    <repository>
-      <id>jboss</id>
-      <name>JBoss Repo</name>
-      <url>http://repository.jboss.org/maven2</url>
-    </repository>
-  </repositories>
+    </dependencies>
+    <profiles>
+        <profile>
+            <id>eclipselink</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.wamblee</groupId>
+                    <artifactId>wamblee-test-eclipselink</artifactId>
+                    <version>0.2.3-SNAPSHOT</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+            <repositories>
+                <repository>
+                    <id>jboss</id>
+                    <name>JBoss Repo</name>
+                    <url>http://repository.jboss.org/maven2</url>
+                </repository>
+            </repositories>        
+        </profile>
+        <profile>
+            <id>hibernate</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.hibernate</groupId>
+                    <artifactId>hibernate-entitymanager</artifactId>
+                    <version>3.5.0-Final</version>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>javax.transaction</groupId>
+                            <artifactId>jta</artifactId>
+                        </exclusion>
+                    </exclusions>
+                </dependency>
+                <dependency>
+                    <groupId>org.wamblee</groupId>
+                    <artifactId>wamblee-test-hibernate</artifactId>
+                    <version>0.2.3-SNAPSHOT</version>
+                    <scope>test</scope>
+                </dependency>                
+            </dependencies>
+        </profile>
+    </profiles>
+    
 
 </project>
index 1573f4734b52efed34dc344ec45739e323c81201..d67e09c4fd3975d5c314077af04a41ad85b37f56 100644 (file)
  */
 package org.wamblee.security.authorization.jpa;
 
+import static org.wamblee.security.authorization.AuthorizationResult.*;
+
 import javax.persistence.EntityManager;
 
 import org.apache.log4j.Logger;
-import org.wamblee.security.authorization.AbstractAuthorizationService;
 import org.wamblee.security.authorization.AllOperation;
-import org.wamblee.security.authorization.AuthorizationResult;
+import org.wamblee.security.authorization.AuthorizationRule;
 import org.wamblee.security.authorization.AuthorizationService;
 import org.wamblee.security.authorization.AuthorizationServiceTest;
-import org.wamblee.security.authorization.TestAuthorizationRule;
+import org.wamblee.security.authorization.DefaultAuthorizationService;
 import org.wamblee.support.persistence.JpaTester;
 import org.wamblee.support.persistence.TransactionProxyFactory;
 import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
@@ -62,6 +63,12 @@ public class JpaAuthorizationServiceTest extends AuthorizationServiceTest {
         super.setUp();
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        jpaTester.stop();
+        super.tearDown();
+    }
+
     /*
      * (non-Javadoc)
      * 
index a0c0eb1a4d87af121f473e2e7e399dfa5195dcee..e823d94474606d8a3c3a7a4bd55f6823ccd8963b 100644 (file)
@@ -20,6 +20,7 @@ import java.sql.Connection;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.junit.Ignore;
 import org.wamblee.cache.EhCache;
 import org.wamblee.io.ClassPathResource;
 import org.wamblee.security.encryption.Md5HexMessageDigester;
@@ -105,7 +106,7 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
     protected UserAdministration createAdmin() {
         return userAdmin;
     }
-
+    
     public void testAllTestsInASeparateTransaction() throws Exception {
         Method[] methods = UserAdministrationImplTest.class.getMethods();
 
index 23c6f5f7593a73d31c87fe58139e0668f694fb62..bfb2dda58d3cbeb6ef12e1c454a95a2c11473cf8 100644 (file)
@@ -1,56 +1,63 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <parent>
-    <groupId>org.wamblee</groupId>
-    <artifactId>wamblee-utils</artifactId>
-    <version>0.2.3-SNAPSHOT</version>
-  </parent>
-
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.wamblee</groupId>
-  <artifactId>wamblee-test-eclipselink</artifactId>
-  <packaging>jar</packaging>
-  <name>/test/eclipselink</name>
-  <url>http://wamblee.org</url>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-test-enterprise</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.wamblee</groupId>
-      <artifactId>wamblee-test-enterprise</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
-      <type>test-jar</type>
-    </dependency>
-
-    <dependency>
-      <groupId>org.dbunit</groupId>
-      <artifactId>dbunit</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>javax.persistence</groupId>
-      <artifactId>persistence-api</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.persistence</groupId>
-      <artifactId>eclipselink</artifactId>
-    </dependency>
-
-  </dependencies>
-
-   <repositories>
-        <repository>
-            <id>EclipseLink Repo</id>
-            <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
-        </repository>
-
-    </repositories>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+       <parent>
+               <groupId>org.wamblee</groupId>
+               <artifactId>wamblee-utils</artifactId>
+               <version>0.2.3-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.wamblee</groupId>
+       <artifactId>wamblee-test-eclipselink</artifactId>
+       <packaging>jar</packaging>
+       <name>/test/eclipselink</name>
+       <url>http://wamblee.org</url>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.wamblee</groupId>
+                       <artifactId>wamblee-test-enterprise</artifactId>
+                       <version>0.2.3-SNAPSHOT</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.wamblee</groupId>
+                       <artifactId>wamblee-test-enterprise</artifactId>
+                       <version>0.2.3-SNAPSHOT</version>
+                       <type>test-jar</type>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.dbunit</groupId>
+                       <artifactId>dbunit</artifactId>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.eclipse.persistence</groupId>
+                       <artifactId>javax.persistence</artifactId>
+                       <version>2.0.0</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>javax.persistence</groupId>
+                       <artifactId>persistence-api</artifactId>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.eclipse.persistence</groupId>
+                       <artifactId>eclipselink</artifactId>
+               </dependency>
+
+       </dependencies>
+
+       <repositories>
+               <repository>
+                       <id>EclipseLink Repo</id>
+                       <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
+               </repository>
+
+       </repositories>
 
 
 </project>
index 368629659dfa4da9c94bfe51be90435911401adc..97df5de99d879efa241c57317c50d172e9491e41 100644 (file)
@@ -44,6 +44,9 @@ public class EclipselinkJpaCustomizer implements JpaCustomizer {
 
         // DDL generation for toplink
         aJpaProperties.put("eclipselink.ddl-generation", "create-tables");
+        
+        // Use JTA transaction type
+        aJpaProperties.put("javax.persistence.transactionType", "JTA");
     }
 
     @Override
index 4db8a1126f4a3358e3d3aacf20af7f59740d9d94..5300a8b6a5f230ca84ea375b28dcedd03723b50a 100644 (file)
@@ -12,7 +12,7 @@
  * 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.wamblee.support.jndi;
 
 import java.util.HashMap;
@@ -20,6 +20,7 @@ import java.util.Map;
 
 import javax.naming.InitialContext;
 import javax.naming.Name;
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 
 public class StubInitialContext extends InitialContext {
@@ -36,11 +37,19 @@ public class StubInitialContext extends InitialContext {
 
     @Override
     public Object lookup(String aName) throws NamingException {
-        return bindings.get(aName);
+        Object value = bindings.get(aName);
+        if (value == null) {
+            throw new NameNotFoundException(aName);
+        }
+        return value;
     }
 
     @Override
     public Object lookup(Name aName) throws NamingException {
-        return super.lookup(aName.toString());
+        Object value = super.lookup(aName.toString());
+        if (value == null) {
+            throw new NameNotFoundException(aName.toString());
+        }
+        return value;
     }
 }
index 4d1921f5abf5a7c8f7d06d5bbd0f1824f4f96b02..d3b7e179f9e0d56ffe781c7c482e1d8f0470365b 100644 (file)
@@ -12,7 +12,7 @@
  * 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.wamblee.support.persistence;
 
 import java.util.Map;
@@ -26,6 +26,7 @@ import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
 import javax.sql.DataSource;
 
 import org.wamblee.support.jndi.StubInitialContextFactory;
@@ -93,12 +94,17 @@ public class JpaBuilder {
             throw new RuntimeException("JNDI problem", e);
         }
         factory = createFactory();
-        execute(new JpaUnitOfWork<Void>() {
-            public Void execute(EntityManager aEm) {
-                // Empty, just to trigger database schema creation.
-                return null;
-            }
-        });
+        try {
+            execute(new JpaUnitOfWork<Void>() {
+                public Void execute(EntityManager aEm) {
+                    // Empty, just to trigger database schema creation.
+                    return null;
+                }
+            });
+        } catch (PersistenceException e) {
+            factory.close();
+            throw e;
+        }
     }
 
     /**
index 26fe6a54885740cc2a633047a5a974311579985b..f9be8e4771939607c26806e1680601e3eadde277 100644 (file)
@@ -44,6 +44,9 @@ public class ToplinkJpaCustomizer implements JpaCustomizer {
 
         // DDL generation for toplink
         aJpaProperties.put("toplink.ddl-generation", "create-tables");
+        
+        // Use JTA transaction type
+        aJpaProperties.put("javax.persistence.transactionType", "JTA");
     }
 
     @Override