Craig Russell - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Craig Russell

Description:

... properties, fields to columns. create new implementation ... match any one character .* match any number (0 to n) of ... Remove pre-processor, post-processor ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 29
Provided by: afceu
Category:

less

Transcript and Presenter's Notes

Title: Craig Russell


1
JavaTM Data Objects 2.0 Preview
Craig Russell Architect Sun Java Enterprise System
This is the preview for Java Data Objects 2.0
2
Presentation Objectives
  • Java Data Objects Overview
  • Current status of Java Data Objects
  • Strategic goals of Java Data Objects
  • Java Data Objects 2.0

3
Presenter's Qualifications
  • Architect, Sun Java Enterprise System
  • Specification Lead, Java Data Objects
  • JSR 12
  • JSR 243
  • Author of "Java Data Objects" published 2003,
    O'Reilly

4
Java Data Objects Overview
  • Transparent Persistence for Java
  • Java objects mapped to database objects
  • Application objects automatically retrieved,
    stored, updated
  • No database code in Domain Objects
  • NOT a Framework (but plays well with others)
  • Runs with frameworks (app server, web server)
  • Datastore independent
  • Application interfaces
  • life-cycle, query, transactions

5
Java Data Objects Interfaces
  • PersistenceManagerFactory
  • bootstrap
  • identifies data source
  • PersistenceManager
  • life-cycle (makePersistent, deletePersistent)
  • Query
  • filter collections of persistent instances
  • Transaction
  • begin, complete transactions

6
Current Status
  • Java Data Objects proposed as Java Specification
    Request 12 in May 1999
  • 1.0 released April 2002
  • 1.0.1 released August 2003
  • New Java Specification Request for 2.0 proposed
    in 2004 JSR 243
  • Vendors, Users working on detailed user interfaces

7
Strategic Goals
  • Easy to Use...
  • natural programming model
  • configuration and deployment
  • In a Wide Variety of Environments...
  • Java 2 Standard Edition (rich clients)
  • application, web servers

8
Goals for Java Data Objects 2.0
  • Maintain JDO 1.0 Compatibility
  • Standardize Mapping to Relational DB
  • Multi-tier Development Improvements
  • Usability Improvements
  • Better Object Modeling
  • Richer Queries
  • More Vendor Support

9
Standardize Mapping to RDBMS
  • Simple Mapping
  • Class lt-gt Table
  • Field lt-gt Column
  • 1-1 relationship lt-gt unique foreign key
  • 1-many relationship lt-gt foreign key
  • many-many relationship lt-gt join table
  • Complex Mapping
  • Inheritance strategies
  • Multiple tables per class
  • List, Map, Embedded

10
Multi-tier Development
  • Disconnected Object Graphs
  • Disconnect objects from PersistenceManager
  • Close PersistenceManager
  • Modify disconnected objects
  • send to different tier, or
  • apply changes directly to objects
  • Begin new transaction
  • Reconnect objects to PersistenceManager
  • Commit transaction (applies changes)
  • Disconnected Objects keep original identity and
    version

11
Usability (Bootstrap)
  • How do you find a PersistenceManagerFactory?
  • Java Data Objects 1.0 Properties
  • javax.jdo.PersistenceManagerFactoryClass\
  • com.sun.jdori.fostore.FOStorePMF
    javax.jdo.option.ConnectionURL\
  • fostore/shared/databases/jdo/dbdir
    javax.jdo.option.ConnectionUserNamecraig
    javax.jdo.option.ConnectionPasswordfaster
    javax.jdo.option.Optimistictrue
  • javax.jdo.option.RetainValuestrue
  • javax.jdo.option.NontransactionalReadtrue

12
Bootstrap
  • JDO 1.0 Properties instance
  • getPersistenceManagerFactory (Properties props)
  • JDO 2.0 Properties loaded from
  • stream
  • getPersistenceManagerFactory (InputStream props)
  • File (use to get a stream)
  • getPersistenceManagerFactory (File propsFile)
  • resource name (use to get a stream)
  • getPersistenceManagerFactory (String
    propsResource)
  • JDO 2.0 JNDI lookup
  • getPersistenceManagerFactory (String name,
    Context c)

