EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 12. November 2009.
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
Container Managed Persistence. General Guidelines Home and Remote interfaces are implemented the same as for bean managed persistence Entity Bean class.
Enterprise JavaBeans 2.0 Wu Lu (Cont’d). EJB2.0 Query Language EJB QL is a declarative language similar in many respects to SQL Is intended to be portable.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
1 CS 483 Enterprise and Web Application Programming Week 6 Session Beans JSP Tutorial.
Enterprise Java Beans (EJB)
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
Brad Rippe Fullerton College. What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
EJB.
Writing Enterprise Applications with J2EE (Second lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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.
Lecture 8 Advanced Topics in Enterprise JavaBeans.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
Enterprise Java Beans Part II Kyungmin Cho 2001/04/13.
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.
Middleware Technology (J2EE/EJB) Stateful Session Bean.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
Enterprise Java Bean Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
J2EE Structure & Definitions Catie Welsh CSE 432
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
© jGuru.com EJB State Diagrams. Simple Lifecycle of Session Bean ClientEJBHomeEJBObjectContainerContextInstanceData Store setSessionContext(ctxt)
Enterprise Java Bean Technology Briefing Markus Hebach.
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.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
EJB Enterprise Java Beans JAVA Enterprise Edition
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.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Understanding and Designing with EJB
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
EJB Types Alessio Bechini June 2002.
Understanding and Designing with EJB
Entity Beans B.Ramamurthy 2/17/2019 BR.
Knowledge Byte In this section, you will learn about:
Understanding and Designing with EJB
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Presentation transcript:

EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04

2 EJB 2.0 Overview Bean Types  Entity (EB) – represent persistent state that is stored in a database or other storage. Usually represent “nouns”. Can be accessed concurrently. Long-lived.  Session (SB) – models a workflow, or set of actions that a user may want to perform (actions) Stateless – Return values from methods do not depend on instance state Instance state may be recorded, but it will not be persisted A single instance can service multiple clients (long-lived) Stateful – Maintains conversational state between method calls Dedicated to a single client for life of an instance Cannot be accessed concurrently (vendor-specific)  Message-Driven (MDB) – process asynchronous (remote) messages for multiple clients, one message at a time

3 Ways to Access Beans Home Interfaces – Lifecycle methods for use by client (remote or local) Bean Interfaces – Business methods available for use by client (remote or local) Handle – a serializable reference to a remote EJB object  Can get back same type of SB or unique instance of EB

4 The Big Picture: Remote Invocation The container provides varying levels of services for the bean, including persistence, transaction management, naming directory service, and more

5 Remote EJB Class Diagram

6 Local EJB Class Diagram

7 Implementation Options Container (CMP) vs. Bean managed persistence (BMP)  Responsibility for writing data to database, maintaining relationships between entity beans, implementing finder methods Container (CMT) vs. Bean managed transactions (BMT)  Responsibility for transaction support and defining transaction boundaries

8 Local vs. Remote Interfaces Local – intra-JVM  Pros: saves overhead of remote calls, pass by reference  Cons: restricts deployment configurations pass by reference semantics can lead to data corruption Remote – inter-JVM, uses RMI  Pros: Location transparency, pass by value, MetaData access  Cons: huge overhead (even intra-JVM) casting requires use of narrow() method parameter types must be Serializable need to handle RemoteException s

9 Lifecycle Methods All:  ejbCreate(…)  ejbRemove() For SBs and EBs:  ejbFindByPrimaryKey() EB only:  ejbPostCreate() -- 1 per create() method  ejbFind*() methods  ejbSelect*() methods  ejbLoad(), ejbStore() – for BMP only  ejbSet/UnsetEntityContext()  ejbHome() Stateful SB only:  setSessionContext()  ejbActivate()  ejbPassivate() MDB only:  onMessage()

10 Lifecycle of an Entity Bean Instance

11 Lifecycle of a Stateless Session Bean Instance

12 Lifecycle of a Stateful Session Bean Instance

13 Lifecycle of a MDB instance

14 Major EJB Constraint Types A _____ must inherit from _____ interface/class or one of its children Certain lifecycle methods (per bean type) must exist and have (or not have) certain modifiers, parameters, return types You shouldn’t use this of methods for this, instead use Never call ____ from _____ When ___ is called, do something

15 Some “Interesting” Constraints and Guidance Remote Interfaces (and related)  Having both a remote and local interface is allowed, but not recommended Question: When/why would this happen?  Should use EJBObject.isIdentical() instead of Object.equals() Because remote objects can have additional networking state, but may still represent the same object  Remote interfaces may access persistence fields in a Bean class, but not relationship fields (references to other Beans)  BMP should use Collection type, although they are allowed to use Enumeration type Make more compatible with CMP, which only uses Collection

16 “Interesting” (cont.) Primary Keys (and related)  PKs only set once In CMP, by container during creation In BMP, in ejbCreate() method  ejbCreate() has a return type same as the Primary Key type (specified in XML file) Always returns null for CMP Must return the primary key for BMP  For BMP, should use EntityContext object to get the primary key, even if it is just a field in the EB Data in bean could be stale Rarely used outside of ejbLoad() and ejbStore() methods  PK classes must implement equals() and hashCode()

17 “Interesting” (cont.) Inter-EB Relationships (and related)  If an entity bean is the target of a container-managed relationship, then it must have local interfaces and be collocated with the related bean(s)  Inter-EB relationships are not initialized until the ejbPostCreate() method Primary key is required for use as a foreign key in other EBs, and may not be initialized until ejbCreate() has been called  Relationship fields can only access local interface of a bean  When creating related entities, need to preserve referential integrity by assigning relationship fields after new object creations Otherwise, unconnected entries in database  Relationship fields with >1 multiplicity may never return null Instead, they return an empty Collection

18 “Interesting” (cont.) Stateful Session Beans  Must be activated and passivated to preserve conversational state of instance  On calls to ejbPassivate(), Bean should close any open resources Set all non-transient, non-serializable fields to null

19 “Interesting” (cont.) Stateless Session Beans  Stateless SBs can only retain information between method calls via SessionContext and JNDI ENC Also can have instance variables that won’t be persisted if instance is removed  Stateless SBs don’t ever have their create() method called, so no local object created, only one for the client

20 “Interesting” (cont.) Etc.  In BMP, use only ejbLoad() and ejbStore() for synchronizing state with database Do not use ejbActivate(), ejbPassivate(), setEntityContext(), or unsetEntityContext() for this purpose  If a system exception is thrown by a bean method, the ejbRemove() method is not invoked  Constructors should never be defined in an EB class  You should never throw RemoteException s from callback methods

21 Ensuring Constraints in JBoss Package org.jboss.verifier provides implementation of an EJB checker Verifier is (optionally) run during the Deployment process Deployer may decide whether or not deployment should be terminated if an error is found by the verifier in any of the EJBs in a Jar file

22 Ensuring Constraints in JBoss (2)  strategy.EJBVerifier20 is most relevant class  Uses class loader to load bean class  Checks for appropriate restrictions based on if it’s a Session, Entity, or MD Bean Checks subclassing of correct interfaces/classes by loading “to” class and calling Class.isAssignableFrom() Checks that method names/arguments match expected E.g., between local/remote interfaces and bean Checks for correct return types Checks for correct Exceptions thrown (or not) Checks for no constructor

23 Future Work Identify and describe all “interesting” EJB constraints, explicit and implicit, positive and negative Find in JBoss implementation where these are checked, or what will happen if one of these constraints is violated Using queries to identify possible constraint violations