Java Data Objects Write Once Persist Everywhere - PowerPoint PPT Presentation

1 / 77
About This Presentation
Title:

Java Data Objects Write Once Persist Everywhere

Description:

UK. Milton Keynes. Edinburgh. USA. New York. Washington ... Pre-order at Amazon.co.uk now. Complete coverage of JDO, many examples. including J2EE and JDOQL ... – PowerPoint PPT presentation

Number of Views:315
Avg rating:5.0/5.0
Slides: 78
Provided by: robin94
Category:

less

Transcript and Presenter's Notes

Title: Java Data Objects Write Once Persist Everywhere


1
Java Data ObjectsWrite Once - Persist
Everywhere!
  • Robin M. Roos
  • Principal Consultant
  • Ogilvie Partners
  • www.OgilviePartners.com

2
Introduction
  • Robin Roos (Robin_at_OgilviePartners.com)
  • Using Java since 1997
  • Sun certified
  • Programmer, Developer, Architect, WCD
  • Java instructor architecture consultant
  • Member of JDO Expert Group (JSR12)
  • Training course JDO Book

3
Background
  • JDO Specification...
  • Transparent Persistence for Java Objects
  • Café June 1999
  • Participant Review May 2000
  • Public Review July 2000
  • 1st Proposed Final Draft May 2001
  • Standardized March 2002

4
Acknowledgements
  • Java
  • is a Trade Mark of Sun Microsystems
  • JDOQL
  • The Query examples are taken from the JDO
    Specification
  • JDO
  • would not have happened without the efforts of
    the JDO Expert Group

5
Agenda
  • Part 1 JDO - Write Once, Persist Anywhere
  • 1. Overview
  • 2. JDO Architecture
  • 3. JDO Instance Lifecycle
  • 4. Persistent Object Model
  • 5. Primary Interfaces and Classes
  • 6. Queries with JDOQL

6
WARNING
  • This presentation contains Java and XML

7
Persistence Overview
  • Object-Relational Mapping
  • Most Java application objects need to be
    persisted
  • Object/Relational impedance mismatch
  • Until now, JDBC programming used to map between
    rows/columns and object properties
  • JDBC must be crafted by an SQL expert
  • Resulting objects restricted to Relational
    persistence

8
UML for JDBC Example
9
JDBC Pros and Cons
  • Advantages
  • Application works with any JDBC-compliant
    database
  • Can adapt to existing Customer table structure
  • Disadvantages
  • Only JDBC-compliant (Relational) databases
  • Must write persistence infrastructure taking
    resource away from application logic.
  • Need SQL expertise
  • SQL not always portable

10
Java Data Objects
  • Specification for Transparent Persistence
  • Abstract API for persistence services
  • Influenced by ODMG and Forté for Java
  • Supported by many vendors
  • Program to the standard API
  • Select a compliant implementation based on
    quality of service

11
Elementary JDO (1/4)
  • Some domain classes capable of persistence
  • Write as ordinary classes and compile them.
  • Describe their persistence needs in XML
  • Enhance by hand or using the enhancer tool
  • Provided by your JDO vendor
  • Might generates DDL file for relational tables
  • Create the tables using the DDL file as required

12
Elementary JDO (2/4)
  • Some applications read/write Persistent objects
  • Lookup or otherwise obtain a factory
  • Use PersistenceManagerFactory instance to obtain
    a PersistenceManager instance
  • Invoke methods on the PersistenceManager
  • makePersistent() to store a new object
  • getExtent() to read lists of objects

13
Elementary JDO (3/4)
  • Developer does not
  • use SQL
  • know or worry about table structure
  • map objects/attributes to tables/columns
  • write infrastructure code

14
Elementary JDO (4/4)
  • Application is independent of
  • JDO Vendor
  • OpenFusion JDO from Prism Technologies today
  • Xxx JDO from Xxx Corporation tomorrow
  • Storage technology
  • RDBMS today, ODBMS tomorrow, low-footprint
    storage engine next week.

