nl.knowledgeplaza.util.jpa
Class EntityManagerFinderSwing

java.lang.Object
  extended by nl.knowledgeplaza.util.jpa.EntityManagerFinder
      extended by nl.knowledgeplaza.util.jpa.EntityManagerFinderThread
          extended by nl.knowledgeplaza.util.jpa.EntityManagerFinderSwing

public class EntityManagerFinderSwing
extends EntityManagerFinderThread

This is a combination of a focus based and thread based. First a check is done if there is a EM associated with this thread. If not and the current thread is the EDT, then a check is done if a EM is associated with the component that currently has the focus. If not, then its parent component is checked. This does require some special coding in the application, when using threads: final EntityManager lEntityManager = EntityManagerFinder.find(); new Thread( new Runnable() { public void run() { EntityManagerFinderSwing.associateWithCurrentThread(lEntityManager); //... SwingUtilities.invokeLater( new Runnable() { public void run() { EntityManagerFinderSwing.associateWithCurrentThread(lEntityManager); // ... EntityManagerFinderSwing.deassociateFromCurrentThread(); // reused threads need explicit deassociations } } ); //... }}).start();

Version:
$Revision: 1.6 $

Constructor Summary
EntityManagerFinderSwing()
           
 
Method Summary
static void associate(Component c, javax.persistence.EntityManager em)
           
static void deassociate(Component c)
           
static javax.persistence.EntityManager getAssociation(Component c)
           
 javax.persistence.EntityManager getEntityManager(Object context)
           
static void register()
           
 
Methods inherited from class nl.knowledgeplaza.util.jpa.EntityManagerFinderThread
associate, associateWithCurrentThread, deassociate, deassociateFromCurrentThread, runAssociatedWithCurrentThread
 
Methods inherited from class nl.knowledgeplaza.util.jpa.EntityManagerFinder
find, find, findEntityManager, getEMAssociation, getEMAssociation, getEntityManagerFinder, removeAssociation, removeEMAssociation, setEMAssociation, setEMAssociation, setEntityManagerFinder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityManagerFinderSwing

public EntityManagerFinderSwing()
Method Detail

getEntityManager

public javax.persistence.EntityManager getEntityManager(Object context)
Overrides:
getEntityManager in class EntityManagerFinderThread

register

public static void register()

associate

public static void associate(Component c,
                             javax.persistence.EntityManager em)
Parameters:
c -
em -

deassociate

public static void deassociate(Component c)
Parameters:
c -

getAssociation

public static javax.persistence.EntityManager getAssociation(Component c)
Parameters:
c -
Returns:


Copyright © 2011 KnowledgePlaza. All Rights Reserved.