[jboss-cvs] JBossAS SVN: r79915 - in projects/jpa/trunk/deployers/src: main/java/org/jboss/jpa/deployment and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 22 05:11:34 EDT 2008
Author: wolfc
Date: 2008-10-22 05:11:33 -0400 (Wed, 22 Oct 2008)
New Revision: 79915
Added:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/injection/
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/injection/InjectedEntityManagerFactory.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/util/ManagedEntityManagerFactoryHelper.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/Person.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jndi/
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jndi/JNDITestCase.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/META-INF/
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/META-INF/persistence.xml
Removed:
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/Person.java
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/RemoteTestCase.java
Log:
JBAS-6093: exposing EM and EMF in JNDI
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-10-22 07:04:30 UTC (rev 79914)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -32,15 +32,19 @@
import java.util.Set;
import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.ejb.HibernatePersistence;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.injection.InjectedEntityManagerFactory;
import org.jboss.jpa.spi.PersistenceUnit;
import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.jpa.tx.TransactionScopedEntityManager;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.util.naming.NonSerializableFactory;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
@@ -289,19 +293,18 @@
managedFactory = new ManagedEntityManagerFactory(actualFactory, kernelName);
- // FIXME: Reinstate
-// String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
-// if (entityManagerJndiName != null)
-// {
-// EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
-// NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
-// }
-// String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
-// if (entityManagerFactoryJndiName != null)
-// {
-// EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
-// NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
-// }
+ String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
+ if (entityManagerJndiName != null)
+ {
+ EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
+ NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
+ }
+ String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
+ if (entityManagerFactoryJndiName != null)
+ {
+ EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
+ NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
+ }
}
public void stop() throws Exception
Copied: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/injection/InjectedEntityManagerFactory.java (from rev 79803, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java)
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/injection/InjectedEntityManagerFactory.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/injection/InjectedEntityManagerFactory.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.injection;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.tx.TransactionScopedEntityManager;
+import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class InjectedEntityManagerFactory implements EntityManagerFactory, Externalizable
+{
+ private static final long serialVersionUID = -3734435119658196788L;
+
+ private transient EntityManagerFactory delegate;
+ private transient ManagedEntityManagerFactory managedFactory;
+
+ public InjectedEntityManagerFactory() {}
+
+ public InjectedEntityManagerFactory(ManagedEntityManagerFactory managedFactory)
+ {
+ assert managedFactory != null : "managedFactory is null";
+
+ this.delegate = managedFactory.getEntityManagerFactory();
+ this.managedFactory = managedFactory;
+ }
+
+
+ public EntityManagerFactory getDelegate()
+ {
+ return delegate;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeUTF(managedFactory.getKernelName());
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ String kernelName = in.readUTF();
+ managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if(managedFactory == null)
+ throw new IOException("Unable to find persistence unit in registry: " + kernelName);
+ delegate = managedFactory.getEntityManagerFactory();
+ }
+
+ public EntityManager createEntityManager()
+ {
+ return getDelegate().createEntityManager();
+ }
+
+ public EntityManager createEntityManager(Map map)
+ {
+ return delegate.createEntityManager(map);
+ }
+
+
+ public EntityManager getEntityManager()
+ {
+ return new TransactionScopedEntityManager(managedFactory);
+ }
+
+ public void close()
+ {
+ throw new IllegalStateException("It is illegal to close an injected EntityManagerFactory");
+ }
+
+ public boolean isOpen()
+ {
+ return getDelegate().isOpen();
+ }
+}
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,81 @@
+/*
+ * 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.spi;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.jpa.util.ThreadLocalStack;
+
+/**
+ * XPC aware components use this registry to subscribe to XPCs.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class XPCAware
+{
+ /*
+ * I would rather call out on some SPI to ask for the current context, but
+ * since this is mostly static stuff there is no real way to configure this class.
+ */
+
+ private static ThreadLocalStack<Map<String, EntityManager>> currentXPCs = new ThreadLocalStack<Map<String, EntityManager>>();
+
+ /**
+ * Return the identified XPC, if it is active.
+ *
+ * @param id the id of the XPC
+ * @return the XPC or null if none is found
+ */
+ public static EntityManager getExtendedPersistenceContext(String id)
+ {
+ List<Map<String, EntityManager>> list = currentXPCs.getList();
+ if(list == null)
+ return null;
+ for(Map<String, EntityManager> xpcs : list)
+ {
+ EntityManager em = xpcs.get(id);
+ if(em != null)
+ return em;
+ }
+ return null;
+ }
+
+ public static Map<String, EntityManager> popXPCs()
+ {
+ return currentXPCs.pop();
+ }
+
+ /**
+ * Called by an XPC consumer to make the call stack aware of XPCs.
+ * @param xpcs the XPCs initiated by the XPC consumer
+ */
+ public static void pushXPCs(Map<String, EntityManager> xpcs)
+ {
+ assert xpcs != null : "xpcs is null";
+
+ currentXPCs.push(xpcs);
+ }
+}
Copied: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java (from rev 79803, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java)
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,257 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.tx;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+
+import org.hibernate.Session;
+import org.hibernate.ejb.HibernateEntityManager;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.spi.XPCAware;
+import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class TransactionScopedEntityManager implements EntityManager, Externalizable
+{
+ private static final long serialVersionUID = 4260828563883650376L;
+
+ private static final Logger log = Logger.getLogger(TransactionScopedEntityManager.class);
+
+ private transient ManagedEntityManagerFactory factory;
+
+ public Session getHibernateSession()
+ {
+ EntityManager em = factory.getTransactionScopedEntityManager();
+ if (em instanceof HibernateEntityManager)
+ {
+ return ((HibernateEntityManager) em).getSession();
+ }
+ throw new RuntimeException("ILLEGAL ACTION: Not a Hibernate pe" +
+ "rsistence provider");
+ }
+
+ public TransactionScopedEntityManager(ManagedEntityManagerFactory factory)
+ {
+ if (factory == null) throw new NullPointerException("factory must not be null");
+ this.factory = factory;
+ }
+
+ public TransactionScopedEntityManager()
+ {
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeUTF(factory.getKernelName());
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ String kernelName = in.readUTF();
+ factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
+ }
+
+ public Object getDelegate()
+ {
+ return getEntityManager().getDelegate();
+ }
+
+ public void joinTransaction()
+ {
+ factory.verifyInTx();
+ getEntityManager().joinTransaction();
+ }
+
+ public void clear()
+ {
+ getEntityManager().clear();
+ }
+
+ public FlushModeType getFlushMode()
+ {
+ return getEntityManager().getFlushMode();
+ }
+
+ public void lock(Object entity, LockModeType lockMode)
+ {
+ factory.verifyInTx();
+ getEntityManager().lock(entity, lockMode);
+ }
+
+ public <T> T getReference(Class<T> entityClass, Object primaryKey)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ try
+ {
+ return em.getReference(entityClass, primaryKey);
+ }
+ finally
+ {
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ }
+ }
+
+ public void setFlushMode(FlushModeType flushMode)
+ {
+ getEntityManager().setFlushMode(flushMode);
+ }
+
+ public Query createQuery(String ejbqlString)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ return em.createQuery(ejbqlString);
+ }
+
+ public Query createNamedQuery(String name)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ return em.createNamedQuery(name);
+ }
+
+ public Query createNativeQuery(String sqlString)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ return em.createNativeQuery(sqlString);
+ }
+
+ public Query createNativeQuery(String sqlString, Class resultClass)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ return em.createNativeQuery(sqlString, resultClass);
+ }
+
+ public Query createNativeQuery(String sqlString, String resultSetMapping)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ return em.createNativeQuery(sqlString, resultSetMapping);
+ }
+
+ public <A> A find(Class<A> entityClass, Object primaryKey)
+ {
+ EntityManager em = getEntityManager();
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ try
+ {
+ return em.find(entityClass, primaryKey);
+ }
+ finally
+ {
+ if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+ }
+ }
+
+ public void persist(Object entity)
+ {
+ factory.verifyInTx();
+ getEntityManager().persist(entity);
+ }
+
+ public <A> A merge(A entity)
+ {
+ factory.verifyInTx();
+ return (A) getEntityManager().merge(entity);
+ }
+
+ public void remove(Object entity)
+ {
+ factory.verifyInTx();
+ getEntityManager().remove(entity);
+ }
+
+ public void refresh(Object entity)
+ {
+ factory.verifyInTx();
+ getEntityManager().refresh(entity);
+ }
+
+ public boolean contains(Object entity)
+ {
+ return getEntityManager().contains(entity);
+ }
+
+ public void flush()
+ {
+ factory.verifyInTx();
+ getEntityManager().flush();
+ }
+
+ public void close()
+ {
+ throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+ }
+
+ public boolean isOpen()
+ {
+ throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+ }
+
+ public EntityTransaction getTransaction()
+ {
+ throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+ }
+
+ protected EntityManager getEntityManager()
+ {
+ /* legacy
+ StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
+
+ EntityManager em;
+ if (beanContext != null)
+ {
+ List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
+ for( StatefulBeanContext bc : beanContexts)
+ {
+ em = bc.getExtendedPersistenceContext(factory.getKernelName());
+ if (em != null)
+ return em;
+ }
+ }
+ */
+ String id = factory.getKernelName();
+ EntityManager em = XPCAware.getExtendedPersistenceContext(id);
+ if(em != null)
+ return em;
+
+ return factory.getTransactionScopedEntityManager();
+ }
+
+}
Copied: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/util/ManagedEntityManagerFactoryHelper.java (from rev 79803, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java)
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/util/ManagedEntityManagerFactoryHelper.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/util/ManagedEntityManagerFactoryHelper.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,41 @@
+/*
+ * 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.util;
+
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ManagedEntityManagerFactoryHelper
+{
+ public static ManagedEntityManagerFactory getManagedEntityManagerFactory(String kernelName)
+ {
+ PersistenceUnitDeployment pu = (PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+ if(pu != null)
+ return pu.getManagedFactory();
+ return null;
+ }
+}
Modified: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java 2008-10-22 07:04:30 UTC (rev 79914)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -64,8 +64,15 @@
protected void deploy(String spec) throws DeploymentException, IOException
{
URL url = getClass().getResource(spec);
+ if(url == null)
+ throw new IllegalArgumentException("Can't find resource '" + spec + "'");
+ deploy(url);
+ }
+
+ protected static void deploy(URL url) throws DeploymentException, IOException
+ {
VirtualFile file = VFS.getRoot(url);
VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
- delegate.getMainDeployer().deploy(deployment);
+ delegate.getMainDeployer().deploy(deployment);
}
}
Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/Person.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/Person.java (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/Person.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,90 @@
+/*
+ * 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.deployers.test.common;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * A generic entity with an id and a string for testing.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Person
+{
+ @Id
+ private int id;
+
+ private String name;
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof Person))
+ return false;
+ Person other = (Person) obj;
+ if(other.id != this.id)
+ return false;
+ // TODO: name
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId()
+ {
+ return id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jndi/JNDITestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jndi/JNDITestCase.java (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jndi/JNDITestCase.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,77 @@
+/*
+ * 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.deployers.test.jndi;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.TransactionManager;
+
+import org.jboss.jpa.deployers.test.common.PersistenceTestCase;
+import org.jboss.jpa.deployers.test.common.Person;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JNDITestCase extends PersistenceTestCase
+{
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ PersistenceTestCase.beforeClass();
+
+ deploy(JNDITestCase.class.getResource("/org/jboss/jpa/deployers/test/jndi"));
+ }
+
+ @Test
+ public void testEM() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+ EntityManager em = (EntityManager) ctx.lookup("JndiEM");
+ tm.begin();
+ try
+ {
+ Person p = new Person();
+ p.setName("Debby");
+ em.persist(p);
+ }
+ finally
+ {
+ tm.rollback();
+ }
+ }
+
+ @Test
+ public void testEMF() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ EntityManagerFactory emf = (EntityManagerFactory) ctx.lookup("JndiEMF");
+ EntityManager em = emf.createEntityManager();
+ Person p = new Person();
+ p.setName("Debby");
+ em.persist(p);
+ }
+}
Deleted: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/Person.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/Person.java 2008-10-22 07:04:30 UTC (rev 79914)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/Person.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -1,36 +0,0 @@
-/*
- * 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.remote.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;
-}
Modified: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/RemoteTestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/RemoteTestCase.java 2008-10-22 07:04:30 UTC (rev 79914)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/remote/test/remote/RemoteTestCase.java 2008-10-22 09:11:33 UTC (rev 79915)
@@ -29,6 +29,7 @@
import javax.persistence.EntityManagerFactory;
import org.jboss.jpa.deployers.test.common.DerbyService;
+import org.jboss.jpa.deployers.test.common.Person;
import org.jboss.jpa.remote.RemotelyInjectEntityManagerFactory;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
import org.jboss.metadata.jpa.spec.TransactionType;
Added: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/META-INF/persistence.xml
===================================================================
--- projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/META-INF/persistence.xml (rev 0)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jndi/META-INF/persistence.xml 2008-10-22 09:11:33 UTC (rev 79915)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+ <persistence-unit name="jndi">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <class>org.jboss.jpa.deployers.test.common.Person</class>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="jboss.entity.manager.jndi.name" value="JndiEM"/>
+ <property name="jboss.entity.manager.factory.jndi.name" value="JndiEMF"/>
+ </properties>
+ </persistence-unit>
+</persistence>
More information about the jboss-cvs-commits
mailing list