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.

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.
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.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Fundamentals Celsina Bignoli
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 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.
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.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
Enterprise Java Beans. Distributed Computing Distributed computing is a field of computer science that studies distributed systems. A distributed system.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
CD Database Server (CDDB) Zachary Carter Alan Savage Diana Abbas Kyle Dorman.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.
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.
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.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
J2EE Structure & Definitions Catie Welsh CSE 432
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
© jGuru.com Enterprise JavaBeans Fundamentals.
Enterprise Java v041102EJB QL1 EJB Query Language Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
Collaborate Lesson 4C / Slide 1 of 22 Collaborate Knowledge Byte In this section, you will learn about: The EJB timer service Message linking in EJB 2.1.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Enterprise Java v041109Container Managed Relationships1 Container Managed Relationships (CMR) Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
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:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Knowledge Byte In this section, you will learn about:
Component-based Applications
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Presentation transcript:

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 to all EJB2.0-compliant containers and persistence managers.

The Usage of Find Method in EJB1.1 Declare find method in home interface Modify the xml file: C:\orion\application-deployments\factory\ejbs\orion-ejb-jar.xml  Advange of Query Language (QL) : Developed and tested once, Use anywhere

Methods which use QL Finder Methods Select Methods 1. They are not exposed to clients. They are used in the implementation class alone. 2. They allow the programmer to retrieve dependent objects, values, or related EJBs based on relevant search criteria.

Advantages of using a select method A select method written in QL can be more efficient than java programming. Declarative SQL language is more maintainable and less error prone

Types of Select Method ejbSelect ---Operate on all instances of that entity ---Can return individual instances or collections of any type represented by a cmp-field, as well as remote interfaces represented by a cmr-field. ejbSelect InEntity ---Associated with a particular entity identity. ---Can not be used from the implementations of a home-interface business method. ---Introduced as a way of efficiently navigating the EJBs relationships with other entity beans and with its dependent objects **METHOD represents a descriptive name for the activity of the method.

Where to specify a Query A query is specified in two parts: Method declaration Specify the QL in XML deployment descriptor

Find Method: Declared in the home interface, just as it is for EJB1.1 cmp Returning the remote interface type Must have a name of the form findByXXX Throw RemoteException and FinderException Method declaration(1)

Method declaration(2) Public abstract class SportTeamEJB implements EntityBean { abstract public String ejbSelectShipToCityInEntity() throws FinderExecption; } Select Method: 1.Declared as abstract in the bean’s main implementation class. 2. Must have a name of the form ejbSelect () or ejbSelect InEntity() 3. Throw javax.ejb.FinderException 4. Return type can be individual instances or collections of any type of cmp-field and cmr-field 5. The collection class must be either java.util.Collection or java.util.Set

Specify query language 1.Specify in the XML deployment descriptor 2.A query is defined as a element as a child of the relevant element. 3.A query has 3 parts: ---an optional description ---a method it applied ---the query language string ejbSelectOverdueLibraryBooksInEntity SELECT b FROM b in books WHERE overdue is TRUE

How to specify a query An EJB QL string may have up to 3 clauses: 1. Select : indicate the return type of the query or of the instances in a returned collection. 2. From: declare variables that represent navigation paths in your schema ( correlation variables). These variables are used in SELECT or WHERE clauses. 3. Where: a conditional expression that limits the results of your query. It can include parameters from the finder or select method.

The concept of schema Is the definition of its cmp-fields and cmr-fields A schema type has a name. Entity bean: the name is specified in the deployment descriptor with the element Dependent object: same as the dependent object name

The concept of schema Every query in an entity bean must use that bean’s schema, or the schema of a related objects in the same ejb-jar, for navigation. A bean’s schema is different from its remote interface. Can not refer to a schema of an entity or dependent object that is defined outside your ejb-jar. You may call finder methods on entities outside your JAR, but you may not navigate to their dependent objects or refer to their state.

OrderBean Number custname lineitems Order_date Shippine_address Billing_address Address ( dependent object ) street city state Postal_code Lineitem ( dependent object ) product quantity shipped ProductBean name description type

Navigation Operator “.” Use navigation operator “.” to traverse cmp-and cmr- fields. SELECT shipping_address.city String ejbSelectShipToCityInEntity() throws FinderException Java.util.Collection ejbSelectShipToCity() throws FinderException Java.util.Set ejbSelectShipToCity() throws FinderException SELECT shipping_address WHERE shipping_address.state=‘NY’ WHERE billing_address.state=‘MA’