15
UML for JDO Example
16
Persistence Descriptor (XML)
  • Customer.jdo

17
Understanding the JDO Example
  • Bootstrap the JDO Implementation
  • Get a PersistenceManagerFactory
  • Get a PersistenceManager
  • Create and Persist a new Customer
  • Read and display all persistent Customers
  • Close Resources

18
jdo.properties
  • jdo.properties is not part of the JDO standard
  • it is used by the helper class JDOBootstrap
  • javax.jdo.PersistenceManagerFactoryClasscom.prism
    t.j2ee.jdo.PersistenceManagerFactoryImpl
  • javax.jdo.option.ConnectionUserNamesa
  • javax.jdo.option.ConnectionPassword
  • javax.jdo.option.ConnectionURLjdbchsqldbhsql//
    localhost
  • javax.jdo.option.ConnectionDriverNameorg.hsqldb.j
    dbcDriver

19
Bootstrap JDO Implementation
  • JDOBootstrap bootstrap new JDOBootstrap()
  • PersistenceManagerFactory pmf
  • pmf bootstrap.getPersistenceManagerFactory()
  • pm pmf.getPersistenceManager()

20
Create a new Customer
  • Customer c new Customer()
  • c.setCustomerNumber(args0)
  • c.setName(args1)
  • c.setAddress(args2)
  • try
  • c.setCreditLimit(Double.parseDouble(args3))
  • catch (NumberFormatException nfe)
  • c.setCreditLimit(0)

21
Persist the new Customer
  • Transaction t pm.currentTransaction()
  • t.begin()
  • pm.makePersistent(c)
  • t.commit()

22
Read and display all Customers
  • t.begin()
  • Extent ext pm.getExtent(Customer.class, true)
  • Iterator i ext.iterator()
  • System.out.println(Listing all Customers)
  • while (i.hasNext())
  • System.out.println(i.next())
  • System.out.println(Done.)

23
Close Resources
  • // close the iterator
  • ext.close(i)
  • // commit transaction
  • t.commit()
  • // close the PersistenceManager
  • pm.close()

24
JDO Pros and Cons
  • Advantages
  • Application works with any compliant JDO
    implementation
  • RDBMS, OODBMS or lightweight alternative
  • Dont write persistence infrastructure just
    application logic
  • No SQL dependency
  • Disadvantages
  • Mapping to existing relational schema is
    described in a vendor-specific manner.

25
JDO Instance
  • Java language instance of a class which
  • usually part of business domain object model
  • implements application functionality
  • can represent data from a persistent store
  • Implement the PersistenceCapable interface
  • explicitly via class developer
  • implicitly via class Enhancer

26
JDO Implementation
  • Set of classes implementing JDO Interfaces
  • implementations are expected to be appropriate
    for one particular storage medium
  • a generic JDBC-compliant RDBMS, or a particular
    RDBMS (optimised at expense of SQL portability)
  • a particular ODBMS
  • a lightweight medium such as binary files
  • Applications using JDO portable across different
    JDO Vendors implementations

27
Enhancer
  • Byte-Code Enhancer
  • Modifies .class files to facilitate field access
    by JDO infrastructure
  • methods/attributes do not have to be public
  • Result implements PersistenceCapable and provides
    concrete method implementations
  • Full binary compatibility

28
Transparent Persistence (1/2)
29
Transparent Persistence (2/2)
  • Persistence by Reachability
  • very rarely need to use makePersistent()
  • Automatic change tracking
  • Automatic synchronization of dirty Instances on
    commit
  • no need to save() changes to persistent
    instances

30
JDO Environments
  • JDO usage is envisaged in 2 environments
  • Non-managed Environment
  • usage independent of J2EE Application Servers
  • all the benefits of transparent persistence
  • Managed Environment
  • Entity, Session, MessageDriven Beans,
    Servlets/JSP
  • Additional transparency for components use of
    infrastructure (transactions, security,
    connections)

