Java Data Object Che-Rung Lee. JDO Objectives Transparent persistence Range of implementations  embedded (J2ME)  two tier (J2SE)  enterprise (J2EE,

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

An Object/Relational Mapping tool Free and open source Simplifies storage of object data in a relational database Removes the need to write and maintain.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Java and Databases PPJDG, May 2004 Chris Smith, MindIQ.
Distributed DBMS©M. T. Özsu & P. Valduriez Ch.15/1 Outline Introduction Background Distributed Database Design Database Integration Semantic Data Control.
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.

Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ORM Object-Relational Mapping 1. Object Persistence Persistence is the ability of an object to survive the lifecycle of the process, in which it resides.
Session-02.
By: Devesh Sharma.  Why Cloud Computing? ◦ Traditional Business Applications  Expensive  Complicated  Difficult to manage  Idea behind Cloud Computing.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
INTRODUCTION TO TRANSACTION PROCESSING CHAPTER 21 (6/E) CHAPTER 17 (5/E)
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Entity Beans BMP Celsina Bignoli
Lecture 8 Advanced Topics in Enterprise JavaBeans.
Introduction to Databases A line manager asks, “If data unorganized is like matter unorganized and God created the heavens and earth in six days, how come.
Java Persistence Frameworks No Fluff, Just Stuff 2003 By Bruce A. Tate J2Life, LLC.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Java Transaction API Sean C. Sullivan
1 An Approach to Intra-Vehicular Data Registration and Management Presented by Mr. William Pritchett DCS Corporation 1330 Braddock Place Alexandria, VA.
1 LIBeLIS JDO verleiht Flügel Enterprise Information Access Scalable, robust JDO solutions « JDO: Just Do Objects ! » Alexander v. Zitzewitz
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Object-Relational Mapping with Hibernate Brian Sam-Bodden Principal Partner Integrallis Software, LLC. August 1 - 5, 2005.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
July 7-11, 2003  Portland, Oregon JDO (Java Data Objects) What It Is And Why It Matters Ron Hitchens JavaPolis.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
COMP30311: Advanced Database Systems: Object Databases Norman Paton University of Manchester
MCS 270 Spring 2014 Object-Oriented Software Development.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Persistent State Service 1  Concept  Persistence is the ability of an object state to survive termination of the process in which the object executes.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
IST 220 – Intro to Databases Lecture 2 Touring Microsoft Access.
1 Nov 29, 2005 Object Relational Mapping Frameworks Wiene Höweler.
Session 1 Module 1: Introduction to Data Integrity
Hibernate Basics. Basics What is persistence? Persistence in Object Oriented Applications? Paradigm Mismatch.  The Problem of Granularity.  The Problem.
Object storage and object interoperability
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
Using Datastore with JDO 1. Setting up DataNucleus Access Platform 2. JDO class enhancement 3. POJOs and JDO Annotations 4. PersistencyManager and its.
OOPSLA Lab1 Chapter 7 Java Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Don't Know Jack About Object-Relational Mapping?
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
CPSC-310 Database Systems
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Knowledge Byte In this section, you will learn about:
Developing and testing enterprise Java applications
Object Relational Mapping Tools
CMPE/SE 131 Software Engineering March 7 Class Meeting
Presentation transcript:

Java Data Object Che-Rung Lee

JDO Objectives Transparent persistence Range of implementations  embedded (J2ME)  two tier (J2SE)  enterprise (J2EE, EJB) Datastore independence  relational, object, hierarchical databases  XML DB, file systems

What’s the difference? Serialization  no database capabilities (transactions, queries) JDBC  cannot storing Java object models.  incompatibilities among SQL implementations can result in a loss of application portability CMP (Container Managed Persistence)  a distributed model of computation, imposing performance degradations

JDO Introduction JDO API An example Datastore mapping JDO implementation

JDO API Two classes  I18NHelper  JDOHelper Six interfaces 1.PersistenceManagerFactory 2.PersistenceManager 3.Transaction 4.Extent 5.Query 6.InstanceCallbacks Persistence Manager Factory Persistence Manager TransactionQueryExtent Instance Callbacks JDOHelper I18NHelper

1. PersistenceManagerFactory Create PersistenceManager  May implement PersistenceManager pooling, connection pooling among PersistenceManagers Datastore configuration  Supports JNDI Persistence Manager Factory Persistence Manager TransactionQueryExtent Instance Callbacks JDOHelper I18NHelper

2. PersistenceManager Primary application interface PersistenceCapable instance management  identity  life cycle Transaction factory Query factory Extent factory Persistence Manager Factory Persistence Manager TransactionQueryExtent Instance Callbacks JDOHelper I18NHelper

3. Transactions One-one relation to Persistence Manager Transaction interface for local transactions  isActive, begin, commit, rollback Provide ACID transaction  Atomic, Consistent, Isolated, Durable Persistence Manager Factory Persistence Manager TransactionQueryExtent Instance Callbacks JDOHelper I18NHelper

4. Extents Defined for PersistenceCapable classes  pm.getExtent (Class pc, boolean subclasses); Used in Query and class navigation Persistence Manager Factory Persistence Manager TransactionQuery Extent Instance Callbacks JDOHelper I18NHelper

5. Query Can do filtering and ordering Outer/inner join Has JDOQL Persistence Manager Factory Persistence Manager Transaction Query Extent Instance Callbacks JDOHelper I18NHelper

6. InstanceCallbacks Event trigger functions in DBMS PersistenceCapable class that provides callback methods implements this interface Methods  jdoPostLoad(),  jdoPreStore(),  jdoPreClear(),  jdoPreDelete() Persistence Manager Factory Persistence Manager Transaction Query Extent Instance Callbacks JDOHelper I18NHelper

How to use JDO Write persistent object (Persistence Capable) 1.Write normal java objects 2.Specify their relation in a XML file 3.Enhance classes for persistence Make transactions (Persistence Aware)  Create and connect to a datastore  Insert / update / delete  Query

Write PersistenceCapable objects.java.class Java Compiler JDO Enhancer JDO MetaData (XML) Byte code enhancement

Address book example Persistent Object Model  Many to many relation PersonCategory *

Classes to Persist public class Person { Vector category;// element is Category … public Person() {} } public class Category { Vector person;// element is Person … private Category() {} }

JDO MetaData

JDO Enhancer Enhance classes to implement the interface PersistenceCapable run Enhancer with JDO metadata (.xml file) and class files  $enhancer$ addressbook.jdo Person.class Category.class

JDO Runtime Environment JVM Application PersistenceManager PersistenceCapable transient PersistenceCapable Query Transaction Extent

Access PersistenceCapable objects Code template 1.PersistenceManagerFactory pmf = JDOHelper. getPersistenceManagerFactory(properties); 2.PersistenceManager pm = pmf.getPersistenceManager(); 3.Transaction tx = pm.currentTransaction(); 4.tx.begin(); 5.execute(); // transaction code 6.tx.commit(); 7.pm.close();

Create a Datastore JDO will create database, tables, indexes Set property ConnectCreate = true  Unset this property if not creating a datastore Do nothing on code  void execute() {}

Create persistence object void execute(){ Person p = new Person(…); pm.makePersistent(p); // pm is a PersistenceManager }

Update persistence object We need get persistent objects from datastore for update and delete Assume we already got the object (Person p) from datastore. For update, it’s simple  void execute(){ p.setName (newName); }

Delete persistence object Assume we get the object (Person p) from datastore, and we want to delete it  void execute(){ Vector cat = p.getCategory(); for ( i=0;i<cat.size(); i++) { Category c = (Category)cat.elementAt(i); c.getPerson().remove (p); } pm.deletePersistent(p); }

Get objects from datastore Navigation Query From PersistenceManager  Object getObjectById(Object oid)  Object getTransactionalInstance(Object pco)

Navigate whole class void execute(){ Extent ext = pm.getExtent(Person.class); Iterator itor = ext.iterator(); while (itor.hasNext()) { Person p = (Person) itor.next(); }

Query with Filters void execute(){ Query qry = pm.newQuery(Person.class); qry.setFilter(filters); // filter is a String qry.setOrdering(“name ascending; birth descending”); Collection result = (Collection) qry.execute(); for(Iterator i = result.iterator();i.hasNext();) Person p = (Person) i.next(); }

Query examples Find the person named “Roger”  qry.setFilter (“name == \”Roger\”“); Find the person by parameter (String who)  qry.declareParameters (“String who"); qry.setFilter (“name == who"); result = qry.execute (who)

JDO Query Language JDO defines a set of functions for querying  isEmpty(): null singleton or collection or empty collection.  contains(): collection  startsWith(), endWith(): String matching Find persons in “CS*” Category  qry.declareParameters (“Category cat"); qry.setFilter(“category.contains(cat) && cat.name.startWith(\”CS\”)”);

Inside JDO PersistenceCapable  Object identity  Object life cycle Data mapping  Inheritance  Collection Other issues

Primary key of PersistenceCapable In datastore  assigned by the datastore and is not based on field values in the object In application  uses values of object state to form a unique identity Nondurable  not uniquely identifiable

How to compare o1 and o2? Java identity  implemented by JVM  o1 == o2 Object equality  implemented by class developer  o1.equals (o2) JDO identity  implemented by JDO vendor  o1.jdoGetObjectId().equals(o2.jdoGetObjectId())

Life Cycle of PersistenceCapable

Life Cycle States (1) Persistent-new.  During the current transaction, the instance has been placed under the control of JDO and a JDO identity has been assigned. Persistent-clean.  The instance’s fields have been read but not modified in the current transaction. Persistent-dirty.  The instance’s fields have been modified in the current transaction.

Life Cycle States (2) Hollow.  Only the JDO identity is loaded. Non-key fields are reread from the datastore in subsequent transactions.  Provides uniqueness of persistent instances across transactions.  Hollow objects are subject to garbage collection if the application does not hold strong references to them.  Persistent-clean, persistent-dirty and persistent- new instances all become hollow after commit.

Life Cycle States (3) Persistent-deleted.  Deleted in the current transaction. Access to non-key fields will throw a JDOUserException. Persistent-new-deleted.  Made persistent-new and then deleted in the current transaction. Transient, Transient-clean, Transient-dirty  The instance has not been placed under the control of JDO.

Data Mapping Issues  Database normalization: multi-table per class…  Performance: number of joins, update…  Field mapping: data types, read only…  Relation: delete policy… Implementation dependence  Some implementations can configure data mapping in JDO meta file

Data Mapping Inheritance  Map all hierarchy to base class  Discriminator is required Collection  Collection objects are second order object Not have a JDO identity Its owner can aware of its change  Difference among Set, List and Map

Other issues Object instantiation during query execution  Invocation of object methods Persistence by reachability  Garbage collector in database JDOQL to SQL compilation  Allowing SQL in JDOQL Cache management  Search caches for uncommitted objects More …

Some JDO Implementations Free  Sun Reference Implementation  Object Relational Bridge (OJB) Commercial  Fast Objects  Frontier Suit for JDO (Object Frontier)  JDO Genie  LIBeLIS LiDO  SolarMetric Kodo JDO

Next version ? Managed relationship support Inter-PersistenceManager references JDOQL to support projections API for specification of pre-read policy Enhancer invocation API Read-only fields Generation of sequence numbers for fields. Aggregation functions for JDOQL

Summery

References ch01.pdf ch01.pdf