[jboss-cvs] JBossAS SVN: r78234 - in projects/jpa/trunk: sandbox and 20 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 9 05:10:59 EDT 2008
Author: wolfc
Date: 2008-09-09 05:10:59 -0400 (Tue, 09 Sep 2008)
New Revision: 78234
Added:
projects/jpa/trunk/sandbox/
projects/jpa/trunk/sandbox/.classpath
projects/jpa/trunk/sandbox/.project
projects/jpa/trunk/sandbox/.settings/
projects/jpa/trunk/sandbox/.settings/org.eclipse.jdt.core.prefs
projects/jpa/trunk/sandbox/.settings/org.maven.ide.eclipse.prefs
projects/jpa/trunk/sandbox/pom.xml
projects/jpa/trunk/sandbox/src/
projects/jpa/trunk/sandbox/src/main/
projects/jpa/trunk/sandbox/src/main/java/
projects/jpa/trunk/sandbox/src/main/java/org/
projects/jpa/trunk/sandbox/src/main/java/org/jboss/
projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/
projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/
projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/remote/
projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/remote/RemotelyInjectEntityManagerFactory.java
projects/jpa/trunk/sandbox/src/test/
projects/jpa/trunk/sandbox/src/test/java/
projects/jpa/trunk/sandbox/src/test/java/org/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/common/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/common/DerbyService.java
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/Person.java
projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/RemoteTestCase.java
projects/jpa/trunk/sandbox/src/test/resources/
projects/jpa/trunk/sandbox/src/test/resources/META-INF/
projects/jpa/trunk/sandbox/src/test/resources/META-INF/persistence.xml
projects/jpa/trunk/sandbox/src/test/resources/jndi.properties
projects/jpa/trunk/sandbox/src/test/resources/log4j.xml
Log:
A remote entity manager factory
Property changes on: projects/jpa/trunk/sandbox
___________________________________________________________________
Name: svn:ignore
+ eclipse-target
target
Added: projects/jpa/trunk/sandbox/.classpath
===================================================================
--- projects/jpa/trunk/sandbox/.classpath (rev 0)
+++ projects/jpa/trunk/sandbox/.classpath 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,8 @@
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+</classpath>
\ No newline at end of file
Added: projects/jpa/trunk/sandbox/.project
===================================================================
--- projects/jpa/trunk/sandbox/.project (rev 0)
+++ projects/jpa/trunk/sandbox/.project 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,17 @@
+<projectDescription>
+ <name>jboss-jpa-sandbox</name>
+ <comment>The playground.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: projects/jpa/trunk/sandbox/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jpa/trunk/sandbox/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ projects/jpa/trunk/sandbox/.settings/org.eclipse.jdt.core.prefs 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,5 @@
+#Tue Sep 09 09:30:48 CEST 2008
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
Added: projects/jpa/trunk/sandbox/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/jpa/trunk/sandbox/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ projects/jpa/trunk/sandbox/.settings/org.maven.ide.eclipse.prefs 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,8 @@
+#Tue Sep 09 09:50:07 CEST 2008
+activeProfiles=eclipse
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+version=1
Added: projects/jpa/trunk/sandbox/pom.xml
===================================================================
--- projects/jpa/trunk/sandbox/pom.xml (rev 0)
+++ projects/jpa/trunk/sandbox/pom.xml 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,106 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<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.jboss.jpa</groupId>
+ <artifactId>jboss-jpa-build</artifactId>
+ <relativePath>../build/pom.xml</relativePath>
+ <version>0.1.1</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jboss-jpa-sandbox</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss Container Managed JPA Sandbox</name>
+ <description>
+ The playground.
+ </description>
+
+ <dependencies>
+ <!-- For 'mocking' a TransactionManager we use JBossTS -->
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjta</artifactId>
+ <version>4.3.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- For 'mocking' a DataSource we use Derby -->
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.4.1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.3.2.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-transaction-spi</artifactId>
+ <version>5.0.0.Beta4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>1.0.5.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ <version>2.0.0.Beta18</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs-spi</artifactId>
+ <version>2.0.0.Beta18</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jpa</groupId>
+ <artifactId>jboss-jpa-deployers</artifactId>
+ <version>0.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.metadata</groupId>
+ <artifactId>jboss-metadata</artifactId>
+ <version>1.0.0.Beta26</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.naming</groupId>
+ <artifactId>jnpserver</artifactId>
+ <version>5.0.0.CR1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- For Arjuna / JBoss Transaction -->
+ <dependency>
+ <groupId>apache-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.0.jboss</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>oswego-concurrent</groupId>
+ <artifactId>concurrent</artifactId>
+ <version>1.3.4-jboss-update1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ <version>4.3.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/remote/RemotelyInjectEntityManagerFactory.java
===================================================================
--- projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/remote/RemotelyInjectEntityManagerFactory.java (rev 0)
+++ projects/jpa/trunk/sandbox/src/main/java/org/jboss/jpa/sandbox/remote/RemotelyInjectEntityManagerFactory.java 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,316 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.sandbox.remote;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+
+import org.hibernate.ejb.HibernatePersistence;
+import org.jboss.jpa.deployment.PersistenceUnitInfoImpl;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.TransactionType;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemotelyInjectEntityManagerFactory implements EntityManagerFactory, Serializable
+{
+ private static final Logger log = Logger.getLogger(RemotelyInjectEntityManagerFactory.class);
+
+ private static final long serialVersionUID = 1L;
+
+ private PersistenceUnitMetaData metaData;
+
+ private EntityManagerFactory actualFactory;
+ private Properties defaultPersistenceProperties = new Properties();
+ private List<String> explicitEntityClasses = new ArrayList<String>();
+ private String jaccContextId;
+
+ /**
+ * Assume the data source name has been changed to a remote data source name.
+ */
+ public RemotelyInjectEntityManagerFactory(PersistenceUnitMetaData metaData, String jaccContextId)
+ {
+ assert metaData != null : "metaData is null";
+ this.metaData = metaData;
+ this.jaccContextId = jaccContextId;
+ }
+
+ public void close()
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ private void createEntityManagerFactory() throws Exception
+ {
+ Properties props = new Properties();
+ props.putAll(defaultPersistenceProperties);
+ props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
+
+ PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl();
+// log.debug("Using class loader " + di.getClassLoader());
+// pi.setClassLoader(di.getClassLoader());
+ pi.setClassLoader(Thread.currentThread().getContextClassLoader());
+
+ ArrayList<URL> jarFiles = new ArrayList<URL>();
+ pi.setJarFiles(jarFiles);
+ pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
+ log.debug("Found persistence.xml file in EJB3 jar");
+ props.putAll(getProperties());
+ pi.setManagedClassnames(safeList(metaData.getClasses()));
+ pi.setPersistenceUnitName(metaData.getName());
+ pi.setMappingFileNames(safeList(metaData.getMappingFiles()));
+ pi.setExcludeUnlistedClasses(metaData.isExcludeUnlistedClasses());
+ /*
+ VirtualFile root = getPersistenceUnitRoot();
+ log.debug("Persistence root: " + root);
+ // TODO - update this with VFSUtils helper method
+ // hack the JPA url
+ URL url = root.toURL();
+ // is not nested, so direct VFS URL is not an option
+ if (VFSUtils.isNestedFile(root) == false)
+ {
+ String urlString = url.toExternalForm();
+ if (urlString.startsWith("vfs"))
+ {
+ // treat vfszip as file
+ if (urlString.startsWith("vfszip"))
+ url = new URL("file" + urlString.substring(6));
+ else
+ url = new URL(urlString.substring(3)); // (vfs)file and (vfs)jar are ok
+ }
+ }
+ */
+ URL url = getPersistenceUnitRoot();
+ log.debug("Persistence root: " + url);
+ pi.setPersistenceUnitRootUrl(url);
+ PersistenceUnitTransactionType transactionType = getJPATransactionType();
+ pi.setTransactionType(transactionType);
+
+ Set<String> files = metaData.getJarFiles();
+ if (files != null)
+ {
+ for (String jar : files)
+ {
+ jarFiles.add(getRelativeURL(jar));
+ }
+ }
+
+ if (metaData.getProvider() != null) pi.setPersistenceProviderClassName(metaData.getProvider());
+ if (explicitEntityClasses.size() > 0)
+ {
+ List<String> classes = pi.getManagedClassNames();
+ if (classes == null) classes = explicitEntityClasses;
+ else classes.addAll(explicitEntityClasses);
+ pi.setManagedClassnames(classes);
+ }
+ if (metaData.getJtaDataSource() != null)
+ {
+ pi.setJtaDataSource((javax.sql.DataSource) lookup(metaData.getJtaDataSource()));
+ }
+ else if (transactionType == PersistenceUnitTransactionType.JTA)
+ {
+ throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
+ + "You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
+ }
+ if (metaData.getNonJtaDataSource() != null)
+ {
+ pi.setNonJtaDataSource((javax.sql.DataSource) lookup(metaData.getNonJtaDataSource()));
+ }
+ else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
+ {
+ throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
+ + "You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: "
+ + metaData.getName());
+ }
+ pi.setProperties(props);
+
+ if (pi.getPersistenceUnitName() == null)
+ {
+ throw new RuntimeException("you must specify a name in persistence.xml");
+ }
+
+ Class<?> providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
+
+ // EJBTHREE-893
+ /* TODO: can this work remotely?
+ if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
+ {
+ pi.getProperties().put("hibernate.session_factory_name", kernelName);
+ }
+ */
+
+ PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
+ actualFactory = pp.createContainerEntityManagerFactory(pi, null);
+ }
+
+ public EntityManager createEntityManager()
+ {
+ return actualFactory.createEntityManager();
+ }
+
+ public EntityManager createEntityManager(@SuppressWarnings("unchecked") Map map)
+ {
+ return actualFactory.createEntityManager(map);
+ }
+
+ protected String getJaccContextId()
+ {
+ //return di.getSimpleName();
+ return jaccContextId;
+ }
+
+ protected PersistenceUnitTransactionType getJPATransactionType()
+ {
+ TransactionType type = metaData.getTransactionType();
+ if (type == TransactionType.RESOURCE_LOCAL)
+ return PersistenceUnitTransactionType.RESOURCE_LOCAL;
+ else // default or actually being JTA
+ return PersistenceUnitTransactionType.JTA;
+ }
+
+ /**
+ * Find the persistence unit root, which can be the root of a jar
+ * or WEB-INF/classes of a war.
+ * @return the persistence unit root
+ */
+ protected URL getPersistenceUnitRoot() throws IOException
+ {
+ // FIXME: What is the correct way to find the persistence unit root?
+ List<URL> list = new ArrayList<URL>();
+ Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/persistence.xml");
+ while(e.hasMoreElements())
+ list.add(e.nextElement());
+ if(list.size() > 1)
+ throw new RuntimeException("Can't handle more than 1 persistence unit on the class path");
+ if(list.size() == 0)
+ throw new IllegalStateException("Can't find META-INF/persistence.xml");
+ URL url = list.get(0);
+ String spec = url.toExternalForm();
+ spec = spec.substring(0, spec.length() - "META-INF/persistence.xml".length());
+ return new URL(spec);
+ /*
+ try
+ {
+ VirtualFile metaData = di.getMetaDataFile("persistence.xml");
+ assert metaData != null : "Can't find persistence.xml in " + di;
+ return metaData.getParent().getParent();
+ }
+ catch(IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ */
+ }
+
+ protected Map<String, String> getProperties()
+ {
+ Map<String, String> properties = metaData.getProperties();
+ return (properties != null) ? properties : Collections.<String, String>emptyMap();
+ }
+
+ private URL getRelativeURL(String jar)
+ {
+ /*
+ try
+ {
+ return new URL(jar);
+ }
+ catch (MalformedURLException e)
+ {
+ try
+ {
+ URL url = di.getFile("").toURL();
+ return new URL(url, jar);
+ }
+ catch (Exception e1)
+ {
+ throw new RuntimeException("could not find relative path: " + jar, e1);
+ }
+ }
+ */
+ throw new RuntimeException("NYI");
+ }
+
+ private static Object lookup(String name) throws NamingException
+ {
+ InitialContext ctx = new InitialContext();
+ try
+ {
+ return ctx.lookup(name);
+ }
+ finally
+ {
+ ctx.close();
+ }
+ }
+
+ public boolean isOpen()
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ System.err.println("readObject");
+ in.defaultReadObject();
+
+ try
+ {
+ createEntityManagerFactory();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static List<String> safeList(Set<String> set)
+ {
+ return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException
+ {
+ System.err.println("writeObject");
+ out.defaultWriteObject();
+ }
+}
Added: projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/common/DerbyService.java
===================================================================
--- projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/common/DerbyService.java (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/common/DerbyService.java 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.sandbox.test.common;
+
+import java.sql.Connection;
+
+import javax.naming.InitialContext;
+
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DerbyService
+{
+ private static final Logger log = Logger.getLogger(DerbyService.class);
+
+ private String className = "org.apache.derby.jdbc.EmbeddedDataSource";
+ private String databaseName = "./target/derby.db";
+ private boolean createDatabase = true;
+ private String jndiName = "java:/DefaultDS";
+
+ private EmbeddedDataSource ds;
+ private InitialContext ctx;
+
+ public void create() throws Exception
+ {
+ log.info("Creating derby service");
+
+ System.setProperty("derby.stream.error.file", "target/derby.log");
+
+ Class<? extends EmbeddedDataSource> cls = (Class<? extends EmbeddedDataSource>) Class.forName(className);
+ this.ds = cls.newInstance();
+ ds.setDatabaseName(databaseName);
+ if(createDatabase)
+ ds.setCreateDatabase("create");
+
+ ctx = new InitialContext();
+ }
+
+ public void destroy() throws Exception
+ {
+ log.info("Destroying derby service");
+
+ ctx.close();
+ ctx = null;
+ ds = null;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public void start() throws Exception
+ {
+ log.info("Starting derby service");
+
+ // Make sure that database is created before we go on.
+ Connection con = ds.getConnection();
+ con.close();
+
+ ctx.bind(jndiName, ds);
+ }
+
+ public void stop() throws Exception
+ {
+ log.info("Stopping derby service");
+
+ ctx.unbind(jndiName);
+ }
+}
Added: projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/Person.java
===================================================================
--- projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/Person.java (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/Person.java 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.sandbox.test.remote;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Person
+{
+ @Id
+ private int id;
+}
Added: projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/RemoteTestCase.java
===================================================================
--- projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/RemoteTestCase.java (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/java/org/jboss/jpa/sandbox/test/remote/RemoteTestCase.java 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.sandbox.test.remote;
+
+import java.io.IOException;
+import java.rmi.MarshalledObject;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.jpa.sandbox.remote.RemotelyInjectEntityManagerFactory;
+import org.jboss.jpa.sandbox.test.common.DerbyService;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.TransactionType;
+import org.jnp.server.SingletonNamingServer;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Note that this test doesn't really do remote, it uses serialization.
+ * After deserialization care has to be taking not to use any of the
+ * facilities that are already in the VM.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteTestCase
+{
+ private static SingletonNamingServer namingServer;
+
+ private static DerbyService derbyService;
+
+ private MarshalledObject<EntityManagerFactory> mo;
+
+ private InitialContext ctx;
+
+ @AfterClass
+ public static void afterClass() throws Exception
+ {
+ if(derbyService != null)
+ {
+ derbyService.stop();
+ derbyService.destroy();
+ derbyService = null;
+ }
+
+ if(namingServer != null)
+ {
+ namingServer.destroy();
+ namingServer = null;
+ }
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ namingServer = new SingletonNamingServer();
+
+ derbyService = new DerbyService();
+ derbyService.setJndiName("remoteDS");
+
+ derbyService.create();
+ derbyService.start();
+ }
+
+ @Before
+ public void setup() throws IOException
+ {
+ PersistenceUnitMetaData metaData = new PersistenceUnitMetaData();
+ metaData.setName("remotePU");
+ metaData.setNonJtaDataSource("remoteDS");
+ metaData.setTransactionType(TransactionType.RESOURCE_LOCAL);
+
+ RemotelyInjectEntityManagerFactory factory = new RemotelyInjectEntityManagerFactory(metaData, "dummy");
+
+ mo = new MarshalledObject<EntityManagerFactory>(factory);
+ }
+
+ @Test
+ public void test1() throws IOException, ClassNotFoundException
+ {
+ EntityManagerFactory factory = mo.get();
+
+ EntityManager em = factory.createEntityManager();
+
+ em.close();
+ }
+
+
+ @Test
+ public void test2() throws IOException, ClassNotFoundException
+ {
+ EntityManagerFactory factory = mo.get();
+
+ EntityManager em = factory.createEntityManager();
+
+ Person person = new Person();
+ em.persist(person);
+
+ em.close();
+ }
+}
Added: projects/jpa/trunk/sandbox/src/test/resources/META-INF/persistence.xml
===================================================================
--- projects/jpa/trunk/sandbox/src/test/resources/META-INF/persistence.xml (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/resources/META-INF/persistence.xml 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="remotePU" transaction-type="RESOURCE_LOCAL">
+ <non-jta-data-source>remoteDS</non-jta-data-source>
+ </persistence-unit>
+</persistence>
Added: projects/jpa/trunk/sandbox/src/test/resources/jndi.properties
===================================================================
--- projects/jpa/trunk/sandbox/src/test/resources/jndi.properties (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/resources/jndi.properties 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: projects/jpa/trunk/sandbox/src/test/resources/log4j.xml
===================================================================
--- projects/jpa/trunk/sandbox/src/test/resources/log4j.xml (rev 0)
+++ projects/jpa/trunk/sandbox/src/test/resources/log4j.xml 2008-09-09 09:10:59 UTC (rev 78234)
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- ================================= -->
+ <!-- Preserve messages in a local file -->
+ <!-- ================================= -->
+
+ <!-- A time/date based rolling appender -->
+ <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+ <param name="File" value="target/test.log"/>
+ <param name="Append" value="false"/>
+
+ <!-- Rollover at midnight each day -->
+ <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+ <!-- Rollover at the top of each hour
+ <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+ -->
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+ <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+ <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+ -->
+ </layout>
+ </appender>
+
+ <!-- A size based file rolling appender
+ <appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
+ <param name="File" value="${jboss.server.home.dir}/log/server.log"/>
+ <param name="Append" value="false"/>
+ <param name="MaxFileSize" value="500KB"/>
+ <param name="MaxBackupIndex" value="1"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+ </layout>
+ </appender>
+ -->
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="DEBUG"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <!-- Limit JBoss categories to INFO
+ <category name="org.jboss">
+ <priority value="INFO" class="org.jboss.logging.XLevel"/>
+ </category>
+ -->
+
+ <!-- Increase the priority threshold for the DefaultDS category
+ <category name="DefaultDS">
+ <priority value="FATAL"/>
+ </category>
+ -->
+
+ <!-- Decrease the priority threshold for the org.jboss.varia category
+ <category name="org.jboss.varia">
+ <priority value="DEBUG"/>
+ </category>
+ -->
+
+ <!--
+ | An example of enabling the custom TRACE level priority that is used
+ | by the JBoss internals to diagnose low level details. This example
+ | turns on TRACE level msgs for the org.jboss.ejb.plugins package and its
+ | subpackages. This will produce A LOT of logging output.
+ <category name="org.jboss.system">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+ -->
+
+ <category name="org.jboss.aop">
+ <priority value="WARN"/>
+ </category>
+
+ <category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+
+ <!--
+ Unnecessary, EJB3 is exposed as DEBUG
+ <category name="org.jboss.ejb3.interceptors.aop.DomainClassLoader">
+ <priority value="DEBUG"/>
+ </category> -->
+
+ <category name="org.jboss.ejb3">
+ <priority value="DEBUG"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <priority value="ALL" />
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="FILE"/>
+ </root>
+
+</log4j:configuration>
More information about the jboss-cvs-commits
mailing list