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/18 12:31:05 UTC

svn commit: r900348 - in /incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context: impl/ transaction/impl/

Author: timothyjward
Date: Mon Jan 18 11:31:04 2010
New Revision: 900348

URL: http://svn.apache.org/viewvc?rev=900348&view=rev
Log:
ARIES-118 : Add support for container managed persistence contexts

Added:
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextServiceFactory.java
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
Modified:
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistry.java

Added: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextServiceFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextServiceFactory.java?rev=900348&view=auto
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextServiceFactory.java (added)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextServiceFactory.java Mon Jan 18 11:31:04 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.context.impl;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContextType;
+
+import org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManager;
+import org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+/**
+ * A service factory that can lazily create persistence contexts
+ */
+public class ManagedPersistenceContextServiceFactory implements ServiceFactory {
+
+  private final ServiceReference emf;
+  private final Map<String, Object> properties;
+  private final JTAPersistenceContextRegistry registry;
+  
+  private EntityManager em;
+  
+  public ManagedPersistenceContextServiceFactory(ServiceReference unit,
+      Map<String, Object> props, JTAPersistenceContextRegistry contextRegistry) {
+
+      emf = unit;
+      properties = props;
+      registry = contextRegistry;
+      
+  }
+
+  public Object getService(Bundle bundle, ServiceRegistration registration) {
+    
+    if(em == null) {
+      EntityManagerFactory factory = (EntityManagerFactory) emf.getBundle().getBundleContext().getService(emf);
+      
+      synchronized(this) {
+        if (em == null) {
+          PersistenceContextType type = (PersistenceContextType) properties.get(PersistenceContextManager.PERSISTENCE_CONTEXT_TYPE);
+          if(type == PersistenceContextType.TRANSACTION || type == null)
+            em = new JTAEntityManager(factory, properties, registry);
+          else {
+            //TODO add support, or log the failure
+          }
+        }
+      }
+    }
+    return em;
+  }
+
+  public void ungetService(Bundle bundle, ServiceRegistration registration,
+      Object service) {
+    //No-op
+
+  }
+
+}

