You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2010/01/14 15:34:57 UTC

svn commit: r899218 - in /incubator/aries/trunk: jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing...

Author: timothyjward
Date: Thu Jan 14 14:34:56 2010
New Revision: 899218

URL: http://svn.apache.org/viewvc?rev=899218&view=rev
Log:
ARIES-79: Create and manage EntityManagerFactory services for persistence units

Modified:
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfo.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfoFactory.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/ParsedPersistenceUnit.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptor.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
    incubator/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleContextMock.java

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfo.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfo.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfo.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfo.java Thu Jan 14 14:34:56 2010
@@ -1,13 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container;
 
 import java.util.Map;
 
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
 import javax.persistence.spi.PersistenceUnitInfo;
 
+/**
+ * This interface is used to provide the Aries JPA container with
+ * the information it needs to create a container {@link EntityManagerFactory}
+ * using the {@link PersistenceProvider} service from a JPA provider.
+ * Instances of this interface should be obtained from a 
+ * {@link ManagedPersistenceUnitInfoFactory}
+ */
 public interface ManagedPersistenceUnitInfo {
 
-  PersistenceUnitInfo getPersistenceUnitInfo();
+  /**
+   * Get the {@link PersistenceUnitInfo} object for this persistence unit.
+   * This method should only be called when the backing bundle for the
+   * persistence unit has been resolved. If the bundle later becomes unresolved
+   * then any {@link PersistenceUnitInfo} objects obtained from this object
+   * will be discarded.
+   * 
+   * @return A {@link PersistenceUnitInfo} that can be used to create an {@link EntityManagerFactory}
+   */
+  public PersistenceUnitInfo getPersistenceUnitInfo();
   
-  Map<String, Object> getContainerProperties();
+  /**
+   * Get a {@link Map} of continer properties to pass to the {@link PersistenceProvider}
+   * when creating an {@link EntityManagerFactory}.  
+   * @return A {@link Map} of properties, or null if no properties are needed.
+   */
+  public Map<String, Object> getContainerProperties();
   
 }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfoFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfoFactory.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfoFactory.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/ManagedPersistenceUnitInfoFactory.java Thu Jan 14 14:34:56 2010
@@ -1,17 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container;
 
 import java.util.Collection;
 
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitInfo;
+
 import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
