Developing data access applications
You can use data access applications to manipulate data from outside sources for use within your application serving environment.
About this task
- using standard or extended APIs
- using container-managed persistence beans
- using bean-managed persistence beans, session beans, or web components.
- using Service Data Objects (SDO)
Procedure
- 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.
See the topic, Developing enterprise beans for information on developing entity beans.Tips:To maximize the efficiency of application requests to relational databases, consider using Structured Query Language in Java™ (SQLJ) when developing BMP and CMP beans. This option is available for applications that use the DB2® JDBC Universal Driver to access DB2 databases.
The only exception to this driver requirement applies to SQLJ-backed BMP beans that access DB2 for z/OS®; this schema requires the DB2 for z/OS Legacy Driver (required for the DB2 for z/OS Local JDBC Provider RRS).
Also consider using cursor holdability for potential performance gains; see the topic, JDBC application cursor holdability support, for details.
Consider using cursor holdability to maximize the efficiency of application requests to relational databases;
An alternative to developing entity beans is using the Service Data Objects (SDO) framework, which is 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 sources, including relational databases, entity EJB components, XML pages, web services, the Java Connector Architecture, JavaServer Pages, and more.
- Look up a data source or connection factory using a resource
reference. See the topic, Looking up data sources with resource references
for relational access for more information. Do not perform
this step if you work with CMP beans. The EJB container handles this
process for CMP beans. To run applications on WebSphere® Application Server, your code must use resource references to logically named data sources or connection factories. Mapping the resource references to actual resources is usually done at assembly time. The Application Server administrator configures those resources.
- For relational database access, administrators configure a JDBC provider and associated data sources, which work with the embedded WebSphere Relational Resource Adapter.
- For non-relational database access, administrators install a Java Platform, Enterprise Edition (Java EE) Connector Architecture (JCA) resource adapter onto an application server and configure associated connection factories.
Generic work context implementation provides a mechanism for a resource adapter to control the contexts in which instances of work submitted by the resource adapter to the product work manager for execution are executed. By submitting a work instance that implements the WorkContextProvider interface, the resource adapter can propagate various types of context to the WebSphere Application Server. The application server then, if it supports the propagated context type, sets the provided context as the execution context of the work instance during its execution.
- Get a connection to a data source or a connection factory.
See the "Getting connections" section of the topic, Connection life
cycle for details.) Do not perform this step if you
work with CMP beans. 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 Java EE 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 data sources defined by the JDBC Extensions Specification.
Use thread identity to assign an owner to the connection. See the topic, Using thread identity, support for more information.
次主題
Using thread identity support
The thread identity function allows you to assign a thread identifier as an owner of a connection when you first obtain the connection. This function only applies to Java Platform, Enterprise Edition (Java EE) Connector Architecture (JCA) resource adapters and Relational Resource Adapter (RRA) wrappered Java Database Connectivity (JDBC) providers that support the use of thread identity for connection ownership.Porting a Liberty application that uses MongoDB to the full profile
You can port a Liberty application that uses MongoDB to run on the WebSphere Application Server full profile.Using Bean Validation in RAR modules
WebSphere Application Server validates resource archive (RAR) JavaBeans constraints in compliance with the Java Connector Architecture (JCA) version 1.6 specification.RAR 模組中的 JCA 1.6 註釋支援
Java Connector Architecture (JCA) 1.6 版規格新增了資源保存檔 (RAR) 模組中的 Java 註釋支援。註釋是在組成 RAR 模組的類別檔中,用來指定 RAR 模組的 meta 資料或配置資料的方法。Extensions to data access APIs
If a single data access API does not provide a complete solution for your applications, use WebSphere Application Server extensions to achieve interoperability between both the JCA and JDBC APIs.Recreating database tables from the exported table data definition language
When the WebSphere Application Server deployment tooling deploys an EJB jar file containing container-managed persistence (CMP) enterprise beans, it selects the target database and creates a corresponding Table.ddl file. This file contains the SQL statement necessary to generate the database table for your CMP beans.Container managed persistence bean associated technologies
WebSphere Application Server delivers container-managed persistence (CMP) services beyond the standards set by the Enterprise JavaBeans (EJB) specification.Manipulating synchronization of entity beans and datastores
You can indicate that a particular Enterprise JavaBeans (EJB) type should not synchronize its state to persistent storage prior to each findBy invocation by using environment variables or a marker interface.Avoiding ejbStore invocations on non-modified EntityBean instances
You can configure your EntityBean instances to bypass an invocation of the ejbStore method if they have not been modified during the current transaction.Resource reference benefits
WebSphere Application Server requires your code to reference application server resources (such as data sources or J2C connection factories) through logical names, rather than access the resources directly in the Java Naming and Directory Interface (JNDI) name space. These logical names are called resource references.Accessing data using Java EE Connector Architecture connectors
To access data from a Java EE Connector Architecture (JCA) compliant application in WebSphere Application Server, you configure and use resource adapters and connection factories.JDBC application development tips
By using best practices to help maximize the efficiency of JDBC queries, you can potentially increase application performance.JDBC application cursor holdability support
The cursor holdability feature can reduce the overhead of JDBC interaction with your relational database, thereby helping to increase application performance.Data access bean types
For easy data access programming, WebSphere Application Server provides a special class library that implements many methods of the Java Database Connectivity (JDBC) API for you. The library is essentially a set of Service Data Objects (SDO).Accessing data from application clients
To access a database directly from a Java Platform, Enterprise Edition (Java EE) application client, you retrieve a javax.sql.DataSource object from a resource reference configured in the client deployment descriptor. This resource reference is configured as part of the deployment descriptor for the client application, and provides a reference to a pre-configured data source object.Data access with Service DataObjects, API versions 1.0 and 2.01
The Service Data Objects (SDO) framework is a data-centric, disconnected, XML-integrated, data access mechanism that provides a source-independent result set.Using the Java Database Connectivity data mediator service for data access
The following steps demonstrate how to create the metadata for a Java Database Connectivity (JDBC) data mediator service (DMS), as well as how to instantiate the DMS dataGraph.Using the EJB data mediator service for data access
The following steps use code samples to describe a simple instance of how to create the Enterprise JavaBeans (EJB) data mediator service (DMS) metadata.Developing a custom DataStoreHelper class
Apply the WebSphere extension, GenericDataStoreHelper class, to create your own data store helper for data sources that the application server does not support. With this helper class, your JDBC configuration can use database-specific functions during transactions.Porting a Liberty application that uses MongoDB to the full profile
You can port a Liberty application that uses MongoDB to run on the WebSphere Application Server full profile.Using Bean Validation in RAR modules
WebSphere Application Server validates resource archive (RAR) JavaBeans constraints in compliance with the Java Connector Architecture (JCA) version 1.6 specification.RAR 模組中的 JCA 1.6 註釋支援
Java Connector Architecture (JCA) 1.6 版規格新增了資源保存檔 (RAR) 模組中的 Java 註釋支援。註釋是在組成 RAR 模組的類別檔中,用來指定 RAR 模組的 meta 資料或配置資料的方法。Extensions to data access APIs
If a single data access API does not provide a complete solution for your applications, use WebSphere Application Server extensions to achieve interoperability between both the JCA and JDBC APIs.Recreating database tables from the exported table data definition language
When the WebSphere Application Server deployment tooling deploys an EJB jar file containing container-managed persistence (CMP) enterprise beans, it selects the target database and creates a corresponding Table.ddl file. This file contains the SQL statement necessary to generate the database table for your CMP beans.Container managed persistence bean associated technologies
WebSphere Application Server delivers container-managed persistence (CMP) services beyond the standards set by the Enterprise JavaBeans (EJB) specification.Manipulating synchronization of entity beans and datastores
You can indicate that a particular Enterprise JavaBeans (EJB) type should not synchronize its state to persistent storage prior to each findBy invocation by using environment variables or a marker interface.Avoiding ejbStore invocations on non-modified EntityBean instances
You can configure your EntityBean instances to bypass an invocation of the ejbStore method if they have not been modified during the current transaction.Resource reference benefits
WebSphere Application Server requires your code to reference application server resources (such as data sources or J2C connection factories) through logical names, rather than access the resources directly in the Java Naming and Directory Interface (JNDI) name space. These logical names are called resource references.Accessing data using Java EE Connector Architecture connectors
To access data from a Java EE Connector Architecture (JCA) compliant application in WebSphere Application Server, you configure and use resource adapters and connection factories.JDBC application development tips
By using best practices to help maximize the efficiency of JDBC queries, you can potentially increase application performance.JDBC application cursor holdability support
The cursor holdability feature can reduce the overhead of JDBC interaction with your relational database, thereby helping to increase application performance.Data access bean types
For easy data access programming, WebSphere Application Server provides a special class library that implements many methods of the Java Database Connectivity (JDBC) API for you. The library is essentially a set of Service Data Objects (SDO).Accessing data from application clients
To access a database directly from a Java Platform, Enterprise Edition (Java EE) application client, you retrieve a javax.sql.DataSource object from a resource reference configured in the client deployment descriptor. This resource reference is configured as part of the deployment descriptor for the client application, and provides a reference to a pre-configured data source object.Data access with Service DataObjects, API versions 1.0 and 2.01
The Service Data Objects (SDO) framework is a data-centric, disconnected, XML-integrated, data access mechanism that provides a source-independent result set.Using the Java Database Connectivity data mediator service for data access
The following steps demonstrate how to create the metadata for a Java Database Connectivity (JDBC) data mediator service (DMS), as well as how to instantiate the DMS dataGraph.Using the EJB data mediator service for data access
The following steps use code samples to describe a simple instance of how to create the Enterprise JavaBeans (EJB) data mediator service (DMS) metadata.Developing a custom DataStoreHelper class
Apply the WebSphere extension, GenericDataStoreHelper class, to create your own data store helper for data sources that the application server does not support. With this helper class, your JDBC configuration can use database-specific functions during transactions.


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tdat_impdatacc
檔名:tdat_impdatacc.html