Architecture of eSobi club
based on J2EE
Allan Huang @ eSobi Inc.
Agenda





Software Layers for J2EE Application
Table Schema structure and Domain Object
design
Look from Top-Down, Carry out from BottomUp
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
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 …
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)
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
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)
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) ?
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 ...
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
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
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)
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 ?
Table Schema structure and Domain
Object design
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
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
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
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
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
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
Look from Top-Down, Carry out from
Bottom-Up
Ready for APIs & Components I


User Authenticator


Related Tables & Classes







User-centric

Login & Logout
Cookie mechanics
Password Digester
Random 12-characters Password Generator
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
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
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
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
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
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
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
Concurrent Access Risk




Deadlock while insert & update concurrently
Dirty columns of table for performance gain
AJAX seems delicious, but ...
Performance Issue & Tuning


High availability & High scalability





Clustering & Load Balancing
Fail Over & Session Persistence

Code Refactoring




SQL statement (DAO) Tuning
Business Logic (BO) Tuning
Cached Result Page





Event-Driven: JMS (Synchronous)
Scheduling: Quartz (Asynchronous)

Database Refactoring




Re-Index on Tables
Database Trigger
Database Stored Procedure
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
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
Reference









Core J2EE Patterns
J2EE Patterns Catalog
GoF Patterns
AJAX Patterns
Java Naming Convention
Essential Database Naming Conventions
SQL Syntax Conventions
Extreme Programming
Q&A

Architecture of eSobi club based on J2EE

  • 1.
    Architecture of eSobiclub based on J2EE Allan Huang @ eSobi Inc.
  • 2.
    Agenda    Software Layers forJ2EE Application Table Schema structure and Domain Object design Look from Top-Down, Carry out from BottomUp
  • 3.
    Software Layers forJ2EE 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    Genericapplication 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   Lightweightstructures for related business information Enterprise Java Bean    BMP Entity Bean (EJB1.0) CMP Entity Bean (EJB2.0) POJO (EJB3.0)
  • 6.
    Ratings of DataPersistence 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 ObjectLayer  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      Managesbusiness 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 businessobject 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 DeploymentWrapper 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   Hideclients 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 displayto 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 somepart 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 ?
  • 14.
    Table Schema structureand Domain Object design
  • 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
  • 21.
    Look from Top-Down,Carry out from Bottom-Up
  • 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     Accordingto 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    SpellsSQL 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     ReplaceSystem.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
  • 30.
    Concurrent Access Risk    Deadlockwhile insert & update concurrently Dirty columns of table for performance gain AJAX seems delicious, but ...
  • 31.
    Performance Issue &Tuning  High availability & High scalability    Clustering & Load Balancing Fail Over & Session Persistence Code Refactoring    SQL statement (DAO) Tuning Business Logic (BO) Tuning Cached Result Page    Event-Driven: JMS (Synchronous) Scheduling: Quartz (Asynchronous) Database Refactoring    Re-Index on Tables Database Trigger Database Stored Procedure
  • 32.
    Test-driven development  Planning      Release planningcreates 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 mustbe 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
  • 34.
    Reference         Core J2EE Patterns J2EEPatterns Catalog GoF Patterns AJAX Patterns Java Naming Convention Essential Database Naming Conventions SQL Syntax Conventions Extreme Programming
  • 35.