Added: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java?rev=900348&view=auto
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java (added)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java Mon Jan 18 11:31:04 2010
@@ -0,0 +1,343 @@
+/*
+ * 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.context.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContextType;
+
+import org.apache.aries.jpa.container.PersistenceUnitConstants;
+import org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This class is responsible for managing all of the persistence contexts at a defined scope
+ * It will automatically manage the lifecycle of all registered persistence contexts
+ */
+public class PersistenceContextManager extends ServiceTracker{
+  /** The key to use when storing the {@link PersistenceContextType} for this context */
+  public static final String PERSISTENCE_CONTEXT_TYPE = "org.apache.aries.jpa.context.type";
+  /** The filter this tracker uses to select Persistence Units. */
+  private static final Filter filter; 
+  static {
+    Filter f = null;
+    try {
+      f = FrameworkUtil.createFilter("(&(" + Constants.OBJECTCLASS
+        + "=" + "javax.persistence.EntityManagerFactory" + ")(" + 
+        PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))" );
+    } catch (InvalidSyntaxException e) {
+      // TODO This should never ever happen!
+      e.printStackTrace();
+    }
+    filter = f;
+  }
+  /** A Map of bundles that reference a particular persistence unit. Only access when synchronized on <code>this</code>.*/ 
+  private final Map<String, Set<Bundle>> persistenceContextConsumers = new HashMap<String, Set<Bundle>>();
+  /** 
+   * A Map persistence unit names to persistenceContextDefinitions. We use HashMap in the generic definition to ensure that 
+   * we get the correct deep <code>equals()</code> behaviour. Only access when synchronized on <code>this</code>.
+   */
+  private final Map<String, HashMap<String, Object>> persistenceContextDefinitions = new HashMap<String, HashMap<String,Object>>();
+  /** A Map of persistence units tracked by the tracker. Only access when synchronized on <code>this</code>. */
+  private final Map<String, ServiceReference> persistenceUnits = new HashMap<String, ServiceReference>();
+  /** A Map for storing the registered ManagedPersistenceContextServiceFactory. Only access when synchronized on <code>this</code>. */
+  private final Map<String, ServiceRegistration> entityManagerRegistrations = new HashMap<String, ServiceRegistration>();
+  private final JTAPersistenceContextRegistry persistenceContextRegistry;
+  
+  /**
+   * Create a new PersistenceContextManager at a scope defined by the supplied {@link BundleContext}
+   * @param ctx the bundle context to use for tracking services. In order to prevent this
+   *            object becoming prematurely invalid it is best to use the {@link BundleContext} of
+   *            the system bundle (Bundle 0).
+   */
+  public PersistenceContextManager(BundleContext ctx, JTAPersistenceContextRegistry registry) {
+
+    super(ctx, filter, null);
+    persistenceContextRegistry = registry;
+  }
+
+  @Override
+  public Object addingService(ServiceReference reference) {
+
+    String unitName = (String) reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME);
+    boolean register;
+    //Use a synchronized block to ensure that we get an atomic view of the persistenceUnits
+    //and the persistenceContextDefinitions
+    synchronized (this) {
+      //If we already track a unit with the same name then we are in trouble!
+      //only one unit with a given name should exist at a single scope
+      if(!!!persistenceUnits.containsKey(unitName)) {
+        //TODO log a big warning here!
+        //Stop tracking the duplicate unit.
+        return null;
+      }
+      //If this is a new unit, then add it, and check whether we have any waiting
+      //persistenceContextDefinitions
+      persistenceUnits.put(unitName, reference);
+      register = persistenceContextDefinitions.containsKey(unitName);
+    }
+    //If there are persistenceContexts then register them
+    if(register){
+      registerEM(unitName);
+    }
+    return reference;
+  }
+
+  public void removedService(ServiceReference ref, Object o)
+  {
+    String unitName = (String) ref.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME);;
+    //Remove the persistence Unit service to prevent other people from trying to use it
+    synchronized (this) {
+      persistenceUnits.remove(unitName);
+    }
+    //Unregister any dependent contexts
+    unregisterEM(unitName);
+  }
+
+  /**
+   * Register a persistence context definition with this manager
+   * @param name  The name of the persistence unit for this context
+   * @param client The {@link Bundle} that uses this persistence context
+   * @param properties The Map of properties for this persistence context
+   *                   This must contain the {@link PersistenceContextType}
+   */
+  public void registerContext(String name, Bundle client, HashMap<String, Object> properties) {
+    
+    HashMap<String, Object> oldProps;
+    boolean register;
+    //Use a synchronized to get an atomic view
+    synchronized (this) {
+      //Add a new consumer for the context, including the Set if necessary
+      Set<Bundle> bundles = persistenceContextConsumers.get(name);
+      if(bundles == null) {
+        bundles = new HashSet<Bundle>();
+        persistenceContextConsumers.put(name, bundles);
+      }
+      bundles.add(client);
+      
+      //Check that we don't have different properties to other clients.
+      //This would not make sense, as all clients should share the same
+      //context!
+      oldProps = persistenceContextDefinitions.put(name, properties);
+      if(oldProps != null) {
+        if(!!!oldProps.equals(properties)) {
+          //TODO log an error and use the old properties
+        }
+      }
+      //We should only register if our persistence unit exists
+      register = persistenceUnits.containsKey(name);
+    }
+      
+    if(register) {
+      registerEM(name);
+    }
+  }
+
+  /**
+   * Unregister the supplied bundle as a client of the supplied persistence context
+   * @param name  The name of the context
+   * @param client The bundle that is using the persistence context
+   */
+  public void unregisterContext(String name, Bundle client)
+  {
+    boolean unregister = false;
+    //Keep an atomic view of our state
+    synchronized (this) {
+      //Remove the client
+      Set<Bundle> clients = persistenceContextConsumers.get(name);
+      clients.remove(client);
+      //If no clients remain then tidy up the context
+      if(clients.isEmpty()) {
+        persistenceContextDefinitions.remove(name);
+        persistenceContextConsumers.remove(name);
+        unregister = true;
+      }
+    }
+    //Unregister the context if it is no longer used
+    if(unregister)
+      unregisterEM(name);
+  }
+
+  /**
+   * Register a {@link ManagedPersistenceContextServiceFactory} for the named persistence context
+   * 
+   * This must <b>never</b> be called from a <code>synchronized</code> block.
+   * @param name
+   */
+  private void registerEM(String name) {
+    
+    ServiceFactory entityManagerServiceFactory;
+    ServiceReference unit;
+    ServiceRegistration reg = null;
+    try
+    {
+      //Synchronize for an atomic view
+      synchronized (this) {
+        //Not our job to register if someone is already doing it, or has already done it
+        if(entityManagerRegistrations.containsKey(name))
+          return;
+        //Block other threads from trying to register by adding the key
+        entityManagerRegistrations.put(name, null);
+        
+        //Get hold of the information we need to create the context
+        unit = persistenceUnits.get(name);
+        Map<String, Object> props = persistenceContextDefinitions.get(name);
+        
+        //If either of these things is undefined then the context cannot be registered
+        if(props == null || unit == null)
+          return;
+
+        //Create the service factory
+        entityManagerServiceFactory = new ManagedPersistenceContextServiceFactory(unit, props, persistenceContextRegistry);
+      }
+     
+      //Always register from outside a synchronized 
+      Hashtable<String, Object> props = new Hashtable<String, Object>();
+      
+      props.put(PersistenceUnitConstants.OSGI_UNIT_NAME, name);
+      props.put(PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT, Boolean.TRUE);
+      props.put(PersistenceUnitConstants.OSGI_UNIT_PROVIDER, unit.getProperty(PersistenceUnitConstants.OSGI_UNIT_PROVIDER));
+      
+      BundleContext persistenceBundleContext = unit.getBundle().getBundleContext();
+      reg = persistenceBundleContext.registerService(
+          EntityManager.class.getName(), entityManagerServiceFactory, props);
+    } finally {
+      //As we have to register from outside a synchronized then someone may be trying to
+      //unregister us. They will try to wait for us to finish, but in order to prevent 
+      //live-lock they may flag to us that we need to do the unregistration by removing
+      //the persistence context key.
+      boolean recoverFromLiveLock = false;
+    
+      //Synchronize to get an atomic view
+      synchronized (this) {
+        //If we created a registration
+        if(reg != null) {
+          //If the key still exists then all is well
+          if(entityManagerRegistrations.containsKey(name))
+            entityManagerRegistrations.put(name, reg);
+          //Else we were in a potential live-lock and the service could not be unregistered
+          //earlier. This means we have to do it (but outside the synchronized. Make sure we
+          //also remove the registration key!
+          else {
+            entityManagerRegistrations.remove(name);
+            recoverFromLiveLock = true;
+          }
+        }
+        //There was no registration created. Remove the key.
+        else
+          entityManagerRegistrations.remove(name);
+        
+        //Notify any waiting unregistrations that they can proceed
+        this.notifyAll();
+      }
+      //If we were live-locked then unregister the registration here
+      if(recoverFromLiveLock)
+        reg.unregister();
+    }
+  }
+  
+  /**
+   * Unregister the named persistence context. This code attempts to ensure that
+   * the calling thread performs the unregistration to ensure the calls are
+   * synchronous. If a potential live-lock is detected then the unregistration may
+   * occur on a different thread or at a different time.
+   * 
+   * This must <b>never</b> be called from a <code>synchronized</code> block.
+   * @param unitName
+   * 
+   */
+  private void unregisterEM(String unitName) {
+    ServiceRegistration reg = null;
+    //Look for the registration
+    synchronized (this) {
+      //We use a loop to prevent live-locking, we
+      //loop a maximum of 4 times before
+      boolean found = false;
+      int tries = 0;
+      while (!!!found && tries < 4) {
+        //If we contain the key then get the registration,
+        //If not, then we have nothing to unregister
+        if(entityManagerRegistrations.containsKey(unitName))
+          reg = entityManagerRegistrations.get(unitName);
+        else
+          return;
+        
+        //It is possible that the registration is null. This means we are in
+        //the transient case where a registration is being created. If we wait
+        //then everything should be fine. If the registration is not null, then
+        //remove it from the map and escape the loop
+        if(reg != null) {
+          found = true;
+          entityManagerRegistrations.remove(unitName);
+        } else
+          //We didn't find it, wait and try again
+          try {
+            this.wait(500);
+          } catch (InterruptedException e) {
+            // TODO Log this properly
+            e.printStackTrace();
+          }
+        //Increment the loop to prevent us from live-locking
+        tries++;
+      }
+      //If we didn't find the registration in the loop then still
+      //remove the key to warn the registering thread to unregister
+      //immediately.
+      if(!found) {
+        //Possible Live lock, just remove the key
+        entityManagerRegistrations.remove(unitName);
+        //TODO log the potential issue
+      }
+    }
+    //If we found the registration then unregister it outside the synchronized.
+    if (reg != null) {
+      reg.unregister();
+    }
+  }
+
+  @Override
+  /**
+   * Open this <code>PersistenceContextManager</code> and begin tracking services.
+   * 
+   * <p>
+   * This implementation calls <code>open(true)</code>.
+   * 
+   * @throws java.lang.IllegalStateException If the <code>BundleContext</code>
+   *         with which this <code>ServiceTracker</code> was created is no
+   *         longer valid.
+   * @see #open(boolean)
+   */
+  public void open() {
+    super.open(true);
+  }
+}

