@Harry You are discussing three levels: 1) Presentation 2) Business 3) Persistence
Case 1 - Application Client. You used the main class for presentation, validatePDF, processPDF, createPrintJob is your business level. 3) EntityDAOClient and JPA - your persistence level.
Case 2 - Web module - you used (want to use) jsf for presentation, CoreEJB for perseverance - I don't know where you intend to put business logic, since now a bad take is another ejb class.
The main problem in this approach is "Using two different approaches for the level of business logic." Case 1 is a simple Java variant of Case 2 Ejb.
When you use plain java, you lose the luxury of dependency injection, tx control, concurrency control, interceptors, etc.
When you use EJB, you lose the flexibility to exchange code with the application client.
The solution is to use CDI. With CDI, you can integrate both of your use cases. It works like a bridge between three layers. Provide all the capabilities of dependency injection, interceptors, decorators for the application client.
Effectively there will be zero changes in the level of your business level and the code of the save level in the client application, as well as in JavaEE.
I mentioned in the CDI programming model that you do not need to use @managed. All pojo are CDI beans.
In CDI you do not need to write a main class. Start writing business logic below
<to> //This class works as is in both javaEE and client. //There is no need of managedbean in CDI. //This class can be accessed in jsf using EL #businessProcessor @Singleton @Named public class BusinessProcessor { private @Inject EntityDAO entityDAO; // CDI will inject an implementation of EntityDao. //In our case there is only one impl for client as well as JavaEE //This class works as is in both javaEE and client. //There is no need of managedbean in CDI. //This class can be accessed in jsf using EL #businessProcessor @Singleton @Named public class BusinessProcessor { private @Inject EntityDAO entityDAO; // CDI will inject an implementation of EntityDao. //In our case there is only one impl for client as well as JavaEE
// CDI will invoke below method on startup. Not used in JavaEE. // In JavaEE JSF will execute process () directly using Expression Language public void init (@Observes ContainerInitialized event, @Parameters List parameters) {process (entityDAO); }
public void process (@Inject EntityDAO entityDAO) {validatePDF (List); processPDF (List, entityDAO); createPrintJob (List, entityDAO); }
public void processPDF (List, EntityDAO entityDAO) {for (File file: pdfFiles) {entityDAO.create (file); }}}
<Preview> // this class is same for both JavaEE and Client public class EntityDAOClient implements EntityDAO {
private @Inject EntityManager em;
private static Logger logger = Logger.getLogger (EntityDAOClient.class); @Override public T create (T t) {em.getTransaction (). Begin (); em.persist (t); em.getTransaction (). commit (); return t; }
@Override public T find (Class type, Object id) {em.getTransaction (). Begin (); T t = em.find (type, id); em.getTransaction (). commit (); return t; } ...}
To start the application client <Preview> java org.jboss.weld.environment.se.StartMain For more meat, check www.seamframework.org