BMP vs. CMP in Entity EJBs Acronyms Gone Wild (AGW)

Similar documents
CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS

SAP Web Application Server 6.30: Learning Map for Development Consultants

Java EE 7: Back-End Server Application Development

Enterprise Applications

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

David Dye. Extract, Transform, Load

Object-Oriented Databases Course Review

Java E-Commerce Martin Cooke,

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

EJB & J2EE. Component Technology with thanks to Jim Dowling. Components. Problems with Previous Paradigms. What EJB Accomplishes

CONSUMER DEMAND MONITORING AND SALES FORECASTING (CDMFS) SYSTEM

Distributed Objects and Components

Japan Communication India Skill Development Center

OptimalJ Foundation. PSM EJB Model. Roadmap. What is the EJB model? EJB model as a PSM model Mapping the EJB model Model elements and code generation

Expert One-on-One J2EE Design and Development

Chapter 4. Architecture. Table of Contents. J2EE Technology Application Servers. Application Models

Component Middleware. Sophie Chabridon. INT - INF Department - Distributed Systems team 2006

Diagnosing Production Java Applications Madhav Sathe

Software Development using MacroMedia s JRun

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Requirements Design Implementation. Software Architectures. Components Software Component Architecture. DSSA: Domain-Specific Software Architectures

Oracle WebLogic Server 11g Administration

Japan Communication India Skill Development Center

Core Java+ J2EE+Struts+Hibernate+Spring

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

Building Web Applications, Servlets, JSP and JDBC

CS346: Database Programming.

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Performance Tuning for the JDBC TM API

Java Data Objects. JSR000012, Version 0.8 Public Review Draft. Specification Lead: Craig Russell, Sun Microsystems Inc.

Real-time Data Replication

<Insert Picture Here> Java EE 7: the New Cloud Platform

Agile Business Suite: a 4GL environment for.net developers DEVELOPMENT, MAINTENANCE AND DEPLOYMENT OF LARGE, COMPLEX BACK-OFFICE APPLICATIONS

<Insert Picture Here> Java EE 7: the New Cloud Platform

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Distributed Database Design

How To Develop An Application Developer For An Ubio Websphere Studio 5.1.1

Cache Database: Introduction to a New Generation Database

Object Oriented Database Management System for Decision Support System.

era J2EE Platform and Tool Recommendations

The end. Carl Nettelblad

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

<Insert Picture Here> Oracle Application Express 4.0

Japan Communication India Skill Development Center

IBM Rational Web Developer for WebSphere Software Version 6.0

25 May Code 3C3 Peeling the Layers of the 'Performance Onion John Murphy, Andrew Lee and Liam Murphy

Exam Name: IBM InfoSphere MDM Server v9.0

ORM IN WEB PROGRAMMING. Course project report for 6WW Erik Wang

C/S Basic Concepts. The Gartner Model. Gartner Group Model. GM: distributed presentation. GM: distributed logic. GM: remote presentation

Patterns of Enterprise Application Architecture

Open For Business in a Nutshell

Monitoring Pramati EJB Server

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

Announcements. Comments on project proposals will go out by in next couple of days...

Enterprise Application Integration

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

MagDiSoft Web Solutions Office No. 102, Bramha Majestic, NIBM Road Kondhwa, Pune Tel: /

The EMSX Platform. A Modular, Scalable, Efficient, Adaptable Platform to Manage Multi-technology Networks. A White Paper.

Working with WebSphere 4.0

WebLogic Server 7.0 Single Sign-On: An Overview

Micro Focus Database Connectors

EII - ETL - EAI What, Why, and How!

1. Introduction What is Slice? Background Why Slice? Purpose of this Document Intended Audience...

<Insert Picture Here> Java Application Diagnostic Expert

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

Oracle Weblogic. Setup, Configuration, Tuning, and Considerations. Presented by: Michael Hogan Sr. Technical Consultant at Enkitec

J2EE Web Development. Agenda. Application servers. What is J2EE? Main component types Application Scenarios J2EE APIs and Services.

Oracle8/ SQLJ Programming

Configuring Apache Derby for Performance and Durability Olav Sandstå

Understanding Application Servers

PROGRESS Portal Access Whitepaper

Oracle Forms Developer 10g: Build Internet Applications

MAKING ORACLE AND SQLJ WORK FOR YOU John Jay King, King Training Resources

What Is the Java TM 2 Platform, Enterprise Edition?

ERDAS ADE Enterprise Suite Products Overview and Position

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

<Insert Picture Here> Java EE 7. Linda DeMichiel Java EE Platform Lead

1 File Processing Systems

JSLEE and SIP-Servlets Interoperability with Mobicents Communication Platform

Monitoring applications in multitier environment. Uroš Majcen A New View on Application Management.

Techniques for Scaling Components of Web Application

<Insert Picture Here> Extending Hyperion BI with the Oracle BI Server