Added: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java?rev=900348&view=auto
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java (added)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java Mon Jan 18 11:31:04 2010
@@ -0,0 +1,316 @@
+/*
+ * 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.context.transaction.impl;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.metamodel.Metamodel;
+
+/**
+ * A <code>PersistenceContextType.TRANSACTION</code> {@link EntityManager} instance
+ */
+public class JTAEntityManager implements EntityManager {
+
+  private final EntityManagerFactory emf;
+  private final Map<String, Object> props;
+  private final JTAPersistenceContextRegistry reg;
+  
+  public JTAEntityManager(EntityManagerFactory factory,
+      Map<String, Object> properties, JTAPersistenceContextRegistry registry) {
+    emf = factory;
+    props = properties;
+    reg = registry;
+  }
+
+  public void clear()
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em != null)
+      em.clear();
+  }
+
+  public void close()
+  {
+    //TODO add a message here
+    throw new IllegalStateException();
+  }
+
+  public boolean contains(Object arg0)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em != null)
+     return em.contains(arg0);
+    else
+      return false;
+  }
+
+  public Query createNamedQuery(String arg0)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.createNamedQuery(arg0);
+  }
+
+  public Query createNativeQuery(String arg0)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.createNativeQuery(arg0);
+  }
+
+  @SuppressWarnings("unchecked")
+  public Query createNativeQuery(String arg0, Class arg1)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.createNativeQuery(arg0, arg1);
+  }
+
+  public Query createNativeQuery(String arg0, String arg1)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.createNativeQuery(arg0, arg1);
+  }
+
+  public Query createQuery(String arg0)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.createQuery(arg0);
+  }
+
+  public <T> T find(Class<T> arg0, Object arg1)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.find(arg0, arg1);
+  }
+
+  public void flush()
+  {
+    reg.getCurrentPersistenceContext(emf, props).flush();
+  }
+
+  public Object getDelegate()
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.getDelegate();
+  }
+
+  public FlushModeType getFlushMode()
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.getFlushMode();
+  }
+
+  public <T> T getReference(Class<T> arg0, Object arg1)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    return em.getReference(arg0, arg1);
+  }
+
+  public EntityTransaction getTransaction()
+  {
+    //TODO add a message here
+    throw new IllegalStateException();
+  }
+
+  public boolean isOpen()
+  {
+    return true;
+  }
+
+  public void joinTransaction()
+  {
+    //This should be a no-op for a JTA entity manager
+  }
+
+  public void lock(Object arg0, LockModeType arg1)
+  {
+    reg.getCurrentPersistenceContext(emf, props).lock(arg0, arg1);
+  }
+
+  public <T> T merge(T arg0)
+  {
+    return reg.getCurrentPersistenceContext(emf, props).merge(arg0);
+  }
+
+  public void persist(Object arg0)
+  {
+    reg.getCurrentPersistenceContext(emf, props).persist(arg0);
+  }
+
+  public void refresh(Object arg0)
+  {
+    reg.getCurrentPersistenceContext(emf, props).refresh(arg0);
+  }
+
+  public void remove(Object arg0)
+  {
+    reg.getCurrentPersistenceContext(emf, props).remove(arg0);
+  }
+
+  public void setFlushMode(FlushModeType arg0)
+  {
+    EntityManager em = reg.getCurrentPersistenceContext(emf, props);
+    if(em == null)
+      em = emf.createEntityManager(props);
+    
+    em.setFlushMode(arg0);
+  }
+
+  public <T> TypedQuery<T> createNamedQuery(String arg0, Class<T> arg1)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public <T> TypedQuery<T> createQuery(CriteriaQuery<T> arg0)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public <T> TypedQuery<T> createQuery(String arg0, Class<T> arg1)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public void detach(Object arg0)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String, Object> arg3)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public CriteriaBuilder getCriteriaBuilder()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public EntityManagerFactory getEntityManagerFactory()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public LockModeType getLockMode(Object arg0)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public Metamodel getMetamodel()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public Map<String, Object> getProperties()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public void lock(Object arg0, LockModeType arg1, Map<String, Object> arg2)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void refresh(Object arg0, Map<String, Object> arg1)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void refresh(Object arg0, LockModeType arg1)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void refresh(Object arg0, LockModeType arg1, Map<String, Object> arg2)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public void setProperty(String arg0, Object arg1)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  public <T> T unwrap(Class<T> arg0)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+}

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistry.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistry.java?rev=900348&r1=900347&r2=900348&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistry.java (original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAPersistenceContextRegistry.java Mon Jan 18 11:31:04 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.context.transaction.impl;
 
 import java.util.IdentityHashMap;
@@ -41,7 +59,7 @@
    *         need to be wrappered to obey the JPA spec by throwing the correct exceptions
    * @throws {@link TransactionRequiredException} if there is no active transaction.
    */
-  public EntityManager getCurrentPersistenceContext(EntityManagerFactory persistenceUnit, Map<?,?> properties)
+  public EntityManager getCurrentPersistenceContext(EntityManagerFactory persistenceUnit, Map<?,?> properties) throws TransactionRequiredException
   {
     //There will only ever be one thread associated with a transaction at a given time
     //As a result, it is only the outer map that needs to be thread safe.