Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial
Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under
vendor’s standard commercial license.
The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express
warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall
not be liable for technical or editorial errors or omissions contained herein.
Export of the information contained in this publication may require authorization from the U.S. Department of Commerce.
Microsoft, Windows, and Windows NT are U.S. registered trademarks of Microsoft Corporation.
Intel, Pentium, and Celeron are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
Java is a registered trademark of Oracle and/or its affiliates.
Motif, OSF/1, UNIX, X/Open, and the "X" device are registered trademarks, and IT DialTone and The Open Group are trademarks of The Open
Group in the U.S. and other countries.
Open Software Foundation, OSF, the OSF logo, OSF/1, OSF/Motif, and Motif are trademarks of the Open Software Foundation, Inc. OSF MAKES
NO WARRANTY OF ANY KIND WITH REGARD TO THE OSF MATERIAL PROVIDED HEREIN, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. OSF shall not be liable for errors contained herein or for
incidental consequential damages in connection with the furnishing, performance, or use of this material.
JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.
Spring Framework is an open source project and is a trademark of Interface 21.
This manual provides information on how Spring, Hibernate, MyFaces, and Axis2/Java frameworks,
referred to as SASH, can be used to develop applications that can run on the HP NonStop™
system. The relevant sections contain information on:
•Installing and configuring these frameworks on NonStop
•Developing sample web applications using these frameworks
•Integrating Spring with Hibernate, MyFaces, and Axis2/Java frameworks
For detailed information about a framework, see the links to online and public resources provided
in the relevant sections.
NOTE:
•This manual does not explain the frameworks in detail; however, it provides information to
get you familiarized with these frameworks. The frameworks have not been modified or
customized for use on NonStop.
•This manual includes code snippets and code for sample applications for all frameworks. HP
recommends that you copy the code to a text editor so that unwanted special and ASCII
characters are not copied along with the code you want to use to build and test your
applications.
Supported Release Version Updates (RVUs)
This manual supports J06.11 and all subsequent J-series RVUs, and H06.22 and all subsequent
H-series RVUs, until otherwise indicated by its replacement publications.
Intended Audience
This manual is intended for application programmers who want to develop Java-based web
applications using Spring, Hibernate, MyFaces, or Axis2/Java frameworks.
New and Changed Information in This Edition
Changes to 698927–002 Manual:
•Updated the supported RVU information on the cover page and in the “Supported Release
Version Updates (RVUs)” (page 6) section.
Changes to 698927–001 Manual:
•Updated the Prerequisites in the “Installing the Spring Framework” (page 18) section.
•Updated the Spring distribution version in the “Downloading the Spring Distribution on
Windows” (page 19) section.
•Added the Prerequisites for the Spring sample applications in the “Setting up Sample Spring
Applications on NonStop” (page 20) section.
•Added the “Integrating Spring with Transaction Management Facility (TMF)” (page 27) section.
•Updated “Configurations in the applicationContext.xml File” (page 35) under “Spring
•Updated the Prerequisites in the “Installing the Hibernate Framework” (page 92) section.
6
•Updated the Hibernate distribution version in the “Downloading the Hibernate Distribution on
Windows” (page 93) section.
•Added the “Downloading Hibernate Dependency JAR Files using Gradle” (page 93) section.
•Added the “Customizing the Hibernate Dialect for NonStop” (page 95) section.
•Added a note and the Prerequisites for the Hibernate sample applications in the “Setting up
Sample Hibernate Applications on NonStop” (page 98) section.
•Updated “Connection Pooling” (page 112).
•Added recommendations under “Module File Caching Configurations” (page 330).
Document Organization
This manual is organized as follows:
Chapter 1: Introduction
This chapter provides an overview of Java frameworks on
NonStop systems.
This chapter describes the following topics:Chapter 2: Spring Framework
• An overview of Spring
• Installing and configuring Spring Framework
• Developing sample Java applications using Spring
• Integrating Spring with TMF
This chapter describes the following topics:Chapter 3: Hibernate Framework
• An overview of Hibernate
• Installing and configuring Hibernate on NonStop
• Developing sample Java applications using Hibernate
• Customizing Hibernate dialect for NonStop
This chapter describes the following topics:Chapter 4: MyFaces Framework
• An overview of MyFaces
• Installing and configuring MyFaces on a NonStop
system
• Developing sample Java applications using MyFaces
This chapter describes the following topics:Chapter 5: Axis2/Java Framework
• An overview of Axis2/Java
• Installing and configuring Axis2/Java on NonStop
• Developing sample Java applications using Axis2/Java
Appendix B: NonStop Specific Configurations
Appendix C: Deploying Sample Applications on NonStop
This chapter provides you information on how to:Chapter 6: Integrating Frameworks
• Use the Spring Transaction Manager
• Integrate Spring into Hibernate
• Develop Spring JPA applications using Hibernate
• Integrate Axis2/Java into Spring
• Integrate MyFaces into Spring
This appendix contains the EmpInfo database script.Appendix A: EmpInfo Database Script
This appendix provides information on the common
NonStop configuration requirements for the frameworks.
This appendix describes how to deploy sample applications
on NonStop systems.
Document Organization7
Appendix D: Sample JDBC Configuration for Spring
This appendix describes the JDBC configuration for the
Spring framework using NonStop JDBC Type 2 and JDBC
Type 4 drivers.
Appendix E: Installing Spring Web Flow
Appendix F: Sample JDBC Configuration for Hibernate
Appendix H: Installing MyFaces Trinidad/Tomahawk
Framework Libraries on NonStop
Appendix I: Frequently Asked Questions
Notation Conventions
General Syntax Notation
This list summarizes the notation conventions for syntax presentation in this manual.
UPPERCASE LETTERS
Uppercase letters indicate keywords and reserved words. Type these items exactly as shown.
Items not enclosed in brackets are required. For example:
MAXATTACH
Italic Letters
Italic letters, regardless of font, indicate variable items that you supply. Items not enclosed in
brackets are required. For example:
file-name
This appendix describes the steps required to install Spring
Web Flow on your NonStop system.
This appendix describes the JDBC configuration for the
Hibernate framework using NonStop JDBC Type 2 and
JDBC Type 4 drivers.
This appendix contains the ei_setenv script.Appendix G: Hibernate Environment Setup Script
This appendix describes the steps required to install
MyFaces Trinidad and Tomahawk framework libraries on
your NonStop system.
This appendix provides answers to some frequently asked
questions.
Computer Type
Computer type letters indicate:
•C and Open System Services (OSS) keywords, commands, and reserved words. Type
these items exactly as shown. Items not enclosed in brackets are required. For example:
Use the cextdecs.h header file.
•Text displayed by the computer. For example:
Last Logon: 14 May 2006, 08:02:23
•A listing of computer code. For example
if (listen(sock, 1) < 0)
{
perror("Listen Error");
exit(-1);
}
Bold Text
Bold text in an example indicates user input typed at the terminal. For example:
ENTER RUN CODE
?123
CODE RECEIVED: 123.00
The user must press the Return key after typing the input.
8
[ ] Brackets
Brackets enclose optional syntax items. For example:
TERM [\system-name.]$terminal-name
INT[ERRUPTS]
A group of items enclosed in brackets is a list from which you can choose one item or none.
The items in the list can be arranged either vertically, with aligned brackets on each side of
the list, or horizontally, enclosed in a pair of brackets and separated by vertical lines. For
example:
FC [ num ]
[ -num ]
[ text ]
K [ X | D ] address
{ } Braces
A group of items enclosed in braces is a list from which you are required to choose one item.
The items in the list can be arranged either vertically, with aligned braces on each side of the
list, or horizontally, enclosed in a pair of braces and separated by vertical lines. For example:
LISTOPENS PROCESS { $appl-mgr-name }
{ $process-name }
ALLOWSU { ON | OFF }
| Vertical Line
A vertical line separates alternatives in a horizontal list that is enclosed in brackets or braces.
For example:
INSPECT { OFF | ON | SAVEABEND }
… Ellipsis
An ellipsis immediately following a pair of brackets or braces indicates that you can repeat
the enclosed sequence of syntax items any number of times. For example:
M address [ , new-value ]…
- ] {0|1|2|3|4|5|6|7|8|9}…
An ellipsis immediately following a single syntax item indicates that you can repeat that syntax
item any number of times. For example:
"s-char…"
Punctuation
Parentheses, commas, semicolons, and other symbols not previously described must be typed
as shown. For example:
error := NEXTFILENAME ( file-name ) ;
LISTOPENS SU $process-name.#su-name
Quotation marks around a symbol such as a bracket or brace indicate the symbol is a required
character that you must type as shown. For example:
"[" repetition-constant-list "]"
Item Spacing
Spaces shown between items are required unless one of the items is a punctuation symbol such
as a parenthesis or a comma. For example:
CALL STEPMOM ( process-id ) ;
If there is no space between two items, spaces are not permitted. In this example, no spaces
are permitted between the period and any other items:
$process-name.#su-name
Notation Conventions9
Line Spacing
If the syntax of a command is too long to fit on a single line, each continuation line is indented
three spaces and is separated from the preceding line by a blank line. This spacing distinguishes
items in a continuation line from items in a vertical list of selections. For example:
ALTER [ / OUT file-spec / ] LINE
[ , attribute-spec ]…
!i and !o
In procedure calls, the !i notation follows an input parameter (one that passes data to the called
procedure); the !o notation follows an output parameter (one that returns data to the calling
program). For example:
In procedure calls, the !i,o notation follows an input/output parameter (one that both passes
data to the called procedure and returns data to the calling program). For example:
error := COMPRESSEDIT ( filenum ) ; !i,o
!i:i
In procedure calls, the !i:i notation follows an input string parameter that has a corresponding
parameter specifying the length of the string in bytes. For example:
In procedure calls, the !o:i notation follows an output buffer parameter that has a corresponding
input parameter specifying the maximum length of the output buffer in bytes. For example:
This list summarizes the notation conventions for the presentation of displayed messages in this
manual.
Bold Text
Bold text in an example indicates user input typed at the terminal. For example:
ENTER RUN CODE
?123
CODE RECEIVED: 123.00
The user must press the Return key after typing the input.
Nonitalic Text
Nonitalic letters, numbers, and punctuation indicate text that is displayed or returned exactly
as shown. For example:
Backup Up.
Italic Text
Italic text indicates variable items whose values are displayed or returned. For example:
p-register
process-name
[ ] Brackets
Brackets enclose items that are sometimes, but not always, displayed. For example:
Event number = number [ Subject = first-subject-value ]
10
A group of items enclosed in brackets is a list of all possible items that can be displayed, of
which one or none might actually be displayed. The items in the list can be arranged either
vertically, with aligned brackets on each side of the list, or horizontally, enclosed in a pair of
brackets and separated by vertical lines. For example:
proc-name trapped [ in SQL | in SQL file system ]
{ } Braces
A group of items enclosed in braces is a list of all possible items that can be displayed, of
which one is actually displayed. The items in the list can be arranged either vertically, with
aligned braces on each side of the list, or horizontally, enclosed in a pair of braces and
separated by vertical lines. For example:
obj-type obj-name state changed to state, caused by
{ Object | Operator | Service }
process-name State changed from old-objstate to objstate
{ Operator Request. }
{ Unknown. }
| Vertical Line
A vertical line separates alternatives in a horizontal list that is enclosed in brackets or braces.
For example:
Transfer status: { OK | Failed }
% Percent Sign
A percent sign precedes a number that is not in decimal notation. The % notation precedes an
octal number. The %B notation precedes a binary number. The %H notation precedes a
hexadecimal number. For example:
%005400
%B101111
%H2F
P=%p-register E=%e-register
Notation for Management Programming Interfaces
This list summarizes the notation conventions used in the boxed descriptions of programmatic
commands, event messages, and error lists in this manual.
UPPERCASE LETTERS
Uppercase letters indicate names from definition files. Type these names exactly as shown. For
example:
ZCOM-TKN-SUBJ-SERV
lowercase letters
Words in lowercase letters are words that are part of the notation, including Data Definition
Language (DDL) keywords. For example:
token-type
!r
The !r notation following a token or field name indicates that the token or field is required. For
example:
ZCOM-TKN-OBJNAME token-type ZSPI-TYP-STRING. !r
!o
The !o notation following a token or field name indicates that the token or field is optional. For
example:
ZSPI-TKN-MANAGER token-type ZSPI-TYP-FNAME32. !o
Notation Conventions11
General Syntax Notation
This list summarizes the notation conventions for syntax presentation in this manual.
UPPERCASE LETTERS
Uppercase letters indicate keywords and reserved words. Type these items exactly as shown.
Items not enclosed in brackets are required. For example:
SELECT
Italic Letters
Italic letters, regardless of font, indicate variable items that you supply. Items not enclosed in
brackets are required. For example:
file-name
Computer Type
Computer type letters within text indicate case-sensitive keywords and reserved words. Type
these items exactly as shown. Items not enclosed in brackets are required. For example:
myfile.sh
Bold Text
Bold text in an example indicates user input typed at the terminal. For example:
ENTER RUN CODE
?123
CODE RECEIVED: 123.00
The user must press the Return key after typing the input.
[ ] Brackets
Brackets enclose optional syntax items. For example:
DATETIME [start-field TO] end-field
A group of items enclosed in brackets is a list from which you can choose one item or none.
The items in the list can be arranged either vertically, with aligned brackets on each side of
the list, or horizontally, enclosed in a pair of brackets and separated by vertical lines. For
example:
DROP SCHEMA schema [CASCADE]
[RESTRICT]
DROP SCHEMA schema [ CASCADE | RESTRICT ]
{ } Braces
Braces enclose required syntax items. For example:
FROM { grantee[, grantee]...}
A group of items enclosed in braces is a list from which you are required to choose one item.
The items in the list can be arranged either vertically, with aligned braces on each side of the
list, or horizontally, enclosed in a pair of braces and separated by vertical lines. For example:
INTERVAL { start-field TO end-field }
{ single-field }
INTERVAL { start-field TO end-field | single-field }
| Vertical Line
A vertical line separates alternatives in a horizontal list that is enclosed in brackets or braces.
For example:
{expression | NULL}
… Ellipsis
An ellipsis immediately following a pair of brackets or braces indicates that you can repeat
the enclosed sequence of syntax items any number of times. For example:
ATTRIBUTE[S] attribute [, attribute]...
12
{, sql-expression}...
An ellipsis immediately following a single syntax item indicates that you can repeat that syntax
item any number of times. For example:
expression-n…
Punctuation
Parentheses, commas, semicolons, and other symbols not previously described must be typed
as shown. For example:
DAY (datetime-expression)
@script-file
Quotation marks around a symbol such as a bracket or brace indicate the symbol is a required
character that you must type as shown. For example:
"{" module-name [, module-name]... "}"
Item Spacing
Spaces shown between items are required unless one of the items is a punctuation symbol such
as a parenthesis or a comma. For example:
DAY (datetime-expression)
DAY(datetime-expression)
If there is no space between two items, spaces are not permitted. In this example, no spaces
are permitted between the period and any other items:
myfile.sh
Line Spacing
If the syntax of a command is too long to fit on a single line, each continuation line is indented
three spaces and is separated from the preceding line by a blank line. This spacing distinguishes
items in a continuation line from items in a vertical list of selections. For example:
match-value [NOT] LIKE pattern
[ESCAPE esc-char-expression]
Related Information
For a better understanding of the frameworks, see the following websites:
•http://www.springsource.org
•http://www.hibernate.org
•http://myfaces.apache.org/
•http://axis.apache.org/axis2/java/core/
Publishing History
HP Encourages Your Comments
HP encourages your comments concerning this document. We are committed to providing
documentation that meets your needs. Send any errors found, suggestions for improvement, or
compliments to docsfeedback@hp.com.
Include the document title, part number, and any comment, error found, or suggestion for
improvement you have concerning this document.
Publication DateProduct VersionPart Number
November 2012698927-001
December 2012698927-002
Related Information13
1 Introduction
Java-based web application development has been inundated by frameworks of every kind. There
is a framework available for almost every application development requirement.
The effort for developing an application using the framework approach is significantly less as
compared to developing an application afresh. The efficiency of Java-based Web development
can be increased by using the appropriate framework.
OpenSource Java frameworks on NonStop systems offer a Java environment on NonStop systems
that enable the development of Enterprise Java applications using standards-based, open source
technologies that are architecturally compatible with NonStop systems.
HP certifies Spring, Hibernate, Apache MyFaces, and Apache Axis2/Java frameworks for use on
NonStop systems.
Some of the advantages of these frameworks are:
•Spring - provides a lightweight framework to implement the business logic.
Spring has a layered architecture and also provides an abstraction layer to integrate with
other frameworks, such as Hibernate. It also provides lightweight remote support.
•Hibernate - is an Object Relational Mapping (ORM) tool for database access.
Hibernate scales well in any environment and is highly extensible and customizable. It also
supports lazy initialization, fetching strategies, and optimistic locking with automatic versioning
and time stamping.
•MyFaces - is a Java Server Faces (JSF) implementation used to design the user interface for
an application.
MyFaces is a component-oriented, event-based framework, which also supports validation of
user inputs. It also provides useful features, such as support for Tiles, use of converters, etc.
•Axis2/Java - is a web services SOAP and WSDL engine.
Axis2/Java is a high speed, flexible framework to develop web services. It provides features
such as hot deployment, scalability, and WSDL support.
Axis2/Java can plug into servlet engines as a server and provides extensive support for the
Web Service Description Language (WSDL). It also includes tools that can be used to create
Java classes from the WSDL and back.
The frameworks are not restricted to these roles and can be customized for specific development
requirements. The following versions of the frameworks are currently certified for use on NonStop:
•Spring 3.0.2 and Spring 3.1.0
•Hibernate 3.2.6, Hibernate 3.5.1, Hibernate 3.6.8, and Hibernate 4.1.1
•MyFaces 1.2.5 and MyFaces 2.0.2
•Axis2/Java 1.4.1 and Axis2/Java 1.5.2
NOTE:The steps to download the frameworks, and build sample applications, are explained
using the Microsoft Windows platform.
Advantages of developing applications using Java frameworks on NonStop
14Introduction
NonStop provides a highly scalable servlet/JSP container to host the web applications developed
using the frameworks. Because the applications are deployed on NSJSP, the Java frameworks can
leverage the following advantages of NonStop:
•Scalability
Scalability in NSJSP refers to its ability to increase its capacity to process a large number of
requests simultaneously, by adding resources, such as additional processes and logical
processors, to a system. Because applications developed using the frameworks are deployed
as a servlet under NSJSP, the applications are able to leverage features of NSJSP. This means
that when the application is heavily loaded and all the static servers are busy, a dynamic
server is created to cater to the excess load. Thus, scalability also promotes need-based
allocation of the system resources.
•Availability
High-availability guarantees continuous availability of services even during a failure of some
system resources, such as processors. The Java frameworks, deployed under NSJSP, use
NonStop TS/MP to ensure high availability and scalability, which enables you to run, as a
server class, several instances of the same process. If any of the application server processes
fail, TS/MP restarts the server process and maintains a minimum number of server application
processes running on the system.
•Load Balancing
With NSJSP, load balancing is achieved through the use of multiple NonStop subsystems,
including NonStop TCP/IPv6, TS/MP, iTP Secure WebServer, and NSJSP. Using NonStop
TCP/IPv6 ensures that the incoming HTTP requests are distributed equally across the HTTPD
processes running on all the processors. Also, because HTTPD communicates with NSJSP using
server class send calls, TS/MP link management can help ensure that HTTPD requests for
NSJSP services are balanced across all the available server class processes of NSJSP.
15
2 Spring Framework
Spring Overview
Spring is an open source framework that you can use to develop enterprise applications. Its features
and functions are packaged in different modules. It includes a lightweight container that provides
a centralized, automated configuration and wiring of your application objects.
NOTE:Throughout this document, Spring refers to Spring version 3.1.0.
Spring includes the following:
•A flexible MVC web application framework, built on core Spring functionality. This framework
is highly configurable using strategy interfaces, and accommodates multiple view technologies,
such as JSF.
•Integration with other frameworks, such as Hibernate, with lots of IoC convenience features,
addressing many typical Hibernate integration issues.
•A JDBC abstraction layer that supports exception hierarchy, simplifies error handling, and
reduces the effort in generating code.
•Support for application testability and scalability by allowing software components to be first
developed and tested in isolation, then scaled up for deployment in any environment.
The NonStop system provides a platform comprising the Java Virtual Machine (JVM) and a servlet
container ― NSJSP. On NonStop systems, Java applications (created using Spring libraries) can
be run/deployed as:
•Standalone applications on the JVM
•Web applications under NSJSP
Spring Projects
The Spring community maintains several projects such as Spring Web Flow, Spring framework,
Spring Web Services, and Spring Security. Among these projects, only the Spring framework and
the Spring Web Flow is presently certified for use on the NonStop platform.
Spring Framework
The Spring framework is a layered development platform for developing Java applications in
different environments. Because the framework provides abstraction layers and modules, you can
use the Spring modules selectively based on your requirement.
The basic Spring framework consists of:
•Core Container
•Data Access/Integration layer (For examples on the Data Access/Integration layer, see
“Integrating Frameworks” (page 222).)
•Web layer (For examples on the Web layer, see “Getting Started with Spring” (page 38).)
•AOP and Instrumentation module (For examples on the AOP and Instrumentation layer, see
“Integrating Spring with Transaction Management Facility (TMF)” (page 27).
•Test module
For more information about Spring frameworks, see http://static.springsource.org/spring/docs/
3.1.x/spring-framework-reference/html.
For information on how to use the Spring framework to develop a web application for a NonStop
platform, see “Getting Started with Spring” (page 38).
16Spring Framework
Spring Web Flow
At times, web applications need to execute the same sequence of steps in different contexts. The
Spring Web Flow can be used to implement such repetitive steps or flows because it integrates
with the Spring Web Model View Control (MVC) platform to provide a flow definition language.
For information about downloading and installing the Spring Web Flow, see Appendix E: Installing
Spring Web Flow.
Spring Applications on NonStop
Spring web applications, when deployed on NonStop, can leverage features provided by the
NonStop platform.
Figure 1 shows how a Spring application can interface with other NonStop products.
NOTE:In Figure 1, the Spring applications are deployed on NSJSP. The same holds true when
running the Spring applications as a standalone application too.
Figure 1 Spring Web Applications
The combinations displayed in Figure 1 are as follows:
1.Spring web applications accessing RMI services (using Spring Remoting).
The Spring framework includes integration classes for remoting support using various
technologies (RMI, http invoker, hessian, burlap, jax-spc, jax-ws, JMS). Using Spring and RMI,
you can expose services through the RMI infrastructure. You must use NonStop TCP/IPv6 or
NonStop IP-CIP as the TCP/IP transport provider because the default RMI implementation uses
TCP/IP as it underlying transport layer.
There can be multiple RMI server instances listening on the same port. When an RMI client
invokes an RMI server, the TCP/IP provider distributes the requests across the RMI server
instances listening on the port in a round-robin manner. If the RMI servers are distributed across
all the processors, RMI calls are distributed across all the processors.
Spring Overview17
NOTE:NonStop TCP/IPv6 limits one process per processor to listen on any given port, while
IP-CIP does not have any such restriction. However, in the RMI Service Exporter configuration
the following property must be defined:
2.Spring applications accessing an SQL/MX database.
Spring web applications can be configured to access an SQL/MX database through the JDBC
drivers (JDBC Type 2 or JDBC Type 4 drivers).
3.Spring web applications accessing TS/MP applications.
The Spring framework can be integrated with the JToolkit library to expose legacy TS/MP
applications as web applications without major changes to the application.
4.Spring applications accessing SOAP services.
Spring web applications can be configured to access SOAP services hosted on a NonStop
platform or any other platform.
Installing the Spring Framework
This section describes the procedure to install Spring framework libraries on a Nonstop system.
Prerequisites
Before getting started, make sure that you have the following software installed on the NonStop
and Windows systems:
NonStop System
Table 1 Softwares to be installed on the NonStop system
For more information:Software
NSJ version 6.0
For information on installing NSJ on a NonStop system, see the NonStop Server for Java 6.0Programmer's Reference.
Windows System
Table 2 Softwares to be installed on the Windows system
DownloadSoftware
JDK version 1.6
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html and
set the PATH and JAVA_HOME environment variables.
Installing Spring Framework Libraries on a NonStop System
Installing Spring framework libraries on a NonStop system requires the following actions:
18Spring Framework
1.“Downloading the Spring Distribution on Windows” (page 19)
2.“Copying Spring Runtime Libraries from Windows to NonStop” (page 19)
NOTE:Throughout the section, references are made to the following directories:
•<Spring Home>: The directory on the Windows system where the Spring distribution
files are extracted.
•<NonStop Spring Home>: The OSS directory on the NonStop system where the Spring
runtime JAR files are located.
•<My SASH Home>: The directory on the Windows system where the contents of the
SAMPLES.zip file (distributed as a part of the NonStop Samples for Java frameworks T0874 and available for download in Scout) is extracted.
•<NSJSP Deployment Directory>: The location of the iTP WebServer deployment
directory (on the NonStop system) in which NSJSP is setup.
Downloading the Spring Distribution on Windows
To download the Spring distribution on the Windows system, complete the following steps:
1.Go to http://www.springsource.com/download/community?project=Spring%20Framework
.
The Spring Community Downloads web page appears.
2.Do one of the following:
1.Register yourself.
2.Click I'd rather not fill in the form. Just take me to the download page.
The Spring frameworks available for download appear.
3.Select 3.1.0.RELEASE and download the spring-framework–3.1.0.RELEASE.zip file.
NOTE:The spring-framework–3.1.0.RELEASE.zip file does not include the Spring
sample applications, the Spring framework libraries, and dependency JAR files that are
required to build the sample applications.
4.Extract the spring-framework–3.1.0.RELEASE.zip file into a directory on the Windows
system.
This directory will be referred as <Spring Home>.
Copying Spring Runtime Libraries from Windows to NonStop
1.Create JAR files in the <Spring Home> directory on the Windows system:
command prompt> cd <Spring Home>
command prompt> jar -cvf spring_dist.jar dist
For example:
command prompt> cd C:\spring-framework-3.1.0.RELEASE
command prompt> jar -cvf spring_dist.jar dist
2.Create the <NonStop Spring Home> directory in the OSS environment on the NonStop
system:
OSS> mkdir -p <NonStop Spring Home>
For example, create a directory structure /usr/tandem/sash/spring_3.1.0.
OSS> mkdir -p /usr/tandem/sash/spring_3.1.0
3.Transfer the spring_dist.jar file from <Spring Home> to <NonStop Spring Home>
and extract it:
OSS> cd <NonStop Spring Home>
Installing the Spring Framework19
OSS> jar -xvf spring_dist.jar
NOTE:The sub-directories on the NonStop system must contain the same list of files as those in
the <Spring Home>\dist directory on the Windows system.
The Spring runtime libraries are installed on the NonStop system. You can use these libraries to
develop and run Spring applications on a NonStop system.
Setting up Sample Spring Applications on NonStop
The sample Spring applications (PetClinic and JPetStore) are included in the SAMPLES.zip file.
This file contains the modifications made to PetClinic and JPetStore to make them compatible with
NonStop systems.
NOTE:The SAMPLES.zip file is distributed as a part of the NonStop Samples for Java frameworks
- T0874.
SAMPLES.zip is present in the T0874AAB.BIN file in Scout. For information on how to install
the T0874AAB.BIN file from Scout, see https://h20453.www2.hp.com/scout/download_help.htm.
Before you deploy the sample applications, complete the following steps:
1.Download the SAMPLES file from Scout.
2.Add the .zip extension to it.
The file is renamed as SAMPLES.zip.
3.Extract the SAMPLES.zip file to a location on the Windows system.
This section describes the steps to build, set up, deploy, and run the PetClinic and JPetStore sample
applications on NonStop systems.
Prerequisites
•For NonStop system:
The NS-Samples-for-Java-Frameworks folder appears.
NOTE:The absolute path of the NS-Samples-for-Java-Frameworks folder is referred
as <My SASH Home>.
Table 3 Softwares to be installed on the NonStop system
For more information:Software
NonStop iTP WebServer version
7.x or later
NSJSP version 6.1
NonStop SQL/MX version 2.3
For information on installing and setting up iTP WebServer (secure and
non-secure) on a NonStop system, see the iTP Secure WebServer SystemAdministrator's Guide.
For information on installing and setting up NSJSP on a NonStop system, see
the NonStop Servlets for JavaServer Pages (NSJSP) 6.1 System Administrator'sGuide.
For information on installing SQL/MX on a NonStop system, see the SQL/MXInstallation and Upgrade Guide.
JDBC Type 2 driver or JDBC Type
4 driver for the installed SQL/MX
version
NSJ version 6.0
20Spring Framework
For information on installing JDBC Type 2 driver and JDBC Type 4 driver on
a NonStop system, see JDBC Type 2 Driver Programmer's Reference forSQL/MX and JDBC Type 4 Driver Programmer's Reference for SQL/MX.
For information on installing NSJ on a NonStop system, see the NonStopServer for Java 6.0 Programmer's Reference manual.
•For Windows system:
Table 4 Softwares to be installed on the Windows system
DownloadSoftware
PetClinic
JDK version 1.6
Maven version
2.2.1
JDBC Type 4 driver
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html
and set the PATH and JAVA_HOME environment variables.
Download from http://maven.apache.org/download.html and set the PATH andMAVEN_HOME environment variables.
For information on installing JDBC Type 4 driver on a Windows system, see JDBC Type 4Driver Programmer's Reference for SQL/MX.
The PetClinic sample application is an information system that is accessible using a web browser.
The intended users of the application are employees of the clinic who need to view and manage
information regarding veterinarians, clients, and their pets.
NOTE:The PetClinic sample application described here uses Spring 3.0.2 version.
To use PetClinic, complete the following steps:
•“Building PetClinic on Windows” (page 21)
•“Setting up PetClinic Database on NonStop” (page 22)
•“Deploying PetClinic on NonStop” (page 23)
•“Running PetClinic on NonStop” (page 23)
Building PetClinic on Windows
1.Go to the <My SASH Home>\spring\samples\petclinic directory on the Windows
system.
2.Configure the JDBC driver settings for the NonStop SQL/MX database.
1.Go to the <My SASH Home>\spring\samples\petclinic\src\main\resources
directory on the Windows system.
2.Modify the jdbc.properties file to update the JDBC configuration. You can use either
the JDBC Type 2 driver or the JDBC Type 4 driver by setting their SQL/MX settings as
follows:
•For JDBC Type 2 driver, uncomment the SQL/MX settings for the JDBC Type 2 driver,
so that it appears as:
# Properties that control the population of schema and data for a new data source
# SQL/MX Settings for JDBC Type 2 Driver
jdbc.driverClassName=com.tandem.sqlmx.SQLMXDriver
jdbc.url=jdbc:sqlmx://
jdbc.username=
jdbc.password=
jdbc.catalog=petcliniccat
jdbc.schema=petclinicsch
hibernate.dialect=org.hibernate.dialect.SqlmxDialect
NOTE:Because the JDBC Type 2 driver is located on the NonStop system, you
need not specify the values for jdbc.username and jdbc.password fields.
•For JDBC Type 4 driver, uncomment the SQL/MX settings for the JDBC Type 4 driver
, and enter the values for the JDBC URL (NonStop system IP Address and port number
of the JDBC data source), NonStop system username, and password so that it appears
as:
Installing the Spring Framework21
#------------------------------------------------------------# Properties that control the population of schema and data for a new data source
# SQL/MX Settings for JDBC Type 4 Driver
jdbc.driverClassName= com.tandem.t4jdbc.SQLMXDriver
jdbc.url= jdbc:t4sqlmx://<HP NonStop System IP Address>:<Port No.>
jdbc.username=<HP NonStop Username>
jdbc.password=<HP NonStop Password>
jdbc.catalog=petcliniccat
jdbc.schema=petclinicsch
hibernate.dialect=org.hibernate.dialect.SqlmxDialect
3.Build the PetClinic web application archive (WAR)file (petclinic.war).
1.Go to the <My SASH Home>\spring\samples\petclinic directory:
command prompt> cd <My SASH Home>\spring\samples\petclinic
2.Build the PetClinic web archive using JDBC Type 2 driver or JDBC Type 4 driver.
1.Enter the following command:
command prompt> mvn clean package
The application WAR file (petclinic.war) is created in the <My SASH
Home>\spring\samples\petclinic\target directory.
2.Create the WEB-INF\lib folder in the <My SASH
Home>\spring\samples\petclinic\target directory and copy the SQL/MX
hibernate dialect JAR file (hibernate35sqlmx.jar) to this directory.
3.Go to <My SASH Home>\spring\samples\petclinic\target and run the
following commands:
command prompt> cd <My SASH Home>\spring\samples\petclinic\target
command prompt> jar uf petclinic.war WEB-INF\lib\hibernate35sqlmx.jar
The hibernate35sqlmx.jar is copied to the <My SASH
Home>\spring\samples\petclinic\target\petclinic.war\WEB-INF\lib
directory.
NOTE:If you are using the JDBC Type 4 driver:
•In step 2, copy the t4sqlmx.jar file also to the \WEB-INF\lib directory in
addition to the hibernate35sqlmx.jar file.
•In step 3, run this jar command:
jar uf petclinic.war
WEB-INF\lib\hibernate35sqlmx.jar WEB-INF\lib\t4sqlmx.jar
Setting up PetClinic Database on NonStop
1.Edit the <My SASH Home>\spring\samples\petclinic\src\main\resources\db\mxci\petclinic_tables_script.sql file to include the following:
•<$datavol>: specify the Guardian volume for the primary partition of the table. For
example: $data01
•<user>: specify the owner of the schema. For example: super.sashusr
•<node.$vol>: specify the location of the metadata tables for the catalog. For example:
\NSK01.$data01
•<subvol reference>: specify the designated subvolume name for the schema. For
example: SASH1
NOTE:The subvolume name is always prefixed by ZSD and must have eight characters
(including ZSD).
2.Create a directory in OSS to place the database script files, using the command:
NOTE:<NonStop SASH Home> can be any working directory. It is suggested that you
create spring/samples/petclinic/dbconfig directory structure in <NonStop SASH
Home>.
3.Copy the following scripts from the <My SASH
Home>\spring\samples\petclinic\src\main\resources\db\mxci\ Windows
directory to the OSS directory created in Step 2:
•petclinic_tables_script.sql
•petclinic_dataload_script.sql
NOTE:
•The petclinic_tables_script.sql script creates the SQL/MX database catalog,
schema, and tables for PetClinic.
•The petclinic_dataload_script.sql script loads the database with sample data.
4.Go to the OSS directory where the petclinic_tables_script.sql and
petclinic_dataload_script.sql files are copied, and create the PetClinic database
catalog, schema, and tables, using the SQL/MX command:
OSS> obey petclinic_tables_script.sql;
NOTE:By default, the petclinic_tables_script.sql file creates the database catalog
name as petcliniccat and schema name as petclinicsch. If these names conflict with
any of the existing catalog and schema names, modify the database catalog and schema
names in the petclinic_tables_script.sql script file.
If you modify the database catalog and schema names, edit the jdbc.properties file
present in the <My SASH Home>\spring\samples\petclinic\src\main\resources
directory, present in the SAMPLES.zip file.
5.Load the sample data in the PetClinic sample application database tables using the SQL/MX
command:
OSS> obey petclinic_dataload_script.sql;
The PetClinic database is setup on your NonStop system.
Deploying PetClinic on NonStop
For information on how to deploy PetClinic on the NonStop system, see Appendix C: Deploying
Sample Applications on NonStop.
Running PetClinic on NonStop
To run PetClinic on the NonStop system, in the NSJSP Web Application Manager screen, under
Applications, click /<servlet directory>/petclinic.
You can now perform the following actions using PetClinic:
•View a list of veterinarians and their specialties
•View and update information of a pet owner
•Add a new pet owner to the system
•View and update information of a pet
Installing the Spring Framework23
JPetStore
•Add a new pet to the system
•View information about the pet's visit to the clinic
The intended users of the JPetStore sample application are Visitors and Shoppers. A Visitor is
anyone who visits the site. A Shopper is an authenticated visitor who is signed in to the site. Visitors
can browse the site for items of their interest. Shoppers can purchase items of their interest.
NOTE:The JPetStore sample application described here uses Spring 3.0.2 version.
To use JPetStore, complete the following steps:
•“Building JPetStore on Windows” (page 24)
•“Setting up JPetStore Database on NonStop” (page 25)
•“Deploying JPetStore on NonStop” (page 26)
•“Running JPetStore on NonStop” (page 26)
Building JPetStore on Windows
1.Go to the <My SASH Home>\spring\samples\jpetstore directory on the Windows
system.
2.Configure the JDBC driver settings for the NonStop SQL/MX database.
1.Go to the <My SASH
Home>\spring\samples\jpetstore\src\main\webapp\WEB-INF directory on
the Windows system.
2.Modify the jdbc.properties file to update the JDBC configuration. You can use either
the JDBC Type 2 driver or the JDBC Type 4 driver by setting their SQL/MX settings as
follows:
•For JDBC Type 2 driver, uncomment the SQL/MX settings for the JDBC Type 2 driver,
so that it appears as:
#------------------------------------------------------------# SQL/MX Settings for JDBC Type 2 Driver
jdbc.driverClassName=com.tandem.sqlmx.SQLMXDriver
jdbc.url=jdbc:sqlmx://
jdbc.username=
jdbc.password=
jdbc.catalog=jpetstorecat
jdbc.schema=jpetstoresch
NOTE:Because the JDBC Type 2 driver is located on the NonStop system, you
need not specify the values for jdbc.username and jdbc.password fields.
•For JDBC Type 4 driver, uncomment the SQL/MX settings for the JDBC Type 4 driver
, and enter the values for the JDBC URL (NonStop system IP Address and port number
of the JDBC data source), NonStop system username, and password so that it appears
as:
#------------------------------------------------------------# SQL/MX Settings for JDBC Type 4 Driver
jdbc.driverClassName= com.tandem.t4jdbc.SQLMXDriver
jdbc.url= jdbc:t4sqlmx://<HP NonStop System IP Address>:<Port No.>
jdbc.username=<HP NonStop Username>
jdbc.password=<HP NonStop Password>
jdbc.catalog=jpetstorecat
jdbc.schema=jpetstoresch
24Spring Framework
NOTE:<HP NonStop Username> must have access to the schema created for
JPetstore.
3.Build the JPetStore WAR file
(org.springframework.samples.jpetstore-1.0.0-SNAPSHOT.war).
1.Go to the <My SASH Home>\spring\samples\jpetstore directory:
command prompt> cd <My SASH Home>\spring\samples\jpetstore
2.Build the JPetStore web archive using the JDBC Type 2 driver or JDBC Type 4 driver.
1.Enter the following command:
command prompt> mvn clean package
The application WAR file
(org.springframework.samples.jpetstore-1.0.0-SNAPSHOT.war) is
created in the <My SASH Home>\spring\samples\jpetstore\target
directory.
2.Create the WEB-INF\lib folder in the <My SASHHome>\spring\samples\jpetstore\target directory.
If you are using JDBC Type 4 driver, proceed with Step 3.
3.Copy the JDBC Type 4 driver file (t4sqlmx.jar) to the <My SASHHome>\spring\samples\jpetstore\target directory.
4.Go to <My SASH Home>\spring\samples\jpetstore\target and run the
following commands:
command prompt> cd <My SASH Home>\spring\samples\jpetstore\target
command prompt> jar uf org.springframework.samples.jpetstore-1.0.0-SNAPSHOT.war
WEB-INF\lib\t4sqlmx.jar
The t4sqlmx.jar file is copied to the <My SASH
Home>\Home>\spring\samples\jpetstore\target\
NOTE:<NonStop SASH Home> can be any working directory. It is suggested that you
create the spring/samples/jpetstore/dbconfig directory structure in <NonStop
SASH Home>.
Installing the Spring Framework25
3.Copy the following scripts from the <My SASHHome>\spring\samples\jpetstore\db\mxci Windows directory to the OSS directory
created in Step 2:
•jpetstore_tables_script.sql
•jpetstore_dataload_script.sql
NOTE:
•The jpetstore_tables_script.sql script creates the SQL/MX database catalog,
schema, and tables for JPetStore.
•The jpetstore_dataload_script.sql script loads the database with sample data.
4.Go to the OSS directory where the jpetstore_tables_script.sql and
jpetstore_dataload_script.sql files are copied, and create the JPetStore database
catalog, schema, and tables, using the SQL/MX command:
OSS> obey jpetstore_tables_script.sql;
NOTE:By default, the jpetstore_tables_script.sql file creates the database catalog
name as jpetstorecat and schema name as jpetstoresch. If these names conflict with
the existing catalog and schema names, modify the database catalog and schema names in
the jpetstore_tables_script.sql script file.
If you modify the database catalog and schema names, the new names must be updated in
the jdbc.properties file located in the <My SASHHome>\spring\samples\jpetstore\src\main\webapp\WEB-INF directory, included
in the SAMPLES.zip file.
5.Load the sample data in the JPetStore database tables:
OSS> obey jpetstore_dataload_script.sql;
The JPetStore database is setup on the NonStop system.
Deploying JPetStore on NonStop
For information on how to deploy JPetStore on the NonStop system, see Appendix C: Deploying
Sample Applications on NonStop.
Running JPetStore on NonStop
To run JPetStore on the NonStop system, in the NSJSP Web Application Manager screen, under
As a visitor, you can now perform the following activities:
•Select a Product Category labeled with words or icons, view the item detail, or access the
MenuBar features.
•Search by entering a keyword or phrase to locate items.
•Add an item to a Cart, either from a summary list or from a detail view.
•Collect items for later purchase.
•Increase or decrease the quantity for any item in a Cart, up to available inventory, or remove
the item from the Cart by changing the quantity to zero.
•Complete an online form to create an Account.
26Spring Framework
As a shopper, you can perform the following activities (including those performed by a visitor):
•Enter a username and password to access your account.
•Store shipping information and preferences for your use at future sessions.
•Purchase the items collected in a Cart.
•Provide payment information.
Integrating Spring with Transaction Management Facility (TMF)
The NonStop Transaction Management Facility (TMF) provides transaction protection, database
consistency, and database recovery, which are critical in high-volume transaction processing.
TMF protects databases in a wide variety of environments such as online transaction processing
(OLTP), online query processing (OLQP), batch processing, and decision support systems.
TMF protects databases by managing database transactions, monitoring database activity through
the use of audit trails, and providing database recovery methods while sustaining high performance
in a high-volume, distributed application environment.
For more information, see the TMF Introduction manual and the TMF Reference Manual.
This section describes how to use a TMF Adapter in Spring application.
What is Spring TMF Adapter?
Spring provides the AbstractPlatformTransactionManager, which can be used to develop
a TMF adapter for Spring. Integration of NonStop TMF with Spring applications is provided by
implementing Spring's AbstractPlatformTransactionManager. The class used for this
implementation is called TmfTransactionManager. When TmfTransactionManager is used
in a Spring application, a transaction is started by using the Spring TMF adapter and creates a
TMF transaction on Nonstop.
TmfTransactionManager exposes the following methods to Spring applications:
•getTransaction
•commit
•rollback
NOTE:For the actual signature of the methods mentioned above, see the Spring documentation
at http://static.springsource.org/spring/docs/3.1.0.RELEASE/api/org/springframework/
transaction/PlatformTransactionManager.html.
For information about TmfTransactionManager configuration, see “Integrating Spring with
Transaction Management Facility (TMF)” (page 27).
The getTransaction method may be invoked with or without TMF transaction context. The behavior
of TmfTransaction will be based on the transaction propagation attribute set on it. The following
are the Propagation behaviors:
1.PROPAGATION_REQUIRED: This is the default setting of a transaction definition, and typically
defines a transaction synchronization scope. If a transaction exists, it supports the current
transaction; otherwise, it creates a new one.
2.PROPAGATION_SUPPORTS: Supports a current transaction; executes non-transactionally if no
transaction exists.
3.PROPAGATION_MANDATORY: Supports a current transaction; if no transaction exists, throws
an exception.
4.PROPAGATION_REQUIRES_NEW: Creates a new transaction; suspends the current transaction
if one exists.
5.PROPAGATION_NOT_SUPPORTED: Does not support a current transaction; always executes
non-transactionally.
Integrating Spring with Transaction Management Facility (TMF)27
6.PROPAGATION_NEVER: Does not support a current transaction; throws an exception if a
current transaction exists.
7.PROPAGATION_NESTED: If a current transaction exists, it executes within a nested transaction:
otherwise, the behavior is similar to PROPAGATION_REQUIRED. This behavior is not supported
on NonStop.
Setting up the Sample SpringTMFAdapter on NonStop
The sample SpringTMFAdapter is included along with the Spring application. springtmf.jar
is the SpringTMFAdapter, which is used by the Spring application to create tmf transactions.
The SpringTMFAdapter is available via the SAMPLES.zip file, which is distributed as a part
of T0937.
To obtain the springtmf.jar and the samples, complete the following steps:
1.Create a directory on your Windows system. This directory is referred as <TMF AdapterHome>.
For example, C:\TMF
2.Download the ADAPTER and SAMPLES file from Scout. For information on how to download
from Scout, see https://h20453.www2.hp.com/scout/download_help.htm.
3.Add the .zip extensions to both the files. The files will be renamed ADAPTER.zip and
SAMPLES.zip.
4.Extract the ADAPTER.zip file to <TMF Adapter Home>.
5.Extract the SAMPLES.zip file to <TMF Adapter Home> to get the sample application. The
You can now use springtmf.jar in a Spring application to create TMF transactions.
After obtaining the springtmf.jar and samples, you can build, set up, deploy, and run the
sample SpringTMFAdapter application on a NonStop system. The following sections describe
how to build, set up, deploy, and run the application.
Prerequisites
Before getting started, make sure that you have the following software installed on the NonStop
and Windows systems:
•NonStop System
The SpringTMFAdapter folder containing the springtmf.jar file appears. For example,
C:\TMF\SpringTMFAdapter\springtmf.jar
sample application can be found at C:\TMF\Samples
Table 5 Softwares to be installed on the NonStop system
For more information:Software
NonStop SQL/MX version 3.2
JDBC Type 2 driver or JDBC Type
4 driver for the installed SQL/MX
version
For information on installing SQL/MX on a NonStop system, see the SQL/MXInstallation and Upgrade Guide.
For information on installing JDBC Type 2 driver and JDBC Type 4 driver on
a NonStop system, see JDBC Type 2 Driver Programmer's Reference forSQL/MX and JDBC Type 4 Driver Programmer's Reference for SQL/MX.
NSJ version 6.0
•Windows System
28Spring Framework
For information on installing NSJ on a NonStop system, see the NonStopServer for Java 6.0 Programmer's Reference manual.
Table 6 Softwares to be installed on the Windows system
DownloadSoftware
JDK version 1.6
JDBC Type 4 driver
version
Ant 1.8.2
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html
and set the PATH and JAVA_HOME environment variables.
For information on installing JDBC Type 4 driver on a Windows system, see JDBC Type 4Driver Programmer's Reference for SQL/MX.
Download from http://archive.apache.org/dist/ant/binaries/ and set the PATH andANT_HOME environment variables.
Setting up an SQL/MX Database on NonStop
1.Edit the <TMF Adapter Home>\Samples\TMF_Adapter_Sample\dbconfig\student_script.sql file to include
the following:
•<$datavol>: specify the Guardian volume for the primary partition of the table. For
example: $data01
•<user>: specify the owner of the schema. For example: super.sashusr
•<node.$vol>: specify the location of the metadata tables for the catalog. For example:
\NSK01.$data01
•<subvol reference>: specify the designated subvolume name for the schema. For
example: SASH1
NOTE:The subvolume name is always prefixed by ZSD and must have eight characters
(including ZSD).
2.Create a directory in OSS to place the database script files, using the command:
NOTE:HP recommends that you create /spring/samples/TMFAdapter/dbconfig
directory structure under <NonStop TMF Adapter Home>.
3.Copy the student_script.sql from the<TMF Adapter Home>\Samples\TMF_Adapter_Sample\dbconfig\ Windows directory to the OSS directory
created in Step 2.
4.Go to the OSS directory where the student_script.sql file is copied, and create the
database catalog and schema, using the SQL/MX command:
OSS> obey student_script.sql;
NOTE:By default, the student_script.sql file creates the database catalog name as
simplecat and schema name as simplesch. If these names conflict with any of the existing
catalog and schema names, modify the database catalog and schema names in the
student_script.sql script file.
If you modify the database catalog and schema names, update the
application.properties file present in SAMPLES.zip, available in the <TMF Adapter
Home>\Samples\TMF_Adapter_Sample\src directory.
The SQL/MX database is setup on your NonStop system.
Integrating Spring with Transaction Management Facility (TMF)29
Dependent Libraries for the Sample TMFAdapter
Before executing the sample TMFAdapter application, get the following libraries to the <TMFAdapter Home>\Samples\TMF_Adapter_Sample\lib directory on Windows. Then transfer
these files (via FTP) to the <NonStop TMF Adapter Home>/spring/samples/TMFAdapter/lib/ directory on the NonStop system.
To run the TMFAdapter application, you can use either JDBC Type 2 driver or JDBC Type 4 driver.
When you extract the sample application on a Windows system, the following jar files for
Programmatic, Annotation, and AOP are placed in the <TMF AdapterHome>\Samples\TMF_Adapter_Sample\jar\t2 location:
•TMFAdapter_Sample_Programmatic.jar
•TMFAdapter_Sample_Annotation.jar
•TMFAdapter_Sample_AOP.jar
Using a JDBC Type 2 driver:
If you use a JDBC Type 2 driver and have not modified the default catalog and schema when
setting up the database, you can use these packaged jar files as is for execution (starting with step
3).
If you modify the default catalog and schema, then update the schema and catalog entries in the
application.properties file and follow these steps to build and deploy the jar files:
1.Go to the location where the samples are extracted using the command line in your Windows
system.
2.Create the jar files by using the following command:
ant -f build.xml jar
<JDBC T2 Driver Installation
Directory>/lib
If the Java files must be compiled, use:
ant -lib <TMF Adapter Home>\Samples\TMF_Adapter_Sample\lib\ -f
build.xml cleanjar
The following jar files are created under <TMF Adapter
Home>\Samples\TMF_Adapter_Sample\jar:
•TMFAdapter_Sample_Programmatic.jar
•TMFAdapter_Sample_Annotation.jar
•TMFAdapter_Sample_AOP.jar
3.Transfer the jar files (via FTP) to <NonStop TMF Adapter
Home>/spring/samples/TMFAdapter/ on the NonStop system.
If you use a JDBC Type 4 driver, you must modify the jdbc.url, jdbc.username, and
jdbc.password entries in application.properties, and then build the jar files. If you
modify the default catalog and schema, then those entries must also be updated in the
application.properties files. Next, follow these steps to build and deploy the jar files:
1.When you extract the sample application on a Windows system, the build files are placed in
the <TMF Adapter Home>\Samples\TMF_Adapter_Sample location.
2.Go to the location using the command line in your Windows system.
3.Create the jar files by using the following command:
ant -f build.xml jar
If the Java files need to be compiled, use:
ant -f build.xml cleanjar
The following jar files are created under <TMF Adapter
Home>\Samples\TMF_Adapter_Sample\jar:
•TMFAdapter_Sample_Programmatic.jar
•TMFAdapter_Sample_Annotation.jar
•TMFAdapter_Sample_AOP.jar
4.Transfer these jar files (via FTP) to <NonStop TMF Adapter
Home>/spring/samples/TMFAdapter/ on the NonStop system.
When these commands are run, the output appears as follows:
Sample output for Programmatic method:
With TMF transaction manager
log4j:WARN No appenders could be found for logger
(org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
begin called
Transaction id created is: -576178764821102591
Check the transaction and press any key to proceed further...
Saving the data: id : 15 name : b weight : 4.4
Hibernate: insert into SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT (NAME, WEIGHT, ID) values (?, ?, ?)
doCommit called
begin called
Getting the specific data with id: 15
Hibernate: select simplebean0_.ID as ID0_, simplebean0_.NAME as NAME0_, simplebean0_.WEIGHT as WEIGHT0_ from
SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT simplebean0_ where simplebean0_.ID=?
There is a Data in the database: id : 15 name : b weight : 4.4
Deleting the data : id : 15 name : b weight : 4.4
Hibernate: delete from SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT where ID=?
doCommit called
Without TMF transaction manager
Saving the data: id : 15 name : b weight : 4.4
Hibernate: insert into SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT (NAME, WEIGHT, ID) values (?, ?, ?)
Getting ALL data
Hibernate: select simplebean0_.ID as ID2_, simplebean0_.NAME as NAME2_, simplebean0_.WEIGHT as WEIGHT2_ from
SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT simplebean0_
There is no data in database with id=15
Sample output for Annotation/AOP method:
With TMF transaction manager
log4j:WARN No appenders could be found for logger
(org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
begin called
Saving the data: id : 15 name : b weight : 4.4
Hibernate: insert into SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT (NAME, WEIGHT, ID) values (?, ?, ?)
doCommit called
begin called
Getting the specific data with id: 15
Hibernate: select simplebean0_.ID as ID0_, simplebean0_.NAME as NAME0_, simplebean0_.WEIGHT as WEIGHT0_ from
SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT simplebean0_ where simplebean0_.ID=?
doCommit called
There is a data with id 15 in database
begin called
Deleting the data : id : 15 name : b weight : 4.4
Hibernate: select simplebean_.ID, simplebean_.NAME as NAME0_, simplebean_.WEIGHT as WEIGHT0_ from
SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT simplebean_ where simplebean_.ID=?
Hibernate: delete from SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT where ID=?
doCommit called
Without TMF transaction manager
Saving the data: id : 15 name : b weight : 4.4
Hibernate: insert into SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT (NAME, WEIGHT, ID) values (?, ?, ?)
Getting ALL data
Hibernate: select simplebean0_.ID as ID2_, simplebean0_.NAME as NAME2_, simplebean0_.WEIGHT as WEIGHT2_ from
SIMPLECAT.SIMPLESCH.STUDENTSWEIGHT simplebean0_
There is no data in database with id=15
Integrating Spring with Transaction Management Facility (TMF)33
Configuring Spring Applications on NonStop Systems
This section provides information about configuring Spring applications on NonStop systems. To
configure spring applications, the following configurations are necessary:
•“NonStop Platform Configurations” (page 320)
•“Spring Framework Configurations” (page 34)
•“Module File Caching Configurations” (page 330)
Spring Framework Configurations
This section discusses the following configurations for your Spring applications:
•“Configuring JDBC Driver for SQL/MX Database” (page 34)
•“Configuring TmfTransactionManager” (page 36)
JDBC configurations are done in applicationContext.xml and jdbc.properties files.
All the configurations for Transaction Management are configured in applicationContext.xml.
Configuring JDBC Driver for SQL/MX Database
The JDBC driver to be used when a Spring application (using Spring DAO) connects to the SQL/MX
database must be specified in the applicationContext.xml and jdbc.properties file
provided by the Spring framework. You can configure JDBC Type 2 or JDBC Type 4 Driver. The
following configurations are required:
Configurations in the jdbc.properties File
Defining JDBC Driver Class for SQL/MX Database
For Type 2 Driver:
Specify the JDBC Type 2 driver class com.tandem.sqlmx.SQLMXDriver for the SQL/MX
database.
jdbc.driverClassName=com.tandem.sqlmx.SQLMXDriver
For Type 4 Driver:
Specify the JDBC Type 4 driver class com.tandem.t4jdbc.SQLMXDriver for the SQL/MX
database.
After you have set the JDBC driver, specify the location of the SQL/MX server. For URLs referring
to SQL/MX database, use the jdbc: protocol embedded within the URL. Specify the connection
URL as follows:
For Type 2 Driver:
jdbc.url=jdbc:sqlmx://
For Type 4 Driver:
jdbc.url=jdbc:t4sqlmx://<HP NonStop System IP Address>:<Port No.>
Establishing the Connection
For Type 2 Driver:
Specify the username and password with no values.
jdbc.username=
jdbc.password=
34Spring Framework
For Type 4 Driver:
Specify the username and password of your NonStop system.
After the database properties are set, wire the jdbc.properties file in the
applicationContext.xml file so that the actual values are available during runtime. The
PropertyPlaceholderConfigurer class provided by the Spring framework substitutes the
Configuring Spring Applications on NonStop Systems35
database properties specified in the applicationContext.xml file with the values specified
in the jdbc.properties file during runtime.
Modify the applicationContext.xml file for wiring the jdbc.properties file as shown
below:
NOTE:For information on the complete configuration snippet of the applicationContext.xml
file and the jdbc.properties file for JDBC Type 2 driver, see “Sample JDBC Configuration for
Spring” (page 334).
Configuring TmfTransactionManager
Spring framework provides the following ways for configuring the TmfTransactionManager:
•Declarative Transaction Management: In this case, the transaction action is defined in an XML
configuration file for each method (or class).
•Programmatic Transaction Management: In this case, the transaction action is hardcoded in
the code. This is similar to the JDBC transaction.
Consider a simple Plain Old Java Object (POJO) having a simple service. Let us see how to
configure the TmfTransactionManager in various ways to execute the POJO service in a TMF
transaction on a Nonstop system.
The POJO class is
public class SimpleService {
public void addRecord(){
//code to insert a record into a database
}
}
The bean definition for the Transaction Manager is as shown:
Assume that the file containing this definition is txbean.xml.
Declarative Transaction Management
Using declarative transaction management, you can configure the TmfTransactionManager
in the following ways:
•Annotations
•Aspect Oriented Programming (AOP)
Annotations
To configure the TmfTransactionManager using the annotation method, you must configure
the application's XML file. An example of the XML configuration is as shown:
The POJO Class SimpleService can use @Transactional annotation on its methods. The
SimpleService class using the @Transactional annotation is as shown:
public class SimpleService {
@Transactional
public void addRecord(SimpleBean b){
//<your code here>
}
public SimpleBean[] getRecords(){
//<your code here>
return null;
}
}
In this case, when the addRecord transaction is invoked, it is invoked under a TMF transaction.
When getRecords is invoked, a TMF transaction is not created.
Aspect Oriented Programming (AOP)
Configuration using AOP involves the following approach:
•Defining a service object to be used as a transactional object.
•Adding the transactional advice to the transactional object. The transaction semantics that
must be applied are encapsulated in the <tx:advice/> definition.
•Defining the transactional execution point to ensure that the transactional advice defined in
the previous step is executed at an appropriate point in the program. This is done using the
<aop:config/> definition.
A sample AOP configuration for configuring TmfTransactionManager is as shown:
In the above configuration, SimpleService and TmfTransactionManager are beans. An
AOP transaction advice is defined on the method name having a pattern “add*” with propagation
behavior “PROPAGATION_REQUIRED”, and the rest of the methods in the bean to have the
propagation behavior “PROPAGATION_SUPPORTS”.
Programmatic Transaction Management
Using programmatic transaction management, you can configure the TmfTransactionManager
in the following ways:
•Using the Transaction Template
•Using TmfTransactionManager programmatically
Configuring Spring Applications on NonStop Systems37
Configuring Using the Transaction Template
The following configuration shows how TmfTransactionManager can be used in a Spring
Transaction Template:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“txbean.xml");
transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallback()
{
// the code in this method executes in a transactional context
public Object doInTransaction(TransactionStatus status)
{
//code to invoke the POJO Service for example.
//it can be new SimpleService().addRecord();
//then add record will be executed in a TMF Transaction.
}
});
Configuring Using the TmfTransactionManager Programmatically
The following configuration shows how TmfTransactionManager can be created
programmatically and used in a TMF transaction:
public class SimpleService {
public void addRecord(SimpleBean b){
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
/* setting the transaction name explicitly can only be done programmatically*/
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try {
//code to invoke the POJO Service for example.
//it can be new SimpleService().addRecord();
//then add record will be executed in a TMF Transaction.
txManager.commit(status);
}
catch (MyException ex)
{
txManager.rollback(status);
throw ex;
}
}
}
A sample SpringTMFAdapter is included with Spring 3.1.0 application. For setup information, see
“Setting up the Sample SpringTMFAdapter on NonStop” (page 28).
Getting Started with Spring
This section explains how to develop a web application using Spring. It describes the steps to build
a basic employee management system on the Windows system and deploy it on the NonStop
system.
NOTE:The EmpInfo application described here is certified with Spring 3.0.2 version.
38Spring Framework
Prerequisites
•For NonStop system:
Table 8 Softwares to be installed on the NonStop system
For more information:Software
NonStop iTP WebServer version
7.x or later
NSJSP version 6.1
NonStop SQL/MX version 2.3
JDBC Type 2 driver or JDBC Type
4 driver for the installed SQL/MX
version
NSJ version 6.0
For information on installing and setting up iTP WebServer (secure and
non-secure) on a NonStop system, see the iTP Secure WebServer SystemAdministrator's Guide.
For information on installing and setting up NSJSP on a NonStop system, see
the NonStop Servlets for JavaServer Pages (NSJSP) 6.1 System Administrator'sGuide.
For information on installing SQL/MX on a NonStop system, see the SQL/MXInstallation and Upgrade Guide.
For information on installing JDBC Type 2 driver and JDBC Type 4 driver on
a NonStop system, see JDBC Type 2 Driver Programmer's Reference forSQL/MX and JDBC Type 4 Driver Programmer's Reference for SQL/MX.
For information on installing NSJ on a NonStop system, see the NonStopServer for Java 6.0 Programmer's Reference manual.
•For Windows system:
Table 9 Softwares to be installed on the Windows system
DownloadSoftware
JDK version 1.5
JDBC Type 4 driver
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html
and set the PATH and JAVA_HOME environment variables.
For information on installing JDBC Type 4 driver on a Windows system, see JDBC Type 4Driver Programmer's Reference for SQL/MX.
Eclipse Galileo IDE
version 3.5.2 or
later
Overview of EmpInfo
EmpInfo is a basic employee management system developed using Spring. This application enables
you to perform the following tasks:
•Add an employee record.
•Search an employee record using Employee ID.
•Delete an employee record using Employee ID.
In this application:
•The presentation layer is developed using the Spring-MVC framework.
•The business services layer is developed using the Spring framework.
•The persistence services are developed using Spring JDBC API.
•The employee data is stored in the NonStop SQL/MX database.
Download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/
packages/release/galileo/sr2.
Getting Started with Spring39
The following sections describe the steps required to develop, deploy, and run the EmpInfo
application.
•“Developing EmpInfo on Windows using the Eclipse Galileo IDE” (page 40)
•“Deploying EmpInfo on NonStop” (page 87)
•“Running EmpInfo on NonStop” (page 89)
Developing EmpInfo on Windows using the Eclipse Galileo IDE
NOTE:
•It is not mandatory for you to use the Eclipse Galileo IDE. You can use any IDE that supports
Java.
•The screen captures in this section are based on Eclipse Galileo IDE version 3.5.2. The screen
captures may look different if you use a different version of Eclipse Galileo.
The following activities are required to develop the EmpInfo application using the Eclipse Galileo
IDE:
1.“Developing a Basic EmpInfo Application” (page 41)
2.“Developing and Configuring Views and the Controller” (page 57)
3.“Developing Business Logic and Providing the Web Interface” (page 62)
4.“Integrating the Web-tier of EmpInfo with NonStop SQL/MX Database” (page 65)
5.“Enabling EmpInfo to Delete and Retrieve Employee Details” (page 73)
Creating the Eclipse Workspace
1.To open the Eclipse workspace, double-click the eclipse.exe file in <Eclipse IDEInstallation Directory>.
The Workspace Launcher dialog box appears. By default, the workspace is set to the existing
workspace, if already created.
You can use the existing workspace or create a new one by clicking Browse... and selecting
a folder.
Figure 2 Workspace Launcher Dialog Box
40Spring Framework
2.Click OK.
The Eclipse SDK Welcome screen appears.
NOTE:D:\sash_usr\spring is the sample workspace used to develop the EmpInfo
application.
Figure 3 Eclipse SDK Welcome Screen
Developing a Basic EmpInfo Application
Developing the EmpInfo application using Eclipse Galileo IDE involves the following activities:
1.“Creating a Dynamic Web Project” (page 41)
2.“Creating the index.jsp File” (page 43)
3.“Modifying the index.jsp File” (page 46)
4.“Modifying the web.xml File” (page 47)
5.“Creating the EmpInfo-servlet.xml File” (page 48)
6.“Adding Dependency JAR Files in the Project Library Path” (page 52)
7.“Creating the Controller for EmpInfo” (page 54)
8.“Creating the View” (page 57)
Creating a Dynamic Web Project
1.Click File > New > Project.
The New Project dialog box appears.
2.From the list of folders, select Web > Dynamic Web Project and click Next.
Getting Started with Spring41
Figure 4 New Project Wizard Dialog Box
The New Dynamic Web Project dialog box appears.
3.In the Project name field, type EmpInfo and click Finish.
NOTE:The other fields in the New Dynamic Web Project dialog box are selected by default.
Figure 5 New Dynamic Web Project Dialog Box
42Spring Framework
When prompted, change the perspective to Java EE and click Yes to open the new perspective.
NOTE:The perspective must be changed to Java EE because the Dynamic Web Project is
associated with the Java EE perspective.
The Project Structure appears.
4.In the Project Structure, ensure that the JRE System Library is set to JRE version 1.6 or later, as
shown in Figure 6.
If the JRE version is not set to 1.6, right-click JRE System Library to select JRE 1.6.
NOTE:The JRE version used in this example is 1.6.
The EmpInfo project with the project directory structure is created.
Figure 6 Project Explorer View
Creating the index.jsp File
Create the index.jsp file in the EmpInfo/WebContent directory as follows. This JSP page is
the entry point EmpInfo.
1.In the Project Explorer frame, right-click EmpInfo and select New > Other.
The New File dialog box appears.
2.From the list of folders, select Web > JSP and click Next.
Getting Started with Spring43
Figure 7 New File Dialog Box
The New JavaServer Page dialog box appears.
3.In the File name field, type index and ensure that the parent folder is set toEmpInfo/WebContent. Click Next.
44Spring Framework
Figure 8 New JavaServer Page Dialog Box
The New JavaServer Page: Select JSP Template dialog box appears.
4.From the Select JSP Template dialog box, select New JSP File (html) and click Finish.
NOTE:The Use JSP Template check box is selected by default.
Getting Started with Spring45
Figure 9 New JavaServer Page: JSP Template Dialog Box
The template for the index.jsp file is generated.
Modifying the index.jsp File
Add the header item and body content in the JSP file as shown:
<title>Spring Getting Started with EmpInfo Application</title>
</head>
46Spring Framework
<body>
<h2 align="center">Welcome to the EmpInfo Application</h2>
<br>
<p>This is EmpInfo Test Page.</p>
</body>
</html>
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-1.
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can proceed with the steps for modifying the web.xml file.
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
http://<IP Address of the iTP WebServer>:<port#>/<servlet directory>/EmpInfo.
Modifying the web.xml File
To modify the web.xml file, set the dispatcher servlet and its mapping as follows:
1.Open the EmpInfo/WebContent/WEB-INF/web.xml file by double-clicking it in the Project
Explorer frame.
NOTE:By default, XML files open in the XML Editor. The XML Editor has two views: Design
and Source view. Select the Source view.
The template for the default web.xml file generated during project creation is:
Create a WebApplicationContext file, which contains references to all the web-related
components. The name of this file is determined by the value of the <servlet-name/> element
in the web.xml file, with -servlet appended to it (hence, EmpInfo-servlet.xml). This is
the standard naming convention used with the Spring Web MVC framework.
The EmpInfo-servlet.xml file contains the bean definitions (plain Java objects) used by the
DispatcherServlet.
To create the EmpInfo-servlet.xml file in the EmpInfo/WebContent/WEB-INF directory:
1.In the Project Explorer frame, right-click EmpInfo and select New > Other.
The New File Wizard dialog box appears.
48Spring Framework
2.From the list of folders, select XML > XML and click Next.
Figure 10 New File Wizard Dialog Box
The New XML File dialog box appears.
3.In the File name field, type EmpInfo-servlet.xml and ensure that the parent folder is set
to EmpInfo/WebContent/WEB-INF. Click Next.
Getting Started with Spring49
Figure 11 New XML File Dialog Box
The New XML File: Options dialog box appears.
4.Select Create XML file from an XML template and click Finish.
50Spring Framework
Figure 12 New XML File: Options Dialog Box
The EmpInfo-servlet.xml file is created in the EmpInfo/WebContent/WEB-INF
directory.
5.Modify the EmpInfo-servlet.xml file by adding a bean entry named insert.htm and
com.hp.empinfo.web.EmployeeController as its class.
NOTE:The com.hp.empinfo.web.EmployeeController class provides controller for
the EmpInfo application to service a request according to its corresponding URL mapping in
/insert.htm. The Spring Web MVC framework uses an interface class called
HandlerMapping to define the mapping between a request URL and the handler object,
which handles the request. The controller ensures that the URL mapping the EmpInfo application
is com.hp.empinfo.web.EmployeeController, instead of DispatcherServlet.
After modification, the EmpInfo-servlet.xml file appears as:
public class EmployeeController extends SimpleFormController{
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
56Spring Framework
logger.info("Returning hello view");
return new ModelAndView("insert.jsp");
}
}
Your basic controller implementation is ready. This controller is expanded further to add more
functionality to the EmpInfo application.
Creating the View
After completing the controller implementation for EmpInfo, complete the following steps to create
the first view of the EmpInfo application:
1.Create a new JSP page insert.jsp in EmpInfo/WebContent by completing the steps
explained in “Creating the index.jsp File” (page 43).
2.Add the header and body content as shown:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Getting Started with EmpInfo Application</title>
</head>
<body>
<h2 align="center"> Welcome to the EmpInfo Application </h2>
<br>
<p><B><font color = "003399">Enter Employee Details</font></B></p>
</body>
</html>
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-2.
At this point, you can either deploy and verify the EmpInfo application you have developed
so far on the NonStop system, or you can proceed to the “Developing and Configuring Views
and the Controller” (page 57) section.
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
http://<IP Address of the iTP WebServer>:<port#>/<servletdirectory>/EmpInfo/insert.htm
To verify the EmpInfo application, complete the following steps:
1.Deploy the EmpInfo application using the steps described in “Deploying EmpInfo on
NonStop” (page 87).
2.Verify the EmpInfo application by accessing the following URL:
The Welcome screen of the EmpInfo application appears.
Developing and Configuring Views and the Controller
This section describes the process to develop and configure Views and the Controller.
Views are provided by JSP pages and the controller has the intelligence to recognize the business
logic based on the input provided in the JSP pages.
This section describes the following activities:
1.“Configuring the JSP Standard Tag Library (JSTL)” (page 58)
2.“Adding JSTL and JSP Related Dependency JARs” (page 60)
3.“Enhancing the Controller” (page 60)
4.“Decoupling View from the Controller” (page 61)
Getting Started with Spring57
Configuring the JSP Standard Tag Library (JSTL)
This section involves the following activities:
1.“Creating a folder to store JSPs” (page 58)
2.“Creating the include.jsp File” (page 58)
3.“Modifying the index.jsp File” (page 59)
4.“Modifying the insert.jsp File” (page 59)
To configure the JSTL, complete the following steps:
Creating a folder to store JSPs
1.In the Project Explorer frame, right-click EmpInfo and select New > Folder.
A New Folder dialog box appears.
2.In the Folder name field, type jsp and select EmpInfo/WebContent/WEB-INF as the parent
folder.
Figure 17 New Folder Dialog Box
3.Click Finish.
The jsp folder is created.
Creating the include.jsp File
1.Create the include.jsp file in the EmpInfo/WebContent/WEB-INF/jsp directory as
described in “Creating the index.jsp File” (page 43).
58Spring Framework
2.Add the tag extensions (taglibs) to include the.jsp file so that the include.jsp file appears
as:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page session="false"%>
NOTE:The created header file must be included in every JSP page. This ensures that the
same definitions are included in all JSPs. You must add all the JSPs in a subdirectory named
jsp in the WEB-INF directory. This allows views to be accessible via the controller because
these pages cannot be accessed via a URL.
Modifying the index.jsp File
1.Include the include.jsp file:
<%@ include file="/WEB-INF/jsp/include.jsp" %>
2.Provide a link to the insert.jsp page as follows:
After modification, the index.jsp file appears as:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Getting Started with EmpInfo Application</title>
</head>
<body>
<h2 align="center"> Welcome to the EmpInfo Application </h2>
<br>
1.Move the insert.jsp file to the EmpInfo/WebContent/WEB-INF/jsp directory by
dragging and dropping the file on the Eclipse window.
2.Include the include.jsp file in insert.jsp:
<%@ include file="/WEB-INF/jsp/include.jsp" %>
3.Add the <c:out> tag to display the current date and time retrieved from the model passed
to the view, which will be rendered using the JSTL.
For example:
<h3 align="center"><c:out value="${now}"/></h3>
After modification, the insert.jsp file appears as:
Getting Started with Spring59
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Getting Started with EmpInfo Application</title>
</head>
<body>
<h2 align="center"> We
lcome to the EmpInfo Application </h2>
To add the dependency JAR files in the project library path and to resolve the J2EE module
dependency on these JARs, follow the instructions described in “Adding Dependency JAR Files in
the Project Library Path” (page 52).
Enhancing the Controller
To add more functionality to the controller class, complete the following steps:
1.Update the EmployeeController.java by setting the resource reference of the view to
its new location EmpInfo/WebContent/WEB-INF/jsp/insert.jsp. Set the key/value
pair for the current date and time value in the model with the key identifier: "now" and the
string value: 'now' as shown below:
Before modification:
logger.info("Returning hello view");
return new ModelAndView("insert.jsp");
After modification:
String now = (new Date()).toString();
logger.info("Returning view with " + now);
return new ModelAndView("WEB-INF/jsp/insert.jsp", "now", now);
2.Add the following import statement:
import java.util.Date;
After modification, the controller file EmployeeController.java appears as:
public class EmployeeController extends SimpleFormController {
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String now = (new Date()).toString();
logger.info("Returning view with " + now);
return new ModelAndView("WEB-INF/jsp/insert.jsp", "now", now);
}
}
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-3
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can continue with the steps explained in “Decoupling View from
the Controller” (page 61).
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
http://<IP Address of the iTP WebServer>:<port#>/<servlet directory>/EmpInfo.
Decoupling View from the Controller
So far, the controller is specifying full path of the view, thereby creating unnecessary dependency
between the controller and the view. Ideally, the view must be mapped using a logical name, so
that the view can be switched without changing the controller.
To decouple the view from the controller:
1.Modify the EmpInfo-servlet.xml file in the EmpInfo/WebContent/WEB-INF directory
to add the following bean to declare a new ViewResolver entry.
2.Modify the EmployeeController class EmpInfo/com/hp/empinfo/web/
EmployeeController.java to decouple the controller from view using ViewResolver
, as shown:
Before modification:
return new ModelAndView("WEB-INF/jsp/insert.jsp", "now", now);
After modification:
return new ModelAndView("insert", "now", now);
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-4
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can continue with the steps described in “Developing Business
Logic and Providing the Web Interface” (page 62).
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
Getting Started with Spring61
http://<IP Address of the iTP WebServer>:<port#>/<servlet directory>/EmpInfo.
Developing Business Logic and Providing the Web Interface
This section describes the following tasks:
1.“Creating a Simple POJO” (page 62)
2.“Creating Data Access Object Implementation for JDBC” (page 63)
3.“Creating and Modifying Supporting Views to Display Business Data” (page 63)
4.“Adding Dependency JAR Files” (page 64)
Creating a Simple POJO
1.Create a com.hp.empinfo.domain package and an Employee class in the
com.hp.empinfo.domain package, as described in “Creating the Controller for EmpInfo”
(page 54).
2.Modify the Employee.java class file to add some properties and their getter and setter
methods.
After modification, the Employee.java file must appear as:
package com.hp.empinfo.domain;
public class Employee implements java.io.Serializable {
private int empid;;
private String firstname;
private String lastname;
private int age;
private String email;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getFirstname() {
return firstname;
}
public void setFirstname (String firstname) {
this. firstname= firstname;
}
public String getLastname () {
return lastname;
}
public void setLastname (String lastname) {
this. lastname= lastname;
}
public int getAge () {
return age;
}
public void setAge (int age) {
this. age= age;
}
public String getEmail () {
return email;
}
public void setEmail (String email) {
this. email= email;
}
}
62Spring Framework
Creating Data Access Object Implementation for JDBC
1.Create a com.hp.empinfo.service package and an EmployeeDao class under the
com.hp.empinfo.service package, as described in “Creating the Controller for EmpInfo”
(page 54). This will contain the logic for handling Employee Database Transactions.
2.Modify the EmployeeDao.java class file to add the function for inserting employee details.
After modification, the EmployeeDao.java file must appear as:
package com.hp.empinfo.service;
import java.sql.SQLException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class EmployeeDao extends JdbcDaoSupport{
public void insertDetail(int empid, String firstname,
String lastname, int age, String email)
throws SQLException
{
getJdbcTemplate().update("insert into employee values(?,?,?,?,?)",
new Object[] { empid,firstname,lastname,age,email});
}
}
Creating and Modifying Supporting Views to Display Business Data
To create and modify supporting views to display business data, create the JSP files to create the
view by completing the following steps:
1.Create the insertresult.jsp file in the Empinfo/WebContent/Web-INF/jsp directory
as described in “Creating the index.jsp File” (page 43).
2.Modify the insertresult.jsp file to provide a link to the insert.jsp page.
After modification, the insertresult.jsp file must appear as:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Getting Started with EmpInfo Application</title>
</head>
<body>
<h2 align="center"> Insert Operation Successfully Executed </h2>
<br>
${model.add}
<br>
3.Modify the insert.jsp file in the EmpInfo/WebContent/Web-INF/jsp/insert.jsp
directory to receive all the input data required to add a new employee record to the database,
by completing the following steps:
1.Delete the following <c:out> tag from the <body> tag.
<h3 align="center"><c:out value="${now}"/></h3>
2.Add the following lines of code in the body tag to receive all the inputs required to add
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<html>
<head>
<title> Spring Getting Started with EmpInfo Application </title>
</head>
<body>
<br>
<p><B><font color = "003399">Enter Employee Details</font></B></p>
Add the following JAR file required for XML parsing:
Table 12 XML Parser Dependency JAR File
com.springsource.org.dom4j-1.6.1.jar
64Spring Framework
Dependency JAR Files
NOTE:The jar file mentioned in the above table can be found in the following spring repository:
http://ebr.springsource.com/repository/app/.
To add the dependency JAR file in the project library path and to resolve the J2EE module
dependency on it, follow the instructions described in “Adding Dependency JAR Files in the Project
Library Path” (page 52).
NOTE:The code of the EmpInfo application developed so far is located in <My SASH
The project directory structure for the EmpInfo application must appear as follows:
Figure 18 Project Explorer View
Integrating the Web-tier of EmpInfo with NonStop SQL/MX Database
This section describes the following tasks:
1.“Creating the applicationContext.xml File” (page 66)
2.“Creating the jdbc.properties File” (page 66)
3.“Modifying the EmpInfo-servlet.xml File” (page 68)
4.“Improving the Controller” (page 69)
5.“Modifying the web.xml File” (page 70)
Getting Started with Spring65
6.“Adding Dependency JAR Files” (page 71)
7.“Creating Database Catalog, Schema, and Tables on NonStop” (page 71)
Creating the applicationContext.xml File
1.Create the applicationContext.xml file in the EmpInfo/WebContent/WEB-INF/
directory, as described in “Creating the EmpInfo-servlet.xml File” (page 48).
2.Create a new XML file in the EmpInfo/WebContent/WEB-INF directory and type the name
of the XML file as applicationContext.
3.Modify the applicationContext.xml file to add a bean definition of the EmployeeDao
class. After modification, the applicationContext.xml file must appear as:
The JdbcDaoSupport feature of Spring framework is used for connecting to the NonStop SQL/MX
database and for carrying out requested database transactions. To fulfill this requirement, the
jdbc.properties file must be created to include all the database related information.
1.In the Project Explorer frame, right-click EmpInfo and select New > File.
The New File dialog box appears.
2.In the File name field, type jdbc.properties and ensure that the parent folder is set to the
EmpInfo/WebContent/WEB-INF directory. Click Finish.
66Spring Framework
Figure 19 New File Dialog Box
The jdbc.properties file is created.
Getting Started with Spring67
3.Modify the jdbc.properties file based on the JDBC driver type you use:
•If you use the JDBC Type 2 driver, the SQL/MX settings for JDBC Type 2 driver in the
jdbc.properties file must appear as:
#---------------------------------------------------------------------------# SQL/MX Settings for JDBC Type 2 Driver
NOTE:Because JDBC Type 2 driver resides on the NonStop system, you need not type
the username and password in the jdbc.username and jdbc.password fields.
•If you use the JDBC Type 4 driver, the SQL/MX settings for JDBC Type 4 driver in the
jdbc.properties file must appear as:
#---------------------------------------------------------------------------# SQL/MX Settings for JDBC Type 4 Driver
jdbc.driver=com.tandem.t4jdbc.SQLMXDriver
jdbc.url=jdbc:t4sqlmx://<HP NonStop System IP Address>:<Port No.>
jdbc.user=<HP NonStop Username>
jdbc.password=<HP NonStop Password>
jdbc.catalog=empinfocat
jdbc.schema=empinfosch
NOTE:
◦To use the JDBC Type 4 driver, type the JDBC URL (NonStop system IP Address and
Port Number of the JDBC data source), NonStop system username, and password.
◦The name of the database catalog used in the example is empinfocat and the
schema name is empinfosch. If these database catalog and schema names conflict
with any of the existing catalog and schema names on the NonStop system, modify
the database catalog and schema names in the jdbc.properties file.
Modifying the EmpInfo-servlet.xml File
Modify the EmpInfo-servlet.xml file in the EmpInfo/WebContent/WEB-INF directory to
define the new form and controller as shown below:
Map<String, String> model = new HashMap<String, String>();
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
Getting Started with Spring69
3.Add the following import statements to include the classes used in the controller.
Map<String, String> model = new HashMap<String, String>();
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
Modifying the web.xml File
1.Add ContextLoaderListener to load the applicationContext.xml file under the
<web-app> tag.
2.Increase the startup load to 2 after adding the ContextLoaderListener to make
DispatcherServlet as the secondary servlet class. The ContextLoaderListener
servlet class becomes the primary servlet class.
After modification, the web.xml file must appear as:
If you plan to use the JDBC Type 4 driver, you must add the JAR file of the JDBC Type 4 driver to
the EmpInfo project library.
Table 14 JDBC Type 4 Dependency JAR File
Source LocationDependency JAR File
<JDBC T4 Installation Directory>\libt4sqlmx.jar
To add the dependency JAR files in the project library path and to resolve the J2EE module
dependency on these JAR files, follow the instructions described in “Adding Dependency JAR Files
in the Project Library Path” (page 52).
Creating Database Catalog, Schema, and Tables on NonStop
This section describes the steps to create the database catalog, schema, and tables on the NonStop
system.
Getting Started with Spring71
NOTE:The database catalog, schema, and table creation script
empinfo_tables_script.sql is included in the SAMPLES.zip file.
For information on the empinfo_tables_script.sql, see “EmpInfo Database Script” (page 319).
To create a database catalog, schema, and table on NonStop, complete the following steps:
1.Copy the empinfo_tables_script.sql script from the <My SASH
Home>\spring\getting-started\dbconfig Windows directory to the <NonStop
SASH Home>/spring/my_samples/empinfo/dbconfig OSS directory.
2.Go to the OSS directory, where the empinfo_tables_script.sql script is copied, using
the OSS command:
OSS> cd <NonStop SASH Home>/spring/my_samples/empinfo/dbconfig
For example:
OSS> cd /home/sash_usr/sash/spring/my_samples/empinfo/dbconfig
3.Create the EmpInfo application database catalog, schema, and tables using the SQL/MX
command:
OSS> obey empinfo_tables_script.sql;
NOTE:By default, the empinfo_tables_script.sql script creates the database
catalog name as empinfocat and the schema name as empinfosch. If these database
catalog and schema names conflict with any of the existing catalog and schema names on
the NonStop system, modify the database catalog and schema in the
empinfo_tables_script.sql script file.
If you modify the database catalog and schema names, the new database catalog names
must be updated in the EmpInfo/WebContent/WEB-INF/jdbc.properties file.
The project directory structure for the EmpInfo application must appear as follows:
72Spring Framework
Figure 20 Project Explorer View
The code of the EmpInfo application developed so far is located in <My SASH
Home>\spring\getting-started\EmpInfo-InParts\Part-6.
At this point, you can either deploy and verify the EmpInfo application you have developed so far
on the NonStop system, or you can proceed to the “Enabling EmpInfo to Delete and Retrieve
Employee Details” (page 73) section.
For deployment, see the steps described in “Deploying EmpInfo on NonStop” (page 87).
You can verify the EmpInfo application by accessing the following URL:
http://<IP Address of the iTP WebServer>:<port#>/<servlet directory>/EmpInfo.
NOTE:The code for the EmpInfo application developed so far is located in <My SASH
4.Modify the deleteresult.jsp file to remove the details of an employee record from the
JSP page as follows:
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<%@ taglib prefix="form"
uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<title> Spring Getting Started with EmpInfo Application </title>
public Employee getDetail(int empid) throws SQLException {
Employee employee;
employee = (Employee) getJdbcTemplate().queryForObject(
"select * from employee where emp_id =?",
new Object[] { empid }, new EmployeeRowMapper());
return employee;
}
public void insertDetail(int empid, String firstname, String lastname,
int age, String email) throws SQLException {
getJdbcTemplate().update("insert into employee values(?,?,?,?,?)",
new Object[] { empid, firstname, lastname, age, email });
}
public String deleteEmployee(int empid) {
getJdbcTemplate().update("delete from employee where emp_id= ?",
new Object[] { empid });
return "Employee deleted";
}
}
Modifying the Employee.java File
You must modify the Employee.java file in the com.hp.empinfo.domain package to add a
property record, which can be used to distinguish between the retrieve and delete request.
Modify the POJO to add a new property rord and its getter and setters.
After modification, the Employee.java file appears as:
package com.hp.empinfo.domain;
public class Employee implements java.io.Serializable {
private int empid;;
private String firstname;
private String lastname;
private int age;
private String email;
private String rord;
public String getRord() {
return rord;
}
public void setRord(String rord) {
this.rord = rord;
}
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getFirstname() {
return firstname;
}
public void setFirstname (String firstname) {
this. firstname= firstname;
76Spring Framework
}
public String getLastname () {
return lastname;
}
public void setLastname (String lastname) {
this. lastname= lastname;
}
public int getAge () {
return age;
}
public void setAge (int age) {
this. age= age;
}
public String getEmail () {
return email;
}
public void setEmail (String email) {
this. email= email;
}
}
Modifying the EmployeeController.java File
The EmployeeController.java file in the com.hp.empinfo.web package is modified to
map the retrieve or delete request to the underlying database operations.
After modification, the EmployeeController.java file appears as:
Map<String, String> model = new HashMap<String, String>();
model
.put("add",
"Transaction Complete - One Employee Added to Employee Database");
return new ModelAndView("insertresult", "model", model);
}
}
}
Modifying the EmpInfo-servlet.xml File
Modify the EmpInfo-servlet.xml file in the EmpInfo/WebContent/WEB-INF directory to
map the command name and its corresponding command class for retrieveordelete.jsp.
After modification, the EmpInfo-servlet.xml file appears as:
public static String [] configFileNames = new String [] {"applicationContext.xml","clientContext.xml"};
private static ApplicationContext applicationContext = null;
public static void main(String[] args) {
applicationContext = new ClassPathXmlApplicationContext(configFileNames);
EmployeeInfo empInfo = (EmployeeInfo)applicationContext.getBean("rmiProxy");
Employee employee = empInfo.getEmployee(2);
System.out.println("Employee First Name : "+employee.getFirstname());
System.out.println("Employee Last Name : "+employee.getLastname());
System.out.println("Employee Email : "+employee.getEmail());
System.out.println("Employee Id : "+employee.getEmpid());
}
}
Creating the clientContext.xml file
1.Create the clientContext.xml file in the EmpInfo/WebContent/WEB-INF/ directory,
as described in “Creating the EmpInfo-servlet.xml File” (page 48).
2.Modify the clientContext.xml file to add the RMI client bean. After modification, the
clientContext.xml file must appear as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
1.Create the client.properties file in the EmpInfo/WebContent/WEB-INF/ directory,
as described in “Creating the jdbc.properties File” (page 66).
2.Modify the client.properties file to add the NonStop System IP address (where your
RMI service is running) and the RMI port number.
serverName= <HP NonStop System IP Address>
rmiPort=<port number>
Adding Dependency JARs
Add the following dependency jars to the EmpInfo project library:
82Spring Framework
Table 15 Aopalliance Dependency JAR Files
Dependency JAR Files
com.springsource.org.aopalliance-1.0.0.jar
NOTE:The jar file mentioned in the above table can be found in the following spring repository:
http://ebr.springsource.com/repository/app/.
To add the dependency JAR files in the project library path and to resolve the J2EE module
dependency on these JAR files, follow the instructions described in “Adding Dependency JAR Files
in the Project Library Path” (page 52).
Figure 22 shows how the EmpInfo application directory structure looks like after creating the
requisite files on the system.
Figure 22 Project Explorer View
The EmpInfo application is complete now. You can now deploy and verify the EmpInfo application
on a NonStop system, by following the steps described in “Deploying EmpInfo on NonStop”
(page 87).
NOTE:The complete code of the EmpInfo application is located in <My SASH
Home>\spring\getting-started\EmpInfo.
You can verify if the application is working by performing the following steps:
Getting Started with Spring83
To insert an employee record:
1.Start the iTP WebServer and access the index page:
http://<IP Address of the Webserver>>:<<port#>/<servlet directory>/EmpInfo.
Figure 23 EmpInfo: Insert, Retrieve or Delete Employee Details
2.Click Insert Employee. The Enter Employee Details screen appears.
3.Type the employee details and click Insert.
Figure 24 EmpInfo: Employee Details Screen
The Insert Operation Successfully Executed message is displayed.
84Spring Framework
Figure 25 EmpInfo: Message Screen
4.To retrieve or delete an employee record:
Click Retrieve or Delete in the index page.
Figure 26 EmpInfo: Retrieve Screen
5.To retrieve an employee record, in the Action to Perform field, type Retrieve. Click
Retrieve/Delete.
The employee record details are displayed.
Getting Started with Spring85
Figure 27 EmpInfo: Employee Details Screen
6.Click Back to return to the EmpInfo: Delete screen.
Figure 28 EmpInfo: Delete Screen
7.To delete an employee record, in the Action to Perform field, type Delete. Click
Retrieve/Delete.
The employee record is deleted.
86Spring Framework
Figure 29 EmpInfo: Deleted Screen
Deploying EmpInfo on NonStop
This section describes the following tasks:
1.“Creating the Application WAR File on Windows” (page 87)
2.“Deploying the EmpInfo WAR File in NSJSP on NonStop” (page 89)
Creating the Application WAR File on Windows
A WAR file is essential to deploy the web application. It contains property and configuration files,
Java class file, and JSPs of the web application.
To create the application WAR file:
1.In the Project Explorer frame, right-click EmpInfo and select Export > Export.
The Export dialog box appears.
2.From the list of folders, select Web > WAR file and click Next.
Getting Started with Spring87
Figure 30 Export Dialog Box
The WAR Export dialog box appears.
3.In the Web project field, type EmpInfo and browse to the destination where you want to save
the WAR file.
88Spring Framework
Figure 31 WAR Export Dialog Box
4.Click Finish. The WAR file is created.
NOTE:If you have specified an existing name for the WAR file, the Finish button is disabled.
In this case, change the name of the WAR file. If you want use the existing name, select the
Overwrite existing file check box.
Deploying the EmpInfo WAR File in NSJSP on NonStop
To deploy the EmpInfo WAR file on the NonStop system, see “Deploying Sample Applications on
NonStop” (page 331).
Running EmpInfo on NonStop
To run EmpInfo on the NonStop system, click the /<servlet directory>/EmpInfo path under
Applications in the NSJSP Web Application Manager screen.
You can now add, search, and delete employee details.
Getting Started with Spring89
3 Hibernate Framework
Hibernate Overview
Hibernate is an object-relational mapping (ORM) tool for Java environments that provides a
framework for mapping a data representation from an object model to a relational data model
with an SQL-based schema.
Hibernate provides configuration files to map Java classes with database tables, and to configure
database connectivity properties, such as the database URL, database credentials, connection
pooling configuration parameters, and so on. It also provides data query and retrieval facilities.
The NonStop system provides a platform comprising of JVM and a servlet container to run
applications that use Hibernate.
NOTE:Any mention of Hibernate in this document implies association with Hibernate versions
3.5.1, 3.6.8, and 4.1.1. The dialects are different for these versions. You must download the
required dialect and integrate it with the appropriate version of Hibernate as necessary. To get
the most recent features, HP recommends you to download the latest dialect and Hibernate versions.
For information on Hibernate, see http://www.hibernate.org.
Backward compatibility of the Hibernate dialect is not supported. For example, Hibernate 3.6.8
dialect is not compatible with Hibernate version 3.5.1.
Spring 3.X does not support HibernateTemplate when integrated with Hibernate 4.
Hibernate Projects
In addition to the Hibernate core framework, the JBoss community maintains other projects, such
as Hibernate EntityManager, Hibernate Annotations, Hibernate Shards, and so on. Among these
projects, only Hibernate EntityManager and Hibernate Annotations are presently certified for use
on the NonStop platform.
Hibernate Annotations
In Hibernate, the application metadata is commonly provided to the Java Virtual Machine (JVM)
through XML files. You can also use Annotations to provide the application metadata.
Annotations enable you to provide the metadata for the Object and Relational Table mapping by
including the metadata information in the Plain Old Java Objects (POJO) file along with the code.
This helps you to understand the table structure and POJO simultaneously during application
development. This also reduces the complexity of the application because you need not maintain
separate files for the metadata.
To leverage the above-mentioned features of Annotations in Hibernate, the Hibernate community
provides the Hibernate Annotations package.
•Hibernate-specific extension annotations for performance optimization and special mappings
NOTE:The Annotation feature is supported on Java 5.0 and later versions.
Hibernate EntityManager
Java EE provides EJB3 specifications to standardize the basic APIs and the metadata required for
any object/relational persistence mechanism. The Hibernate community provides the Hibernate
EntityManager project, which implements the programming interfaces and lifecycle rules as defined
by the EJB3 persistence specifications.
90Hibernate Framework
The Hibernate EntityManager implements the following:
•Standard Java Persistence management API
•Standard Java Persistence Query Language
•Standard Java Persistence object lifecycle rules
•Standard Java Persistence configuration and packaging
You can implement a complete EJB3 persistence solution using Hibernate Annotations and the
Hibernate EntityManager with the Hibernate package.
NOTE:The EJB3 specification is supported on Java 5.0 and above versions.
Hibernate Applications on NonStop
Hibernate can be used in a standalone Java application or in a Java web application using servlets
or EJB session beans.
This section describes the message flow when Hibernate is used in a Java web application that
uses the NonStop SQL/MX database and is hosted on NSJSP.
Figure 32 Hibernate Application on NonStop
A Hibernate message flows through all the components in the following sequence:
1.An HTTP request passes through the iTP WebServer and then to the NSJSP web container.
2.The Servlet application, which is deployed under the NSJSP web container, processes the
HTTP request and passes it to the Application layer.
Hibernate Overview91
3.The Application layer passes the request to the persistence layer (that is, Hibernate). Hibernate
establishes connection with the database, performs database operations (such as create,
update, retrieve, and delete), and then returns persistent object to the application.
NOTE:Persistent objects are the Java classes, which are mapped with database tables.
Installing the Hibernate Framework
This section describes the procedure to install Hibernate framework libraries on a Nonstop system.
Prerequisites
Before getting started, ensure that you have the following software installed on the NonStop and
Windows system:
NonStop system
Table 16 Softwares to be installed on the NonStop system
For more information:Software
NSJ version 6.0
For information on installing NSJ on a NonStop system, see the NonStop Serverfor Java 6.0 Programmer's Reference Manual.
Windows system
Table 17 Softwares to be installed on the Windows system
DownloadSoftware
JDK version 1.6
Gradle
1.0-milestone-8a
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html and
set the PATH and JAVA_HOME environment variables.
Download from http://gradle.org/downloads and set the PATH and GRADLE_HOME environment
variables.
Installing Hibernate Framework Libraries on NonStop
1.“Downloading the Hibernate Distribution on Windows” (page 93)
2.“Downloading Hibernate Dependency JAR Files using Gradle” (page 93)
3.“Including the Hibernate Dialect for the SQL/MX database” (page 93)
4.“Copying the Hibernate Distribution from Windows to NonStop” (page 94)
NOTE:
•Before you start installing the Hibernate framework, extract the contents of the SAMPLES.zip
file (containing OpenSource Java frameworks for NonStop) to a directory on the Windows
system.
•Throughout the section, references are made to the following directories:
◦<Hibernate Home>: The directory on the Windows system where the Hibernate
distribution files are extracted.
◦<NonStop Hibernate Home>: The OSS directory on the NonStop system where the
Hibernate runtime JAR files are located.
◦<My SASH Home>: The directory on the Windows system where the contents of the
SAMPLES.zip file (distributed as a part of the NonStop Samples for Java frameworks T0874 and available for download in Scout) is extracted.
92Hibernate Framework
Downloading the Hibernate Distribution on Windows
NOTE:The Hibernate distribution described here is for Hibernate version 4.1.1.
1.Go to http://www.hibernate.org/downloads.html.
2.Click on the release bundles hyperlink under Release bundle section.
A web page from sourceforge.net,showing various Hibernate packages that can be
downloaded, appears.
3.Click hibernate4, and then click on 4.1.1.Final.
The links to the following files appear:
•hibernate-release-4.1.1.Final.zip
•hibernate-release-4.1.1.Final.tgz
4.Download the hibernate-release-4.1.1.Final.zip file.
NOTE:
•The hibernate-release-4.1.1.Final.zip and
hibernate-release-4.1.1.Final.tgz files include the Hibernate sample
application, the Hibernate framework libraries, Hibernate Annotations, and Hibernate
Entity Manager sub-projects. They do not include third party libraries that are required
to build the sample application.
•The difference between hibernate-release-4.1.1.Final.zip and
hibernate-release-4.1.1.Final.tgz files is in their compression format.
•The sample applications, namely Caveat Emptor and Event Manager web application,
discussed in this section have been verified using Hibernate version 3.5.1.
5.Extract the hibernate-release-4.1.1.Final.zip file into a directory on the Windows
system.
This directory will be the <Hibernate Home>.
Downloading Hibernate Dependency JAR Files using Gradle
Because Hibernate 4.1.1 dependency JARs are placed in the Maven repository, you must download
the dependency JAR files using Gradle.
NOTE:If you are downloading the Hibernate 3.5.1 or 3.6.8 dependency JARs, you must
download using Maven.
1.Go to the <Hibernate Home>\project directory on the Windows system.
2.Run the following command to build the Hibernate framework and create the Hibernate
dependency JARs:
command prompt> gradle clean build -x test
The Hibernate framework, Hibernate sub-projects, and dependency JAR files are downloaded
to C:\Documents and Settings\<User name
>\.gradle\caches\artifacts-8\filestore
where,
<User name> is the name of the user account being used on the Windows system.
Including the Hibernate Dialect for the SQL/MX database
The Hibernate dialect for the SQL/MX database is required for running any Hibernate application
on a NonStop system.
Installing the Hibernate Framework93
The DIALECT file (which includes hibernate4sqlmx.jar) is distributed as a part of the SQL/MX
Hibernate Dialect - T0873AAD and can be downloaded from Scout.
To obtain the hibernate4sqlmx.jar file, complete the following steps:
1.Download the DIALECT file from Scout. For information on how to download from Scout, see
3.Copy the hibernate_lib.jar and hibernate4.jar files from <Hibernate Home>
to <NonStop Hibernate Home> and extract hibernate_lib.jar:
OSS> cd <NonStop Hibernate Home>
OSS> jar -xvf hibernate_lib.jar
After extraction, <NonStop Hibernate Home> must include the <NonStop Hibernate
Home>/lib sub-directory.
NOTE:The contents of the <NonStop Hibernate Home>/lib directory on the NonStop
system must be exactly same as the <Hibernate Home>\lib directory on the Windows
system.
4.Go to C:\Documents and Settings\<User name> and create a JAR file of the <User
name>\.gradle directory on the Windows system:
command prompt> cd C:\Documents and Settings\<User name>
command prompt> jar -cvf hibernate_Dependency.jar .gradle
For example:
command prompt> cd C:\Documents and Settings\hpadmin
command prompt> jar -cvf hibernate_Dependency.jar .gradle
94Hibernate Framework
5.Transfer the hibernate_Dependency.jar files from C:\Documents and
Settings\<User name> to the OSS root directory.
6.Extract hibernate_Dependency.jar:
OSS> cd <OSS root directory>
OSS> jar -xvf hibernate_Dependency.jar
The Hibernate framework libraries are installed on the NonStop system. You can use these libraries
to develop and run Hibernate applications on a NonStop system.
Customizing the Hibernate Dialect for NonStop
The Hibernate dialect is customized for NonStop to support new features of Hibernate version
4.1.1. These features are supported by making changes to the Hibernate dialect. This section
describes the changes made to the Hibernate dialect for SQL/MX database. The dialect is the
basic component, which Hibernate uses for query generation and execution process for a specific
database. The basic dialect file developed for NonStop users is used.
Hibernate now supports the following features:
•IDENTITY column
•Error Mapping
IDENTITY Column
Hibernate can leverage the IDENTITY column provided by SQL/MX database. To leverage the
column, in Hibernate, the mapped classes must declare the primary key column of the database
table. Most classes also have a JavaBeans-style property holding the unique identifier of an instance.
The <id> element defines the mapping from that property to the primary key column. You can
declare the mapping as follows:
•name: Name of the identifier property. This attribute is optional.
•type: A name that indicates the Hibernate type. This attribute is optional.
•column: Name of the primary key column. This attribute is optional and defaults to the property
name.
•unsaved-value: An identifier property value that indicates an instance is newly instantiated
(unsaved), distinguishing it from detached instances that were saved or loaded in a previous
session. This attribute is optional and defaults to a sensible value.
•access: The strategy Hibernate should use for accessing the property value. This attribute is
optional and defaults to property.
The optional <generator> child element defines a Java class used to generate unique identifiers
for instances of the persistent class. If any parameters are required to configure or initialize the
generator instance, they are passed using the <param> element.
Installing the Hibernate Framework95
All generators implement the interface org.hibernate.id.IdentifierGenerator. Some
applications may have their own specialized implementations; however, Hibernate provides a
range of built-in implementations, such as increment, identity, sequence, hilo, Seqhilo, uuid, guid,
native, assigned, select, foreign, and sequence-identity. You can use any of the built-in
implementations except sequence, guid, native, and sequence-identity.
CAUTION:When using any of the Hibernate built-in generators (not dependent on underlying
database), use your judgment to select the correct id generator, since the built-in generators are
not yet certified to generate unique value in all circumstances on NonStop TSMP environment.
You can choose any of the ID generators that leverage the ID generation mechanism provided by
the underlying database.
NOTE:
•IDENTITY column feature is supported from SQL/MX 3.1 version onwards.
•SQL/MX does not support SEQUENCE generators and GUIDs.
In general, hibernate allows mapping of Plain Old Java Objects (POJO) to tables and its attributes
to columns in an xml file. This file also captures the mapping between POJO fields to table column.
When you define this mapping, you can specify a generator class when a column is of type
IDENTITY.
When you define the mapping between the SQL table and POJO in the hbm.xml file, you can
specify a generator for the id column as follows:
When the generator class is specified as identity, Hibernate will invoke the dialect methods internally
and treats the mapped table column to person_id field in the POJO as an IDENTITY column.
When the generator class is specified as
org.hibernate.dialect.SqlMxIdentityGenerator, the dialect returns an appropriate
error when it is used with an SQL/MX version that does not support IDENTITY column. It has a
built-in mechanism to detect the SQL/MX version.
NOTE:The org.hibernate.dialect.SqlMxIdentityGenerator generator class supports
only the update operation and not the create operation.
The following use cases show the typical errors that may be returned when this mapping is not
specified.
Use case 1
When a table does not contain identity columns and the hibernate mapping contains the generator
class as “identity” or "org.hibernate.dialect.SqlMxIdentityGenerator “, then the dialect returns the
following errors that are captured in the log:
org.hibernate.exception.GenericJDBCException: could not insert:
Caused by: com.tandem.t4jdbc.SQLMXException: *** ERROR[4024] Column ID has no default
value, so it must be explicitly specified in the insert column list.
Use case 2
96Hibernate Framework
When the SQL/MX table contains the identity column and the mapping does not specify the
generator class as “identity or "org.hibernate.dialect.SqlMxIdentityGenerator “, then the dialect
returns the following errors which are captured in the log:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert:
Caused by: com.tandem.t4jdbc.SQLMXException: *** ERROR[3428] IDENTITY column ID defined
as GENERATED ALWAYS cannot accept values specified by the user.
Error Mapping
Sometimes when errors occur in Hibernate, the exceptions (such as database connection errors,
SQL errors, etc.) are displayed with error codes which are not very user-friendly in nature. The
HibernateException, which wraps most of the errors that can occur in a Hibernate persistence
layer, is an unchecked exception. Hibernate wraps these SQLExceptions thrown while interacting
with the database in a JDBCException. It attempts to convert the exception into a more meaningful
subclass of JDBCException. For this purpose, custom error mapping is required as it helps in building
recovery mechanisms for custom SQL/MX errors in a standard way.
To achieve error mapping, a new class, SqlMxSQLStateConverter, has been added to the dialect
package to implement error mapping. This class is available by default when the dialect is installed.
SqlMxSQLStateConverter class uses the SqlErrorCodesMapping.properties property file.
This file can be made available to the class in the following methods:
•By placing the SqlErrorCodesMapping.properties file in the application class path.
•By defining a java property sqlmxhibernate.er-map with a value. This value is the path
to the SqlErrorCodesMapping.properties file. You can make this property available
to the application by passing it as a Java application argument line
NOTE:If the SqlErrorCodesMapping.properties file is not loaded, the following message
is logged into the hibernate log:
“SqlErrorCodesMapping.properties (The system cannot find the file specified)”
The error messages are categorized based on the type of error and each group is assigned to an
exception. Hibernate uses the SQLExceptionConverter to convert an SQLException into an
appropriate JDBCException subclass, provided SQLMXDialect provides a SQLExceptionConverter
implementation so that based on SQL/MX error codes appropriate JDBCException subtype can
be created.
The following exception types are handled:
•JDBCConnectionException: indicates an error with the JDBC communication.
•SQLGrammarException: indicates a grammatical error or a syntax problem with the issued
•LockAcquisitionException: indicates an error acquiring a lock level necessary to
perform the requested operation.
For example, all SQL grammatical or syntax related error messages are categorized under a
subclass and are mapped to the SQLGrammarException.
The following is a simple hibernate code that queries address table and gets the data in a List. The
method list() on the query object queries the underlying database and returns the result as a List
object.
Currently, without SQLExceptionConverter you must catch HibernateException (which is an
unchecked exception) as follows.
Configuration cfg = new Configuration().configure();
SessionFactory sf = cfg.buildSessionFactory();
// Customers must get the corresponding SQL Exception using getCause().
If they want to build recovery mechanism, then the Customer must have
SQLMX specific error codes compared with error code in the SQLException
object embedded in HibernateException which will make the hibernate code
SQLMX specific.
}
When the converter is implemented then,
try {
List s2 = q.list();
}
catch (JDBCConnectionException e)
{
//Connection specific recovery code.
//May be a Connection retry
}
catch (ConstraintViolationException e)
{
//Constraints specific recovery
}
catch (GenericJDBCException e)
{
Setting up Sample Hibernate Applications on NonStop
The sample applications (Caveat Emptor and the Event Manager Web Application) are included
in the SAMPLES.zip file in the Hibernate distribution, and require modifications to make them
compatible with NonStop systems.
98Hibernate Framework
NOTE:The SAMPLES.zip file is distributed as a part of the NonStop Samples for Java frameworks
- T0874.
SAMPLES.zip is present in the T0874AAB.BIN file in Scout. For information on how to install
the T0874AAB.BIN file from Scout, see https://h20453.www2.hp.com/scout/download_help.htm.
Before you deploy the sample applications, complete the following steps:
1.Download the SAMPLES file from Scout.
2.Add the .zip extension to it.
3.Extract the SAMPLES.zip file to a location on the Windows system.
This section describes the steps required to build, set up, deploy, and run the Caveat Emptor and
Event Manager sample applications on NonStop systems.
NOTE:The sample applications, namely Caveat Emptor and Event Manager web application,
discussed in this section have been verified using Hibernate version 3.5.1.
Prerequisites
The file is renamed as SAMPLES.zip.
The NS-Samples-for-Java-Frameworks folder appears.
NOTE:The absolute path of the NS-Samples-for-Java-Frameworks folder is referred
as <My SASH Home>.
•For NonStop system:
Table 18 Softwares to be installed on the NonStop system
For more information:Software
NonStop iTP WebServer version
7.x or later
NSJSP version 6.1
NonStop SQL/MX version 2.3
JDBC Type 2 driver or JDBC Type
4 driver for the installed SQL/MX
version
NSJ version 5.0
For information on installing and setting up iTP WebServer (secure and
non-secure) on a NonStop system, see the iTP Secure WebServer SystemAdministrator's Guide.
For information on installing and setting up NSJSP on a NonStop system, see
the NonStop Servlets for JavaServer Pages (NSJSP) 6.1 System Administrator'sGuide.
For information on installing SQL/MX on a NonStop system, see the SQL/MXInstallation and Upgrade Guide.
For information on installing JDBC Type 2 driver and JDBC Type 4 driver on
a NonStop system, see JDBC Type 2 Driver Programmer's Reference forSQL/MX and JDBC Type 4 Driver Programmer's Reference for SQL/MX.
For information on installing NSJ on a NonStop system, see the NonStopServer for Java 5.0 Programmer's Reference.
•For Windows system:
Table 19 Softwares to be installed on the Windows system
DownloadSoftware
JDK version 1.5
Maven version
2.2.1
JDBC Type 4 driver
Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html
and set the PATH and JAVA_HOME environment variables.
Download from http://maven.apache.org/download.html and set the PATH andMAVEN_HOME environment variables.
For information on installing JDBC Type 4 driver on a Windows system, see JDBC Type 4Driver Programmer's Reference for SQL/MX.
Installing the Hibernate Framework99
Caveat Emptor
The Caveat Emptor sample application is an auction system. The intended users of the application
are bidders and the sellers of various items.
NOTE:The Caveat Emptor sample application described here uses Hibernate 3.5.1 version.
To use Caveat Emptor, the following steps are involved:
•“Building Caveat Emptor on Windows” (page 100)
•“Setting up the Deployment Environment on NonStop” (page 101)
•“Deploying Caveat Emptor on NonStop” (page 103)
•“Running Caveat Emptor on NonStop” (page 103)
Building Caveat Emptor on Windows
1.Go to the <My SASH Home>\hibernate\samples\eg directory on the Windows system.
2.Configure the JDBC driver settings for the NonStop SQL/MX database.
a.Go to the <My SASH HOME>\hibernate\samples\eg\src\main\resources\
b.Modify the hibernate.properties file to update the JDBC configuration. You can
directory on the Windows system.
use either the JDBC Type 2 driver or the JDBC Type 4 driver by setting the SQL/MX
settings as follows:
•For JDBC Type 2 driver, uncomment the SQL/MX settings for the JDBC Type 2 driver
so that it appears as:
#-----------------------------------------------------------------------------# SQL/MX Settings for JDBC Type 2 Driver
hibernate.dialect org.hibernate.dialect.SqlmxDialect
hibernate.connection.driver_class com.tandem.sqlmx.SQLMXDriver
hibernate.connection.url jdbc:sqlmx://
hibernate.connection.username
hibernate.connection.password
hibernate.connection.catalog auctioncat
hibernate.connection.schema auctionsch
NOTE:Because JDBC Type 2 driver is located on the NonStop system, you need
not mention the username and password in the
hibernate.connection.username and the
hibernate.connection.password fields.
•For JDBC Type 4 driver, uncomment the SQL/MX settings for the JDBC Type 4 driver,
and enter the values for the JDBC URL (NonStop system IP Address and port number
of the JDBC data source), NonStop system username, and password so that it appears
as:
#------------------------------------------------------------------------------# SQL/MX Settings for JDBC Type 4 Driver
hibernate.dialect=org.hibernate.dialect.SqlmxDialect
hibernate.connection.driver_class com.tandem.t4jdbc.SQLMXDriver
hibernate.connection.url jdbc:t4sqlmx://<HP NonStop System IP Address>:<Port No.>
hibernate.connection.username <HP NonStop Username>
hibernate.connection.password <HP NonStop Password>
hibernate.connection.catalog auctioncat
hibernate.connection.schema auctionsch
100 Hibernate Framework
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.