Solutions for detect, diagnose and resolve performance problems in J2EE applications

Service Oriented Architectures

Core J2EE Patterns, Frameworks and Micro Architectures

Implementing the Shop with EJB

NetBeans IDE Field Guide

Tier Architectures. Kathleen Durant CS 3200

JReport Server Deployment Scenarios

A Beginners Guide to Fusion Middleware

Japan Communication India Skill Development Center

SQL Server and MicroStrategy: Functional Overview Including Recommendations for Performance Optimization. MicroStrategy World 2016

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Converting Java EE Applications into OSGi Applications

Software Architecture Document

The Top Five Things Every IT Manager Should Know Before Deploying a BPM Solution

Transcription:

BMP vs. CMP in Entity EJBs Acronyms Gone Wild (AGW) Dave Landers BEA Systems, Inc. dave.landers@bea.com

Review Enterprise Java Beans Multi-tier Component Architecture Two kinds of EJBs Session Beans Behaviors & Business Logic Stateless or Stateful Entity Beans Data Model Persisted to Database (usually) 2

Entity EJB Persistence Entity EJB represents data Often thought of as a row in Relational Database (RDBMS) table Although it may span multiple rows, tables May not be RDBMS at all Data is persistent Outlives the client Survives server crash Entity object is a cached view of the persistent store 3

Persistence Entity instance state must be synchronized with persistent store on Life-Cycle boundaries Load, Store called before and after every method If transactional, load only at first method call for instance If transactional, store called at commit 4

Entity Bean Life Cycle create load store remove finders 5

Handling Persistence Two ways to do the persistence: Bean Managed Persistence (BMP) You write the code Container Managed Persistence (CMP) Container handles saving the data 6

Bean Managed Persistence The Bean Developer writes persistence and finder code Usually JDBC / SQL code in EntityBean implementation 7

BMP Advantages Developer has full control of persistence mechanics Deployer has little control, unless developer has provided it Lots of options Non-RDBMS and Legacy systems Multiple databases, tables, etc. Aggregate / Coarse-Grained Entities Complex finder methods 8

BMP Disadvantages May be tied to a single database Use database specific features Lots of detailed code to write Error prone Boring No check on Table and Column names until Runtime Often uses CAP model for code reuse Copy And Paste 9

Container Managed Persistence Container persists bean for you Persistence specified at deployment rather than development Developer provides mapping information to deployer (i.e. documentation) 10

CMP Advantages Easy Straightforward Fewer Errors Containers often check Table and Column mappings at Deploy time More Portable to multiple databases 11

CMP Disadvantages Stuck with container s idea of persistence Less flexibility Fewer advanced features Database portability limited by container features Container portability limited by features you require Not for Control Freaks 12

CMP Support Most Application Server vendors support Basic CMP RDBMS One Bean, One Table Simple field mapping (primitive and basic JDBC types) Feature-rich and Specialized containers often available Object / Relational (O/R) Mapping Object Databases (ODBMS) 13

Entity EJB Persistence History (so far...) EJB 1.0 (March 1998) Entity Beans optional CMP allowed, not specified how Up to the server vendor Deployment Descriptor as Serialized Object, not specified how to create it 14

History... EJB 1.1 (December 1999) Entity support mandatory CMP still not fully specified cmp-field descriptor used to identify persistent fields Not required to map to database May use serialization Some changes to support deployment choice of persistence ejbcreate return - null vs void Deployment Descriptor now in XML 15

History... EJB 2.0 (Public Draft 2) CMP specified Field mappings Finder syntax Aggregate or Coarse-Grained Entities supported Entity-to-Entity relationships supported 16

...Future Next Steps (from 2.0 spec) Pluggable Persistence Managers Read-Only Entities with CMP Aggregate operations for EJB QL finder methods 17

BMP Responsibility Implement persistence in * ejbcreate() ejbload() * ejbremove() ejbstore() * ejbfindbyprimarykey() * ejbfind<foo>() * These methods are defined in the Home Interface create() remove() findbyprimarykey() findby<foo>() 18

BMP Responsibility ejbcreate( createargs... ) SQL INSERT Set state of object instance ejbload() SQL SELECT on Primary Key Set state of object instance ejbstore() Get state from object instance SQL UPDATE 19

BMP Responsibility ejbremove() SQL DELETE on Primary Key ejbfindbyprimarykey() SQL SELECT on Primary Key ejbfind<foo>(... ) SQL SELECT on arguments Return Primary Key or Collection of Primary Keys 20

BMP Persistence Example 21

CMP Responsibility ejbcreate( createargs... ) Set state of object instance from createargs ejbload() Set state of object instance ejbstore() Usually nothing to do ejbremove() Usually nothing to do 22

CMP Responsibility ejbfindbyprimarykey() Automatically generated ejbfind<foo>(... ) Automatically generated Deployment Set mapping of Bean to Table and Fields to Columns Specify queries for finders 23

