Enterprise Java Web Application Frameworks Sample Stack Implementation
1. Enterprise Java Web
Application Frameworks &
Sample Stack Implementation
Mert ÇALIŞKAN
mcaliskan@stm.com.tr
STM Inc.
2009
2. Who am I?
• The Software Plumber :)
SCJP certified dude bla bla...
• Open Source Evangelist
Founder & Author of various Open Source
Projects
• Member of MyFaces Community
OpenLogic Expert Community Member
3. Agenda
• The aim: Enterprise Java WebApp Framework
• Which stack to choose?
•
• The Stack
• Questions are welcome anytime..!
4. The aim: Enterprise WebApp Framework
• MVC pattern
• Quality & Competency of “The Stack”
• Performance & Scalability
• Learning Curve & Development Speed !
don’t let cutting edge turn into bleeding edge...
release early & release often..!
• Community Factor & Open Source support (forums-
mailing lists & etc.)
5. Which stack to choose?
UI Controller/Dep.Inj.
JSF Struts Spring Guice HiveMind
Spring MVC WebWork ZK picoContainer XWork
Wicket Tapestry GWT
Model/Persistence Layer
Echo3 Cocoon
Hibernate iBatis
Integration Toplink KODO
Apache CXF Apache Axis2 IDE EclipseLink
Eclipse IntelliJ
Spring WS
IDEA
JDeveloper
NetBEANS
6. • It’s nothing new!
not “yet another java framework”
• It’s a stack demonstration with OSS
• Released on 01.2009
• http://code.google.com/p/mesir
• 2000+ downloads
7. DOMAIN MODEL
AddressBook Contact
id id
1 0..*
text name
creationDate email
contacts phone
8. THE STACK
VIEW
MAVEN
JSF
ECLIPSE
FACELETS
ORCHESTRA Apache CXF
MODEL
CONTROLLER
JPA
HIBERNATE
H.SEARCH
SPRING
H.VALIDATOR
with SecuRITY
ENVERS
9. JSF-1
• A standard (v1.2_13 and v2.0.1 FCS)
• A component oriented & event-driven framework
• Binding makes JSF Powerful
Bind a bean’s variable to component
<h:inputText value=“#{person.name}” />
Bind a method to the action component
<h:commandButton
action=“#{personSavePage.savePerson}” />
• Conversion & Validation
no hassle with java.util.Date
extensible - write your own converter & validator
10. JSF-2
• 3rd Party Ajaxified Frameworks
PrimeFACES - Crazy Turks
RichFACES - JBoss
IceFACES - Sun
ADFFaces - Oracle
• IDE Support
(Eclipse - NetBeans - JDeveloper)
• Everything’s gonna be alright with JSF 2.0 :)
11. FACELETS
• ViewHandler created for JSF
• mixing JSF + JSP for JSF 1.x
• well balanced HTML : xhtml
• Templating
• Composite Components
12. SPRING-1
• Dependency Injection & IoC
with XML and annotations
• JEE ( JMS, EJBs, JCA ...)
• AOP
• ORM Integration, DAO Support
tx management, entityManager
13. SPRING-2
ORM
DAO Web
Hibernate
Spring JDBC
JPA JEE Spring WEB MVC
TopLink Framework
Transaction
JDO Integration
management JMX
OJB Struts
iBatis JMS Tapestry
JCA JSF
Remoting JSPs
EJB Velocity
Email FreeMarker
AOP JasperReports
Excel
Spring Portlet MVC
Spring AOP
AspectJ Integration
15. SPRING-4
@Service("addressBookService")
public class AddressBookServiceImpl implements
AddressBookService {
...
@Autowired
private AddressBookDAO addressBookDAO;
...
}
@Repository
public class AddressBookDAOImpl implements AddressBookDAO {
...
@PersistenceContext
protected EntityManager entityManager;
...
}
16. MyFaces ORCHESTRA
• Conversation Scoped beans &
Conversation Scoped Persistence Contexts
LazyInitializationException or NonUniqueObjectException
• Heavily built-on Spring Framework
17. JPA-1
• Standard (Java EE 5.0)
object/relational mapping and persistent management interface
• Support from different vendors
hibernate - toplink - eclipselink - kodo ...
• Enhanced Query Langugage (JPQL)
18. JPA-2
@Entity
public class AddressBook extends BaseObject {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(cascade={CascadeType.ALL})
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<Contact> contacts = new ArrayList<Contact>();
}
19. JPA-3
Some DAO code:
public AddressBook loadById(Long id) {
return entityManager.find(AddressBook.class, id);
}
public void save(AddressBook addressBook) {
entityManager.persist(addressBook);
}
public List<String> findAllTitles() {
return entityManager.createQuery("select ab.title from
AddressBook ab").getResultList();
}
20. HIBERNATE-1
• Object / Relational Mapping framework
• No hassle with result set handling object
conversion and SQL, well almost for SQL :)
• Support for any DB with dialects
Oracle, MySQL, PostgreSQL, HSQL, DB2, Sybase and many more....
21. Hibernate Search
• Bringing full text search engine to the
persistence domain model
e.g. : amazon search
• Apache Lucene™ under the hood
• Lucene Directory
File - DB - in mem
• JPA Triggered Event System
Persist - Update - Delete
22. H.S. - How To Use
• Configuration
Transparent with JPA
(hibernate entity manager)
(hibernate annotations)
• Annotation Based
@Indexed
@Field(store, index)
@IndexedEmbedded
.....
23. H.S. - Example
@Entity
@Indexed
public class AddressBook extends BaseObject {
@Field(index=Index.TOKENIZED, store=Store.NO)
private String title;
@OneToMany(cascade={CascadeType.ALL})
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@IndexedEmbedded
private List<Contact> contacts =
new ArrayList<Contact>();
....
}
24. H.S. - Example
@SuppressWarnings("unchecked")
public List<AddressBook> findByWord(String searchWord) throws ParseException {
// Since contacts list is declared as @IndexedEmbedded inside AddressBook,
// we can search through the name or email of a contact also.
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] {
"title", "contacts.name", "contacts.email" },
new StandardAnalyzer());
Query query = parser.parse(searchWord);
FullTextQuery ftq = getFullTextEntityManager().createFullTextQuery(
query, AddressBook.class);
return ftq.getResultList();
}
27. HIBERNATE ENVERS-1
• Versioning for JPA entities
• A part of Hibernate with Hib.3.5
• Simple to implement with annotations
@Audited ....
• Querying on Revisions, Entity at Revisions
28. HIBERNATE ENVERS-2
Entities
R id=”1” id=”4”
e data=”x” data=”p”
v id=”2” id=”3”
i data=”a” data=”x”
s
id=”1” id=”2”
i data=”y” data=”b”
o
n id=”2” id=”4”
data=”c” data=”r”
s
33. MAVEN
• Stop “building the build” and focus on
building the application...!
• A uniform build system...
• Project Object Model (POM)
• Guidelines for best practices while doing
development
(TDD - Cont. Int. & etc.)
34. MAVEN - The POM-1
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>tr.mc</groupId>
<artifactId>mesir</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>mesir</name>
<url>http://code.google.com/p/mesir</url>
<description>Skeleton project for java based web applications</description>
...
...
...
...
</project>
37. ECLIPSE-1
• Universal toolset for Development
• Open Source IDE
• Extensible architecture based on plugins
• Specified mostly on Java but development
language is independent...
CDT - PHP - Cobol
• Plugins used while developing mesir:
subclipse
m2eclipse