(no commit message)
authorErik Brakkee <erik@brakkee.org>
Sun, 4 Apr 2010 20:15:11 +0000 (20:15 +0000)
committerErik Brakkee <erik@brakkee.org>
Sun, 4 Apr 2010 20:15:11 +0000 (20:15 +0000)
15 files changed:
support/test/eclipselink/pom.xml [new file with mode: 0644]
support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java [new file with mode: 0644]
support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkTables.java [new file with mode: 0644]
support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/JndiSessionCustomizer.java [new file with mode: 0644]
support/test/eclipselink/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer [new file with mode: 0644]
support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/DatabaseUtilsTest.java [new file with mode: 0644]
support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/MyEntityExampleTest.java [new file with mode: 0644]
support/test/pom.xml
support/test/toplink-essentials/pom.xml [new file with mode: 0644]
support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/JndiSessionCustomizer.java [new file with mode: 0644]
support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java [new file with mode: 0644]
support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkTables.java [new file with mode: 0644]
support/test/toplink-essentials/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer [new file with mode: 0644]
support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/DatabaseUtilsTest.java [new file with mode: 0644]
support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/MyEntityExampleTest.java [new file with mode: 0644]

diff --git a/support/test/eclipselink/pom.xml b/support/test/eclipselink/pom.xml
new file mode 100644 (file)
index 0000000..271d05a
--- /dev/null
@@ -0,0 +1,49 @@
+<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-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.wamblee</groupId>
+  <artifactId>wamblee-support-test-eclipselink</artifactId>
+  <packaging>jar</packaging>
+  <name>/support/test/eclipselink</name>
+  <url>http://wamblee.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-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>
+
+</project>
diff --git a/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java b/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkJpaCustomizer.java
new file mode 100644 (file)
index 0000000..856b051
--- /dev/null
@@ -0,0 +1,30 @@
+package org.wamblee.support.persistence.eclipselink;
+
+import java.util.Map;
+
+import org.dbunit.dataset.filter.ITableFilterSimple;
+import org.wamblee.support.persistence.JpaCustomizer;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
+
+public class EclipselinkJpaCustomizer implements JpaCustomizer {
+
+    public EclipselinkJpaCustomizer() { 
+        // Empty
+    }
+    
+    @Override
+    public void customize(PersistenceUnitDescription aPersistenceUnit, Map<String, String> aJpaProperties) {
+        // Hack to make JNDI lookup of the datasource work with toplink
+        aJpaProperties.put("eclipselink.session.customizer", JndiSessionCustomizer.class
+                .getName());
+        
+        // DDL generation for toplink
+        aJpaProperties.put("eclipselink.ddl-generation", "create-tables");   
+    }
+    
+    @Override
+    public ITableFilterSimple getJpaTables() {
+        return new EclipselinkTables();
+    }
+
+}
diff --git a/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkTables.java b/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/EclipselinkTables.java
new file mode 100644 (file)
index 0000000..d4df0dd
--- /dev/null
@@ -0,0 +1,20 @@
+package org.wamblee.support.persistence.eclipselink;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.filter.ITableFilterSimple;
+
+/**
+ * Toplink-specific tables. 
+ */
+public class EclipselinkTables implements ITableFilterSimple {
+
+       private static final List<String> TABLES = Arrays.asList(new String[] { "SEQUENCE" } );
+       
+       public boolean accept(String aTableName) throws DataSetException {
+               return TABLES.contains(aTableName);
+       }
+
+}
diff --git a/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/JndiSessionCustomizer.java b/support/test/eclipselink/src/main/java/org/wamblee/support/persistence/eclipselink/JndiSessionCustomizer.java
new file mode 100644 (file)
index 0000000..9b856f0
--- /dev/null
@@ -0,0 +1,59 @@
+package org.wamblee.support.persistence.eclipselink;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.eclipse.persistence.config.SessionCustomizer;
+import org.eclipse.persistence.sessions.DatabaseLogin;
+import org.eclipse.persistence.sessions.JNDIConnector;
+import org.eclipse.persistence.sessions.Session;
+import org.eclipse.persistence.sessions.server.ServerSession;
+/**
+ * See http://wiki.eclipse.org/Customizing_the_EclipseLink_Application_(ELUG) Use for clients that would like to use a
+ * JTA SE pu instead of a RESOURCE_LOCAL SE pu.
+ * 
+ * This utility also makes sure that using a persistence.xml with a JTA datasource works in a standalone Java SE 
+ * environment together with our JNDI stub. 
+ */
+public class JndiSessionCustomizer
+    implements SessionCustomizer {
+       
+       public JndiSessionCustomizer() {
+               // Empty.
+       }
+  /**
+   * Get a dataSource connection and set it on the session with lookupType=STRING_LOOKUP
+   */
+  public void customize(Session session) throws Exception {
+    JNDIConnector connector = null;
+    Context context = null;
+    try {
+      context = new InitialContext();
+      if(null != context) {
+        connector = (JNDIConnector)session.getLogin().getConnector(); // possible CCE
+        // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
+        // Note: if both jta and non-jta elements exist this will only change the first one - and may still result in
+        // the COMPOSITE_NAME_LOOKUP being set
+        // Make sure only jta-data-source is in persistence.xml with no non-jta-data-source property set
+        connector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        // Or, if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe
+        JNDIConnector writeConnector = (JNDIConnector)session.getLogin().getConnector();
+        writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        JNDIConnector readConnector =
+            (JNDIConnector)((DatabaseLogin)((ServerSession)session).getReadConnectionPool().getLogin()).getConnector();
+        readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        System.out.println("JndiSessionCustomizer: configured " + connector.getName());
+      }
+      else {
+        throw new Exception("JndiSessionCustomizer: Context is null");
+      }
+    }
+    catch(Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
\ No newline at end of file
diff --git a/support/test/eclipselink/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer b/support/test/eclipselink/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer
new file mode 100644 (file)
index 0000000..35638de
--- /dev/null
@@ -0,0 +1 @@
+org.wamblee.support.persistence.eclipselink.EclipselinkJpaCustomizer
diff --git a/support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/DatabaseUtilsTest.java b/support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/DatabaseUtilsTest.java
new file mode 100644 (file)
index 0000000..870e20a
--- /dev/null
@@ -0,0 +1,23 @@
+package org.wamblee.support.persistence.eclipselink;
+
+import static junit.framework.Assert.assertEquals;
+
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+
+import org.dbunit.IDatabaseTester;
+import org.dbunit.dataset.ITable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.support.persistence.Database;
+import org.wamblee.support.persistence.DatabaseBuilder;
+import org.wamblee.support.persistence.DatabaseUtils;
+import org.wamblee.support.persistence.DatabaseUtilsTestBase;
+import org.wamblee.support.persistence.JpaBuilder;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
+import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
+
+public class DatabaseUtilsTest extends DatabaseUtilsTestBase {
+   // Empty, all tests inherited
+}
diff --git a/support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/MyEntityExampleTest.java b/support/test/eclipselink/src/test/java/org/wamblee/support/persistence/eclipselink/MyEntityExampleTest.java
new file mode 100644 (file)
index 0000000..84c3fff
--- /dev/null
@@ -0,0 +1,29 @@
+package org.wamblee.support.persistence.eclipselink;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+import javax.sql.DataSource;
+
+import org.dbunit.DataSourceDatabaseTester;
+import org.dbunit.DatabaseTestCase;
+import org.dbunit.IDatabaseTester;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.filter.ITableFilterSimple;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.support.persistence.DatabaseUtils;
+import org.wamblee.support.persistence.JpaBuilder;
+import org.wamblee.support.persistence.JpaTester;
+import org.wamblee.support.persistence.MyEntityExampleTestBase;
+import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
+
+import static junit.framework.Assert.*;
+
+
+/**
+ * This class shows an example of how to test an entity  using jpa. 
+ */
+public class MyEntityExampleTest extends MyEntityExampleTestBase {
+    // Empty, all tests are inherited
+}
index 0952eee7c41708939f7fdeb61aad6af62ca1f495..1a2617fc17019d4584d394d14a8b14406acec8e2 100644 (file)
@@ -18,5 +18,7 @@
   <modules>
     <module>enterprise</module>
     <module>hibernate</module>
+       <module>eclipselink</module>
+       <module>toplink-essentials</module>
   </modules>
 </project>
diff --git a/support/test/toplink-essentials/pom.xml b/support/test/toplink-essentials/pom.xml
new file mode 100644 (file)
index 0000000..07af926
--- /dev/null
@@ -0,0 +1,50 @@
+<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-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.wamblee</groupId>
+  <artifactId>wamblee-support-test-toplink-essentials</artifactId>
+  <packaging>jar</packaging>
+  <name>/support/test/toplinkessentials</name>
+  <url>http://wamblee.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.wamblee</groupId>
+      <artifactId>wamblee-support-test-enterprise</artifactId>
+      <version>0.2-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>toplink.essentials</groupId>
+      <artifactId>toplink-essentials</artifactId>
+    </dependency>
+
+
+  </dependencies>
+
+</project>
diff --git a/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/JndiSessionCustomizer.java b/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/JndiSessionCustomizer.java
new file mode 100644 (file)
index 0000000..814fe59
--- /dev/null
@@ -0,0 +1,59 @@
+package org.wamblee.support.persistence.toplink;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import oracle.toplink.essentials.jndi.JNDIConnector;
+import oracle.toplink.essentials.sessions.DatabaseLogin;
+import oracle.toplink.essentials.sessions.Session;
+import oracle.toplink.essentials.threetier.ServerSession;
+import oracle.toplink.essentials.tools.sessionconfiguration.SessionCustomizer;
+/**
+ * See http://wiki.eclipse.org/Customizing_the_EclipseLink_Application_(ELUG) Use for clients that would like to use a
+ * JTA SE pu instead of a RESOURCE_LOCAL SE pu.
+ * 
+ * This utility also makes sure that using a persistence.xml with a JTA datasource works in a standalone Java SE 
+ * environment together with our JNDI stub. 
+ */
+public class JndiSessionCustomizer
+    implements SessionCustomizer {
+       
+       public JndiSessionCustomizer() {
+               // Empty.
+       }
+  /**
+   * Get a dataSource connection and set it on the session with lookupType=STRING_LOOKUP
+   */
+  public void customize(Session session) throws Exception {
+    JNDIConnector connector = null;
+    Context context = null;
+    try {
+      context = new InitialContext();
+      if(null != context) {
+        connector = (JNDIConnector)session.getLogin().getConnector(); // possible CCE
+        // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
+        // Note: if both jta and non-jta elements exist this will only change the first one - and may still result in
+        // the COMPOSITE_NAME_LOOKUP being set
+        // Make sure only jta-data-source is in persistence.xml with no non-jta-data-source property set
+        connector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        // Or, if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe
+        JNDIConnector writeConnector = (JNDIConnector)session.getLogin().getConnector();
+        writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        JNDIConnector readConnector =
+            (JNDIConnector)((DatabaseLogin)((ServerSession)session).getReadConnectionPool().getLogin()).getConnector();
+        readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+        System.out.println("JndiSessionCustomizer: configured " + connector.getName());
+      }
+      else {
+        throw new Exception("JndiSessionCustomizer: Context is null");
+      }
+    }
+    catch(Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
\ No newline at end of file
diff --git a/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java b/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkJpaCustomizer.java
new file mode 100644 (file)
index 0000000..5ba15e8
--- /dev/null
@@ -0,0 +1,30 @@
+package org.wamblee.support.persistence.toplink;
+
+import java.util.Map;
+
+import org.dbunit.dataset.filter.ITableFilterSimple;
+import org.wamblee.support.persistence.JpaCustomizer;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
+
+public class ToplinkJpaCustomizer implements JpaCustomizer {
+
+    public ToplinkJpaCustomizer() { 
+        // Empty
+    }
+    
+    @Override
+    public void customize(PersistenceUnitDescription aPersistenceUnit, Map<String, String> aJpaProperties) {
+        // Hack to make JNDI lookup of the datasource work with toplink
+        aJpaProperties.put("toplink.session.customizer", JndiSessionCustomizer.class
+                .getName());
+        
+        // DDL generation for toplink
+        aJpaProperties.put("toplink.ddl-generation", "create-tables");   
+    }
+    
+    @Override
+    public ITableFilterSimple getJpaTables() {
+        return new ToplinkTables();
+    }
+
+}
diff --git a/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkTables.java b/support/test/toplink-essentials/src/main/java/org/wamblee/support/persistence/toplink/ToplinkTables.java
new file mode 100644 (file)
index 0000000..cd3a056
--- /dev/null
@@ -0,0 +1,20 @@
+package org.wamblee.support.persistence.toplink;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.filter.ITableFilterSimple;
+
+/**
+ * Toplink-specific tables. 
+ */
+public class ToplinkTables implements ITableFilterSimple {
+
+       private static final List<String> TABLES = Arrays.asList(new String[] { "SEQUENCE" } );
+       
+       public boolean accept(String aTableName) throws DataSetException {
+               return TABLES.contains(aTableName);
+       }
+
+}
diff --git a/support/test/toplink-essentials/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer b/support/test/toplink-essentials/src/main/resources/META-INF/services/org.wamblee.support.persistence.JpaCustomizer
new file mode 100644 (file)
index 0000000..82d1265
--- /dev/null
@@ -0,0 +1 @@
+org.wamblee.support.persistence.toplink.ToplinkJpaCustomizer
diff --git a/support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/DatabaseUtilsTest.java b/support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/DatabaseUtilsTest.java
new file mode 100644 (file)
index 0000000..095109d
--- /dev/null
@@ -0,0 +1,23 @@
+package org.wamblee.support.persistence.toplink;
+
+import static junit.framework.Assert.assertEquals;
+
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+
+import org.dbunit.IDatabaseTester;
+import org.dbunit.dataset.ITable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.support.persistence.Database;
+import org.wamblee.support.persistence.DatabaseBuilder;
+import org.wamblee.support.persistence.DatabaseUtils;
+import org.wamblee.support.persistence.DatabaseUtilsTestBase;
+import org.wamblee.support.persistence.JpaBuilder;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
+import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
+
+public class DatabaseUtilsTest extends DatabaseUtilsTestBase {
+   // Empty, all tests inherited
+}
diff --git a/support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/MyEntityExampleTest.java b/support/test/toplink-essentials/src/test/java/org/wamblee/support/persistence/toplink/MyEntityExampleTest.java
new file mode 100644 (file)
index 0000000..415ee70
--- /dev/null
@@ -0,0 +1,29 @@
+package org.wamblee.support.persistence.toplink;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+import javax.sql.DataSource;
+
+import org.dbunit.DataSourceDatabaseTester;
+import org.dbunit.DatabaseTestCase;
+import org.dbunit.IDatabaseTester;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.filter.ITableFilterSimple;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.support.persistence.DatabaseUtils;
+import org.wamblee.support.persistence.JpaBuilder;
+import org.wamblee.support.persistence.JpaTester;
+import org.wamblee.support.persistence.MyEntityExampleTestBase;
+import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
+
+import static junit.framework.Assert.*;
+
+
+/**
+ * This class shows an example of how to test an entity  using jpa. 
+ */
+public class MyEntityExampleTest extends MyEntityExampleTestBase {
+    // Empty, all tests are inherited
+}