Develop data access applications

 

Overview

We can access data in various ways:

 

Procedure

  1. Decide how to implement data access.

    The Enterprise JavaBeans (EJB) programming model provides several distinct server-side component types: entity, session, and message-driven beans, and servlets. Of these types, entity beans are typically used to model business components in an application. Entity beans have both state and behavior.

    The state of entity beans is persistent and is stored in a database. As changes are made to an entity bean, its state is kept in synchronization with the database record representing the bean. There are two types of entity beans provided by the EJB model and these two types differ in the mechanism used to provide persistence. These two types of entity beans are container-managed persistence (CMP) beans and bean-managed persistence (BMP) beans.

    With BMP beans, the developer manually produces code to manage the persistent state of the bean.

    With CMP beans, the EJB container manages the persistent state of the bean. Persistent state management is a complex and difficult task; using CMP beans allows the developer to concentrate on business logic by delegating persistence behavior to the container. Typical examples of CMP beans are Customer, Account, and so on. Because CMP beans are objects, their data (state) is accessed using field accessors. For example, a Customer entity bean is likely to have fields such as name and phoneNumber. These pieces of data are accessed using the accessor methods getName()/setName() and getPhoneNumber()/setPhoneNumber(). As a developer, you are not concerned with how this data is eventually stored and retrieved from the backend database and can assume that the integrity of the data is maintained by the container.

    Use Structured Query Language in Java (SQLJ) with both BMP and CMP beans when you are using the DB2 JDBC Universal Driver with DB2 as your backend database. For users of DB2 for z/OS, the DB2 Universal JDBC Driver is the only JDBC driver that supports SQLJ use with CMP beans.

    The Service Data Objects (SDO) framework provides a unified framework for data application development. With SDO, you do not need to be familiar with a technology-specific API in order to access and utilize data. You need to know only one API, the SDO API, which lets you work with data from multiple data sources, including relational databases, entity EJB components, XML pages, Web services, the Java Connector Architecture, JavaServer Pages, and more.

  2. Look up a data source or connection factory using a resource reference (Looking up data sources with resource references for relational access). Do not perform this step if you work with CMP beans, however; the EJB container handles this process for CMP beans.

    Using a resource reference to access your data source or connection factory is required when running in WebSphere Application Server. (The J2EE application deployer actually creates a JDBC provider and data source for relational database access, or creates a J2EE Connector Architecture (JCA) connection factory for non-relational database access. See Deploying data access applications for more information.)

  3. Get a connection to a data source (the "Getting connections" section of Connection life cycle). Do not perform this step if you work with CMP beans, however; the EJB container handles this process for CMP beans.

    The connection management architecture for both relational and procedural access to enterprise information systems (EIS) is based on the J2EE Connector Architecture (JCA) specification. The Connection Manager (CM), which pools and manages connections within an application server, is capable of managing connections obtained through both resource adapters (RAs) defined by the JCA specification, and DataSources defined by the JDBC 2.0 Extensions Specification.

 

See also


Extensions to data access APIs
Container-managed persistence features
Looking up data sources with resource references for relational access
Data access from J2EE Connector Architecture applications
Tips for developing entity beans
Data access bean types
Accessing data from application clients
Data access with Service DataObjects
Using the Java Database Connectivity data mediator service for data access
Using the Enterprise JavaBeans data mediator service for data access
Exceptions pertaining to data access
Embedded Structured Query language in Java (SQLJ) support
Using embedded Structured Query Language in Java (SQLJ) support