Oracle Application Server TopLink Application Developer's Guide 10g (9.0.4) Part Number B10313-01 |
|
With your Oracle Application Server TopLink application built, you are ready to package and deploy the project to your enterprise. This chapter discusses:
This chapter discusses packaging and deployment from an OracleAS TopLink perspective. However, if you deploy your application to a J2EE container, you must configure elements of your application to enable OracleAS TopLink container support.
For more information, see also Appendix B, "Configuring OracleAS TopLink for J2EE Containers".
This chapter introduces a basic approach to packaging that offers consistency across your projects, and the flexibility to work with projects of all kinds.
The OracleAS TopLink approach to deployment involves packaging application files into a single file, such as a Java archive (JAR) file, or an enterprise archive (EAR) file. This approach enables you to create clean and self-contained deployments that do not require significant file management.
After you create these files, you deploy the project.
As an integral part of the enterprise application, OracleAS TopLink provides persistence and object-to-relational mapping functions. In most cases, the client does not interact with OracleAS TopLink directly; instead, clients access a client application that passes requests to OracleAS TopLink. As a result, there are two important steps to OracleAS TopLink deployment: make the packaged OracleAS TopLink application available; and add code to the client application to invoke OracleAS TopLink.
The goal of deployment is to provide the project to the client applications. Before you attempt to deploy an OracleAS TopLink application, complete the following:
You can deploy the application mappings that you define in the OracleAS TopLink Mapping Workbench with your application as an XML file or as a compiled Java class. The OracleAS TopLink Mapping Workbench supports exporting for both of these formats.
The more traditional approach to deployment is to export Java source files from the OracleAS TopLink Mapping Workbench. It requires you to recompile the resulting Java files.
XML deployment files offer better flexibility both before and after deployment, and are easier to troubleshoot if a problem occurs. Because of this, in most cases, you should deploy your project using XML files rather than Java source files.
The OracleAS TopLink Mapping Workbench provides the ability to create deployment files from a OracleAS TopLink Mapping Workbench project. After you build a project, you have two options to create the deployment files:
XML deployment is the preferred method of deployment, because XML files are easier to deploy and troubleshoot than compiled Java files.
This section discusses:
To deploy an OracleAS TopLink application, create a project file, in addition to one or more supporting files, as follows:
sessions.xml
file.
Related beans share the same ejb-jar.xml
file, J2EE container-specific file, and toplink-ejb-jar.xml
file.
For more information, see "Container-Managed Persistence Applications".
The project.xml
file is the core of your application. It contains the mappings and descriptors you define in the OracleAS TopLink Mapping Workbench, and also includes any named queries or finders associated with your project.
Because you must synchronize the project.xml
file with the classes and database associated with your application, we recommend you not modify this file manually. The OracleAS TopLink Mapping Workbench ensures proper synchronization, and is the best way to make changes to the project. Simply modify the project in the OracleAS TopLink Mapping Workbench and redeploy the file project.xml
file.
To redeploy a project.xml
file, shut down and restart your OracleAS TopLink application.
In addition to generating the deployment XML from the OracleAS TopLink Mapping Workbench, you can use either of the following methods and use the DeploymentXMLGenerator
API:
DeploymentXMLGenerator
and your java source. Call the following method:
generate (<MW_Project.mwp>, <output file.xml>)
java -classpath toplink.jar;toplinkmw.jar;xmlparserv2.jar;ejb.jar;. oracle.toplink.workbench.external.api.DeploymentXMLGenerator
<MW_ Project.mwp> <output file.xml>
The sessions.xml
file provides a simple and flexible way to configure, modify, and troubleshoot the application database sessions. Because of these attributes, the sessions.xml
file is the preferred way to configure an OracleAS TopLink session.
The OracleAS TopLink Sessions Editor is a graphical tool to build and edit the sessions.xml
file, but you can also use a text editor.
For more information about the OracleAS TopLink Sessions Editor, see "Understanding the OracleAS TopLink Sessions Editor" in the Oracle Application Server TopLink Mapping Workbench User's Guide.
For more information, see "Configuring Sessions with the sessions.xml File".
The toplink-ejb-jar.xml
file specifies all OracleAS TopLink-related information for an EJB entity bean deployment to a J2EE container. It includes several elements you use to configure the application.
The OracleAS TopLink deployment descriptor is included in the EJB JAR in the same META-INF directory as the ejb-jar.xml
.
The session
element contains settings for the entire project. The toplink-ejb-jar.xml
file must include a session section, which includes the following XML elements:
name
: A session name (unique among all deployed JARs) that is used as a key for the deployed OracleAS TopLink project (or the JAR that contains the project).
project-xml
: Specifies the name of the XML file that contains the OracleAS TopLink project metadata. Specify the fully qualified file name, including the .xml
extension.
session-type
: The session type must always be set to server-session
.
platform-class
: The platform class controls the format of the SQL generated and other database specific behavior.
uses-external-connection-pool
and uses-external-transaction-controller
: For OracleAS TopLink to participate in WebSphere JTS transactions set both of these to TRUE.
external-transaction-controller-class
: This is the OracleAS TopLink server-specific JTS controller class required when using external transaction control. For WebSphere 4.0, use oracle.toplink.jts.was.JTSExternalTransactionController_4_0
.
enable-logging
: When set to TRUE, OracleAS TopLink prints logging information for several of its operations. This is very useful for debugging.
logging-options
: Options for different levels of OracleAS TopLink logging.
For more information about the toplink-was-ejb-jar_904.dtd
, see <
ORACLE_HOME
>\toplink\config\dtds
.
The toplink-ejb-jar.xml
file specifies all OracleAS TopLink-related information for an EJB entity bean deployment to a J2EE container. It includes several elements you use to configure the application.
The OracleAS TopLink deployment descriptor is included in the EJB JAR in the same META-INF directory as the ejb-jar.xml
.
The session
element contains settings for the entire project. The toplink-ejb-jar.xml
file must include a session section, which may include the following XML elements:
name
: Specifies the name of the session. Assign a unique session name to all projects deployed in a given server. This tag is mandatory.
project-class
: Specifies the name of the class that contains the OracleAS TopLink project metadata. Specify the fully qualified Java class name, but do not include the .class
or .java
extension.
Use this tag (and not the project-xml
tag) if you deploy your projects using exported and compiled Java code.
project-xml
: Specifies the name of the XML file that contains the OracleAS TopLink project metadata. Specify the fully qualified file name, including the .xml
extension.
Use this tag (and not the project-class
tag) if you deploy your project using an exported XML file.
login
: Specifies the login parameters for the session. This element includes the sub elements listed in Table 9-1.
Element | Description |
---|---|
connection-pool |
Identifies a JDBC pool for the current OracleAS TopLink project. The name of the pool must correspond to a JDBC connection pool specified in the WebLogic administration console.
Specify a |
datasource |
Identifies JTA datasource for the current project. Use
Use For more information about datasources, see "J2EE Integration" and the J2EE container documentation. |
non-jts-datasource |
Identifies the read only datasource for the current project. Use For more information about datasources, see "J2EE Integration" and the J2EE container documentation. |
should-bind-all-parameters (optional) |
Indicates whether all queries use parameter binding. Valid values are TRUE or FALSE. Default is FALSE. |
uses-byte-array-binding (optional) |
Indicates whether byte arrays are bound. Valid values are TRUE or FALSE. Default is FALSE. |
uses-string-binding (optional) |
Indicates whether strings are bound. Valid values are TRUE or FALSE. Default is FALSE. |
cache-synchronization
(optional): This element indicates that changes made to one OracleAS TopLink cache in a cluster are automatically propagated to all other server caches. You can also include the optional sub elements listed in Table 9-2.
Table 9-2 Optional cache-synchronization Elements
use-remote-relationships
(optional): OracleAS TopLink enables you to define relationships between beans in terms of their remote interfaces. This is especially useful when you port EJB 1.1 applications to EJB 2.0. When you enable this option, OracleAS TopLink defines all relationships in the JAR using remote interfaces. Valid values are TRUE or FALSE. Default is FALSE.
customization-class
(optional): specifies the fully qualified name of a DeploymentCustomization
class.
Although XML deployment is the preferred deployment method, you can also deploy your OracleAS TopLink project as Java source files. To deploy a project as Java source files, create your project, and export the Java source files from the OracleAS TopLink Mapping Workbench. After you generate the files, compile them with an integrated development environment (IDE). This more traditional deployment method results in OracleAS TopLink applications with the following characteristics:
In addition to generating the Java Source from the OracleAS TopLink Mapping Workbench, you can use either of the following methods and use the JavaSourceGenerator API:
generate (<MW_Project.mwp>, <output file.xml>)
java -classpath toplink.jar;toplinkmw.jar;xmlparserv2.jar;ejb.jar;. oracle.toplink.workbench.external.api.
JavaSourceGenerator
<MW_Project.mwp> <output file.xml>
As with an XML deployment, a Java source deployment requires the sessions.xml
file (for non-EJB applications) or EJB deployment descriptor files (for EJB projects). Build these files the same way you do for an XML deployment, and deploy it with your project.
For more information, see "Sessions.xml File", and "Configuring the toplink-ejb-jar.xml File with the BEA WebLogic Server".
If you deploy your application to a J2EE container that implements Container-managed Persistence (CMP), you may have to configure additional files to support the deployment. This section discusses:
There is one ejb-jar.xml
file for every JAR, although you can specify multiple beans in a single ejb-jar.xml
file. The EJB specification you use determines the contents of this file.
Most IDEs provide facilities to create the ejb-jar.xml
file. For more information about generating this file, see your IDE documentation.
If you build an EJB 2.0 application, the OracleAS TopLink Mapping Workbench can build the ejb-jar.xml
file for you. Because the OracleAS TopLink Mapping Workbench can both read and write the ejb-jar.xml
, you can either drive changes in the ejb-jar.xml
file using the OracleAS TopLink Mapping Workbench:
ejb-jar.xml
file into the OracleAS TopLink Mapping Workbench project to refresh the project.
ejb-jar.xml
file automatically when you save the project.
For more information about managing the ejb-jar.xml
file in the OracleAS TopLink Mapping Workbench, see the Oracle Application Server TopLink Mapping Workbench User's Guide.
The contents of the [J2EE-Container]
-ejb-jar.xml
file depends on the container to which you deploy your beans. To create this file, use the tools that accompany your container.
In most cases, the [J2EE-Container]
-ejb-jar.xml
file integrates with OracleAS TopLink without revision. However, when you deploy to a WebLogic Server container, modify the weblogic-ejb-jar.xml. The topics in this section explore the required modifications.
To deploy to a BEA WebLogic Server, modify the webLogic-ejb-jar.xml
file. Within that file, each bean must have a persistence-descriptor
entry with subentries, as follows:
persistence-descriptor
entry with subentries that indicate OracleAS TopLink is available and should be used:
persistence-type
element and a persistence-use
element. Both elements require a type-identifier
and a type-version
tag. Table 9-3 lists the options for the type-identifier
tag, and Table 9-4 lists the options for the type-version
tag.
persistence-use
element with a type-identifier
and a type-version
tag. Table 9-3 lists the options for the type-identifier
tag, and Table 9-4 lists the options for the type-version
tag.
type-storage
to the persistence-type
element, and set it to META-INF\toplink-ejb-jar.xml
.
type-storage
to the persistence-use
element, and set it to META-INF\toplink-ejb-jar.xml
.
enable-call-by-reference
element to TRUE
to enable Call by Reference:
<weblogic-enterprise-bean> <ejb-name>AccountBean</ejb-name> ... <enable-call-by-reference>True</enable-call-by-reference> ... </weblogic-enterprise-bean>
EJB Version | XML Elements |
---|---|
1.1 |
<type-identifier>TopLink_CMP_1_1</type-identifier> |
2.0 |
<type-identifier>TopLink_CMP_2_0</type-identifier> |
WebLogic Version | XML Elements |
---|---|
6.1 |
<type-version>4.0</type-version> |
7.0 |
<type-version>4.5</type-version> |
8.1 |
<type-version>9.0.4</type-version> |
The weblogic-ejb-jar.xml
file includes several tags that OracleAS TopLink either does not support or does not require:
concurrency-strategy
: This tag specifies how WebLogic manages concurrent users for a given bean. Because OracleAS TopLink manages concurrent access internally, it does not require this element.
For more information about OracleAS TopLink concurrency strategy, see "Locking Policy".
The OracleAS TopLink approach to deployment involves packaging application files into a single file, such as a JAR file, or an EAR file. Each of the deployment strategies discussed in this section use this approach. The nature of the application also influences the approach you take to deploying the project. This section illustrates deployment strategies for:
The OracleAS TopLink application does not use a J2EE container for deployment. Instead, it relies on OracleAS TopLink mechanisms to provide functionality and persistence. The key elements of this type of application are the lack of a J2EE container and the fact that you deploy the application by placing the application JAR on the class path.
You deploy Java applications simply by placing them on the class path. To follow the standard OracleAS TopLink approach of encapsulating applications in an archive, deploy the application in a JAR file, as follows:
sessions.xml
and project.xml
files in the root of the JAR.
Build the JAR and place it on the class path. Include the following Java code in your client application to access the OracleAS TopLink application from a client:
Session mysession = SessionManager.getManager().getSession("[SESSION-NAME]");
Many designers build OracleAS TopLink applications that use Java server pages (JSPs) and Java servlets. This type of design generally supports Web-based applications.
When you build an application to deploy to the Web, package the application components in separate archives based on function. You can then assemble the separate archive files in a single deployment archive file.
The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\
directory of the EAR. In addition, the EAR contains the following archive files:
The domain JAR contains the OracleAS TopLink files and domain objects required by the application, including:
sessions.xml
project.xml
(or the compiled project.class
file if you are not using XML files for deployment)
When you create the JAR file, the JAR building utility automatically creates a directory structure within the JAR. Ensure that the sessions.xml
file and the project.xml
file (or project.class
file) appear at the root of the JAR file. Also ensure that the class directory structure starts at the root of the JAR.
The WAR file contains the Web application files, including:
S
tatic HTML content for the client application
To complete the WAR file, modify the manifest.mf
file (located in the \meta-inf
directory) to include a reference to the domain JAR file. The standard manifest is generally empty except for the header and two carriage returns.
Example 9-1 illustrates how to add a class path attribute.
Manifest-Version: 1.0 Created-By: 1.3.1 (Sun Microsystems Inc.) // Add the following line Class-Path: [Domain-Archive-Name].jar // Two carriage returns to complete the file [CR] [CR]
After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your JSP servlet server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.
Include the following Java code in your client application to access the OracleAS TopLink application from a client:
Session s = SessionManager.getManager().getSession("[SESSION-NAME]",[classloader]);
In most cases, [classloader]
represents the class loader from the current thread context, specified as follows:
Thread.current().getContextClassLoader()
However, if your J2EE container does not support using this class loader, you can substitute the class loader from the current class, as follows:
this.getClass().getLoader()
Session beans generally model a process, operation, or service and as such are not persistent. You can build OracleAS TopLink applications that wrap interaction with OracleAS TopLink in session beans. Session beans execute all OracleAS TopLink-related operations on behalf of the client.
This type of design leverages JTS and externally managed transactions, but does not incur the overhead associated with CMP applications. Session bean applications also scale and deploy easily.
When you build an application to deploy to the Web, package the application components in separate archives based on function. You can then assemble the separate archive files in a single deployment archive file.
The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\
directory of the EAR. In addition, the EAR contains the following archive files
The domain JAR contains the OracleAS TopLink files and domain objects required by the application, including:
sessions.xml
file
project.xml
file (or the compiled project.class
file if you are not using XML files for deployment)
When you create the JAR file, the JAR building utility automatically creates a directory structure within the JAR. Ensure that the sessions.xml
file and the project.xml
file (or project.class
file) appear at the root of the JAR file. Also ensure that the class directory structure starts at the root of the JAR.
The EJB JAR file specifically services the session beans in the application. It includes:
ejb-jar.xml
file, stored in the \meta-inf\
directory of the JAR
In addition, modify the manifest.MF
file, found in the \meta-inf\
directory, to include a reference to the domain JAR. The standard manifest is generally empty except for the header and two carriage returns.
Example 9-1 illustrates how to add a class path attribute.
The WAR file contains the Web application files, including:
S
tatic HTML content for the client application
In addition, modify the manifest.MF
file, found in the \meta-inf\
directory, to include a reference to the domain JAR. The standard manifest is generally empty except for the header and two carriage returns.
Example 9-1 illustrates how to add a class path attribute.
After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.
Include the following Java code in your client application to access the OracleAS TopLink application from a client:
Sessions = SessionManager.getManager().getSession("[SESSION-NAME]",[classloader]);
In most cases, [classloader]
represents the class loader from the current thread context, specified as follows:
Thread.current().getContextClassLoader()
However, if your J2EE container does not support using this class loader, you can substitute the class loader from the current class, as follows:
this.getClass().getLoader()
Many applications leverage the persistence mechanisms a J2EE container offers. OracleAS TopLink provides full support for this type of application.
The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\
directory of the EAR. In addition, the EAR contains the following archive files:
The EJB JAR file specifically services the EJB entity beans in the application. It includes:
Store the following XML files in the \meta-inf\
directory:
The WAR file contains the Web application files, including:
S
tatic HTML content for the client application
After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.
OracleAS TopLink CMP support includes integration for BEA WebLogic Server. To enable OracleAS TopLink CMP for WebLogic entity beans, use the WebLogic EJB Compiler (ejbc) to compile the EJB JAR, as follows:
When you run ejbc:
For more information about running ejbc, see the BEA WebLogic documentation.
When you start ejbc, it processes the data in a series of stages. If errors occur while running ejbc, attempt to determine which stage causes the problem. Common problems include:
javac
) problems, often caused by using an incorrect version of the JDK
rmic
)
OracleAS TopLink CMP support includes an integration for IBM WebSphere 4.x Server. Use the following procedure to deploy your application to WebSphere:
For more information, see "Deploy Tool for WebSphere Server".
For more information about deploying the JAR, see the IBM WebSphere documentation.
It is not necessary to deploy the EJB JAR in WSAD, because deployment is carried out using the Deploy Tool (see "Deploy Tool for WebSphere Server").
You can start the bean in either the WebSphere Application Server or in WSAD.
A message dialog appears if the bean starts successfully. If an error occurs, consult Appendix C, "Error Codes and Messages" for troubleshooting information.
OracleAS TopLink enables developers to leverage bean-managed persistence in their OracleAS TopLink applications. The OracleAS TopLink base class for the BMP entity beans implements the methods required for the EJB specification.
For more information about OracleAS TopLink BMP support, see "Overview of Bean-Managed Persistence".
The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\
directory of the EAR. In addition, the EAR contains the following archive files
The EJB JAR file specifically services the EJB entity beans in the application. It includes:
Store the following XML files as follows:
ejb-jar.xml
file in the \meta-inf\
directory
sessions.xml
and the project.xml
files in the root directory
The WAR file contains the Web application files, including:
S
tatic HTML content for the client application
After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.
Many J2EE containers support hot deployment, a feature that enables you to deploy EJBs on a running server. Hot deployment allows you to:
When you take advantage of hot deployment, consider the following:
The client receives deployment exceptions when attempting to access undeployed or re-deployed bean instances. The client application must catch and handle the exceptions.
For more information about hot deployment, see the J2EE container documentation.
|
Copyright © 2000, 2003 Oracle Corporation. All Rights Reserved. |
|