/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.tutorial.packaging.bean;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

/**
 * Comment
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 * @version $Revision: 1.1.2.3 $
 */
@Stateless
@Remote(Session1.class)
public class Session1Bean implements Session1
{
   @PersistenceContext(unitName="manager1") EntityManager manager1;
   @PersistenceContext(unitName="manager2") EntityManager manager2;
   @PersistenceUnit(unitName="manager1") EntityManagerFactory factory1;
   @PersistenceUnit(unitName="manager2") EntityManagerFactory factory2;

   public int create1FromManager()
   {
      Entity1 one = new Entity1();
      one.setString("oneManager");
      manager1.persist(one);
      return one.getId();
   }
   public int create1FromFactory()
   {
      Entity1 one = new Entity1();
      one.setString("oneFactory");
      EntityManager m = factory1.getEntityManager();
      m.persist(one);
      System.out.println(one.getId());
      return one.getId();
   }

   public int create2FromManager()
   {
      Entity2 two = new Entity2();
      two.setString("twoManager");
      manager2.persist(two);
      return two.getId();
   }
   public int create2FromFactory()
   {
      Entity2 two = new Entity2();
      two.setString("twoFactory");
      EntityManager m = factory2.createEntityManager();
      m.persist(two);
      return two.getId();
   }
}
