[jboss-cvs] JBossAS SVN: r75948 - in projects/jpa/tags: jboss-jpa-deployers-0.1.1 and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 17 03:19:54 EDT 2008


Author: wolfc
Date: 2008-07-17 03:19:53 -0400 (Thu, 17 Jul 2008)
New Revision: 75948

Added:
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/jbcts822/
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/resources/org/jboss/jpa/deployers/test/jbcts822/
Removed:
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml
   projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
Log:
[maven-release-plugin]  copy for tag jboss-jpa-deployers-0.1.1

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1 (from rev 75588, projects/jpa/trunk/deployers)

Deleted: projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml
===================================================================
--- projects/jpa/trunk/deployers/pom.xml	2008-07-10 08:30:05 UTC (rev 75588)
+++ projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml	2008-07-17 07:19:53 UTC (rev 75948)
@@ -1,99 +0,0 @@
-<!--
-  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.0-SNAPSHOT</version>
-  </parent>
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>jboss-jpa-deployers</artifactId>
-  <packaging>jar</packaging>
-  <name>JBoss Container Managed JPA Deployers</name>
-  
-  <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.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>

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml (from rev 75947, projects/jpa/trunk/deployers/pom.xml)
===================================================================
--- projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml	                        (rev 0)
+++ projects/jpa/tags/jboss-jpa-deployers-0.1.1/pom.xml	2008-07-17 07:19:53 UTC (rev 75948)
@@ -0,0 +1,105 @@
+<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-deployers</artifactId>
+  <version>0.1.1</version>
+  <packaging>jar</packaging>
+  <name>JBoss Container Managed JPA Deployers</name>
+  <description>
+    The JBoss Container Managed JPA Deployers for deploying persistence units.
+    See EJB 3 JPA chapter 6 and 7.
+  </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.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>
+
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jpa/tags/jboss-jpa-deployers-0.1.1</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jpa/tags/jboss-jpa-deployers-0.1.1</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jpa/tags/jboss-jpa-deployers-0.1.1</url>
+  </scm>
+</project>

