Speedo: a JDO open source implementation for persistency

Download Report

Transcript Speedo: a JDO open source implementation for persistency

http://speedo.objectweb.org
[email protected]
www.objectweb.org
Plan
• Speedo: the project view
• JDO Model
By the example
The API
• Speedo: the implementation
Architecture
The generator (enhancer)
www.objectweb.org
Speedo presentation - 2
Speedo: The project view
http://speedo.objectweb.org
[email protected]
www.objectweb.org
Speedo, What is it ?
• Implementation of the JDO 2.0 specification
• http//www.objectweb.org open source community
• built on top of:
Jorm: mapping of objects into a persistent support
Medor: query framework
Perseus: persistence framework
• Use Fractal, Julia, ASM, Monolog, MX4J
• Leader: France Telecom R&D
• Project responsible: S.Chassande-Barrioz
www.objectweb.org
Speedo presentation - 4
Speedo in Objectweb
Application = { Components }
Container
Framework
Data
support
www.objectweb.org
EJB CMP2
Concurrency
(Perseus)
Speedo
Transaction
(JCA)
ODB
Mapping
(JORM)
RDB
Query
(MEDOR)
File
Cache
(Perseus)
LDAP
Speedo presentation - 5
Speedo: features (1/2)
• JDO 2.0
Query aggregate
Detach/attach mechanism
•
•
•
•
Byte code enhancement (ASM)
Data support: relational databases only
Support legacy database
Various concurrency management:
By Speedo itself: Optimistic, pessimistic or Mutex
Delegated to the database
Granularity: Collection | element
• L2 Cache (persistent objects)
replacement policy: LRU | MRU | FIFO | …
Configuration per classes
www.objectweb.org
Speedo presentation - 6
Speedo: Features (2/2)
• Lazy loading by default but fetch group (JDO2)
• Data prefetching on query and collection loading
 Avoid useless I/O  increase the performance
• Fractal
component architecture
JMX
• Component pooling
Avoid the creation of java objects
Avoid the creation and the fractal component binding
• Jorm/Medor advantages
Legacy support
Other than relationnal data base
Futur: Distribution / federation
www.objectweb.org
Speedo presentation - 7
Speedo: tools
• EclipseJDO
• Eclipse plugin for speedo.properties
• PONEI: Eclipse plugin for nagivate and edit JDO persistent
model
For JDO developer
• Speedo documentation as Eclipse Plugin
• Ant task for enhancement step
• HTTP console for administration/monitoring
www.objectweb.org
Speedo presentation - 8
Work plan
3Q2005:
Several inheritance mappings (horizontal & vertical)
JDO 2: features
– Standard mapping in .jdo/.orm
– Interface
3Q2005:
Support EJB 3.0 API / JOnAS CMP3
2006:
Distributed concurrency: Perseus on JGroups
Distributed cache:
– Perseus, Oscache,Tangosol, gigaspaces
www.objectweb.org
Speedo presentation - 9
The JDO Model
http://java.sun.com/products/jdo/
www.objectweb.org
JDO: What is it ?
• SUN specification
Persistent
object
• Persistence of java objects
JDO
Data source
www.objectweb.org
Speedo presentation - 11
JDO: the principles (1/4)
• Persistent descriptor = .jdo file
Which classes are persistent ?
Which fields are persistent ?
Vendor extension for the mapping
<package name="org.objectweb.speedo.example1">
<class name="Department">
<field name="name"/>
<field name="emps"/>
</class>
<class name="Employee">
<field name="name"/>
<field name="dept"/>
</class>
www.objectweb.org
</package>
Speedo presentation - 12
JDO: the principles (2/4)
• Explicit persistence management
makePersistent(Object o)
deletePersistent(Object o)
getObjectById(Object oid)
…
• Implicit persistence
A a1 = …; //a persistent object
B b1 = … ; // a non persistent object
a1.setMyB(b1);
//Now the ‘b1’ instance is persistent
www.objectweb.org
Speedo presentation - 13
JDO: the principles (3/4)
• User transaction demarcation
Begin
Commit | rollback
• queries built by a programatic way
www.objectweb.org
Speedo presentation - 14
JDO: the principles (4/4)
• PersistenceManagerFactory
 Represents a data source
 Provides PersistenceManager instance
• PersistenceManager
 Helper to manage the persistence of objects
