Friday, July 17, 2009

EclipseLink : High Performance Persistence

I have used eclipselink on one of the key projects lastyear. It was donated by Oracle to Eclipse foundation. Toplink became eclipselink. I was really impressed by its implementation of JPA and customizations such as Criteria Queries. Hoping to learn more from this session.

EclipseLink Architecture

Supports JavaSE,EE,OSGi and Spring

Eclipselink solution comprises JPA implentation,Moxy,EIS,SDO(service data objects),DBWS (database webservice --> want xml from relational data ).

JPA
--> supports JPA 1.0 with many advanced features
--> simplified configuration of using annotations and/or xml.
--> Best ORM for Oracle database

Tool Support
-->EclipseLink is a runtime project supported by IDEs.
-->Eclipselink supported by Dali
-->MyEclipse
-->Oracle Jdeveloper 11g,Enterprise Pack for eclipse
--> Netbeans
--> Standalone workbench(Swing project)

Eclipselink distributions
--> Eclipse,Oracle toplink,weblogic,glassfish,spring framework,JOnAS

JPA persistence Provider(eclipselink) sits between Java SE/EE and rdbms


Core JPA Mappings

ID (primary key)
Basic (field mappings)
Relationships
OneToOne,ManytoOne,OneToMany,ManyToMany

Configurations
Persistence.xml
Mapping Annotations
Query hints
Advanced Mappings
Eclipselink orm.xml

Examples of Advanced Mappings
class level --> @Converter(name="",converterClass="")
field level --> @Convert(name="")

@PrivateOwned (coming in JPA 2.0) : doesnt exist without parent

Caching :
@Cache(type=SOFT_WEAK,coordinationType=SEND_OBJECT_CHANGES)

Optimistic locking :
@OptimisticLocking(type=CHANGED_COLUMNS)

Custom Data type conversions:
@Converter,@TypeConverter,@ObjectTypeConverter
@StructConverter

Query Framework

5 different ways

Entity Model : JPQL
Expressions
QBE
Native : SQL
Stored Procedures

Customizations in queries
--> Locking,Cache usage
--> Optimizations (batching,joining)
--> Result shaping/conversions
--> Stored Proc support

SQL and Stored Procedure directly hit db.

For other 3 query framework is used. Checks for Cache hit,Cache result is used using Object builder)

Annotations for stored procedures
@NamedStoredProcedureQuery and @NamedStoredProcedureQueries

e.g. @NamedStoredProcedureQuery(name="",procedureName="",parameters={})

Hints
eclipselink.read-only : useful in read only screens

Lazy loading & Fetch Groups
Two fetch groups defined automatically --> eagerly loaded fields and lazily loaded fields.Enabled by byte code weaving

Create your own fetch groups and added to query as hint. Overrides default fetch groups.

Caching Advantage :

Shared L2 and persistence context caching
--> Entity cache and not data cache like ehacache that comes with hibernate

Cache Invalidation --> time to live,fixed times, programmable

Cache Coordination --> Messaging,Type specific configuration (invalidate,sync,sync + new,none)

Invalidate is the most used and cheapest one

Annotations for caching : @Cache,@TimeofDay,@ExistenceChecking

Concurrency Protection :
@OptimisticLocking : Numeric,Timestamp,All Fields,Selected fields,Changed field

Pessimistic locking : using hit eclipselink.pessimistic-lock


Dealing with DB Triggers

@ReturnInsert and @ReturnUpdate : efficiently reread modified data in Oracle db.

Change Tracking
@ChangeTracking annotation to configure the way changes to Entities are computed
Attribute level ,object level, deferred ,auto

Performance Options summary
--> ChangeTracking
--> Read only queries
--> parameter binding
--> joining
--> inheritance
--> concurrency
--> dynamic expressions

Moxy : Object XML Binding

JavaApp --> Objects --> EclipselinkOXM --> xml

Rich set of mappings provides complete control to map objects to any XSD.

Eclipselink JAXB2 Annotations , Moxy XML

twice as fast as sun ri and xml beans.

API steps
1) Create factory,context
2) Marshal and UnMarshal

SDO : Xml Centric

Wow.. too fast session .. but left me lots to explore in JPA.

Eclipselink 1.1.2 released as part of Galileo

Eclipselink 2.0 --> Fall 2009 ; implements JPA 2.0

DBWS : Generated JAX-WS from DB

1 comment:

Anonymous said...

Understandably your article helped me very much in my college assignment. Hats high to you enter, intention look audacious for more cognate articles in a jiffy as its anecdote of my favourite issue to read.