package org.apache.juddi.config;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PersistenceManager
{
  private static Log log = LogFactory.getLog(PersistenceManager.class);
  public static final String PERSISTENCE_UNIT_NAME = "juddiDatabase";
  private static EntityManagerFactory emf;

  public static EntityManager getEntityManager()
  {
    try
    {
      if (emf == null)
        AppConfig.getInstance();
    }
    catch (ConfigurationException e) {
      log.error("Error initializing config in PersistenceManager", e);
      throw new ExceptionInInitializerError(e);
    }

    return emf.createEntityManager();
  }

  public static void closeEntityManager() {
    if (emf.isOpen())
      emf.close();
  }

  protected static void initializeEntityManagerFactory(String persistenceUnitName) {
    try {
      if (emf == null)
        emf = Persistence.createEntityManagerFactory(persistenceUnitName, System.getProperties());
    }
    catch (Throwable t) {
      log.error("entityManagerFactory creation failed", t);
      throw new ExceptionInInitializerError(t);
    }
  }
}

@@ -1,8 +1,636 @@
+/*%0A * Copyright 2001-2008 The Apache Software Foundation.%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *      http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A */%0A%0A
 package 

add missing license header.