makePersistent, deletePersistent, …
 Linked to one PMF
 Linked to one transaction
www.objectweb.org
Speedo presentation - 15
JDO: Example (1/4)
public class Toto {
PersistenceManagerFactory pmf;
Load properties of JDO
driver from a properties
public void initJDO(String fileName) {
file (speedo.properties)
Properties p = new Properties();
p.load(new FileInputStream(fileName));
pmf = JDOHelper.getPersistenceManagerFactory(p);
}
}
Use JDO tool to instanciate/find a
PersistenceManagerFactory with
properties.
www.objectweb.org
Speedo presentation - 16
JDO: Example (2/4)
public class Department {
String name;
Map emps = new HashMap();
public Employee createEmployee(String en) {
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
• Fetch PM
Employee e = new Employee()
e.name = en;
•Transaction begin
e.dept = this;
emps.put(en, e);
• Make persistent
pm.makePersistent(e);
the new Employee
pm.currentTransaction().commit();
pm.close();
• transaction commit
}
• release the pm
}www.objectweb.org
Speedo presentation - 17
JDO: Example (3/4)
public Employee removeEmployee(String en) {
Employee e = emps.get(en);
if (e == null) return null;
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
• Fetch PM
pm.deletePersistent(e);
•Transaction begin
• Remove the Employee
pm.currentTransaction().commit();
pm.close();
}
}
www.objectweb.org
• transaction commit
• release the pm
Speedo presentation - 18
JDO: Example (4/4)
public Collection getPoorEmployee(int salary) {
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
new query over the
Employee class
Query query = pm.newQuery(Employee.class);
query.declareParameters("Float s");
query.setFilter("(salary < s)");
Collection col = new ArrayList(
(Collection) query.execute(new Float(1500.0)));
pm.currentTransaction().commit();
pm.close();
return col;
declare a parameter
declare the filter
Execute the query with
the parameter
}
www.objectweb.org
Speedo presentation - 19
Speedo: The implementation
http://speedo.objectweb.org
[email protected]
www.objectweb.org
The Speedo component
• Speedo = One fractal composite component
PersistenceManagerFactory
ProxyManager
Persistence
Manager
Factory
Persistence
Manager
PoolResource
Pool
www.objectweb.org
Speedo presentation - 21
Speedo lauching
• Two ways:
Use the Speedo component (fractal environnement)
Use the org.objectweb.speedo.Speedo class
– to launch julia,
– to instanciate the component
Interface PersistenceManagerFactory
Application
Speedo
Simple class
www.objectweb.org
Speedo
The component
Speedo presentation - 22
PersistenceManagerFactory
: the component
• PMF = one data source = one mapper
• Pool of PersistenceManager instance
PersistenceManagerFactory
PMapper
Mapper
Persistence
Manager
Factory
PMS
ProxyManagerSwitch
Pool
Pool
PooMatchFactory
www.objectweb.org
Speedo presentation - 23
Pool
Pool
PoolMatchFactory
ProxyManager
Switch
ProxyManagerSwitch
TransactionalPersistence
Manager
ProxyMan
ager
SpeedoTransactional
PersistenceManager
PersistenceManagerFactory
CacheManager
CacheManager
ProxyManager
QueryManager
SpeedoTransaction
SpeedoQueryManager
QueryManager
Transaction
www.objectweb.org
The PersistenceManager
component
Speedo presentation - 24
Pool / Fractal component
• Why pooling some fractal components
Remove the cost of the components creation and
binding
PersistenceManager / Transaction
www.objectweb.org
Speedo presentation - 25
The Speedo container
• My Container definition: code added to the
application using services in order to add semantic.
• Speedo uses several technics:
Code generation (Velocity)
Byte code injection (ASM)
Classes merging (ASM)  One class
www.objectweb.org
Speedo presentation - 26
The Speedo enhancer:
overview
XXX
1/
Byte code
injection
XXX
XXX
Jorm Generation
2/
XXXPBinding
Speedo Generation
3/
XXXProxy
extends
XXXPBinding
extends
XXXProxy
4/ Merging
XXX
www.objectweb.org
Speedo presentation - 27
The persistent object
• Persistent class (SpeedoProxy)
•
•
without any field
State (SpeedoAccessor)
contains persistent fields
Aims:
 concurrency policies
 Unique instance per OID
(less java object creation)
www.objectweb.org
Speedo presentation - 28