Objektorienteret netværkskommuniation(ITONK1) Persistence.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 10: Designing Databases
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
Middleware Fatemeh Hendijanifard 1 آزمايشگاه سيستم هاي هوشمند (
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Data Management Design
Java 2 – Enterprise Edition Kevin J. LaFata April 21, 2003 UM – St. Louis.
J2EE vs..NET Nigam Patel. Topics Background –Web Services, J2EE and.NET Similarities Differences Conclusion –Pros and Con (J2EE and.NET)
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Overview Celsina Bignoli Distributed Business Applications Server DB Client DB Server DB.
Objektorienteret netværkskommuniation(ITONK1) Persistence.
15 - RMI/EJBCSC4071 Distributed Objects Java Remote Method Invocation Enterprise Java Beans.
Enterprise Java Beans - (EJB)
Entity Beans BMP Celsina Bignoli
Middleware Technology (J2EE/EJB) Entity Bean. 2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Chemical Toxicity and Safety Information System Shuanghui Luo Ying Li Jin Xu.
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 Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
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.
Objektorienteret netværkskommuniation(ITONK1) Persistence.
Objektorienteret Middleware (OOMI) Persistence. Ingeniørhøjskolen i Århus Slide 2 af 53 Goal with todays lesson After these 2x35 minutes you will be:
1 LIBeLIS JDO verleiht Flügel Enterprise Information Access Scalable, robust JDO solutions « JDO: Just Do Objects ! » Alexander v. Zitzewitz
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
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.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Fall CIS 764 Database Systems Engineering L18.2 : Object Relational Mapping … ….Object persistence.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Presentation 3: Designing Distributed Objects. Ingeniørhøjskolen i Århus Slide 2 af 14 Outline Assumed students are knowledgeable about OOP principles.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Persistent State Service 1  Concept  Persistence is the ability of an object state to survive termination of the process in which the object executes.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Fall CIS 764 Database Systems Engineering L11: Object Relational Mapping … (a) ORM, Object persistence (b) Pets sequence.
DEPTT. OF COMP. SC & APPLICATIONS
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Objektorienteret Middleware (OOMI)
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
Understanding and Designing with EJB
Knowledge Byte In this section, you will learn about:
Understanding and Designing with EJB
Developing and testing enterprise Java applications
Presentation transcript:

Objektorienteret netværkskommuniation(ITONK1) Persistence

Ingeniørhøjskolen i Århus Slide 2 Goal with todays lesson After these 2x35 minutes you will be: –Comfortable with the expression “persistence”, and how it relates to Distributed Systems –Knowledgeable about different strategies for obtaining persistence for Distributed Systems –Ready to explore the subject further –You will not: Be an expert on persistence, as this is a huge area in itself

Ingeniørhøjskolen i Århus Slide 3 Outline Plenum – experience with persistent datastorage Continuing exercise Principles of Persistence Datastore Technology for Persistence –Files –Relational Databases Examplified OR-mapping with EJB –Object Databases

Ingeniørhøjskolen i Århus Slide 4 Experience with Persistent datastorage To establish a picture of your knowledge –Which types of persistent datastorage do you know? –What experience do you have in using it with (oo) programming languages? –What problems did you face – and how did you solve them?

Ingeniørhøjskolen i Århus Slide 5 Exercise: comparing strategies for persistence This will be a continuing discussion Select one or more entity classes from your own required assignment 1 an discuss how to solve the persistent requirements of the assignment using: –File persistence –Relational Database Management System (toolkit or emb. JDBC) –Object database system (ODBMS, e.g. JDO) Using information obtained from the examples from ONK-2 and the following slides Feel free to use the classroom PC for searching for more information We will stop after each section (files, RDBMS, ODBMS), and allow for 5 min. group work We will end with a follow-up discussion

Principles of Persistence

Ingeniørhøjskolen i Århus Slide 7 What is Persistence – a definition Persistence is the ability of an object to survive the lifetime of the process in which it resides. Persistence is relevant for stateful server objects. What is State? –State = object instance attributes – private & public –Not methods We remember the activation/deactivation discussion? –The state needs to be retained between object deactivation and object activation –Why?

Ingeniørhøjskolen i Århus Slide 8 How to achieve Persistence? Storing object state on persistent datastore before deactivation Upon activation, load object state from persistent datastore –E.g. RMI activation Persistent storage can be obtained by? –File system embedded systems on disk-storage, Flash-RAM and others –Relational Database All from embedded, to desktop and enterprise servers (most widely used is SQL servers) –Object-Database Has been emerging technology for years, but no widespread support yet. JDO for Java is a promising technology however –Others?

Datastore Technology for Persistence

Ingeniørhøjskolen i Århus Slide 10 Datastore Technology Persistence can be implemented using Files –CORBA Externalization –C#/Java type File Serialization –Structured Storage in COM Relational Databases –Object Relational Mapping “Homegrown”, CMP, JDO, Hibernate, Torque, LLBLGen Pro –JDBC/ODBC Oracle, IBM DB2, Microsoft SQL Server & Access, MySQL Object Databases – Versant, JDOhttp://

Ingeniørhøjskolen i Århus Slide 11 Problems with File-based Persistence Mapping to Files can be inefficient for large composite objects File systems only have crude support for concurrency control File systems lack support for fault-tolerance (transactions) Application specific code needed for every persistent class

Ingeniørhøjskolen i Århus Slide 12 Continuing exercise part 1 – file-based Select one or more entity classes from your own required assignment 1 an discuss how to solve the persistent requirements of the assignment using: –File persistence –Pro’s and Con’s –How to implement?

Ingeniørhøjskolen i Århus Slide 13 Relational Database Relational Database Management Systems (RDBMSs) Examples: –Ingres –Oracle –Sybase –DB2 –Microsoft SQL Server –Microsoft Access –MySQL –PostGree DB

Ingeniørhøjskolen i Århus Slide 14 Mapping to RDBMS’s Relational database schemas consist of sets of tables Types of mapping: –Define a table for each type –Complex mapping In each table create –primary key for object identifier –a column for each attribute of the object mapping of middleware atomic types to primitive types supported by RDBMS secondary keys for object references Resolve inheritance statically –This and other problems -> Objects and RDBMS does not map perfectly: –the OR impedance mismatch

Ingeniørhøjskolen i Århus Slide 15 Embedding Queries into Programs Embedded SQL –Macros to embed queries into programs –RDBMS provides processor to expand macros –API to traverse queries –Not standardized Open Database Connectivity (Microsoft) –Standardized API for RDBMS Access available on all Microsoft Platforms Java Database Connectivity (Sun) –Standardized RDBMS Access from Java

Ingeniørhøjskolen i Århus Slide 16 Issues with mapping Does this mean that we should figure out for ourselfes how to obtain the OR-mapping? –No –Frameworks available –CORBA PSS, COM persistence, EJB for Java, CCM, Hibernate, others –JDBC is at a low level –Hibernate project freeware

RDBMS mapping illustrated with EJB’s

Ingeniørhøjskolen i Århus Slide 18 Enterprise JavaBeans (EJB’s) Standard server-side component model for Java Enterprise Applications –security –resource pooling –persistence –concurrency –transactional integrity Has nothing to do with “JavaBeans” –JavaBeans designed for intra-process purposes GUIs, non-visual widgets, entity representations –Enterprise Java Beans (EJB) designed for inter-process purposes

Ingeniørhøjskolen i Århus Slide 19 EJB’s (cont.) Restricted to Java (only implementation language) –platform independence –“write once, run anywhere” EJB components –platform/implementation independence –write once, run in any Application Server complying with the EJB spec J2EE reference implementation Oracle’s Application Server (OAS) IBM’s Websphere BEA’s Weblogic Server and Weblogic Enterprise Sybase’s EAServer Open Source – JBoss (see links)

Ingeniørhøjskolen i Århus Slide 20 Bean Usage Entity beans –model state maintained across all client interactions –represent a row of data in a database Session beans –model business process being performed by a single client involving one or more entity beans –it extends the actions of the client into the server simplifies the actions programmed by the client limits the number of distributed calls required between the client and the entity beans limits the number of stubs that have to be loaded by the client –are not persisted to a database Maps to domain model (Entity classes) Maps to Use Case model (Control classes)

Ingeniørhøjskolen i Århus Slide 21 Entity Bean Types Bean can have total control over loading and storing from database –Bean Managed Persistence (BMP) Container can take over this responsibility –Container Managed Persistence (CMP) Still need to define an OR mapping in admin tool This is the same in CORBA CCM / PSS –Specialized Implementations Legacy applications such as CICS When to choose what? –Well – start out with CMP if possible, and then migrate code as performance issues pops up during testing

Ingeniørhøjskolen i Århus Slide 22 Bean Managed Persistence Have to handle all database interaction –except distributed transactions ejbLoad() and ejbStore() called when bean instance state must be synchronized with database ejbActivate() and ejbPassivate() called when bean is moved between the ready state and pooled state

Ingeniørhøjskolen i Århus Slide 23 Implement a BMP Entity Bean package java.examples.ejb.entity.bean; import javax.ejb.EntityBean; import javax.ejb.EntityContext; … public class BookBMP extends BookEJB { private DataSource dataSource_; private EntityContext ctx_; … Additional setup of database connections needed – some are done in the configuration tool Important features: Entity beans always implement the following event handles: ejbCreate: insert ejbRemove: delete ejbLoad: select ejbStore: update ejbFindByPrimaryKey: select And more can be implemented: ejbFindBooksByAuthor: select

Ingeniørhøjskolen i Århus Slide 24 Implement DB Insertion public String ejbCreate(String id, String title, String author, String topic) { super.ejbCreate(id, title, author, topic); Connection conn = null; PreparedStatement pstatement = null; try { conn = dataSource_.getConnection(); pstatement=conn.prepareStatement("insert into Book (id, title, author, topic)"+ ” values (?, ?, ?, ?)"); pstatement.setString(1,id_); pstatement.setString(2,title_); pstatement.setString(3,author_); pstatement.setString(4,topic_); pstatement.execute(); return id_; } catch(SQLException ex) { throw new EJBException(ex); } finally { … } } idtitleauthortopic 42123EJBSWEJB 43423EJB2SWEJB ………… BookBMP OR-mapping

Ingeniørhøjskolen i Århus Slide 25 Implement DB Load public void ejbLoad() { Connection conn = null; PreparedStatement pstatement = null; ResultSet rs = null; try { conn = dataSource_.getConnection(); pstatement = conn.prepareStatement( "select id, title, author, topic from Book " + "where id = ?"); pstatement.setString(1, (String)ctx_.getPrimaryKey()); rs = pstatement.executeQuery(); if (rs.next()) { id_ = rs.getString("id"); title_ = rs.getString("title"); author_ = rs.getString("author"); topic_ = rs.getString("topic"); super.ejbLoad(); } else { throw new EJBException("unable to locate row"); } catch(SQLException ex) { throw new EJBException(getText(ex)); } finally { … } …

Ingeniørhøjskolen i Århus Slide 26 Implement DB Store public void ejbStore() { Connection conn = null; PreparedStatement pstatement = null; try { super.ejbStore(); conn = dataSource_.getConnection(); pstatement = conn.prepareStatement( "update Book set title=?, author=?, topic=? " + "where id = ?"); pstatement.setString(1,title_); pstatement.setString(2,author_); pstatement.setString(3,topic_); pstatement.setString(4,id_); pstatement.executeUpdate(); } catch(SQLException ex) { throw new EJBException(getText(ex)); } finally { … } }

Ingeniørhøjskolen i Århus Slide 27 Implement DB Remove public void ejbRemove() { Connection conn = null; PreparedStatement pstatement = null; try { super.ejbRemove(); conn = dataSource_.getConnection(); pstatement = conn.prepareStatement("delete from Book " + "where id = ?"); pstatement.setString(1, (String)ctx_.getPrimaryKey()); pstatement.executeUpdate(); } catch(SQLException ex) { throw new EJBException(getText(ex)); } finally { … } }

Ingeniørhøjskolen i Århus Slide 28 Implement Finders public String ejbFindByPrimaryKey(String pk) throws FinderException { Connection conn = null; PreparedStatement pstatement = null; ResultSet rs = null; try { conn = dataSource_.getConnection(); pstatement = conn.prepareStatement("select id from Book " + "where id = ?"); pstatement.setString(1, pk); rs = pstatement.executeQuery(); if (rs.next()) { return rs.getString("id"); } else { throw new ObjectNotFoundException(pk + " no found"); } } catch(SQLException ex) { throw new EJBException(getText(ex)); } finally {... } }

Ingeniørhøjskolen i Århus Slide 29 Implement Finders (cont.) public Collection ejbFindAll() throws FinderException { Connection conn = null; PreparedStatement pstatement = null; ResultSet rs = null; try { Vector pKeys = new Vector(); conn = dataSource_.getConnection(); pstatement = conn.prepareStatement("select id from Book "); rs = pstatement.executeQuery(); while (rs.next()) { pKeys.add(rs.getString("id")); } return pKeys; } catch(SQLException ex) {throw new EJBException(getText(ex)); } finally {... } }

Ingeniørhøjskolen i Århus Slide 30 Continuing exercise part 2 – RDBMS based Select one or more entity classes from your own required assignment 1 an discuss how to solve the persistent requirements of the assignment using: –RDBMS Embedded SQL If you have experience using toolkits, be free to elaborate on this –Pro’s and Con’s –How to implement –Compared to using file externalization

Principles of Persistence continued ODBMS

Ingeniørhøjskolen i Århus Slide 32 ODBMS ODBMSs have been standardized by the Object Database Management Group –Schema definition language (ODL) – subset of CORBA IDL –Programming language bindings to C++ Java And many others –Object Query Language (OQL) –JDO has replaced the Java binding Support persistence of OO programming language objects

Ingeniørhøjskolen i Århus Slide 33 JDO: POJO’s

Ingeniørhøjskolen i Århus Slide 34 Continuing exercise part 3 – ODBMS based Select one or more entity classes from your own required assignment 1 an discuss how to solve the persistent requirements of the assignment using: –ODBMS Use the JDO example from ONK-2 –Pro’s and Con’s –How to implement? –Compared to using RDBMS and file externalization

Ingeniørhøjskolen i Århus Slide 35 Comparison File externalization / serialization is not transparent for implementors of server objects Persistence in RDBMS’s is –complicated by OR-impedance mismatch –simplified by wide availability of RDBMS’s –Well-known tested technology Persistence in ODBMS’s is –simplified by conceptual similarities of object models programming language bindings –No widespread support –(personal view) I would not risk high-performance system on this