13
Usability
  • JDO 2.0 Transaction adds
  • boolean getRollbackOnly()
  • void setRollbackOnly()
  • JDO 2.0 Query can be defined in metadata and
    accessed by name

14
Better Object Modeling
  • Persistent Abstract Class Support
  • map abstract classes to tables
  • map properties, fields to columns
  • create new implementation instances
  • Persistent Interface Support
  • map interfaces to tables
  • map properties to columns
  • create new implementation instances
  • use interfaces in queries

15
Richer Queries
Preserve Expressability in SQL
  • Projections
  • Aggregates
  • More String expressions
  • More numeric, Map functions
  • Paging query results
  • Native SQL
  • User-defined Result Class

16
Projections
  • JDO 1.0 query results are a subset of instances
    in the candidate collection
  • JDO 2.0 query results can be projections of
  • candidate collection instances
  • variable instances
  • fields
  • parameters
  • combinations of the above.

17
Projections Example
Query q pm.newQuery (Employee.class,
"dept.name.startsWith(deptName)") q.declarePara
meters ("String deptName") q.setResult("name,
salary, boss") Collection names (Collection)
q.execute("RD")
18
Aggregates
  • Query Results can be aggregates
  • Aggregates have standard semantics
  • min
  • max
  • avg
  • sum
  • count
  • Group by projected fields
  • Having allows conditional filtering

19
Aggregates Example
Query q pm.newQuery (Employee.class,
"dept.name.startsWith(deptName)") q.declarePara
meters ("String deptName") q.setResult("dept.name
, min(salary), max(salary)") q.setGrouping("dept.
name having count(dept.name) gt 1") Collection
names (Collection) q.execute("RD") for
(Object i (CollectionltObject gt) results)
println(i0, i1, i2)
20
String Expressions
  • toLowerCase(), toUpperCase()
  • indexOf(String), indexOf(String, int)
  • matches(String pattern)
  • pattern is a subset of regular expressions
  • (?i) global case-insensitive
  • . match any one character
  • . match any number (0 to n) of characters
  • pattern is literal or parameter only
  • substring(int), substring(int, int)

21
Other Query Filter Methods
  • Math.abs(numeric expression)
  • Math.sqrt(numeric expression)
  • Map.containsKey(Object)
  • Map.containsValue(Object)

22
Paging Query Results
  • Improves performance for some applications
  • Skips already-returned results
  • Limits number of results
  • Query.setRange (int fromIncl, int toExcl)
  • default
  • fromIncl 0
  • toExcl Integer.MAX_VALUE

23
User-Defined Result Class
  • JDO 1.0 query results are of type Collection
  • JDO 2.0 allows user to specify result class
  • Primitive wrapper (unique results)
  • CollectionltPrimitive wrappergt
  • Object (projected or aggregate unique results)
  • CollectionltObjectgt
  • User-defined Class (unique results)
  • CollectionltUser-defined Classgt

24
ResultClass Example
class Employee private String name private
float salary private Department dept private
Employee boss
class Info public String name public Float
salary public Employee reportsTo
Query q pm.newQuery (Employee.class,
"dept.name deptName") q.declareParameters
("String deptName") q.setResult("name, salary,
boss as reportsTo") q.setResultClass(Info.class)
Collection results (Collection)
q.execute("RD") for (Info i
(CollectionltInfogt) results) println(i.name,
i.salary, i.reportsTo.name)
25
Native SQL
  • JDO 1.0 does not recognize SQL
  • JDO 2.0 supports
  • obtaining java.sql.Connection from
    PersistenceManager
  • defining SQL queries
  • may improve performance (good)
  • makes query non-portable (bad)
  • may support SQL-specific constructs (?)
  • may allow SQL DBA more control (!)

26
More Vendor Support
  • Remove PersistenceCapable requirement
  • Remove pre-processor, post-processor requirement
  • Allow non-enhancer versions of JDO implementation
  • All other compliance requirements remain

27
JDO Strategic Goals
Standardize Relational Mapping Improve
Usability Extend Query Functionality Add Vendor
Support
28
Craig Russell craig.russell_at_sun.com java.sun.com/p
roducts/jdo JDOCentral.com
JDO gives customers compelling persistence
solutions
Write a Comment
User Comments (0)
About PowerShow.com