31
Transactional/Persistent
  • JDO Instances may be
  • Transient or Persistent
  • Transactional or Nontransactional

32
JDO Identity Mechanisms (1/2)
  • Application (Primary Key) Identity
  • values in the instance determine its identity
  • Data Store Identity
  • independent of any instance values
  • Non-durable JDO Identity
  • uniqueness is guaranteed in the JVM but is not
    supported in the data store.

33
Specifying JDO Identity
  • . . .
  • . . .
  • . . .

34
Specifying Application Identity
  • identity-typeapplication
  • objectid-classop.PersonKey

35
Inheritance
  • JDO supports Inheritance

nameProduct persistence-capable-superclass
AbstractItem /
36
Collection Example
  • transient Collection orders
  • orders new HashSet()
  • nameorders
  • persistence-modifier persistent

37
Required Lifecycle States
  • Transient
  • Persistent-New
  • Persistent-New-Deleted
  • Hollow
  • Persistent-Clean
  • Persistent-Dirty
  • Persistent-Deleted

38
Required State Transitions
39
JDO Exception Hierarchy
40
Primary Interfaces
  • JDOHelper
  • PersistenceManagerFactory
  • PersistenceManager
  • Extent
  • Transaction
  • Query
  • (PersistenceCapable)

41
Getting to the First Object
  • Application may access a closure of instances
    navigated to from one instance
  • 3 ways to get the first instance
  • PersistenceManager.getObjectById()
  • must be able to construct the Object ID
  • PersistenceManager.getExtent()
  • must navigate extent of all persistent instances
  • JDOQL

42
JDO Query Language
  • JDO removes SQL-dependencies for manipulating
    persistent data
  • JDOQL is a data store-independent Java-like query
    language
  • Java developers no longer require SQL for queries
    either
  • Efficient architecture (no instantiation)
  • Future migration to ODBMS is seamless

43
Query Structure
  • Candidate class
  • Candidate collection or extent
  • Java-like Syntax for
  • Variable declarations
  • Parameter declarations
  • Filter expression
  • Import declarations
  • Ordering declarations

44
Supported Operators
45
Query Execution
  • Parameters passed to execute methods are for this
    execution only
  • Specify parameters in sequence of declaration
  • execute()
  • execute(Object p1)
  • execute(Object p1, Object p2)
  • execute(Object p1, Object p2, Object p3)
  • executeWithArray(Object a)
  • executeWithMap(Map m)

46
Query Examples
  • 5 examples follow using the classes described
    below

47
Query Example 1
  • Basic query
  • Select all Order instances where the orderValue
    is greater than the constant 250.

48
Query Example 1 - Code
  • Extent extOrder pm.getExtent(Order.class,
    true)
  • String filter orderValue 250
  • Query q pm.newQuery(extOrder, filter)
  • Collection results (Collection) q.execute()

49
Query Example 2
  • Basic query with ordering
  • This query selects all Order instances where the
    orderValue is greater than the constant 250, and
    returns a Collection ordered according to
    orderDate descending

50
Query Example 2 - Code
  • Extent extOrder pm.getExtent(Order.class,
    true)
  • String filter orderValue 250
  • Query q pm.newQuery(extEmployee, filter)
  • q.setOrdering(orderDate descending)
  • Collection results (Collection) q.execute()

51
Query Example 3
  • Parameter passing
  • This query selects all Order Instances where the
    orderValue is greater than the value passed as a
    parameter.

52
Query Example 3 - Code
  • Extent extOrder pm.getExtent(Order.class,
    true)
  • String filter orderValue val
  • Query q pm.newQuery(extOrder, filter)
  • q.setOrdering(orderDate descending)
  • q.declareParameters(Double val)
  • Collection results
  • results (Collection) q.execute(new Double(250))

