430 likes | 580 Views
Hibernate & Design Patterns A Practical Overview. BSc . Thiago Oliveira Technical Manager Galileo Team Coimbra, April 14 th , 2009. Agenda. Design Patterns Transfer Objects Data Transfer Objects Factories Hibernate Framework Connecting the pieces. PART I Design Patterns & Hibernate.
E N D
Hibernate & Design PatternsA Practical Overview BSc. Thiago Oliveira Technical Manager Galileo Team Coimbra, April 14th, 2009
Agenda • Design Patterns • Transfer Objects • Data Transfer Objects • Factories • Hibernate Framework • Connecting the pieces
What Are Design Patterns? • In the simplest term, it’s a solution to a design problem in particular field • It’s define the problem, the solution, when apply it and what are the consequences
Transfer Objects • A Transfer Object is just a Serializable POJO (Plain Old Java Object) • Also called Persistent POJO or Valuable Object
ResourceTO code Indentify Class “Version”. Calculated Hash using the attributes names and methods signatures. It’s not a random number!
Data Access Objects • Implement the CRUD operations: • public intinsertResource(…) • public booleandeleteResource(…) • public ResourceTOfindResource(…) • public booleanupdateResource(…) …
DAO – We want more flexibility Abstract Factory Concrete Factory DAO – Implements the operation for a specific Entity
Hibernate Framework • Hibernate is a object/relational mapping (ORM) tool for Java • Hibernates goal is to relieve the developer from 95% of common data persistence related programming task • Last Release: 3.3.1 GA
Hibernate Framework • It provides: • Mapping from Java Objects to Relational Tables • Automatic conversion from Java Types to SQL Types • Data Query and retrieve facilities that can reduce the time effort of development • Sophisticated Query Options you can use pure SQL or HQL (Hibernate Query Language )
Hibernate Framework • It provides: • Transparent Persistence • SQL generation • Support for Transaction
How this magic became true? Through XML Configuration Files and powerful API • Hibernate Conf File (hibernate.cfg.xml) • Mapping Files (myClass.hbm.xml)
We don’t want to write any single configuration file by hand… • JBoss Tools is a set of plugins for Eclipse for support JBoss and related technology, like Hibernate • The actual stable release is the JBoss Tools 3.0.0.GA, requires Eclipse Ganymede 3.4.2
Hibernate Tools for Hibernate 3.0 • Key Features • Code Generation • Wizards for creation of common Hibernate files • Support auto-completion and syntax highlighting
Yes, I Know… You want to see code…HbmDepartmentDAO – A concrete DAO
Yes, I Know… You want to see code…HbmDAOFactory – A Concrete Factory
Yes, I Know… You want to see code…DAOFactory – An Abstract Factory
Further Reading • More about Hibernate & HSQL • Hibernate Reference Document (http://www.hibernate.org/hib_docs/v3/reference/en/pdf/hibernate_reference.pdf ) • BAUER, Christian; KING, Gavin. Java Persistence with Hibernate. Manning Publications Co: New York, 2007 • More about Data Access Objects • Core J2EE Patterns - Data Access Objects (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html ) • More about Transfer Objects • Core J2EE Patterns - Transfer Objects (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html )
Further Reading • More about Junit • Unit testing with JUnit 4.x and EasyMock in Eclipse (http://www.vogella.de/articles/JUnit/article.html ) • Junit 4.x How to (http://pub.admc.com/howtos/junit4x/junit4x.pdf) • More about Hibernate Tools • Hibernate Tools Reference Guide (http://docs.jboss.org/tools/3.0.0.GA/en/hibernatetools/pdf/Hibernatetools_Reference_Guide.pdf)
BSc. Thiago OliveiraTechnical Managerthiagosilvaoliveira@gmail.com