Upload
eduardo-pelegri-llopart
View
1.614
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Seam a GlassFish Perspective by Dan Allen
Citation preview
SEAMA GLASSFISH PERSPECTIVE
DAN ALLENJBOSS, A DIVISION OF RED HAT
JSF EJB 3
SEAM BRINGS JAVA EE TOGETHER
SEAM'S MISSION
“To provide a fully integrated development platform for building rich Internet applications based upon the Java EE environment.” - Gavin King
http://in.relation.to/Bloggers/Seam3
WHAT SEAM PROVIDES
“Glue”– Contextual component model
– Dependency injection framework
– Enhanced EL
Simplify Java EE trouble spots
Manage Java Persistence correctly
Modules to integrate third-party libraries
Rapid development environment– Project generator, CRUD framework, hot deploy
SEAM TODAY
JavaServer Faces (JSF)
Facelets
Java Persistence API (JPA)
Enterprise JavaBeans 3 (EJB 3)
Java Transaction API (JTA)
JAX-RS (RESTeasy)
jBPM
JavaMail
iText (PDF)
JExcelApi (Excel)
YARFRAW (RSS)
Java Authentication and Authorization Service (JAAS)
Hibernate search
Drools
JavaScript / Ajax
Quartz
Wicket
GWT
Spring framework
JBoss Cache
...and more
SEAM EJB COMPONENT
EJB Local Reference in web.xml
<ejb-local-ref> <ejb-ref-name>vehiclesee/VehicleTradeBean/local</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>org.example.vehicles.action.VehicleTrade</local></ejb-local-ref>
EJB Local Interface and Seam SFSB component
@Localpublic interface VehicleTrade { void trade(); void remove();}
@Stateful@Name("vehicleTrade")public class VehicleTradeBean implements VehicleTrade { public void trade() { ... } @Remove public void remove() {}}
How does Seam make the connection?
RESOLVING AN EJB IN SEAM
A shared concern
First option: @JndiName
Second option: Resolve JNDI from pattern– #{ejbName}
● Value of name attribute on @Stateful/@Stateless● Unqualified class name of component● Value of <ejb-name> in ejb-jar.xml or web.xml
– Plug into Seam's jndiPattern
SFSB reference stored in Seam context– Default is conversation context
INVOKING AN EJB FROM JSF
It's not a crime!
<h:form>
...
<h:commandButton value="Trade"
action="#{vehicleTrade.trade}"/>
</h:form>
@Stateful@Name("vehicleTrade")public class VehicleTradeBean implements VehicleTrade{
public void trade() { ... }
@Remove public void remove() {}
}
CLIENT SERVER
JAVA PERSISTENCE
PERSISTENCE MANAGER
JPA EntityManager or Hibernate Session
Manages object representations of database records
Key services– First-level cache
– Transparent database reads/writes
Aligns well with use case– Seam terms this a “conversation”
CONVERSATION = UNIT OF WORK
The task at hand
Often involves more than one request
Requires state management
EXTENDING THE PERSISTENCE CONTEXT
Not expensive or dangerous!– “Just a HashMap”
Challenging to do in Java EE– No good place to store it
– Complex propagation rules
We turn over this task to Seam
TWO STYLES OF MANAGEMENT
Seam (bi)jection
@InEntityManager entityManager;
Standard Java EE injection
@PersistenceContextEntityManager entityManager;
EXTENDING THE TRANSACTION
Simulate a long transaction– Transcends many database/system transactions
Manual flushing of persistence context– You control when write occurs
– Rollback without involving database
– Persistence context can be read-only
– Only Hibernate provides this extension
Need to replace JPA provider in GlassFish– Seam provides access to Hibernate extensions
– Seam works agreeably with any JPA provider
Conversation (flushMode = MANUAL)
Request RequestResponse Response
load flush
Transaction Transaction...
APPLICATION TRANSACTION
EMBEDDED JAVA EE TESTING
SeamTest– Based on TestNG
Test application “as is”– Full JSF life cycle
– JTA, EJB 3, EL
Currently uses Embedded JBoss– Has baggage
Look forward to EJB 3.1
SEAMA GLASSFISH PERSPECTIVE
DAN ALLENJBOSS, A DIVISION OF RED HAT