Navigating Over Collections Can not use navigation operator to navigate into a many-valued relationship. SELECT lineitems.product.name WHERE lineitems.shipped=TRUE Declare a correlation variable in the From clause SELECT 1.product.name FROM 1 in lineitems WHERE 1.shipped=TRUE

Input Parameters To parameterize a query: 1. Add the appropriate parameters to the method declaration. 2. Refer to those parameters in the WHERE clause with a question mark, followed by a index of the parameter in the method declaration. 3. Date literals need to be expressed as a standard Java long milliseconds value. OrderEJB findByCustomerName(String custname) throws FinderException WHERE custname=?1

Other Entity Beans Query references to entity beans that are within the same ejb-jar and use the EJB2.0 persistence model represent a schema. SELECT 1.product.name FROM 1in lineitems WHERE 1.shipped= TRUE Query references to entity beans that are outside the eib-jar or use the EJB1.1 persistence model represent the remote interface of the entity bean. SELECT 1.product FROM 1in lineitems WHERE 1.shipped= TRUE The remote interface navigation operation => SELECT 1=>product FROM 1 in lineitems WHERE 1.shipped=true

Where Clause Options Logical operator: NOT, AND,OR Comparison operator:=,>,>=, Types: number, string, boolean, object Comparison for entity bean remote references or schemas are done by compare their primary key values. Comparison for dependent objects are also probably done by compare their primary key values. Arithmetic operators: +, -, *, / BETWEEN expression: [NOT] BETWEEN x AND y

IN expression: [NOT] IN (string, …) Entity-reference [NOT] IN (finder-expression) LIKE expression: [NOT] LIKE pattern [ESCAPE character] _: representing any single character %:representing any sequence of zero or more characters NULL test: IS [NOT] NULL

Queries from the Manufacturing Application (1) Location: application-server specific file (2) Format: application-server specific format Orders findOpenOrders Orders findUncompletedOrders

(1)Location: deployment descriptor (2)Format: in a standard format(EJB QL) findOpenOrders WHERE status LIKE ‘o%’ findUncompletedOrders WHERE status NOT LIKE ‘c%’ AND status NOT LIKE ‘f%’

Message-Driven Beans Advantages that messaging can provide: 1. Messaging can provide reliable, asynchronous delivery of information from the client to server. 2. Messaging can be a simple way to provide interoperability with other enterprise components. 3. Messaging can be used to implement a public-subscribe architecture. A message-driven bean can be a component that listens for messages on a particular topic.

MDB Vs Other types of EJB Similar to a stateless session bean in terms of the role it will play in architecture. It is an entry point into your business logic from a client. Can call methods on stateless session EJBs and on entity EJBs. Updates to resources such as a database can be made in the same transaction as message acknowledgement. If the transaction is rolled-back, the message would not be acknowledged and it will be redelivered.

MDB Vs Other types of EJB Difference: It has neither a home nor a remote interface. Instead, its public interface consists of a single onMessage() method called by the EJB container when messages arrive. The onMessage() method has a single argument: the message that is being delivered. Exception handling is different. The onMessage() method does not throw any checked and unchecked exception. If a run time exception is thrown away, the event is logged, the instance of the bean is discarded, and any existing transaction is rolled back.

Message-driven beans do not have a client security context because that information is not propagated with a message. Message-driven beans can execute in the context of a transaction. The transaction can be bean- or container-managed. As there is no way to propagate an existing transactional context, a contained-managed transaction must be newly created. EJB container handles message acknowledgement. The bean developer should not use the JMS API for message acknowledgement.

Lifecycle Methods A message-driven bean must implement the javax.ejb.MessageDrivenBean interface setMessageDrivenContext(MessageDrivenContext mdc) It’s similar to the EntityContext or SessionContext. ejbCreate() ejbRemove() A message-driven bean instance is single-threaded. A container may instantiate multiple instances of message-driven beans to process message concurrently

MDB and JMS A message-driven bean is associated with a single JMS topic or queue. The deployer associates the bean with a particular topic or queue when the bean is deployed in the enterprise’s environment. It’s better to associate ONE message-driven bean with ONE JMS topic or queue. See chap28 for more details

Package mypackage Import javax.ejb.*; Import javax.jms.*; Public void onMessage(Message msg) { //your business logic } Public void setMessageDrivenContext(MessageDrivenContext mdc) { this.mdc=mdc; } Public void ejbCreate() { // often empty } Public void ejbRemove(){ // often empty }

EJB 2.0 compliant persistence manager platform--ePersistJ™ 2.0 Release at 03/12/2001 EJB-QL support for portable select and selectInEntity methods Complete support for one-to-one, one-to-many and many- to-many relations among entity.

Questions ?