53
Query Example 4
  • Navigation through single-valued field
  • This query selects all Order instances from the
    candidate collection where the value of the
    address field in the corresponding Customer
    instance equals the value passed in as a
    parameter.

54
Query Example 4 - Code
  • Extent extOrder pm.getExtent(Order.class,
    true)
  • String filter customer.address addr
  • Query q pm.newQuery(extOrder, filter)
  • q.declareParameters(String addr)
  • Collection emps (Collection) q.execute(London)

55
Query Example 5
  • Navigation through multi-valued field
  • This query selects all Customer instances where
    the orders collection contains at least one Order
    instance having an orderValue greater than the
    value passed in as a parameter.

56
Query Example 5 - Code
  • String filter, vars, param
  • Class custCls Customer.class
  • Extent extCustomer pm.getExtent(custCls, true)
  • vars Order o
  • filter orders.contains(o) o.orderValue
    val
  • param Float val
  • Query q pm.newQuery(extCustomer, filter)
  • q.declareParameters(param)
  • q.declareVariables(vars)
  • Double searchVal new Double(250)
  • Collection result (Collection)
    q.execute(searchVal)

57
But Can I Use JDO Today
?
58
Commercial Implementations
  • enJin by Versant Software
  • FastObjects by Poet Software
  • FrontierSuite by ObjectFrontier
  • IntelliBO by Signsoft GmbH
  • JDO Genie by Hemisphere Technologies
  • JRelay by Object Industries GmbH
  • Kodo JDO by Solarmetric
  • LiDO by LIBeLIS
  • OpenFusion JDO by Prism Technologies
  • Orient by Orient Technologies

59
Managing Complexity
Just one of many diagrams that comprise a
non-trivial object model, designed in Together
6.0 and persisted with JDO as part of a recent
Ogilvie Partners client engagement
60
Conclusion
  • JDO
  • provides significant development time savings
  • is easier than JDBC and can be faster!
  • prepared batched statements
  • is more reliable than JDBC
  • particularly for complex domain object models
  • integrates fully with all J2EE components
  • Vendors will still let you use SQL if you prefer!

61
Ogilvie Partners JDO Training
  • 2-day labs-based vendor-independent
  • Public Training
  • UK
  • Milton Keynes
  • Edinburgh
  • USA
  • New York
  • Washington
  • Others
  • Dedicated Training
  • Available world-wide

62
Ogilvie Partners Consultancy
  • Consultancy
  • JDO applicability to your projects
  • JDO Implementation selection
  • Architecture design
  • Domain object modelling
  • Mentoring
  • Meeting JDO-based learning objectives whilst
    working with developers on their project work

63
Ogilvie Partners The JDO Book
  • Java Data Objects
  • Written by Robin Roos
  • Published by Addison-Wesley Publishers Ltd
  • ISBN 013066839, Available from August 2002
  • Foreword by Craig Russell, JDO Spec Lead
  • Pre-order at Amazon.co.uk now
  • Complete coverage of JDO, many examples
  • including J2EE and JDOQL
  • prerequisite knowledge of the Java language

64
(No Transcript)
65
Online JDO-Related Forums
  • JavaDataObjects at Yahoo!Groups
  • www.groups.yahoo.com/group/JavaDataObjects
  • JDOcentral
  • www.JDOcentral.com
  • Lots more information on our website
  • www.OgilviePartners.com
  • Contact me
  • Robin_at_OgilviePartners.com

66
www.OgilviePartners.com
67
(No Transcript)
68
Rewriting the J2EE Blueprints
  • Integrating JDO with J2EE Architectures and
    Components

69
Client-Server Architecture
  • Before JDO
  • Today

70
RMI Server Architecture
Before JDO Today
71
J2EE Blueprint - Original
72
J2EE Blueprint - Session Façade
73
J2EE Blueprint - Real World
74
JDO in the J2EE Architecture
75
Reassuring Entity Bean Lovers
JDO as delegate for BMP
76
(No Transcript)
77
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com