/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3.test.composite2;

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

/**
 * Comment
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 * @version $Revision: 1.3.2.4 $
 */
@Stateless
@Remote(EntityTest.class)
public class EntityTestBean implements EntityTest
{
   private @PersistenceContext EntityManager manager;
   private static long genid = 0;

   public Composite createComposite()
   {
      Composite composite = new Composite();
      long id1 = genid++;
      long id2 = genid++;

      CompositePK pk = new CompositePK();
      pk.setId1(id1);
      pk.setId2(id2);
      composite.setPk(pk);

      CompositeContainer container = new CompositeContainer();
      container.setId(id2);
      manager.persist(container);
      composite.setContainer(container);
      manager.persist(composite);
      return composite;
   }

   public Composite findComposite(CompositePK pk)
   {
      return manager.find(Composite.class, pk);
   }

}