+/**
+ * A Factory for {@link ManagedPersistenceUnitInfo} objects.
+ * 
+ * This interface marks a plug-point for implementations that wish to extend
+ * the Aries JPA Container by providing customized {@link PersistenceUnitInfo}
+ * objects.
+ *
+ * Customized implementations can be provided in two ways:
+ * <ul>
+ *   <li>
+ *     By setting a config property of the "container" bean in in the blueprint for this bundle.
+ *   </li>
+ *   <li>
+ *     By adding a config property to a properties file added to this bundle using a fragment.
+ *     The properties file should be named "org.apache.aries.jpa.container.properties" and be
+ *     available at the root of the classpath. This properties file name is available as a
+ *     constant ARIES_JPA_CONTAINER_PROPERTIES.
+ *   </li>
+ * </ul>
+ * 
+ * Note that properties provided through the properties file will override properties supplied
+ * through the blueprint container.
+ * 
+ * The property key to use is "org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory"
+ * and is accessible using the DEFAULT_PU_INFO_FACTORY_KEY field. The value associated with this
+ * key should be the class name of the {@link ManagedPersistenceUnitInfoFactory} implementation
+ * that should be used. The provided class name must be loadable by this bundle.
+ * 
+ * Implementations of this interface <b>must</b> have a no-args constructor and be safe for
+ * use by multiple concurrent threads.
+ * 
+ * No locks will be held by the JPA container or framework when calling methods on this interface.
+ */
 public interface ManagedPersistenceUnitInfoFactory {
+  /** 
+   * The config property key that should be used to provide a customized
+   * {@link ManagedPersistenceUnitInfoFactory} to the Aries JPA Container
+   */
+  public static final String DEFAULT_PU_INFO_FACTORY_KEY = "org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory";
+  /** 
+   * The name of the config properties file that can be used to configure
+   * the Aries JPA Container 
+   */
+  public static final String ARIES_JPA_CONTAINER_PROPERTIES = "org.apache.aries.jpa.container.properties";
 
-  Collection<ManagedPersistenceUnitInfo> createManagedPersistenceUnitMetadata(BundleContext containerContext, Bundle persistenceBundle, ServiceReference providerReference, Collection<ParsedPersistenceUnit> persistenceMetadata);
+  /**
+   * This method will be called by the Aries JPA container when persistence descriptors have
+   * been located in a persistence bundle.
+   * 
+   * @param containerContext  The {@link BundleContext} for the container bundle. This can be
+   *                          used to get services from the service registry when creating
+   *                          {@link PersistenceUnitInfo} objects.
+   * @param persistenceBundle The {@link Bundle} defining the persistence units. This bundle may
+   *                          be in any state, and so may not have a usable {@link BundleContext}
+   *                          or be able to load classes.
+   * @param providerReference A {@link ServiceReference} for the {@link PersistenceProvider} service
+   *                          that will be used to create {@link EntityManagerFactory} objects from
+   *                          these persistence units.
+   * @param persistenceMetadata A {@link Collection} of {@link ParsedPersistenceUnit} objects containing the
+   *                            metadata from the persistence descriptor.
+   * @return A Collection of {@link ManagedPersistenceUnitInfo} objects that can be used to create {@link EntityManagerFactory} instances
+   */
+  public Collection<ManagedPersistenceUnitInfo> createManagedPersistenceUnitMetadata(BundleContext containerContext, Bundle persistenceBundle, ServiceReference providerReference, Collection<ParsedPersistenceUnit> persistenceMetadata);
   
-  String getDefaultProviderClassName();
+  /**
+   * If no persistence units in a persistence bundle specify a JPA {@link PersistenceProvider} 
+   * implementation class, then the JPA container will call this method to obtain a default
+   * provider to use.
+   * @return A {@link PersistenceProvider} implementation class name, or null if no default is
+   *         specified.
+   */
+  public String getDefaultProviderClassName();
 
-  void destroyPersistenceBundle(Bundle bundle);
+  /**
+   * This method will be called when the persistence bundle is no longer being managed. This may
+   * be because the bundle is being updated, or because the {@link PersistenceProvider} being
+   * used is no longer available.
+   * 
+   * When this method is called implementations should clear up any resources associated with
+   * persistence units defined by the persistence bundle. 
+   * 
+   * @param bundle The persistence bundle that is no longer valid.
+   */
+  public void destroyPersistenceBundle(Bundle bundle);
 }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.impl;
 
 import java.util.ArrayList;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.impl;
 
 public class InvalidPersistenceUnitException extends Exception {

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.impl;
 
 import org.osgi.framework.Version;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java Thu Jan 14 14:34:56 2010
@@ -55,10 +55,10 @@
   public static Collection<PersistenceDescriptor> findPersistenceXmlFiles(Bundle bundle)
   {
     //The files we have found
-    Collection<PersistenceDescriptor> persistenceXmlFiles = new HashSet<PersistenceDescriptor>();
+    Collection<PersistenceDescriptor> persistenceXmlFiles = new ArrayList<PersistenceDescriptor>();
     
     //Always search the default location
-    List<String> locations = new ArrayList<String>();
+    Collection<String> locations = new HashSet<String>();
     locations.add(PERSISTENCE_XML);
     
     String header = (String) bundle.getHeaders().get(PERSISTENCE_UNIT_HEADER);

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu Jan 14 14:34:56 2010
@@ -72,10 +72,6 @@
   /** Configuration for this extender */
   private Properties config;
 
-  private static final String DEFAULT_PU_INFO_FACTORY = "";
-  
-  private static final String DEFAULT_PU_INFO_FACTORY_KEY = "org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory";
-  
   /**
    * Create the extender. Note that it will not start tracking 
    * until the {@code open()} method is called
@@ -90,7 +86,7 @@
   
   @Override
   public void open() {
-    String className = (String) config.get(DEFAULT_PU_INFO_FACTORY_KEY);
+    String className = (String) config.get(ManagedPersistenceUnitInfoFactory.DEFAULT_PU_INFO_FACTORY_KEY);
     Class<? extends ManagedPersistenceUnitInfoFactory> clazz = null;
     
     if(className != null) {
@@ -216,7 +212,7 @@
   
   public void setConfig(Properties props) {
     config = props;
-    URL u = ctx.getBundle().getResource("org.apache.aries.jpa.container.properties");
+    URL u = ctx.getBundle().getResource(ManagedPersistenceUnitInfoFactory.ARIES_JPA_CONTAINER_PROPERTIES);
     
     if(u != null)
       try {
@@ -428,10 +424,9 @@
   private synchronized ServiceReference getBestProvider(String providerClass, VersionRange matchingCriteria)
   {
     if(!!!persistenceProviders.isEmpty()) {
-      List<ServiceReference> refs = new ArrayList<ServiceReference>();
-      
       if((providerClass != null && !!!"".equals(providerClass))
           || matchingCriteria != null) {
+        List<ServiceReference> refs = new ArrayList<ServiceReference>();
         for(ServiceReference reference : persistenceProviders) {
           
           if(providerClass != null && !!!providerClass.equals(
@@ -445,15 +440,13 @@
         
         if(!!!refs.isEmpty()) {
           //Sort the list in DESCENDING ORDER
-          Collections.sort(refs, new ProviderServiceComparator());
-          return refs.get(0);
+          
+          return Collections.max(refs, new ProviderServiceComparator());
         } else {
           //TODO no matching providers for matching criteria
         }
       } else {
-        refs.addAll(persistenceProviders);
-        Collections.sort(refs, new ProviderServiceComparator());
-        return refs.get(0);
+        return (ServiceReference) Collections.max(persistenceProviders);
       }
     } else {
       //TODO log no matching Providers for impl class
@@ -466,14 +459,13 @@
     {
       Version v1 = object1.getBundle().getVersion();
       Version v2 = object2.getBundle().getVersion();
-      int res = v2.compareTo(v1);
+      int res = v1.compareTo(v2);
       if (res == 0) {
         Integer rank1 = (Integer) object1.getProperty(Constants.SERVICE_RANKING);
         Integer rank2 = (Integer) object2.getProperty(Constants.SERVICE_RANKING);
         if (rank1 != null && rank2 != null)
-          res = rank2.compareTo(rank1);
+          res = rank1.compareTo(rank2);
       }
-      
       return res;
     }
   }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/ParsedPersistenceUnit.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/ParsedPersistenceUnit.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/ParsedPersistenceUnit.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/ParsedPersistenceUnit.java Thu Jan 14 14:34:56 2010
@@ -18,18 +18,25 @@
  */
 package org.apache.aries.jpa.container.parsing;
 
+import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import org.osgi.framework.Bundle;
 
 /**
- * The parsed information from a persistence unit
+ * This interface provides access to the information defined by a 
+ * persistence unit in a persistence descriptor.
+ * 
+ * Implementations of this interface will be returned by calls to
+ * {@link PersistenceDescriptorParser}.
  */
 public interface ParsedPersistenceUnit {
   /*
    * Keys for use in the PersistenceXml Map
    * Stored values are Strings unless otherwise specified, and all values
-   * other than the schema version and unit name may be null.
+   * other than the schema version and unit name may be null. A null value
+   * indicates that the element/attribute was not present in the xml.
    */
   
   /** The version of the JPA schema being used */
@@ -38,13 +45,13 @@
   public static final String UNIT_NAME = "org.apache.aries.jpa.unit.name";
   /** The Transaction type of the persistence unit */
   public static final String TRANSACTION_TYPE = "org.apache.aries.jpa.transaction.type";
-  /** A List of String mapping file names */
+  /** A {@link List} of {@link String} mapping file names */
   public static final String MAPPING_FILES = "org.apache.aries.jpa.mapping.files";
-  /** A List of String jar file names */
+  /** A {@link List} of {@link String} jar file names */
   public static final String JAR_FILES = "org.apache.aries.jpa.jar.files";
-  /** A List of String managed class names */
+  /** A {@link List} of {@link String} managed class names */
   public static final String MANAGED_CLASSES = "org.apache.aries.jpa.managed.classes";
-  /** A Properties object containing the properties from the persistence unit */
+  /** A {@link Properties} object containing the properties from the persistence unit */
   public static final String PROPERTIES = "org.apache.aries.jpa.properties";
   /** The provider class name */
   public static final String PROVIDER_CLASSNAME = "org.apache.aries.jpa.provider";
@@ -52,7 +59,7 @@
   public static final String JTA_DATASOURCE = "org.apache.aries.jpa.jta.datasource";
   /** The non-jta-datasource name */
   public static final String NON_JTA_DATASOURCE = "org.apache.aries.jpa.non.jta.datasource";
-  /** A Boolean indicating whether unlisted classes should be excluded */
+  /** A {@link Boolean} indicating whether unlisted classes should be excluded */
   public static final String EXCLUDE_UNLISTED_CLASSES = "org.apache.aries.jpa.exclude.unlisted";
   
   /* End of Map keys */
@@ -61,13 +68,14 @@
   public static final String JPA_PROVIDER_VERSION = "org.apache.aries.jpa.provider.version";
 
   /**
-   * Return the bundle that defines the persistence unit
+   * Return the persistence bundle that defines this persistence unit
    * @return
    */
   public Bundle getDefiningBundle();
 
   /**
-   * Returns a deep copy of the persistence metadata. 
+   * Returns a deep copy of the persistence metadata, modifications to the
+   * returned {@link Map} will not be reflected in future calls. 
    * @return
    */
   public Map<String, Object> getPersistenceXmlMetadata();

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptor.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptor.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptor.java Thu Jan 14 14:34:56 2010
@@ -1,19 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.parsing;
 
 import java.io.InputStream;
 
+/**
+ * This is a utility interface that is used by the {@link PersistenceDescriptorParser}.
+ *
+ * This interfaces provides access to a single {@link InputStream} that returns the bytes
+ * of the persistence descriptor, and a String denoting the location of the persistence
+ * descriptor as present in the persistence bundle's Meta-Persistence header. 
+ */
 public interface PersistenceDescriptor {
 
   /**
-   * Get the location of the persistence descriptor
+   * Get the location of the persistence descriptor as it appears in the
+   * Meta-Persistence header. The default location should be returned as
+   * "META-INF/persistence.xml".
    * @return
    */
-  public abstract String getLocation();
+  public String getLocation();
 
   /**
-   * Get hold of the wrapped InputStream
-   * @return
+   * Get an {@link InputStream} to the persistence descriptor. This method need not return a
+   * new {@link InputStream} each time, and it is undefined for multiple clients to attempt to use
+   * the {@link InputStream} from this {@link PersistenceDescriptor}. It is also undefined for a
+   * client to try to retrieve multiple {@link InputStream} objects from this method.
+   *
+   * @return An {@link InputStream} to the persistence descriptor.
    */
-  public abstract InputStream getInputStream();
+  public InputStream getInputStream();
 
 }
\ No newline at end of file

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java Thu Jan 14 14:34:56 2010
@@ -35,11 +35,15 @@
 import org.apache.aries.jpa.container.parsing.impl.SchemaLocatingHandler;
 import org.osgi.framework.Bundle;
 
+/**
+ * This class may be used to parse JPA persistence descriptors. The parser validates
+ * using the relevant version of the persistence schema as defined by the xml file. 
+ */
 public class PersistenceDescriptorParser {
 
   /**
-   * This class is used to prevent the first pass parse from
-   * closing the InputStream
+   * This class is used internally to prevent the first pass parse from
+   * closing the InputStream when it exits.
    */
   private static class UnclosableInputStream extends FilterInputStream {
 
@@ -49,21 +53,27 @@
 
     @Override
     public void close() throws IOException {
-      //No op
+      //No op, don't close the parent.
     }
   }
   
   /**
-   * @param args
-   * @throws PersistenceDescriptorParserException 
+   * Parse the supplied {@link PersistenceDescriptor} 
+   * 
+   * @param b  The bundle that contains the persistence descriptor
+   * @param descriptor The descriptor
+   * 
+   * @return A collection of {@link ParsedPersistenceUnit}
+   * @throws PersistenceDescriptorParserException  if any error occurs in parsing
    */
   public static Collection<ParsedPersistenceUnit> parse(Bundle b, PersistenceDescriptor descriptor) throws PersistenceDescriptorParserException {
     Collection<ParsedPersistenceUnit> persistenceUnits = new ArrayList<ParsedPersistenceUnit>();
-    //Parse each xml file in turn
     SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     BufferedInputStream is = null;
     try {
-      //Buffer the InputStream so we can mark it
+      //Buffer the InputStream so we can mark it, though we'll be in 
+      //trouble if we have to read more than 8192 characters before finding
+      //the schema!
       is = new BufferedInputStream(descriptor.getInputStream(), 8192);
       is.mark(8192);
       SAXParser parser = parserFactory.newSAXParser();

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.unit.impl;
 
 import java.util.ArrayList;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.unit.impl;
 
 import java.util.Map;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java Thu Jan 14 14:34:56 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.jpa.container.unit.impl;
 
 import java.net.URL;

Modified: incubator/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleContextMock.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleContextMock.java?rev=899218&r1=899217&r2=899218&view=diff
==============================================================================
--- incubator/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleContextMock.java (original)
+++ incubator/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleContextMock.java Thu Jan 14 14:34:56 2010
@@ -158,7 +158,7 @@
    * This class represents the information registered about a service. It also
    * implements part of the ServiceRegistration and ServiceReference interfaces.
    */
-  private class ServiceData
+  private class ServiceData implements Comparable<ServiceReference>
   {
     /** The service that was registered */
     private ServiceFactory serviceImpl;
@@ -317,6 +317,29 @@
     {
       return new Hashtable<String, Object>(serviceProps);
     }
+
+    /**
+     * Implement the standard behaviour of the registry
+     */
+    public int compareTo(ServiceReference o) {
+      Integer rank = (Integer) serviceProps.get(Constants.SERVICE_RANKING);
+      if(rank == null)
+        rank = 0;
+      
+      Integer otherRank = (Integer) o.getProperty(Constants.SERVICE_RANKING);
+      if(otherRank == null)
+        otherRank = 0;
+      //Higher rank = higher order
+      int result = rank.compareTo(otherRank);
+      
+      if(result == 0) {
+        Long id = (Long) serviceProps.get(Constants.SERVICE_ID);
+        Long otherId = (Long) o.getProperty(Constants.SERVICE_ID);
+        //higher id = lower order
+        return otherId.compareTo(id);
+      }
+      return result;
+    }
   }
 
   /** The bundle associated with this bundle context */