TD MXC Oracle Session Clarke

download TD MXC Oracle Session Clarke

of 36

Transcript of TD MXC Oracle Session Clarke

  • 8/14/2019 TD MXC Oracle Session Clarke

    1/36

  • 8/14/2019 TD MXC Oracle Session Clarke

    2/36

    EclipseLink JPA

    in GlassFish

    Doug Clarke

    Director of Product Management

    Oracle

  • 8/14/2019 TD MXC Oracle Session Clarke

    3/36

    Eclipse Persistence Services

    EclipseLink

    Eclipse Persistence Services Project

    (EclipseLink)

    DBWSDBWS

    SDOSDO

    EISEIS

    MOXyMOXy

    JPAJPA

    XML Data Legacy SystemsDatabases

    Java SEJava SE Java EEJava EE OSGiOSGi SpringSpring ADFADF

  • 8/14/2019 TD MXC Oracle Session Clarke

    4/36

    History of EclipseLink

    1996 2008

    TopLinkEssentials

  • 8/14/2019 TD MXC Oracle Session Clarke

    5/36

    Significance of EclipseLink

    First comprehensive open source persistence solution

    Object-Relational and much more

    Based upon product with 12 years of commercial

    usage

    Shared infrastructure Easily share the same domain model with multiple

    persistence technologies

    Leverage metadata for multiple services

    Important part of the GlassFish and EclipseEcosystems

  • 8/14/2019 TD MXC Oracle Session Clarke

    6/36

    EclipseLink JPA

    JPA 1.0 compliant implementation

    Java EE, Java SE, Web, Spring, and OSGi

    Any JDBC/SQL compliant database

    Advanced database extensions: stored procedures, native SQL,

    Key infrastructure: Caching, Locking, Query Framework, Mapping,

    JDBC connection pooling

    Diagnostics: Logging, Profiling

    DDL Generation

    Customization callbacks

    Highly Extensible

    plus many valuable advanced features

  • 8/14/2019 TD MXC Oracle Session Clarke

    7/36

    Caching

    Hold objects in-memory to avoid unnecessary

    database trips and object construction

    Cache manages identity to support bidirectional and

    cyclical relationships

    Flexible caching options ensure that you get

    maximum performance

    Numerous locking, refreshing, and synchronization

    options are available to minimize cache staleness

    Queries can be run in-memory only against the cache

    Cache Coordination supports clustering

  • 8/14/2019 TD MXC Oracle Session Clarke

    8/36

    Cache Configuration

    Cache Shared (L2)/Isolated (L1 only) Entity cachenot data cache

    Cache Type & Size Soft/Hard Weak

    Weak

    Full

    None

    @Cache(type = CacheType.HARD_WEAK,size = 500,

    isolated = true,coordinationType =

    INVALIDATE_CHANGED_OBJECTS)

  • 8/14/2019 TD MXC Oracle Session Clarke

    9/36

    EclipseLink JPA Caching

    EntityManager EntityManagerFactory

    L2 Cache

    (Shared )

    L1 Cache

    Cache Coordination

  • 8/14/2019 TD MXC Oracle Session Clarke

    10/36

    Minimize stale cache

    Configure the cache relative to application datas

    usage Is the data shared between users/processes?

    Is the data volatile?

    Only through JPA application?

    Through direct DB modification?

    Ensure you protect any data that can be concurrently

    modified with a locking strategy

    Must handle optimistic lock failures on flush/commit

    Use query refreshing to minimize optimistic lock

    failures

  • 8/14/2019 TD MXC Oracle Session Clarke

    11/36

    Leveraging the Shared Cache: Reading

    Client-2Client-1

    EntityManager-1

    EntityManagerFactory

    L2 Cache Connection PoolConnection

    ConnectionConnection

    Connection

    EntityManager-2

    L1 CacheL1 Cache

    Connection

    1

    2

    3

    5

    6

    7

    84

  • 8/14/2019 TD MXC Oracle Session Clarke

    12/36

    EntityManager-2

    L1 Cache

    EntityManagerFactory

    Connection PoolConnection

    ConnectionConnection

    ConnectionConnection

    Leveraging the Shared Cache: Writing

    Client-2

    L2 Cache

    1

    2

    3

    4

  • 8/14/2019 TD MXC Oracle Session Clarke

    13/36

    EntityManagerFactory

    Connection PoolConnection

    ConnectionConnection

    ConnectionConnection

    Leveraging the Shared Cache: Writing

    L2 Cache

  • 8/14/2019 TD MXC Oracle Session Clarke

    14/36

    Advanced Mappings

    @Converter

    @BasicMap and @BasicCollection

    Mapping to database structures @StructConverter Structs, ADTs

    XML types, PL/SQL Records

    Mapping features Private Owned

    Join/Batch Fetch

    Returning

  • 8/14/2019 TD MXC Oracle Session Clarke

    15/36

    @Entity

    public class Employee {

    @Idprivate int id;

    private String name;

    @OneToMany(mappedBy=owner)private List phones;

    private Money salary

    }

    @Cache(type=SOFT_WEAK, coordinationType=SEND_OBJECT_CHANGES)

    @Converter(name=money, converterClass=MoneyConverter.class)@OptimisticLocking(type=CHANGED_COLUMNS)

    Advanced Mapping Example

    @Convert(money)

  • 8/14/2019 TD MXC Oracle Session Clarke

    16/36

    Advanced Querying

    Support for supplying customizing queries

    Native SQL

    @NamedStoredProcQuery

    Graph Loading Optimizations Join and Batch Fetch multi-level

    Cache Usage: In-memory

    Result caching

  • 8/14/2019 TD MXC Oracle Session Clarke

    17/36

    Transactions

    Java apps typically support many clients sharing

    small number of db connections

    Ideally would like to minimize length of transaction on

    database

    Time

    Begin Txn

    Commit Txn Begin TxnCommit Txn

  • 8/14/2019 TD MXC Oracle Session Clarke

    18/36

    Transaction Features

    Minimizes database interactions

    Only the minimal updates are sent to the database

    Respect database integrity Orders INSERT, UPDATE and DELETE statements

    JTA and RESOURCE_LOCAL support

    Attribute-level change tracking

    EntityManager flush SQL prior to commit

    Bulk Update and Delete Cached entities effected

  • 8/14/2019 TD MXC Oracle Session Clarke

    19/36

    Concurrency Protection - Locking

    Optimistic concurrency included in JPA 1.0, but no

    support for pessimistic locking is specified

    EclipseLink has advanced optimistic locking

    strategies Numeric, Timestamp, All fields, Selected fields, Changed field

    EntityManager lock() method can be used with

    optimistic locking, and error handling

    EclipseLink supports pessimistic locking through

    query hints

    query.setHint(PESSIMISTIC_LOCK, LockNoWait);

  • 8/14/2019 TD MXC Oracle Session Clarke

    20/36

    Weaving

    EclipseLink makes use of Weaving (ASM) to

    introduce additional functionality into the JPA entity

    classes Needed for M:1 and 1:1 lazy fetching

    Integrated with Java EE compliant App Servers and Spring2.0

    Available for Java SE using JDK/JREs javaagent:

    Optional

    Static weaving also supported

    Weaving of .class files before deployment

  • 8/14/2019 TD MXC Oracle Session Clarke

    21/36

    JPA Configuration Options

    Annotations

    JPA

    EclipseLink

    ORM.XML JPA

    EclipseLink

    JPA + EclipseLink

    Defaults Configuration by Exception

  • 8/14/2019 TD MXC Oracle Session Clarke

    22/36

    Database Platform

    XML:

  • 8/14/2019 TD MXC Oracle Session Clarke

    23/36

    Target Database Platform

    TargetDatabase (org.eclipse.persistence.jpa.config)

    Auto (Default)

    Oracle, Oracle8i, Oracle9i, Oracle10g, Oracle11, TimesTen

    DB2, DB2Mainframe

    Derby, JavaDB, MySQL

    Informix

    HSQL, PointBase

    PostgreSQL

    SQLAnyWhere SQLServer, DBase

    Sybase

  • 8/14/2019 TD MXC Oracle Session Clarke

    24/36

    Server Platform

    Enables simplified configuration of the target

    application server

    Used to enable integration with: JTA transaction manager

    Logging

    JDBC connection un-wrapping

  • 8/14/2019 TD MXC Oracle Session Clarke

    25/36

    Target Server Options

    TargetServer (org.eclipse.persistence.jpa.config)

    None (Default)

    OC4J, OC4J_10_1_3, OC4J_11_1_1

    SunAS9

    WebSphere WebSphere_6_1

    WebLogic, WebLogic_9, WebLogic_10

    JBoss

  • 8/14/2019 TD MXC Oracle Session Clarke

    26/36

    JDBC Connection Settings

    ...

  • 8/14/2019 TD MXC Oracle Session Clarke

    27/36

    Logging

    ...

  • 8/14/2019 TD MXC Oracle Session Clarke

    28/36

    DDL Generation

    Standard enables it but does not currently dictate that

    providers support it

    Mapping metadata specifies how DDL should be

    generated

    Vendors may offer differing levels of support,

    including: Generating DDL to a file only

    Generating and executing DDL in DB

    Dropping existing tables before creating new ones

  • 8/14/2019 TD MXC Oracle Session Clarke

    29/36

    DDL Generation

    ...

  • 8/14/2019 TD MXC Oracle Session Clarke

    30/36

    Customization Using Properties

    ...

    ...

  • 8/14/2019 TD MXC Oracle Session Clarke

    31/36

    Descriptor & Session Customizers

    public class MySessionCustomizerimplements SessionCustomizer {

    public void customize(Session session) {session.setProfiler(new PerformanceProfiler());

    }}

    public class MyDescriptorCustomizerimplements DescriptorCustomizer {

    public void customize(ClassDescriptor desc) {desc.disableCacheHits();}

    }

  • 8/14/2019 TD MXC Oracle Session Clarke

    32/36

    Performance and Tuning

    Highly configurable and tunable Guiding principle minimize and optimize database

    interactions

    No two applications are the same, EclipseLink allows fordecisions on what specific behavior needs to be configurable

    depending on situation Flexibility of EclipseLink allows efficient business

    models and relational schemas to be used

    Leverages underlying performance tuning features

    Java, JDBC and the underlying database technology Batch Writing

    Parameter Binding

    Statement Caching

  • 8/14/2019 TD MXC Oracle Session Clarke

    33/36

    Performance and Tuning

    Minimal Writes, Updates

    Batch Reading, Writing

    SQL ordering

    Transformation support

    Existence checks Stored procedures

    Statement Caching

    Scrolling cursors

    Projection Queries

    Partial Attribute Queries

    Just in Time reading

    Automatic change detection

    Caching policies and sizes

    Parameterized SQL (binding)

    Pre-allocation of sequencenumbers

    Cache Coordination

    Optimistic, Pessimistic locking

    Joining object retrieval

    optimizationIn memory querying

    Dynamic queries

    AND MUCH MORE!

  • 8/14/2019 TD MXC Oracle Session Clarke

    34/36

    EclipseLink Status

    Incubating Technology Project Initial contribution of Oracle TopLink complete

    Full documentation available on Wiki

    Producing Monthly Milestone builds

    Milestones included in GlassFish V3 Milestones

    1.0 release planned for July 2008 JPA 1.0, SDO 2.1, JAXB

    Simplified XML and annotation config of advanced features

    Packaged for Java SE/EE and OSGi bundles

    Beyond 1.0

    JPA 2.0 (Reference Implementation) Database Web Services

    Data Access Service (DAS) 1.0

    and much more

  • 8/14/2019 TD MXC Oracle Session Clarke

    35/36

    Getting Started with EclipseLink JPA

    EclipseLink Project

    http://www.eclipse.org/eclipselink

    Eclipse newsgroup: eclipse.technology.eclipselink

    GlassFish V3

    https://glassfish.dev.java.net/

    Open Source JPA Tools NetBeanshttp://www.netbeans.org

    Dali JPA Toolshttp://www.eclipse.org/dali

  • 8/14/2019 TD MXC Oracle Session Clarke

    36/36