Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.jpa.spi.se » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.jpa.spi.se;
   15   
   16   import java.util.Map;
   17   import java.util.concurrent.ConcurrentHashMap;
   18   
   19   import javax.persistence.EntityManager;
   20   import javax.persistence.EntityManagerFactory;
   21   import javax.persistence.Persistence;
   22   
   23   import org.apache.webbeans.jpa.spi.JPAService;
   24   import org.apache.webbeans.jpa.spi.se.EntityManagersManager;
   25   
   26   /**
   27    * SPI Implementation which accesses the PersistenceManagerFactory via the Persistence class
   28    */
   29   public class JPAServicePersistenceImpl implements JPAService
   30   {
   31       
   32       public static final String SINGLETON_WEBBEANS_ENTITYMANAGERS_MAP = EntityManagersManager.class.getName();
   33       
   34       private Map<String, EntityManagerFactory> factoryCache = new ConcurrentHashMap<String, EntityManagerFactory>();
   35   
   36       /**
   37        * {@inheritDoc}
   38        * 
   39        */
   40       public EntityManagerFactory getPersistenceUnit(String unitName)
   41       {
   42           if(factoryCache.get(unitName) != null)
   43           {
   44               return factoryCache.get(unitName);
   45           }
   46           
   47           //X TODO this currently ignores JNDI
   48           EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName);
   49           
   50           factoryCache.put(unitName, emf);
   51               
   52           return emf;
   53       }
   54   
   55       /** 
   56        * {@inheritDoc}
   57        * TODO: currently this returns an extended EntityManager, so we have to wrap it
   58        * We have to create a Proxy for injecting entity managers. So, whenever method is called
   59        * on the entity managers, look at current Transaction, if exist call joinTransaction();
   60        */
   61       public EntityManager getPersistenceContext(String unitName, String name)
   62       {
   63           EntityManagerFactory emf = getPersistenceUnit(unitName);        
   64           EntityManager em = emf.createEntityManager();
   65           
   66           return em;
   67       }
   68   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.jpa.spi.se » [javadoc | source]