Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
“Meet business
objectives Application
consistently, nimbly, Foundation
cost-effectively”
3
Overview
4
Recalling EJB 2.1 enterprise javabeans
Enterprise
JavaBeans
CMP Stateful
6
EJB 2.1 beans require deployment descriptors
• An EJB 2.1 deployment descriptor is an XML file that contains:
– Structural information about any EJBs that are part of the module
– A descriptor for container-managed relationships
– Declarations of all EJBs as <entity>, <session>, or <message-driven>
<ejb-jar>
<display-name>LegacyEJBs</display-name>
<enterprise-beans>
<entity>
<ejb-name>Customer</ejb-name>
...
</entity>
...
</enterprise-beans>
<relationships>
...
</relationships>
</ejb-jar>
7
Types of EJB 3.0 beans
Enterprise
JavaBeans
Session Message-
Beans Driven
Beans
Stateless Stateful
@Stateful
public class ItemReserverImpl implements
public class ItemReserverImpl implements
ItemReserver, SessionBean { ItemReserver {
protected ArrayList <String> reserved = new ArrayList protected ArrayList <String> reserved =
<String> ();
new ArrayList <String> ();
public void reserveItem(String isbn){
. . .} public void reserveItem(String isbn){ ...
public void ejbActivate() { } }
public void ejbPassivate() { } @PostActivate
}
public void anymethod() { }
}
10
…
© Copyright IBM Corporation 2008
EJB 3.0 message-driven bean example
@MessageDriven
public class CopyReceiver {
12
13
14
15
try {
InitialContext ctx = new InitialContext();
orderProcessor = (OrderProcessor)
ctx.lookup("java:comp/env/ejb/OrderEJB");
}
catch(Exception e) {
e.printStackTrace(System.out);
throw new ServletException(e);
} 16
17
• Options:
– Map DTO’s directly
• DTO’s are already POJO’s.
• Less work on the coding layer.
– Just annotate POJO’S or translate XML.
• If DTO does not match Entity Bean, then mapping will be difficult.
18
DTO /Entity Bean Patterns – Pattern 1: Session Bean as translator
19
Pattern 1: Session Bean as translator in JPA
20
DTO /Entity Bean Patterns – Pattern 2: Entity Bean as translator
21
Pattern 2: DAO as translator in JPA
22
Pattern 3: Convert Entity Bean to POJO
23
Migration of mapping - WebSphere CMP
• Database Mapping
– XMI files cryptic, mapping happens with tooling.
– Fields
– Relationships
• Navigation, Cardinality
– Inheritance.
24
Entity Bean Mappings
OLD CMP TOOLS
• Old CMP tools
– Only path
• JPA
– RAD 7.5
• JPA Tools
from Eclipse
+ more
JPA Tools RAD 7.5
– Plain Annotation
Editor.
25
Converters and composers
Converters
At times, you might need to convert data that is read from a database
or saved to a database. Converters translate a database
representation to an object type, and they convert object types back
to database representations. For example, you might want to
convert a CHAR database entry 'Y' to a Boolean object set to true.
In this case, you can specify the VapStringToBooleanConverter in
the Properties view of the Mapping editor for the selected attribute
map.
Composers
A composer is used to map a single complex bean field to multiple
database columns. The complex field is a composed type.
26
JPA Custom Mappings
• Value Handlers
Value handlers make it trivial to map any type that you can break down into one or more simple
values. All value handlers implement the org.apache.openjpa.jdbc.meta.ValueHandler interface;
see its Javadoc for details. Also, examine the built-in handlers in the src/openjpa/jdbc/meta/strats
directory of your OpenJPA source distribution. Use these functional implementations as
examples when you create your own value handlers.
• Field Strategies
OpenJPA interacts with persistent fields through the org.apache.openjpa.jdbc.meta.FieldStrategy
interface. You can implement this interface yourself to create a custom field strategy, or extend
one of the existing abstract or concrete strategies in the org.apache.openjpa.jdbc.meta.strats
package. Creating a custom field strategy is more difficult than writing a custom value handler,
but gives you more freedom in how you interact with the database.
27
Isolation Levels
28
Caching
• Bean Caching
• Data Caching
29
JPA Caching
• Data Cache
• Query Cache
• Cache Providers
30
Security
31
Agenda
32
RAD 7.5 new migration wizard
33
RAD 7.5 migration wizard
34
RAD 7.5 migration wizard
35
Agenda
36
Learn More About Dynamic Application Infrastructure!
Application Foundation
ibm.com/appfoundation
Intelligent Management
ibm.com/intellmgmt
ibm.com/appinfrastructure
37
Thank you for Attending. We Value Your Feedback !
38
Questions?
39
Copyright and Trademarks
40
Back up
41
JPA entity managers best practices
• Use the session façade pattern to manage JPA based persistence layer.
– Persistence management is free
• If you intend to keep your EJB 2.x session beans and only migrate the
persistence portion of your application from EJB 2.x CMP or JDBC to JPA.
– You cannot use injection of a persistence context and therefore must use the
application-managed entity manager.
– (You can still use CMT)
42
45
46
– Local EJB
• Create aggregates and filters in IBM
© Copyright JSON, Web
Corporation 2008 Pages, or web service JAXB
Detached entity pattern
• JPA Entitles everywhere.