Deleted: projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2008-07-10 08:30:05 UTC (rev 75588)
+++ projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2008-07-17 07:19:53 UTC (rev 75948)
@@ -1,372 +0,0 @@
-/*
- * 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.deployment;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.naming.InitialContext;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-
-import org.hibernate.ejb.HibernatePersistence;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.jpa.spi.PersistenceUnit;
-import org.jboss.jpa.spi.PersistenceUnitRegistry;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-import org.jboss.metadata.jpa.spec.TransactionType;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class PersistenceUnitDeployment //extends AbstractJavaEEComponent
-   implements PersistenceUnit
-{
-   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
-
-   protected InitialContext initialContext;
-   protected VFSDeploymentUnit di;
-   protected List<String> explicitEntityClasses = new ArrayList<String>();
-   protected ManagedEntityManagerFactory managedFactory;
-   protected EntityManagerFactory actualFactory;
-   protected PersistenceUnitMetaData metaData;
-   protected String kernelName;
-   protected PersistenceDeployment deployment;
-   private Properties defaultPersistenceProperties;
-
-   public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
-   {
-      //super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
-      
-      this.deployment = deployment;
-      this.initialContext = initialContext;
-      this.di = deploymentUnit;
-      this.explicitEntityClasses = explicitEntityClasses;
-      this.metaData = metadata;
-      this.defaultPersistenceProperties = defaultPersistenceProperties;
-      
-      this.kernelName = kernelName;
-   }
-
-   public void create()
-   {
-      // To allow for serializable objects to obtain a reference back
-      PersistenceUnitRegistry.register(this);
-   }
-   
-   public void destroy()
-   {
-      PersistenceUnitRegistry.unregister(this);
-   }
-   
-   public static String getDefaultKernelName(String unitName)
-   {
-      int hashIndex = unitName.indexOf('#');
-      if (hashIndex != -1)
-      {
-         String relativePath = unitName.substring(3, hashIndex);
-         String name = unitName.substring(hashIndex + 1);
-         return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
-      }
-      return "persistence.units:unitName=" + unitName;
-   }
-
-   public PersistenceDeployment getDeployment()
-   {
-      return deployment;
-   }
-
-   protected String getJaccContextId()
-   {
-      return di.getSimpleName();
-   }
-
-   public EntityManagerFactory getActualFactory()
-   {
-      return actualFactory;
-   }
-
-   public PersistenceUnitMetaData getXml()
-   {
-      return metaData;
-   }
-
-   public String getKernelName()
-   {
-      return kernelName;
-   }
-
-   public String getName()
-   {
-      return getKernelName();
-   }
-
-   /**
-    * 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 VirtualFile getPersistenceUnitRoot()
-   {
-      // FIXME: What is the correct way to find the persistence unit root?
-      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);
-      }
-   }
-   
-   public EntityManagerFactory getContainerEntityManagerFactory()
-   {
-      return getManagedFactory().getEntityManagerFactory();
-   }
-   
-   public String getEntityManagerName()
-   {
-      return metaData.getName();
-   }
-
-   public ManagedEntityManagerFactory getManagedFactory()
-   {
-      if(managedFactory == null)
-         log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
-      return managedFactory;
-   }
-
-   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 = getDeployment().getDeploymentUnit().getFile("").toURL();
-            return new URL(url, jar);
-         }
-         catch (Exception e1)
-         {
-            throw new RuntimeException("could not find relative path: " + jar, e1);
-         }
-      }
-   }
-   
-//   public void addDependencies(DependencyPolicy policy)
-//   {
-//      Map<String, String> props = getProperties();
-//      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
-//      {
-//         if (metaData.getJtaDataSource() != null)
-//         {
-//            String ds = metaData.getJtaDataSource();
-//            policy.addDatasource(ds);
-//         }
-//         if (metaData.getNonJtaDataSource() != null)
-//         {
-//            String ds = metaData.getNonJtaDataSource();
-//            policy.addDatasource(ds);
-//         }
-//      }
-//      for (Object prop : props.keySet())
-//      {
-//         String property = (String)prop;
-//         if (property.startsWith("jboss.depends"))
-//         {
-//            policy.addDependency(props.get(property));
-//         }
-//      }
-//
-//   }
-
-   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;
-   }
-
-   private List<String> safeList(Set<String> set)
-   {
-      return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
-   }
-
-   public void start() throws Exception
-   {
-      log.info("Starting persistence unit " + kernelName);
-      
-      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());
-
-      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
-         }
-      }
-      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) initialContext.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) initialContext.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
-      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);
-
-      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);
-//      }
-   }
-
-   public void stop() throws Exception
-   {
-      log.info("Stopping persistence unit " + kernelName);
-
-      // FIXME: reinstate
-//      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
-//      if (entityManagerJndiName != null)
-//      {
-//         NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
-//      }
-//      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
-//      if (entityManagerFactoryJndiName != null)
-//      {
-//         NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
-//      }
-      managedFactory.destroy();
-   }
-}

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java (from rev 75762, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java)
===================================================================
--- projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	                        (rev 0)
+++ projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2008-07-17 07:19:53 UTC (rev 75948)
@@ -0,0 +1,372 @@
+/*
+ * 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.deployment;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+
+import org.hibernate.ejb.HibernatePersistence;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.spi.PersistenceUnit;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.TransactionType;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class PersistenceUnitDeployment //extends AbstractJavaEEComponent
+   implements PersistenceUnit
+{
+   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
+
+   protected InitialContext initialContext;
+   protected VFSDeploymentUnit di;
+   protected List<String> explicitEntityClasses = new ArrayList<String>();
+   protected ManagedEntityManagerFactory managedFactory;
+   protected EntityManagerFactory actualFactory;
+   protected PersistenceUnitMetaData metaData;
+   protected String kernelName;
+   protected PersistenceDeployment deployment;
+   private Properties defaultPersistenceProperties;
+
+   public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
+   {
+      //super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
+      
+      this.deployment = deployment;
+      this.initialContext = initialContext;
+      this.di = deploymentUnit;
+      this.explicitEntityClasses = explicitEntityClasses;
+      this.metaData = metadata;
+      this.defaultPersistenceProperties = defaultPersistenceProperties;
+      
+      this.kernelName = kernelName;
+   }
+
+   public void create()
+   {
+      // To allow for serializable objects to obtain a reference back
+      PersistenceUnitRegistry.register(this);
+   }
+   
+   public void destroy()
+   {
+      PersistenceUnitRegistry.unregister(this);
+   }
+   
+   public static String getDefaultKernelName(String unitName)
+   {
+      int hashIndex = unitName.indexOf('#');
+      if (hashIndex != -1)
+      {
+         String relativePath = unitName.substring(3, hashIndex);
+         String name = unitName.substring(hashIndex + 1);
+         return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
+      }
+      return "persistence.units:unitName=" + unitName;
+   }
+
+   public PersistenceDeployment getDeployment()
+   {
+      return deployment;
+   }
+
+   protected String getJaccContextId()
+   {
+      return di.getSimpleName();
+   }
+
+   public EntityManagerFactory getActualFactory()
+   {
+      return actualFactory;
+   }
+
+   public PersistenceUnitMetaData getXml()
+   {
+      return metaData;
+   }
+
+   public String getKernelName()
+   {
+      return kernelName;
+   }
+
+   public String getName()
+   {
+      return getKernelName();
+   }
+
+   /**
+    * 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 VirtualFile getPersistenceUnitRoot()
+   {
+      // FIXME: What is the correct way to find the persistence unit root?
+      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);
+      }
+   }
+   
+   public EntityManagerFactory getContainerEntityManagerFactory()
+   {
+      return getManagedFactory().getEntityManagerFactory();
+   }
+   
+   public String getEntityManagerName()
+   {
+      return metaData.getName();
+   }
+
+   public ManagedEntityManagerFactory getManagedFactory()
+   {
+      if(managedFactory == null)
+         log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
+      return managedFactory;
+   }
+
+   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);
+         }
+      }
+   }
+   
+//   public void addDependencies(DependencyPolicy policy)
+//   {
+//      Map<String, String> props = getProperties();
+//      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
+//      {
+//         if (metaData.getJtaDataSource() != null)
+//         {
+//            String ds = metaData.getJtaDataSource();
+//            policy.addDatasource(ds);
+//         }
+//         if (metaData.getNonJtaDataSource() != null)
+//         {
+//            String ds = metaData.getNonJtaDataSource();
+//            policy.addDatasource(ds);
+//         }
+//      }
+//      for (Object prop : props.keySet())
+//      {
+//         String property = (String)prop;
+//         if (property.startsWith("jboss.depends"))
+//         {
+//            policy.addDependency(props.get(property));
+//         }
+//      }
+//
+//   }
+
+   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;
+   }
+
+   private List<String> safeList(Set<String> set)
+   {
+      return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
+   }
+
+   public void start() throws Exception
+   {
+      log.info("Starting persistence unit " + kernelName);
+      
+      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());
+
+      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
+         }
+      }
+      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) initialContext.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) initialContext.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
+      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);
+
+      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);
+//      }
+   }
+
+   public void stop() throws Exception
+   {
+      log.info("Stopping persistence unit " + kernelName);
+
+      // FIXME: reinstate
+//      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
+//      if (entityManagerJndiName != null)
+//      {
+//         NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
+//      }
+//      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
+//      if (entityManagerFactoryJndiName != null)
+//      {
+//         NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
+//      }
+      managedFactory.destroy();
+   }
+}

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java (from rev 75762, projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java)
===================================================================
--- projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java	                        (rev 0)
+++ projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/common/PersistenceTestCase.java	2008-07-17 07:19:53 UTC (rev 75948)
@@ -0,0 +1,71 @@
+/*
+ * 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 java.io.IOException;
+import java.net.URL;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.jpa.deployers.test.deployment.DeploymentTestCase;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * A base for persistence test cases.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class PersistenceTestCase
+{
+   private static MainDeployerTestDelegate delegate;
+   
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+      delegate.tearDown();
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      delegate = new MainDeployerTestDelegate(DeploymentTestCase.class);
+      delegate.setUp();
+      
+      delegate.deploy("/org/jboss/jpa/deployers/test/common/jndi-beans.xml");
+      delegate.deploy("/org/jboss/jpa/deployers/test/common/jbossts-beans.xml");
+      delegate.deploy("/org/jboss/jpa/deployers/test/deployment/derby-beans.xml");
+      //delegate.deploy("/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml");
+   }
+   
+   protected void deploy(String spec) throws DeploymentException, IOException 
+   {
+      URL url = getClass().getResource(spec);
+      VirtualFile file = VFS.getRoot(url);
+      VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+      delegate.getMainDeployer().deploy(deployment);
+   }
+}

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/java/org/jboss/jpa/deployers/test/jbcts822 (from rev 75762, projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbcts822)

Copied: projects/jpa/tags/jboss-jpa-deployers-0.1.1/src/test/resources/org/jboss/jpa/deployers/test/jbcts822 (from rev 75762, projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbcts822)




More information about the jboss-cvs-commits mailing list