CISH6960: Developing Enterprise Applications - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

CISH6960: Developing Enterprise Applications

Description:

Can create separate tables for each subclass, with foreign ... Persisting Components. Enterprise JavaBeans. Entity beans are an object model on the data store ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 36
Provided by: kenneth116
Category:

less

Transcript and Presenter's Notes

Title: CISH6960: Developing Enterprise Applications


1
CISH-6960 Developing Enterprise Applications
  • Lecture 6
  • June 26, 2004

2
Persistence
  • Object / Relational Mapping

3
Outline
  • Roll your own persistence layer
  • Design patterns
  • Abstract Factory
  • Builder
  • Strategy
  • Data Access Object
  • Java Data Objects
  • Hibernate

4
Persistence Layer
Persistence Layer
Relational Data
Object Model
5
Persistence Layer
  • Object / Relational mismatch
  • Object model based on maintenance
  • Relational model based on data integrity
  • Impedance mismatch
  • Translation issues at the boundary
  • Confine changes to a layer
  • Ease of maintenance
  • Can switch persistence mechanisms

6
Simple Mapping
  • Map classes to database tables
  • One to one mapping
  • Each class becomes a table
  • Each attribute becomes a column
  • Individual rows are objects

7
Simple Mapping
public class Employee private int id private
String firstName private String
lastName private String email public
Employee() // ... // Gets and sets //
Other methods public void work() // ...
8
Simple Mapping
  • Multiple classes
  • Employee to Address
  • One-to-one
  • Employee to Department
  • Many-to-one
  • Employee to Project
  • Many-to-many
  • Object model uses reference attributes
  • Databases use tables
  • Foreign keys for relationships
  • Cross-reference tables for normalization

9
Simple Mapping
  • Inheritance
  • Does not map well to relational structures
  • Can add type field to table
  • 1 Salaried, 2 Hourly, etc
  • Can create separate tables for each subclass,
    with foreign keys to superclass
  • Requires joins, which take time
  • Arent really any great solutions

10
Requirements
  • Ease of transformation
  • Query mechanism to return objects from data
  • Transaction management
  • Scalability and performance
  • Portability across changes in schema, vendors,
    storage technology
  • Ease of development, configuration, testing

11
Object Serialization
  • Flatten object graph into bytes
  • Serialization follows reference attributes
  • Simple library classes available
  • Business classes must implement Serializable
  • Wrap sources inside ObjectInputStream and
    ObjectOutputStream
  • Simple writeObject() method
  • Simple readObject() method
  • Keyword transient
  • Limited to Java
  • Lack of querying capabilities

12
Design Patterns
  • Factory Method
  • Objects instantiated through a method
  • Return type is interface or abstract class
  • Client is shielded from object type
  • Abstract Factory
  • Create families of related objects without
    specifying the actual classes

13
Abstract Factory
14
Data Access Object
  • From Core J2EE Patterns
  • Abstract and encapsulate all access to the
    persistent store
  • DAO manages connection with the data store to
    obtain and store data

15
Data Access Object
16
Data Access Object
17
DAO Factory
18
Data Access Object
public class Client public static void
main(String args) DAOFactory fact
DAOFactory.getDAOFactory(DAOFactory.FI
LE) CustomerDAO custDAO fact.getCustomerDAO()
Customer c1 new Customer("Fred","Flintst
one","fflint_at_bedrock.org") custDAO.insertCustom
er(c1) Customer c2 new
Customer("Barney","Rubble","brubble_at_bedrock.org")
custDAO.insertCustomer(c2) Customer c3
custDAO.findCustomer(c2.getName()) custDAO.dele
teCustomer(c3) Customer c4 new
Customer("Mr.","Slate","boss_at_slate.com") custDA
O.insertCustomer(c4) c1.setEmail("fred.flintsto
ne_at_bedrock.org") custDAO.updateCustomer(c1)

19
Design Patterns
  • Builder
  • Define a class whose purpose is to assemble
    instances of another class
  • Can enforce constraints
  • Builds in complex construction rules
  • Can be used to make SQL more object oriented

20
Builder Pattern
21
Builder Pattern for SQL
22
Design Patterns
  • Strategy
  • Delegate responsibility to one of several
    possible implementations
  • Each strategy represents a set of behaviors
  • Strategy can be set at run time
  • Flexible

23
Strategy Pattern
24
Strategy Pattern
  • Handle different databases
  • Each DB has its own implementation
  • Methods all the same

25
Strategy for SQL
26
Design Patterns
  • Façade
  • Provide a simplified interface to a complex set
    of classes
  • For SQL, use a single class to wrap queries
  • Façade hides Connection, Statement, ResultSet
  • Clients interact with the Façade

27
Façade Pattern for Queries
28
Java Data Objects
  • Specification working through the community
    process (JSR 12)
  • Store POJOs in any kind of storage, transparent
    to the user
  • Specify implementation details in a properties
    file

29
Java Data Objects
JDOHelper
PersistenceManagerFactory
PersistenceManager
Query
Transaction
30
JDO
  • PersistenceManagerFactory used to acquire an
    instance of a PersistenceManager
  • PersistenceManager used to get a reference to a
    Transaction or Query
  • Transactions have standard methods
  • begin()
  • commit()
  • rollback()

31
JDO
  • Source code enhancement
  • Java classs source code is modified before it is
    compiled
  • Byte code enhancement
  • Post compiled class file is modified
  • Binary compatibility required across JDO
    implementations

32
JDO Query Language
  • JDO defines JDOQL
  • Simple, object based SQL
  • Filtering based on booleans and objects
  • Query q persistenceMgr.newQuery( Employee.class
    , firstName\John\)
  • Call execute() method
  • Returns all employees whose first name is John

33
JDO
  • Also defines extents to refer to all instances
    of a class in the data store
  • Returns a java.util.Iterator
  • Can even return instances of subclasses as well
  • Hollow objects return references without
    loading data

34
Hibernate
  • Open source framework
  • No byte or source code enhancing
  • Set up configuration files
  • One file to define data store info
  • One file for each class
  • Can be combined into a single mapping file
  • Again defines its own query language
  • HQL, Hibernate Query Language

35
Persisting Components
  • Enterprise JavaBeans
  • Entity beans are an object model on the data
    store
  • Secure, transactional, distributed,
  • More next time
Write a Comment
User Comments (0)
About PowerShow.com