FileDocCategorySizeDatePackage
EmbeddedIdTestBean.javaAPI DocJBoss 4.2.13606Fri Jul 13 20:53:06 BST 2007org.jboss.ejb3.test.clusteredentity.embeddedid

EmbeddedIdTestBean

public class EmbeddedIdTestBean extends Object implements EmbeddedIdTest
SFSB used for testing replicated query caching with an @EmbeddedId.
author
Brian Stansberry
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private EntityManager
manager
Constructors Summary
Methods Summary
public voidcleanup()

      Query query = manager.createQuery("select musician from Musician as musician");
      List accts = query.getResultList();
      if (accts != null)
      {
         for (Iterator it = accts.iterator(); it.hasNext();)
         {
            try
            {
               Musician musician = (Musician) it.next();
               log.info("Removing " + musician);
               manager.remove(musician);
            }
            catch (Exception ignored) {}
         }
      }
   
public voidcreateMusician(MusicianPK pk, java.lang.String instrument)


        
   
      Musician musician = new Musician();
      musician.setId(pk);
      musician.setInstrument(instrument);
      manager.persist(musician);
   
public java.util.ListgetMusiciansForInstrument(java.lang.String instrument, boolean useNamedRegion)

      String queryName = useNamedRegion ? "musician.byinstrument.namedregion"
                                        : "musician.byinstrument.default";
      Query query = manager.createNamedQuery(queryName);
      query.setParameter(1, instrument);
      List<MusicianPK> result = new ArrayList<MusicianPK>();
      List users = query.getResultList();
      if (users != null)
      {
         for (Iterator it = users.iterator(); it.hasNext();)
         {
            result.add(((Musician) it.next()).getId());
         }
      }
      return result;
   
public voidremove()

      cleanup();