1 Making it Happen with J2EE Russell Castagnaro Chief Mentor 4Charity.com [email protected]Introduction z Presenter yRussell Castagnaro yChief Mentor x4Charity.com xSyncTank Solutions, Inc y[email protected]yExperience Introduction z 4Charity.com yApplication Service Provider for the Non- Profit industry yPure Java development yHttp://www.4charity.com yLocations: x San Francisco,CA x Honolulu, HI yWe’re Hiring…
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
architecturezProvides for portability across server
vendorszWell defined interfaces between client,
server component, server and resourceszHandles data persistence and transaction
integrity
7
Extensible Markup Languagez Self-describing, pure data representationz Compatible with heterogeneous systemszMethod of configuration of most systemsz Can be used within most of the core APIz Transformations via Extensible Stylesheet
Language Transformation (XSLT)
The J2EE
zYou may remain completely within the realm of J2EE and provide enterprise solutions.zOccasionally the Java Native Interface is
needed to access other systems.
J2EE Construction
zI will use a construction metaphor for using the J2EE
8
Enterprise Mortar: JDBC, JNDI and RMI
zJDBC Connects your databases to Java.yUse Connections, Statements, Result Sets,
etc..yCall Stored Procedures, etc..
zJNDI locates distributed components.zRMI allows distributed objects to
communicate as if they were local.
Enterprise Bricks: EJB, JMS, JTS
zEJB encapsulates business logic, insulates you from the persistence layer, provides fault tolerance and fail-overzJMS provides GMD in Queues or TopicszJTS allows you to control transaction
isolation level for better data management
Enterprise support beams:Servlets
zServletsyProvide the application structure.yDictate how to navigate inside the
application. yAre strong, but not pretty.
9
The Enterprise Exterior: JSP
zJSP’s are responsible for the user experiencezHides the internal structure from clientszAllows less experienced developers or
web content producers to focus on presentation
How do the new API’s Help?zInterfaces* that provide maximum
flexibility.zThey provide several contracts:yDeveloper - ComponentyContainer -ComponentyServer - Container
zYou can avoid deployment specifics in client code.
Companies Really Are Using J2EE
zCompanies that use Java:yMost use JDBC and ServletsyMany use JNDI/ RMI or IIOPyBigger players are using EJB, JMS and XML
zCompanies that do not use Java:yMany are using XML, COM, or CORBA
10
Common Acceptance Path
zUse Servlets (performance, speed of deployment, ease of development)zUse JDBC (robust, simple, easy to deploy)zUse RMI/JNDI (distributed applications)zUse JNI (integration with other software)zUse EJB and JMS (high availability,
performance, abstraction)
Now what?zYou already knew all of that…zMaybe:yYour CTO declared that all future
development should be EJB’s!yYour client decided to listen to some Gartner
Group/ Forrester/ Giga Group advice.yYou want to develop distributed, scalable
applications in Java.
Avoiding Success With J2EEzUse one API exclusively, ALL THE TIME.zUse EJB’s, particularly Entity Beans
excessively.zCreate ‘Monolithic’ Distributed
applications.zIgnore other reasonable advice.
11
Heavyweight JSP’s
JSP
RDBMS
JSP
JSP
JDBC
JDBC
JDBC
<jsp:scriptlet>id = null; SQLDataBean bean = new SQLDataBean();bean.setSQL(stmt); bean.setDriver(driver);bean.setURL(url); Properties p = new Properties();p.put("user",user); p.put("password",pass);p.put("url",bean.getURL()); bean.setProperties(p);bean.setColumns(columns); bean.setFields(columns);bean.setReturnClosed(false); java.sql.ResultSet rs = null;try {Object o = bean.execute(request); rs = (java.sql.ResultSet) o;
zDo not use Entity classes to access read-only data
z Compare the number of sql statementsySelect name,ssn,salary from empySelect name,ssn,salary from emp where id=1ySelect name,ssn,salary from emp where id=2ySelect name,ssn,salary from emp where id=3y…
z Consider the RMI communication time.z Contemplate the App Server overhead.
Some Successful StrategieszUse coarse-grained entities where possiblezUse Interfaces from the start of developmentzUse JSP to encapsulate the presentation layerzDo not put business logic in your JSP’szUse Bean Managed Persistence or OR Mapping
toolsz You still need code reviews!
Use coarse-grained Entities
zJDBC is your friend!zContainer Managed Persistence is not
always appropriate.zDo not let the Database structure dictate
your object architecture.
14
Use Remote Interfaces from the beginning
zDefine your interfaces very early in the construction phasezCreate stub implementationszThis allows the presentation layer
development to continue without waiting for the server side components
Use Interfaces with EJB
EJB Data Access
z There are many ways that you can access your data via EJByUsing a Session
⌧SQL in the Session or DD⌧Data Access Objects
yUsing an Entity⌧Container Managed Persistence⌧Bean Managed Persistence
• SQL embedded in the Entity or DD• Data Access Objects• O/R Mapping Tool
15
EJB Data Access
zUsing a Session with SQL EmbeddedyVery straightforwardyEasy to ConfigureySomewhat FlexibleyMay be difficult to maintainyHard to reuse
Session With SQL Embeddedpublic AddressData getBusinessAddress() throws RemoteException {
AddressData address = new AddressData();try {
Connection c = null; PreparedStatement s = null; ResultSet rs = null;try {
c = getConnection(); s = c.createStatement();String query = getEnvironmentValue("ADDRESS_SQL");s.prepareStatement(query); s.setString(id); rs = s.executeQuery();while (rs.next()){