2. Agenda
Software Layers for J2EE Application
Table Schema structure and Domain Object
design
Look from Top-Down, Carry out from BottomUp
3. Software Layers for J2EE Application
Business Delegate Layer
Deployment Layer
Business Tier
Business Logic Layer
(Business Object)
Integration Tier
Data Access Object Layer
Architecture Component Layer
(Framework)
Domain Object Layer
(Domain Model / Entity)
Presentation Layer
(Servlet / JSP)
Presentation Tier
4. Architecture Component Layer
Generic application utilities
Often, these objects are good candidates for
enterprise-wide use
Well-known open source projects
Jakarta commons, dom4j, log4j, xerces, quartz,
java mail, jasypt, captcha …
5. Domain Object Layer
Lightweight structures for related business
information
Enterprise Java Bean
BMP Entity Bean (EJB1.0)
CMP Entity Bean (EJB2.0)
POJO (EJB3.0)
6. Ratings of Data Persistence Methods
Goal
JDBC
EJB/BMP EJB/CMP
JDO
O/R Tool
Min Learning curve
High
Low
Low
Medium
Medium
Min Code and
configuration
Low
Low
Low
Medium
Medium
Max Ability to tune
High
Medium
Low
Low
Low
Min Deployment effort
High
Low
Low
Medium
Medium
Max Code portability
Medium
Medium
High
High
High
Min Vendor reliance
High
Medium
Medium
Medium
Low
Max Availability and
fail-over
Low
High
High
Low
Low
Manageable via JTA
Yes
Yes
Yes
Yes
Yes
7. Data Access Object Layer
Encapsulate data access and manipulation in
a separate layer
DB CRUD, File, XML, FTP Server, Mail Server ...
1:1 correspondence between VO and DAO
Traditional JDBC DAO vs. Spring DAO Bean
Aspect-oriented programming (AOP)
Cross-cutting concerns
Inverse of Control (IOC)
8. Business Logic Layer
Manages business processing rules and logic
Maximize the possibility of reuse
Access Business Objects (BO) via Service Locator
(Pattern)
Stateless Session Bean vs. Spring Bean
Fast Lane Reader (Pattern)
A more efficient way to access tabular, read-only,
potentially stale data
Transfer Object (Pattern)
Carry any multiple data elements across a tier
Previously known as Value Object (is not Pattern) ?
9. Deployment Layer
Publishes business object capabilities
Web Server (e.g. Tomcat) acted business
client, Application Server (e.g. Weblogic)
acted business server
Remote session bean, Message-driven bean,
RMI service, Web service, CORBA service ...
10. Features of Deployment Wrapper Types
Feature
EJB
Web
Service
JMS
RMI
HTTP
CORBA
Caller platform
requirements
Javacomplaint only
Any
Any
Javacomplaint only
Any
Any
Communication
method
supported
Synch. only
Both
Both
Synch. only
Synch.
only
Synch.
only
Tight
Loose
Loose
Tight
Loose
Loose
Local and JTA
Local and JTA
Local
Local
Local
Local
Requires J2EE
container?
Yes
No
No
No
No
No
Supports
clustering for
scalability and
availability?
Yes
Yes
Yes
No
Yes
Yes
Coupling
Transaction
support
11. Business Delegate Layer
Hide clients from the complexity of remote
communication with business service
components
Service Locator (Singleton)
Transparently locate business components and
services in a uniform manner
Class BeanFactoryLocator or
ApplicationContext of Spring Context
12. Presentation Layer
Controls display to the end user
Servlet 2.4 & JSP 2.0
Servlet & Java Bean (View Object)
JSP & Tag library
JavaScript & DHTML & CSS
Asynchronous JavaScript And XML (AJAX)
13. AJAX
Only reload some part and difference of web
page each time the user requests a change
A implementation of design style, not a
framework
Consists of HTML, JavaScript, DHTML, and
DOM, is an outstanding approach
Help you to transform clunky Web interfaces
into interactive AJAX applications
AJAX Web or AJAX Application ?
15. User-centric Tables & Classes
ER Diagram
Class Diagram
Table per subclass
User, Supervisor, Member
MemberFeed, SubscribeFeed, FavoriteFeed,
RecommendFeed, BackupFeed
1:1 Lazy initialization between Member and
MemberProfile
Nested MemberFolder
Tree structure
4 default folders per member
16. Feed-centric Tables & Classes
ER Diagram
Class Diagram
Nested FeedCategory
Nested RecommendReply
Tree structure
While malicious of Reply == true, this reply would be removed from
user’s view
FeedRecommend
Tree structure
While malicious of Recommend == true, this reply would be removed
from user’s view
FeedTagCase between PublicFeed and FeedTag
FeedVote between PublicFeed and User
RecommendVote between FeedRecommend and User
M:M between FeedTag and FeedRecommend
17. Mail-centric Tables & Classes
ER Diagram
Class Diagram
OutMail & InMail
While trashed of OutMail == true, this mail would be
removed from sender’s view
While trashed of InMail == true, this mail would be
removed from receiver’s view
While one trashed of OutMail == true and trashed of it’s
InMails == true simultaneously, these mails will be
deleted from database
18. My Space-centric Tables & Classes
ER Diagram
Class Diagram
MySpaceSetting between MySpace and
MySpaceChoice
MySpaceAnswer between MySpace and
MySpaceQuestion
1:1 Lazy initialization between MemberProfile and
MySpace
19. Access Control-centric Tables & Classes
ER Diagram
Class Diagram
Table per class hierarchy
Nested Group
AccessControl, UserControl, RoleControl, GroupControl
AccessRule, SupervisorRule, MemberRule
Tree structure
M:M between Role and User
M:M between Group and User
Access Rule
Priority UserControl > RoleControl > GroupControl
Resolves conflicts when the same type of AccessControl are
assigned
20. Forum-centric Tables & Classes
ER Diagram
Class Diagram
Nested TopicReply
Tree structure
While malicious of Reply == true, this reply would be
removed from user’s view
Topic Watch
Update last replied time when user replies
Between User and ForumTopic
22. Ready for APIs & Components I
User Authenticator
Related Tables & Classes
User-centric
Login & Logout
Cookie mechanics
Password Digester
Random 12-characters Password Generator
23. Ready for APIs & Components II
eSobi Feed Subscriber
Related Tables & Classes
User-centric
Feed-centric
Public Feed count & Member Feed record
eSobi Feed Recommender
Related Tables & Classes
User-centric
Feed-centric
24. Ready for APIs & Components III
eSobi Folder Backup
Related Tables & Classes
User-centric
Feed-centric
eSobi Folder Restorer
Related Tables & Classes
User-centric
Feed-centric
25. Ongoing for APIs & Components I
Data Migration
Data List Handler
Parse RSS XML to find information of feed
User Authorizer
A pattern for Large Search Result Sets
Paging Controller applied to web page
RSS Parser
Old data is migrated to the new schema
According to Access-Controls to find Access-Rules
Mail Carrier
26. Java Naming Convention
According to Java Bean convention
Attribute firstly, Getter method secondly,
Setter method lastly
Collection-type Attribute, add extra Adder and
Remover method
Convenient findXXXByZZZ method
27. SQL Syntax Convention
Statement
Spells SQL keywords in upper case
SQL statements are often broken into multiple
lines
Table & Column name
Primary key should be the table name suffixed
with "_id“
Separate words and prefixes with underlines,
never use spaces
28. Logging Service Convention
Replace System.out / System.err println with
Logger
Level warning & error & fatal on Production
machine
Level trace & debug & info on SIT / UAT
machine
Logging necessary messages about our
logic.
if log.isXXXEnabled, then log.XXX message
29. Centralized Controlling & Distributed
Computing
There’s no need to reinvent the wheel
Bitter design vs. Appropriate design
Tree traverse method
Universal entry between up-tier and down-tier
J2EE Pattern & GoF Pattern
Hard code vs. Sophisticated Algorithm
Open Source Community
e.g. Service Locator & Session Façade
Divide and conquer inside the same tier
32. Test-driven development
Planning
Release planning creates the schedule
Make frequent small releases
The project is divided into iterations
Iteration planning starts each iteration
Designing
Simplicity
Choose a system metaphor
Refactoring whenever and wherever possible
33. Test-driven development
Coding
Code must be written to agreed standards
Integrate often
Use collective code ownership
Leave optimization till last
Testing
All code must have unit tests
All code must pass all unit tests before release
When a bug is found tests are created
Acceptance tests are run often