PacktLib: EJB 3.1 Cookbook

EJB 3.1 Cookbook

Credits

About the Author

About the Reviewers

www.PacktPub.com

Preface

Getting Started With EJBs

Introduction

Creating a simple session EJB

Accessing a session bean using dependency injection

Accessing the session bean using JNDI

Creating a simple message-driven bean

Sending a message to a message-driven bean

Accessing an EJB from a web service (JAX-WS)

Accessing an EJB from a web service (JAX-RS)

Accessing an EJB from an Applet

Accessing an EJB from JSP

Calling an EJB from JSF

Accessing an EJB from a Java Application using JNDI

Accessing an EJB from a Java Application using an embeddable container

Accessing the EJB container

Session Beans

Introduction

Creating a stateless session bean

Creating a stateful session bean

Creating a singleton bean

Using multiple singleton beans

Using container managed concurrency

Using bean managed concurrency

Controlling the initialization process

Using session beans with more than one business interface

Understanding parameter behavior and granularity

Using an asynchronous method to create a background process

Message-Driven Beans

Introduction

Handling a string-based message

Handling a byte-based message

Handling a stream-based message

Handling a map-based message

Handling an object-based message

Using an MDB in a point-to-point application

Using MDB in a publish-and-subscribe application

Specifying which types of message to receive using the message selector

Browsing messages in a message queue

EJB Persistence

Introduction

Creating an entity

Creating an entity facade

Using the EntityManager

Controlling the Object-Relationship Mapping (ORM) process

Using embeddable classes in entities

Using application-managed persistence

Validating persistent fields and properties

Validating null fields

Validating string fields

Validating temporal fields

Validating using regular expressions

Validating Boolean fields

Validating Integer fields

Using the Validator class

Querying Entities using JPQL and the Criteria API

Introduction

Populating the Patient and Medication tables

Using the Select query

Using the Where clause

Controlling the number of entities returned by a Select query

Using the Delete query

Using the Update query

Using parameters in a query

Using a Named query

Using the Criteria API

Transaction Processing

Introduction

Creating the Demonstration classes

Handling transactions the easy way

Using the SessionSynchronization interface with session beans

Understanding how the TransactionAttributeType affects transactions

Handling transactions manually

Rolling back a transaction

Handling errors in a transaction

Using timeouts with transactions

EJB Security

Introduction

Creating the SecurityApplication

Configuring the server to handle security

Understanding and declaring roles

Controlling security using declarations

Propagating identity

Controlling security programmatically

Interceptors

Introduction

Creating the Registration Application

Defining and using interceptors

Using the InvocationContext to verify parameters

Using interceptors to enforce security

Using interceptors to handle transactions

Using interceptors to handle application statistics

Using lifecycle methods in interceptors

Timer Services

Introduction

Setting up the ReportsApplication

Creating and using declarative timers

Creating and using programmatic timers

Understanding calendar-based scheduling

Using the timer interface

Using persistent and non-persistent timers

Creating timers upon application deployment

Using interceptors with timers

Web Services

Introduction

Creating an EJB-based web service using JAX-WS

Creating an EJB-based web service using JAX-RS

Using an MDB as part of a web service

Packaging the EJB

Introduction

Understanding an application's JAR files using the jar command

Understanding class loading

Using deployment descriptors for interceptors

Using deployment descriptors for timer interceptors

Using deployment descriptor for default interceptors

Using deployment descriptors for callback interceptors

Using a deployment descriptors for transactions

Using deployment descriptors for security

EJB Techniques

Introduction

Exception handling and EJBs

Using logging within an EJB

Using an interceptor for logging and exception handling

Creating your own interceptor

Using time within an EJB

How to support currency

Efficient manipulation of strings

Index