CMP Example - 1.1 24

CMP in EJB 2.0 Container Managed Relationships To other Entities To Dependent Objects Bidirectional or Unidirectional One-to-One, One-to-Many or Many-to- Many Persistence Mappings for Fields and Relationships defined in Deployment Descriptors 25

CMP in EJB 2.0 Finder Query Language (EJB QL) Use in Deployment Descriptor Also used by Select Methods Not exposed to the client Used by the bean s business methods Allows all SQL to be specified in deployment Can return non-entity types Very SQL-like: SELECT sss FROM ttt WHERE www Can refer to other Entity beans (in same ejb-jar file) 26

CMP in EJB 2.0 EJB Bean implementation class is abstract Abstract get/set methods for fields Used by Persistence Manager May be exposed via Remote Interface Abstract get/set methods for relationships Used by Persistence Manager Not exposed via Remote Interface Implementation for Business Methods Use abstract get/set methods to access persistent data 27

CMP Example - 2.0 28

Container Capabilities Default Containers Basic field mapping and Finders May provide database mapping checks at deployment Table and column names and data types 29

Containers O/R Mapping Extensions TOPLink (WebGain), CocoBase (Thought, Inc.), etc. Available for many servers Use as O/R Mapping for BMP or Container for CMP Advanced mapping, relationships, finders, etc. Performance enhancements and caching 30

Containers ODBMS Extensions Versant, ObjectStore (excelon), etc. Object persistence with BMP or Containers available for CMP Object Caches Javlin (excelon) 31

CMP Sounds Great What s the catch?

Limitations of CMP Simple mapping support in EJB 1.1 containers Limited data type support in container When mapping to advanced database types Can you translate to/from more primitive types in business methods? 33

Limitations of CMP Coarse-grained Entitys (pre-2.0) Dependent object and entity relationship support Multiple databases or tables Some containers may support this Many do not Data aliasing When multiple Entities map to the same database fields 34

Limitations of CMP Eager Loading Of large, coarse-grained entities Legacy or non-rdbms systems When no container exists for such a system 35

Limitations of CMP Limited finder syntax Especially in EJB 1.x Need unavailable SQL features (ORDER BY, GROUP BY, COUNT(*), etc.) or advanced search capability (like Oracle s InterMedia) Consider doing these things in a Session Bean with JDBC/ SQLJ 36

Can t Live With CMP? BMP Strategies to Ease the Pain

BMP Strategies Use base classes, examples, templates, and helper classes to reduce chances of errors Don t forget your Java and Object Oriented skills! Give Dependant objects their own persistence manager Rather than entity doing the persistence Promote reuse of these objects for multiple entities 38

BMP Strategies Defer options to Deployer Deploy time choice of CMP or BMP implementation helper class Use table- and field- mappings (in environment properties) to allow deploytime tweaking of BMP code Read the CMP section of the 2.0 Spec Try to implement your BMP consistent with that model 39

BMP Strategies Use a O/R Mapping Tool or ODBMS for Entity s BMP Persistence Helper class Code generation tools for BMP? In an Application Use CMP for simpler beans, BMP for others 40

SQLJ for BMP SQLJ lightens the bulk of the BMP code SQLJ can check SQL mappings at compile time (vs. runtime) Depend on Database vendor for compiler and runtime libraries Available for DB2, Informix, Oracle According to www.sqlj.org 41

SQLJ Example 42

What About Performance?

Performance Testing is difficult (depends on system requirements) Load vs. Single client Concurrent data access vs. private data per client Reads vs. Writes Transactions 44

Performance In general BMP gives you control Performance is more likely to be predictable when porting to other vendors CMP has more opportunity to optimize Container knowledge Transaction state Other beans Vendor may supply CMP as convenience feature rather than performance feature 45

Performance Tools such as O/R mapping can help... or hurt Use container plug-in if available Or use tool to implement BMP May do lots of caching Improves performance More memory, sometimes GC issues if you re not careful May take transaction responsibility from database Can be good or bad, depending on database and system 46

Performance Transactions Cost to begin and commit/rollback Avoid unnecessary transactions Many, short transactions are costly More efficient access within transaction for multiple calls on one Entity ejbload / ejbstore usually called once per transaction rather than once per method Watch Entity Locking Long transactions can hurt concurrency Watch for Deadlock (due to access order and mixed transaction states 47

References EJB Specifications http://java.sun.com/products/ejb/docs.html Other EJB references http://java.sun.com/ejb SQLJ http://www.sqlj.org 48

References Enterprise JavaBeans Richard Monson-Haefel O Reilly Mastering Enterprise Java Beans Ed Roman John Wiley & Sons http://www.theserverside.com 49

Other Talks Willy Farrell Enterprise Java Beans Paul Giangarra Distributed Flying Objects Bryan Zarnett J2EE Anti-Patterns 50

Thank You Please fill out the Evaluation Form