null  User manual
Integrating with Other Products
Sybase® PowerDesigner®
12.5
Windows
Part number: DC00405-01-1250-01
Last modified: April 2007
Copyright © 1991-2007 Sybase, Inc. and its subsidiaries. All rights reserved.
Information in this manual may change without notice and does not represent a commitment on the part of Sybase, Inc. and its subsidiaries.
Sybase, Inc. provides the software described in this manual under a Sybase License Agreement. The software may be used only in accordance with
the terms of the agreement.
No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical, manual, optical, or
otherwise, without the prior written permission of Sybase, Inc. and its subsidiaries.
Use, duplication, or disclosure by the government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of DFARS 52.227-7013 for the
DOD and as set forth in FAR 52.227-19(a)-(d) for civilian agencies.
Sybase, SYBASE (logo), ADA Workbench, Adaptable Windowing Environment, Adaptive Component Architecture, Adaptive Server, Adaptive
Server Anywhere, Adaptive Server Enterprise, Adaptive Server Enterprise Monitor, Adaptive Server Enterprise Replication, Adaptive Server
Everywhere, Advantage Database Server, Afaria, Answers Anywhere, AppModeler, APT Workbench, APT-Build, APT-Edit, APT-Execute,
APT-Translator, APT-Library, ASEP, Avaki, Avaki (Arrow Design), Avaki Data Grid, AvantGo, Backup Server, BayCam, Bit-Wise, BizTracker,
Certified PowerBuilder Developer, Certified SYBASE Professional, Certified SYBASE Professional Logo, ClearConnect, Client-Library, Client
Services, CodeBank, Column Design, ComponentPack, Connection Manager, Convoy/DM, Copernicus, CSP, Data Pipeline, Data Workbench,
DataArchitect, Database Analyzer, DataExpress, DataServer, DataWindow, DataWindow .NET, DB-Library, dbQueue, Dejima, Dejima Direct,
Developers Workbench, DirectConnect Anywhere, DirectConnect, Distribution Director, Dynamic Mobility Model, e-ADK, E-Anywhere, e-Biz
Integrator, E-Whatever, EC Gateway, ECMAP, ECRTP, eFulfillment Accelerator, EII Plus, Electronic Case Management, Embedded SQL, EMS,
Enterprise Application Studio, Enterprise Client/Server, Enterprise Connect, Enterprise Data Studio, Enterprise Manager, Enterprise Portal (logo),
Enterprise SQL Server Manager, Enterprise Work Architecture, Enterprise Work Designer, Enterprise Work Modeler, eProcurement Accelerator,
eremote, Everything Works Better When Everything Works Together, EWA, ExtendedAssist, Extended Systems, ExtendedView, Financial Fusion,
Financial Fusion (and design), Financial Fusion Server, Formula One, Fusion Powered e-Finance, Fusion Powered Financial Destinations, Fusion
Powered STP, Gateway Manager, GeoPoint, GlobalFIX, iAnywhere, iAnywhere Solutions, ImpactNow, Industry Warehouse Studio, InfoMaker,
Information Anywhere, Information Everywhere, InformationConnect, InphoMatch, InstaHelp, Intelligent Self-Care, InternetBuilder, iremote,
iScript, Jaguar CTS, jConnect for JDBC, KnowledgeBase, Logical Memory Manager, lrLite, M2M Anywhere, Mach Desktop, Mail Anywhere
Studio, Mainframe Connect, Maintenance Express, Manage Anywhere Studio, MAP, M-Business Anywhere, M-Business Channel, M-Business
Network, M-Business Suite, MDI Access Server, MDI Database Gateway, media.splash, Message Anywhere Server, MetaWorks, MethodSet,
mFolio, Mirror Activator, ML Query, MobiCATS, Mobil 365, Mobileway, MySupport, Net-Gateway, Net-Library, New Era of Networks, Next
Generation Learning, Next Generation Learning Studio, O DEVICE, OASiS, OASiS logo, ObjectConnect, ObjectCycle, OmniConnect, OmniQ,
OmniSQL Access Module, OmniSQL Toolkit, OneBridge, Open Biz, Open Business Interchange, Open Client, Open ClientConnect, Open
Client/Server, Open Client/Server Interfaces, Open Gateway, Open Server, Open ServerConnect, Open Solutions, Optima++, Partnerships that
Work, PB-Gen, PC APT Execute, PC DB-Net, PC Net Library, Pharma Anywhere, PhysicalArchitect, Pocket PowerBuilder, PocketBuilder,
Power++, Power Through Knowledge, power.stop, PowerAMC, PowerBuilder, PowerBuilder Foundation Class Library, PowerDesigner,
PowerDimensions, PowerDynamo, Powering the New Economy, PowerScript, PowerSite, PowerSocket, Powersoft, PowerStage, PowerStudio,
PowerTips, Powersoft Portfolio, Powersoft Professional, PowerWare Desktop, PowerWare Enterprise, ProcessAnalyst, Pylon, Pylon Anywhere,
Pylon Application Server, Pylon Conduit, Pylon PIM Server, Pylon Pro, QAnywhere, Rapport, Relational Beans, RepConnector, Report Workbench,
Report-Execute, Replication Agent, Replication Driver, Replication Server, Replication Server Manager, Replication Toolkit, Resource Manager,
RFID Anywhere, RW-DisplayLib, RW-Library, SAFE, SAFE/PRO, Sales Anywhere, Search Anywhere, SDF, Search Anywhere, Secure SQL
Server, Secure SQL Toolset, Security Guardian, ShareSpool, Sharelink SKILS, smart.partners, smart.parts, smart.script, SOA Anywhere
Trademark,SQL Advantage, SQL Anywhere, SQL Anywhere Studio, SQL Code Checker, SQL Debug, SQL Edit, SQL Edit/TPU, SQL
Everywhere, SQL Modeler, SQL Remote, SQL Server, SQL Server Manager, SQL SMART, SQL Toolset, SQL Server/CFT, SQL Server/DBM,
SQL Server SNMP SubAgent, SQL Station, SQLJ, Stage III Engineering, Startup.Com, STEP, SupportNow, S.W.I.F.T. Message Format Libraries,
Sybase 365, Sybase Central, Sybase Client/Server Interfaces, Sybase Development Framework, Sybase Financial Server, Sybase Gateways, Sybase
IQ, Sybase Learning Connection, Sybase MPP, SyberLearning LIVE, Sybase SQL Desktop, Sybase SQL Lifecycle, Sybase SQL Workgroup,
Sybase Synergy Program, Sybase Virtual Server Architecture, Sybase User Workbench, SybaseWare, Syber Financial, SyberAssist, SybFlex,
SybMD, SyBooks, System 10, System 11, System XI (logo), SystemTools, Tabular Data Stream, The Enterprise Client/Server Company, The
Extensible Software Platform, The Future Is Wide Open, The Learning Connection, The Model For Client/Server Solutions, The Online Information
Center, The Power of One, TotalFix, TradeForce, Transact-SQL, Translation Toolkit, Turning Imagination Into Reality, UltraLite, UltraLite.NET,
UNIBOM, Unilib, Uninull, Unisep, Unistring, URK Runtime Kit for UniCode, Unwired Accelerator, Unwired Orchestrator,Viafone, Viewer,
VisualWriter, VQL, WarehouseArchitect, Warehouse Control Center, Warehouse Studio, Warehouse WORKS, Watcom, Watcom SQL, Watcom
SQL Server, Web Deployment Kit, Web.PB, Web.SQL, WebSights, WebViewer, WorkGroup SQL Server, XA-Library, XA-Server, XcelleNet, XP
Server, XTNDConnect, and XTNDACCESS are trademarks of Sybase, Inc. or its subsidiaries.
All other trademarks are the property of their respective owners.
ii
Contents
About This Manual
v
1 Working with Apache Ant
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ant Build Script Generation . . . . . . . . . . . . . . . . . . .
Building, Packaging, and Deploying the Application Using Ant
1
2
4
9
2 Creating Borland JBuilder Project Files
Introduction . . . . . . . . . . . . . . . . . . . . . . . .
JBuilder Project File Generation . . . . . . . . . . . .
Verifying The JBuilder Files . . . . . . . . . . . . . . .
Generating Java Code and the JBuilder Project File .
Building and Deploying the Application Using JBuilder
.
.
.
.
.
.
.
.
.
.
3 Creating J2EE Applications for Sybase EAServer
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating EJBs . . . . . . . . . . . . . . . . . . . . . . . .
Adding EAServer Support . . . . . . . . . . . . . . . . . .
Customizing O/R mapping . . . . . . . . . . . . . . . . . .
Defining Extended Attributes . . . . . . . . . . . . . . . .
Verifying the EAServer Configuration Descriptor . . . . .
Generating and Deploying EJBs, Servlets and JSPs
EAServer . . . . . . . . . . . . . . . . . . . . . . . .
Creating Web Services for EAServer . . . . . . . . . . . .
Customizing EAServer Support . . . . . . . . . . . . . . .
4 Deploying Web Applications in Apache Tomcat
Introduction . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Web Application . . . . . . . . . . . . . . . .
Generating the Ant Build Script . . . . . . . . . . . . . .
Building, Packaging and Deploying the Web Application
ing Ant . . . . . . . . . . . . . . . . . . . . . . . . .
Running the Web Application . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
. .
. .
. .
. .
. .
. .
in
. .
. .
. .
. . .
. . .
. . .
Us. . .
. . .
5 Creating J2EE Applications for BEA WebLogic
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Enterprise Java Beans . . . . . . . . . . . . . . .
Adding WebLogic Server Support . . . . . . . . . . . . . .
Parameterizing WebLogic EJB Container in PowerDesigner
.
.
.
.
13
14
16
20
21
23
29
30
33
37
39
44
47
51
61
67
69
70
71
74
77
78
79
80
83
87
89
iii
Configuring WebLogic Persistence Services in PowerDesigner 94
Generating and Deploying EJBs in WebLogic server . . . . . 100
Extended Attributes for WebLogic Server . . . . . . . . . . . 104
6 Creating J2EE Applications for IBM WebSphere 5.0
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating EJBs . . . . . . . . . . . . . . . . . . . . . . . . .
Adding WebSphere 5.0 Support . . . . . . . . . . . . . . .
Customizing the O/R Mapping . . . . . . . . . . . . . . . .
Customizing WebSphere Application Server Generation . .
Customizing WebSphere Application Developer Generation
Verifying WebSphere Descriptors . . . . . . . . . . . . . . .
Generating WebSphere Application Developer Projects . .
Building and Deploying J2EE Applications Without WSAD .
Customizing WebSphere Support . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
117
118
121
125
128
130
135
137
139
144
147
7 O/R Mapping Modeling
Overview . . . . . . . . . . . .
Applying Top-Down Approach .
Applying Bottom-Up Approach
Meet in the Middle . . . . . . .
.
.
.
.
149
150
151
169
172
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8 Generating Persistent Objects for Java and JSF Pages
193
Generating Hibernate Persistent Objects . . . . . . . . . . . . 194
Generating EJB 3 Persistent Objects . . . . . . . . . . . . . . 219
Generating JavaServer Faces (JSF) for Hibernate . . . . . . 241
9 Generating JDO Persistent Objects
Introduction . . . . . . . . . . . . . . . . . . . . . . . . .
Creating JDO Persistent Objects . . . . . . . . . . . . .
Generating Java Code and JDO Persistence Descriptor
Compiling Java Code and Running the JDO Enhancer .
.
.
.
.
.
.
.
.
.
.
.
.
259
260
263
272
275
10 Generating .NET 2.0 Persistent Objects and Windows Applications
281
Introducing the .NET and .NET CF Frameworks . . . . . . . . 282
Generating ADO.NET and ADO.NET CF Persistent Objects . 285
Generating NHibernate Persistent Objects . . . . . . . . . . . 295
Configuring Connection Strings . . . . . . . . . . . . . . . . . 314
Generating Unit Tests . . . . . . . . . . . . . . . . . . . . . . 317
Generating Windows or Smart Device Applications . . . . . . 323
Index
iv
329
About This Manual
Subject
This book describes how to integrate PowerDesigner into your workflow
with various other tools and servers.
Audience
This book is for anyone who will be using PowerDesigner to model an
application that will be build using a tool such as Ant, or that will be
deployed in a server environment such as EAServer.
Documentation primer
The PowerDesigner modeling environment supports several types of models:
♦ Conceptual Data Model (CDM) to model the overall logical structure of
a database, independent from any software or data storage structure
considerations. A valid CDM can be converted to a PDM or an OOM
♦ Physical Data Model (PDM) to model the overall physical structure of a
database, taking into account DBMS software or data storage structure
considerations. A valid PDM can be converted to a CDM or an OOM
♦ Object Oriented Model (OOM) to model a software system using an
object-oriented approach for Java or other object languages. A valid
OOM can be converted to a CDM or a PDM
♦ Business Process Model (BPM) to model the means by which one or
more processes are accomplished in operating business practices
♦ XML Model (XSM) to model the structure of an XML file using a DTD
or an XML schema
♦ Requirements Model (RQM) to list and document the customer needs
that must be satisfied during a development process
♦ Information Liquidity Model (ILM) to model the replication of
information from a source database to one or several remote databases
using replication engines
♦ Free Model (FRM) to create any kind of chart, diagram, in a
context-free environment
v
This book only explains how to integrate PowerDesigner with other
products. For information on specific models or other aspects of
PowerDesigner, consult the following books:
To get familiar with the PowerDesigner interface
before learning how to use any of the models.
General Features Guide
To build a CDM.
Conceptual Data Model User’s Guide
Physical Data Model User’s Guide
To build a PDM.
Object Oriented Model User’s Guide
To build an OOM.
Business Process Model User’s Guide
To build a BPM.
Information Liquidity Model User’s Guide
Requirements Model User’s Guide
XML Model User’s Guide
Reports User’s Guide
To work with an ILM.
To work with an RQM.
To work with an XSM.
To create reports for any or all models.
Repository User’s Guide
To work in a multi-user environment using a
central repository.
Typographic conventions
PowerDesigner documentation uses specific typefaces to help you readily
identify specific items:
♦ monospace text (normal and bold)
Used for: Code samples, commands, compiled functions and files,
references to variables.
Example: declare user_defined..., the BeforeInsertTrigger
template.
♦ bold text
Any new term.
Example: A shortcut has a target object.
♦
SMALL CAPS
Any key name. Example: Press the ENTER key.
vi
CHAPTER 1
Working with Apache Ant
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with
Apache Ant.
Topic:
page
Introduction
2
Ant Build Script Generation
4
Building, Packaging, and Deploying the Application Using Ant
9
1
Introduction
Introduction
PowerDesigner supports many features for J2EE applications like
Object/Relational mapping (O/R mapping), generation of Web Service
artifacts, Enterprise JavaBeanTM (EJBTM), Servlets and JSPs, and can
compile and deploy them directly for you.
However, developers may need to write code in their favorite Java IDE or
text editor, then compile, deploy and test using a build utility like Apache
Ant.
PowerDesigner can generate an Ant build script file in addition to the Java
code, thus allowing you to edit the code using any editor, and to compile,
package and deploy it using the Ant command line.
This chapter explains how to use PowerDesigner to generate an Ant build
script.
Configuration
To follow this chapter, you will need:
♦ Apache Ant 1.5 or higher
♦ J2EE 1.3 (JDK Standard Edition and Enterprise Edition 1.3.1.01) or
higher
PowerDesigner
PowerDesigner supports object modeling, data modeling, business process
modeling, and UML.
For Java development, PowerDesigner allows you to:
♦ Create Web Service, EJB, Servlet and JSP components and generate code
for them
♦ Reverse engineer Java source and binary code
♦ Edit the Java code inside PowerDesigner or using an external editor
♦ Synchronize the model with the Java code
♦ Generate additional files
♦ Compile Java code
♦ Deploy J2EE application into an application server
2
Chapter 1. Working with Apache Ant
The PowerDesigner profile allows you to customize the code generator or
add your own code generators, such as Ant.
Apache Ant
Apache Ant is a Java based open source build utility developed by The
Apache Software Foundation (http://www.apache.org).
Ant is widely used by Java developers. Many Java IDEs use Ant to support
custom build tasks.
You can download Ant from http://jakarta.apache.org/ant/index.html .
Round-Trip Engineering Process for Java Development
By combining PowerDesigner and Ant, you have the following capabilities
for round-trip engineering for Java development:
♦ Do high level analysis and design using PowerDesigner
♦ Design and create Java components in PowerDesigner
♦ Generate Java code and the Ant build script
♦ Finish the implementation of Java classes using a Java IDE or text editor
♦ Compile, package and deploy using Ant
♦ Reverse engineer the final Java code to synchronize the PowerDesigner
model
3
Ant Build Script Generation
Ant Build Script Generation
The Ant build script is an XML file. The default file name is build.xml.
PowerDesigner can generates a build.xml file containing the following
structure:
♦ Common properties - define the properties used for a standard J2EE
application
♦ Server specific properties - define the properties used for a specific
application server
♦ Common tasks - define the tasks used for a standard J2EE application
♦ Server specific tasks - define the tasks used for a specific application
server
♦ Common targets - define the targets used for a standard J2EE application
♦ Server specific targets - define the targets used for a specific application
server
In each server specific Extended Model Definition (XEM), you can define
server specific properties, tasks, and targets for Ant. The following servers
are supported:
♦ BEA WebLogic 6 and higher
♦ IBM WebSphere 5
♦ Sybase EAServer 4 and higher
♦ Apache Tomcat 4 and higher
Enabling Ant Build Script Generation
To generate an Ant build script, you need to create an Object-Oriented
Model (OOM) for the Java object language, and enable the Ant build script
generation (which is, by default, disabled).
v To enable Ant build script generation
1. Select Language ä Generate Java Code.
2. Click on the Options tab.
4
Chapter 1. Working with Apache Ant
3. Set the value of the option “ANT: Generate Ant build.xml file” to true:
4. Click Apply to save the settings.
5. Click Cancel to close the window.
Selecting a Target Application Server
PowerDesigner can generate EJBs, servlets, JSPs and application server
specific descriptors.
In the Ant build script, PowerDesigner can generate server specific
properties, tasks and targets to package and deploy the applications in any of
the following target application servers:
♦ BEA WebLogic 6 and higher
♦ IBM WebSphere 5
♦ Sybase EAServer 4 and higher
♦ Apache Tomcat 4 and higher
v To add the support of an application server
1. Select Model ä Extended Model Definitions.
2. Click on the Import tool in the List of Extended Model Definitions.
3. Click on the Application Server tab:
5
Ant Build Script Generation
4. Select the application server you want to use
5. Click OK. The extended model definition is imported into the current
model.
For more information about how to create EJBs for each application server,
see the relevant chapter in this book.
Verifying the Ant Build Script
You can preview the Ant build.xml file to be generated by PowerDesigner.
v To preview the Ant build.xml file
1. Open the model property sheet.
2. Click on the Preview tab.
3. Click on the Ant build.xml tab to preview the Ant build.xml file:
6
Chapter 1. Working with Apache Ant
Generating Java Code and the Ant Build Script
You can generate all the Java code for EJBs, servlets and JSPs along with the
Ant build.xml file.
v To generate Java code with an Ant build file
1. Select Language ä Generate Java Code.
2. Specify the directory where you want to generate the Java code.
3. [optional] Click the Selection tab to specify the packages, classes, and
interfaces you want to generate.
4. Click the Options tab and set the value of the “ANT: Generate Ant
build.xml file” option to true.
If you are deploying the application to an application server, you may
also need to enter certain deployment options, such as the server name,
port number, user name, and password.
5. [optional] Click the Generated Files tab to preview which files will be
generated.
7
Ant Build Script Generation
6. [optional] Click the Tasks tab to specify any additional generation or
deployment actions. You can change the order in which the tasks will be
performed by using the arrow tools at the top of this tab.
7. Click OK to begin the generation.
8
Chapter 1. Working with Apache Ant
Building, Packaging, and Deploying the
Application Using Ant
The generated Ant build.xml script is specific to the current application.
If you want to deploy the application in an application server, you may need
to check if the build.xml script contains the correct options, such as server
name, port number, user name, or password.
Installation
Before using Ant, you need to install Ant and the Java Runtime Environment
(JRE) or the JDK.
You can download Ant from http://jakarta.apache.org/ant/index.html .
Ant Targets
To build an application using Ant, you can use the command:
ant [-buildfile <filename>.xml] [<targetName>]
The available targets depend on the application server.
PowerDesigner generates an Ant build script including the following targets:
♦ Standard J2EE application - PowerDesigner generates the following
targets:
• help - displays help
• all - Build the entire application
• compile - compiles the entire application
• javadoc - generates Javadocs
• clean - Clean the generated files
• pack - generates the .EAR, .WAR, .JAR files
• verify - verifies the generated .EAR file using the j2eeverifier
• rebuild - Rebuild the entire application
♦ BEA WebLogic Server - PowerDesigner generates the following
additional targets:
• deploy - Deploy J2EE application in BEA WebLogic Server
• –Duser=wxy –Dpassword=wxy deploy - deploys the application,
overriding the default user name and password
9
Building, Packaging, and Deploying the Application Using Ant
♦ IBM WebSphere Application Server - PowerDesigner generates the
following additional targets:
• deploy - Deploy J2EE application in IBM WebSphere Server
• –Duser=wxy –Dpassword=wxy deploy - deploys the application,
overriding the default user name and password
♦ Sybase EAServer - PowerDesigner generates the following additional
targets:
• deploy - Deploy J2EE application in Sybase EAServer
• –Duser=wxy –Dpassword=wxy deploy - deploys the application,
overriding the default user name and password
♦ Apache Tomcat - PowerDesigner generates the following additional
targets:
• deploy - Deploy web applications in Apache Tomcat
• –Duser=wxy –Dpassword=wxy deploy - deploys the application,
overriding the default user name and password
• undeploy - Undeploy deployed web applications from Apache Tomcat
• install - Install web applications in Apache Tomcat
• remove - Remove installed web applications from Apache Tomcat
• reload - Reload web applications in Apache Tomcat
• start - Start web applications in Apache Tomcat
• stop - Stop web applications in Apache Tomcat
• list - List installed web applications in Apache Tomcat
Example of result:
ant pack
Buildfile: build.xml
compile:
[echo] Compiling Java classes...
[javac] Compiling 17 source files to E:\EJB Tests\EAServer\
Test3\classes
pack:
[echo] Packaging the application...
[war] Building war: E:\EJB Tests\EAServer\Test3\Order3.war
[jar] Building jar: E:\EJB Tests\EAServer\Test3\Order3.jar
[ear] Building ear: E:\EJB Tests\EAServer\Test3\Order3.ear
BUILD SUCCESSFUL
Customizing the Ant Build Script Generation
The Ant build script generation in PowerDesigner is defined in:
10
Chapter 1. Working with Apache Ant
♦ the Java language definition file (.xol) - defines the generation templates
for common properties, tasks and targets. It also defines empty custom
templates. The custom templates can be overridden in the application
server specific XEM.
♦ the application server specific extended model definition file (.xem) - can
override the custom templates to generate a complete build.xml including
standard targets and custom targets.
You can customize the Ant build.xml generation, in either of these files.
v To customize the Java XOL
1. Select Tools ä Resources ä Object Languages.
2. Double-click on the Java XOL.
3. Use the XOL editor to modify the Java XOL:
The Ant specific generated file, generation templates are defined in the
Model metaclass, under the Profile node.
v To customize the server specific XEM
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. Double-click on an application server extended model definition in the
list:
11
Building, Packaging, and Deploying the Application Using Ant
3. Use the editor to modify the extended model definition:
The Ant specific generated file, generation templates are defined in the
Model metaclass, under the Profile node.
12
CHAPTER 2
Creating Borland JBuilder Project Files
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with
Borland JBuilder.
Topic:
page
Introduction
14
JBuilder Project File Generation
16
Verifying The JBuilder Files
20
Generating Java Code and the JBuilder Project File
21
Building and Deploying the Application Using JBuilder
23
13
Introduction
Introduction
PowerDesigner supports many features for J2EE applications like
Object/Relational mapping (O/R mapping), generation of Web Service
artifacts, Enterprise JavaBeanTM (EJBTM), Servlets and JSPs, compiling
and deployment of J2EE applications directly from PowerDesigner.
But many developers need to write code, compile, deploy and debug using
an IDE like JBuilder or a build utility like Ant.
PowerDesigner generates a JBuilder project file when you generate Java
code. It allows you to use JBuilder to edit code, compile, deploy and debug.
It greatly simplifies the integration between PowerDesigner, JBuilder and
application servers.
This chapter explains how to use PowerDesigner to generate a JBuilder
project file.
Configuration
To follow this technical document, you need:
♦ Borland JBuilder Enterprise 9 or higher
♦ JDK 1.4 or higher
♦ J2EE 1.3 (JDK Enterprise Edition 1.3.1.01) or higher
PowerDesigner
PowerDesigner supports object modeling, data modeling, business process
modeling, and fully supports UML.
For Java development, PowerDesigner allows you to:
♦ Create Web Service, EJB, Servlet and JSP components and generate code
for them
♦ Reverse engineering Java source and binary code
♦ Edit the Java code inside PowerDesigner or using an external editor
♦ Synchronize the model with the Java code
♦ Generate additional files
♦ Compile Java code
♦ Deploy J2EE application into an application server
14
Chapter 2. Creating Borland JBuilder Project Files
The PowerDesigner profile allows you to customize the code generator or
add your own code generators.
We use this capability to generate JBuilder project files.
JBuilder
JBuilder is a leading Java IDE. It allows developers to:
♦ Write Java code
♦ Create EJB, Servlet and JSP
♦ Compile Java code
♦ Deploy J2EE applications in an application server
♦ Debug an application
Round-Trip Engineering Process for Java Development
By combining PowerDesigner and JBuilder, you have the round-trip
engineering for Java development to:
♦ Do high level analysis and design using PowerDesigner
♦ Design and create Java components in PowerDesigner
♦ Generate Java code and the JBuilder project file
♦ Open the project file in JBuilder
♦ Finish the implementation of Java classes using JBuilder
♦ Compile, deploy and debug using JBuilder
♦ Reverse engineer the final Java code to synchronize the PowerDesigner
model
15
JBuilder Project File Generation
JBuilder Project File Generation
The JBuilder project file is an XML file with a .jpx extension.
PowerDesigner generates a JBuilder project file called <ModelCode>.jpx,
which has the following structure:
♦ <Project Source> node that shows the Java packages and files in
hierarchy format
♦ Packages that show the Java files
♦ EAR file group if the model contains EJBs, Servlets or JSPs
♦ Web application groups if the model or packages correspond to an
archive file that contains Servlets or JSPs
♦ EJB groups if the model or packages correspond to an archive file that
contains EJBs
♦ Target application server type
♦ Application server specific deployment descriptors
Adding JBuilder Profile
To generate a JBuilder project file, you need to create an Object-Oriented
Model (OOM) targeted for the Java language, and then add the JBuilder
profile (Extended Model Definition).
You can add the JBuilder profile when you create a new OOM by selecting
the JBuilder profile in the Extended Model Definitions page:
16
Chapter 2. Creating Borland JBuilder Project Files
You can also add the JBuilder profile in an existing OOM:
1. Verify that the current OOM has Java as the object language.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click the Import tool:
4. In the IDE tab, select the Borland JBuilder profile:
5. Click OK. The profile is imported into the current model.
Selecting a Target Application Server
PowerDesigner can generate EJBs, servlets, JSPs and application server
specific descriptors.
In the JBuilder project file, PowerDesigner can generate the target server
type and the server specific deployment descriptors.
The supported application servers are:
♦ BEA WebLogic Application Server 7.0
♦ IBM WebSphere Application Server 5.0
17
JBuilder Project File Generation
♦ Sybase EAServer 5.x
♦ Apache Tomcat 5
Adding BEA WebLogic Application Server Support
If you create CMP EJB components, PowerDesigner can generate WebLogic
specific O/R mapping descriptor and deployment descriptor.
These descriptors will be generated in the JBuilder EJB group.
v To add WebLogic application server support
1. Select Model ä Extended Model Definitions.
2. In the List of Extended Model Definitions, click the Import tool.
3. Select the BEA WebLogic profile in the Application Server tab:
4. Click OK. The profile is imported into the current model.
For more information on how to generate EJBs for BEA WebLogic, see the
BEA WebLogic chapter.
Adding Sybase EAServer Support
If you create CMP EJB components, PowerDesigner can generate an
EAServer specific configuration descriptor including O/R mapping
information.
This descriptor will be generated in the JBuilder EJB group.
18
Chapter 2. Creating Borland JBuilder Project Files
v To add EAServer support
1. Select Model ä Extended Model Definitions.
2. In the List of Extended Model Definitions, click the Import tool.
3. Select the Sybase EAServer profile from the Application Server tab:
4. Click OK. The profile is imported into the current model.
For more information on how to generate EJBs for Sybase EAServer, see the
EAServer chapter.
19
Verifying The JBuilder Files
Verifying The JBuilder Files
You can preview the JBuilder project file, EAR group file and EJB group
files to be generated from PowerDesigner.
v To preview the JBuilder files
1. Open the model property sheet.
2. Click the Preview tab.
3. Click the JBuilder.Project tab to preview the JBuilder project file:
4. Click the JBuilder.EAR Group tab to preview the JBuilder EAR group
file.
5. Click the JBuilder.EJB Group tab to preview the JBuilder EJB group file.
If you have defined a package as a packaging unit (use the stereotype
archive), you need to open the package property sheet to preview the EJB
group file.
20
Chapter 2. Creating Borland JBuilder Project Files
Generating Java Code and the JBuilder Project
File
v To generate all the Java code for EJBs, Servlets and JSPs along
with the JBuilder project file
1. Select Language ä Generate Java Code.
2. Specify the directory where you want to generate the Java code.
3. [optional] Click the Selection tab to specify the packages, classes, and
interfaces you want to generate.
4. [optional] Click the Options tab to set generation options for Java, EJB
and the target application server:
21
Generating Java Code and the JBuilder Project File
5. [optional] Click the Generated Files tab to preview which files will be
generated.
6. [optional] Click the Tasks tab to specify any additional generation or
deployment actions. You can change the order in which the tasks will be
performed by using the arrow tools at the top of this tab.
7. Click OK to begin the generation. The JBuilder project file name will be
<ModelCode>.jpx.
Activating Application Server Support in JBuilder
By default, JBuilder only supports a limited number of application servers.
If you want to use BEA WebLogic application server or Sybase EAServer,
you need to activate the application server.
For example, to activate Sybase EAServer 5.x support:
1. Launch JBuilder.
2. Select Tools ä Configure Servers.
3. Select Sybase Enterprise Application Server 5.x.
4. Click the “Enable server” checkbox.
5. In the General tab, enter the Sybase EAServer home directory.
6. In the custom tab, enter the JDK home directory for EAServer you want
to use and the EAServer connection information you want to use in order
to deploy components into EAServer.
22
Chapter 2. Creating Borland JBuilder Project Files
Building and Deploying the Application Using
JBuilder
v To open the JBuilder project
1. Start JBuilder Enterprise.
2. Open the generated JBuilder project file: <ModelCode>.jpx.
The following screen shows an example of J2EE project generated from
PowerDesigner and loaded in JBuilder.
Customizing Deployment Descriptor for Sybase EAServer
You can customize the deployment descriptors for the EAR file, WAR files
and JAR files using JBuilder.
For Sybase EAServer, you can:
♦ Define EAServer specific configuration properties
♦ Deploy EAR, WAR and JAR into EAServer
If you define O/R mapping for your EJBs in PowerDesigner and use the
EAServer profile, PowerDesigner will generate all the O/R mapping
properties you need to allow EAServer to implement the persistence.
23
Building and Deploying the Application Using JBuilder
JBuilder allows users to edit Sybase EAServer configuration properties. The
following screen shows an example of O/R mapping properties generated by
PowerDesigner for the Customer EJB.
Building the J2EE Application
v To build the entire application
1. Right click the project node.
2. Select the Make command.
Deploying the J2EE Application
24
Chapter 2. Creating Borland JBuilder Project Files
v To deploy an .EAR file
1. Right click the .EAR file to deploy
2. Select the command Deploy Options for “<EarFileName>.ear” ä
Deploy
Customizing JBuilder Project Generation
The JBuilder project file generation in PowerDesigner is entirely defined in
the JBuilder profile (Extended Model Definition).
The JBuilder profile is based on the Java language definition file (Java.xol).
It uses templates defined in the Java XOL for J2EE application deployment
descriptors.
The JBuilder profile adds JBuilder specific generation templates.
You can customize the generation if necessary.
25
Building and Deploying the Application Using JBuilder
v To customize the JBuilder project file generation
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. Double-click Borland JBuilder 9 in the List of Extended Model
Definitions
3. Use the profile editor to modify the JBuilder profile:
26
Chapter 2. Creating Borland JBuilder Project Files
27
CHAPTER 3
Creating J2EE Applications for Sybase
EAServer
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with Sybase
EAServer.
Topic:
page
Introduction
30
Creating EJBs
33
Adding EAServer Support
37
Customizing O/R mapping
39
Defining Extended Attributes
44
Verifying the EAServer Configuration Descriptor
47
Generating and Deploying EJBs, Servlets and JSPs in EAServer
51
Creating Web Services for EAServer
61
Customizing EAServer Support
67
29
Introduction
Introduction
PowerDesigner supports many features for J2EE applications like
Object/Relational mapping (O/R mapping), Enterprise JavaBeanTM
(EJBTM), Servlets, JSPs and Web Services generation and deployment.
This chapter explains how to use PowerDesigner to create, generate and
deploy these applications for Sybase EAServer 6.
To follow this chapter, you need:
♦ Sybase EAServer 6
♦ J2EE 1.3.1 (JDK Standard Edition and Enterprise Edition 1.3.1.01) or
higher
♦ A Java IDE or a text editor
Enterprise JavaBean
Enterprise JavaBean (EJB) is a component model for Java.
There are several types of EJBs: Entity Bean, Session Bean, and Message
Driven Bean.
Entity Beans are used for persistent objects. There are two types of
persistence management:
♦ Container Managed Persistence (CMP) - the application server handles
persistence. An EJB deployer has to define the O/R mapping information
to allow the application server to know how to manage the persistence.
♦ Bean Managed Persistence (BMP) - the persistence management code is
defined in the EJB implementation class.
J2EE 1.3 has a new EJB 2.0 component model. The EJB 2.0 specification
introduces a number of improvements: better definition for CMP, local
interfaces, EJB Query Language (EJB-QL) and ejbSelect methods.
PowerDesigner supports UML object modeling and data modeling. It is
useful for designers to use the same tool to define objects, database schema,
O/R mapping and to generate EJBs. PowerDesigner supports O/R mapping
definition and EJB generation, including the EJB 2.0 specification. It can
support any application server supporting EJB 2.0.
With PowerDesigner, you can:
♦ Define EJBs using the UML Class Diagram and Component Diagram
♦ Generate or reverse engineer a database using the Physical Data Model
(PDM)
30
Chapter 3. Creating J2EE Applications for Sybase EAServer
♦ Define O/R mapping
♦ Create CMP EJBs, BMP EJBs, Session Beans and Message Driven Beans
♦ Generate EJB source code, deployment descriptor
♦ Generate application server specific descriptor
♦ Compile Java code and generate the EJB JAR file
♦ Run the J2EE verifier
♦ Deploy EJBs into an application server
♦ Customize the EJB code generator and the application server support
Servlets
A Servlet is a Java component for Web Applications. It can be used to render
dynamic web contents, generate web pages based on the results returned by
an EJB or implement Web Services.
PowerDesigner supports Servlet creation, generation and deployment.
Java Server Pages
A Java Server Page (JSP) is an HTML page with Java source code and JSP
specific tags.
It is easier to edit and then modify a Servlet.
When a JSP is deployed into a server, it is transformed into a Servlet.
PowerDesigner supports JSP creation, generation and deployment.
Web Services
PowerDesigner supports several Web Service implementation types for Java:
Apache Axis, JWS, JAX-RPC, JAXM and Web Service for J2EE.
Sybase EAServer 6 supports Apache Axis for Java classes and EJBs, and
enables you to:
♦ Deploy a Java class as Web Service
♦ Expose a deployed Stateless Session Bean as Web Service
PowerDesigner allows you to create Java classes or Stateless Session Beans
as Web Services, compile, package and deploy them into EAServer 6, and
generate an Eclipse project, JBuilder project or Ant script to develop and
deploy from an IDE.
31
Introduction
Sybase EAServer
Sybase EAServer 6 fully supports the J2EE 1.3 specification including EJB
2.0. In addition, Sybase EAServer 6 provides new Web Service support
based on Apache Axis.
With PowerDesigner, you can:
♦ Define EAServer specific O/R mapping SQL queries
♦ Define EAServer specific extended attributes
♦ Generate EAServer configuration descriptor including O/R mapping
(sybase-easerver-config.xml)
♦ Deploy EJB JAR, Web Application WAR or the EAR file in EAServer
using the jagtool command
♦ Deploy Web Services
32
Chapter 3. Creating J2EE Applications for Sybase EAServer
Creating EJBs
To create EJBs, you need to:
1. Define classes using a Class Diagram.
2. Define the database schema using a Physical Data Model (PDM).
3. Define the O/R mapping.
4. Convert classes to EJBs or new EJBs.
5. Define EJB properties.
For more details about how to use a Class Diagram, how to design a
database, how to define O/R mapping and how to create EJBs, refer to the
core PowerDesigner documentation.
Defining Classes and Database Schema
If you have an existing database, you can reverse engineer the database to
create a Physical Data Model (PDM), generate an Object-Oriented Model
(OOM) from the PDM and generate the default O/R mapping, then convert
classes to EJBs.
For a new application, you can create a Class Diagram in an OOM, generate
the PDM from the OOM and generate the default O/R mapping, then convert
classes to EJBs.
If you already have a database schema and an Object Model but they do not
match, you can manually define the O/R mapping, then convert classes to
EJBs.
The following diagram shows an example of PDM:
The following diagram shows the OOM generated from the PDM:
33
Creating EJBs
The class and attribute names can be changed to respect Java naming
conventions. When you rename classes, attributes, tables or columns, the
O/R mapping is automatically updated if the O/R mapping is not
user-defined.
Note: We recommend that you first create a package in the OOM, then define
classes inside the package. The package is used to create the JAR and WAR
files. Without a package, you may not be able to deploy EJBs into EAServer.
Defining O/R Mapping
When you generate an OOM from a PDM or a PDM from an OOM, the
default O/R mapping can be generated and saved in the OOM. You can also
manually define complex O/R mapping. The following screenshot shows the
Attributes Mapping of the class Customer, which is generated from the
PDM.
For O/R mapping, PowerDesigner supports:
♦ Mapping of a class to one or several tables or views
♦ Mapping of an attribute to a column or an expression
34
Chapter 3. Creating J2EE Applications for Sybase EAServer
♦ Select, insert, update and delete queries for a class
♦ Query for an operation
♦ Mapping of an association to a table or a reference
♦ Select, insert and delete queries for an association
♦ Stored procedures
The syntax of SQL queries and stored procedures may vary depending on
the application server.
For EAServer, PowerDesigner generates EAServer specific SQL statements.
Converting classes to EJBs
To convert a class to an EJB, you can right-click a class then select the
Create Enterprise JavaBean command or use the Tools ä Create Enterprise
JavaBean command. The create EJB wizard creates a component to
represent the EJB
It transforms a persistent class into a bean class:
35
Creating EJBs
It then adds a primary key class, adds remote home interface, remote
interface, local home interface, local interface, and creates an EJB specific
Class Diagram.
Since an EJB has several classes and interfaces, PowerDesigner uses a
component to represent the EJB and a Class Diagram for the definition of
the EJB related classes and interfaces. The following diagram shows the
UML Component Diagram:
The following diagram shows the Customer EJB specific Class Diagram:
You can also create a new EJB using the Component Diagram.
36
Chapter 3. Creating J2EE Applications for Sybase EAServer
Adding EAServer Support
PowerDesigner can generate standard CMP or BMP EJBs, Servlets, JSPs,
and application server specific descriptors.
It uses an extended model definition file (.xem) to support additional targets,
such as application servers, O/R mapping tools, IDE workspaces, etc. The
extended model definition defines stereotypes, extended attributes, code
generation templates, commands, and options. It can add new code
templates or override the templates of an object language (Java, XML, and
so on); it can also be independent from the object language. The code
generation templates use code templates and macros.
The EAServer extended model definition defines:
♦ Extended attributes
♦ EAServer specific O/R mapping queries
♦ EAServer Configuration Descriptor template
♦ EAServer Jagant script template
♦ EAServer deployment commands
♦ EAServer options
v To add EAServer support
1. Verify that the current model has the object language Java.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click on the Import tool
37
Adding EAServer Support
4. Select Sybase EAServer 6.x from the list:
5. Click OK. The XEM is imported into the current model.
38
Chapter 3. Creating J2EE Applications for Sybase EAServer
Customizing O/R mapping
Each application server may use different syntax for O/R mapping SQL
queries, variables and stored procedures. For example, to designate the value
of an attribute, application servers can use %attributeName%,
@attributeName or :attributeName.
Sybase EAServer uses @attributeName as the variable name to designate the
value of an attribute. After importing the Sybase EAServer extended model
definition to your model, you can verify that the O/R mapping queries are
properly defined for EAServer.
v To verify the O/R mapping queries
1. Open the property sheet of a bean class.
2. Click on the Mapping tab.
3. Verify the Select, Insert , Update , and Delete queries.
Defining Queries
Once the class mapping and attributes mapping are defined, PowerDesigner
can generate the default SQL queries for select, insert, update and delete
statements. If you change the definition of classes or tables, the SQL queries
will be automatically updated.
If you have a complex O/R mapping, you may need to redefine these
queries. If you change a default query, it will become a user-defined query
and will be saved as it is. Changes made on classes or tables will not update
a user-defined query.
You can use the SQL editor (the Edit tool in the toolbar) to select the table
name, column name or stored procedure name:
39
Customizing O/R mapping
The Select Query
The select query uses @attributeName for both the return value and the
where criteria.
The @attributeName represents the name of a persistent attribute
(CMP-field) of the EJB.
For the select query, you can use a stored procedure. The syntax used for
stored procedures is:
select @attributeName1, @attributeName2, ... {call
procedureName @attributeName1, @attributeName2, ...}
Attribute names are used in the select statement to indicate the types of the
result set, and in the procedure as parameters.
40
Chapter 3. Creating J2EE Applications for Sybase EAServer
The Insert Query
For the insert query, you can use a stored procedure. The syntax used for
stored procedures is:
{call procedureName @attributeName1, @attributeName2, ...}
where the @attributeName represents the name of an attribute of the EJB.
Attribute names are used in the procedure as parameters.
The Update Query
41
Customizing O/R mapping
For the update query, you can use a stored procedure. The syntax used for
stored procedures is:
{call procedureName @attributeName1, @attributeName2, ...}
where the @attributeName represents the name of an attribute of the EJB.
Attribute names are used in the procedure as parameters.
The Delete Query
For the delete query, you can use a stored procedure. The syntax used for
stored procedures is:
{call procedureName @attributeName1, @attributeName2, ...}
where the @attributeName represents the name of an attribute of the EJB.
Attribute names are used in the procedure as parameters.
Defining EJB-QL
You can define EJB-QL for finders and ejbSelect methods.
For CMP EJBs, finders are only defined in remote home and local home
interfaces. ejbSelect methods are defined in bean classes.
v To define EJB-QL
1. Create a finder method or an ejbSelect method.
2. Open the property sheet of the finder method or the ejbSelect method.
3. Define the list of parameters of the method.
42
Chapter 3. Creating J2EE Applications for Sybase EAServer
4. Click on the Implementation tab and then click on the EJB-QL sub-tab to
enter EJB-QL statements for a finder or ejbSelect method:
43
Defining Extended Attributes
Defining Extended Attributes
To be able to generate EAServer Configuration Descriptors, PowerDesigner
uses extended attributes for model, package, component and association.
EAServer-specific extended attributes allow you to specify options like:
♦ JNDIName
♦ Connection cache name
♦ Object caching options
Model and Package extended attributes
The following extended attributes are available:
Extended attribute
Description
DefaultConnectionCache
Specifies the default connection cache for all EJBs
defined in the model or in a package. If you change
the default Connection Cache, all EJBs using the
default Connection cache will be changed.
Default: JavaCache.
Used in property: com.sybase.jaguar.component,
storage
Component extended attributes
The following extended attributes are available:
44
Chapter 3. Creating J2EE Applications for Sybase EAServer
Extended attribute
Description
ConnectionCache
Specifies the connection cache name.
Used in property: com.sybase.jaguar.component
EnableDebug
Enables server side debugging.
Default: false.
Used in property: com.sybase.jaguar.component.debug
JNDIName
Specifies the JNDI name for lookup.
The default name is
<PackageName>/<EJBName>.
Used in property: com.sybase.jaguar.component.bind.naming
JNDILocalName
Specifies the JNDI name for local lookup.
The default name is
<PackageName>/<EJBName>Local.
Used in property: com.sybase.jaguar.component.local.bind.name
NotificationTopic
Specifies the notification topic for table mapping.
Default: <PackageName>_<TableName>_Topic.
Used in property: mapTable:<TableName>:notify
UseObjectCache
Specifies the use of object caching.
Default: false.
Used in property: N/A
ObjectCacheComponent
Specifies the component used to manage the object
caching.
Default: CtsComponents/ObjectCache.
Used in property: com.sybase.jaguar.component.objectCache
ObjectCacheName
Specifies the object cache name.
There is no default value.
Used in property: com.sybase.jaguar.component.objectCache.name
45
Defining Extended Attributes
Extended attribute
Description
ObjectCacheSize
Specifies the object cache size.
There is no default value.
Used in property: com.sybase.jaguar.component.objectCache.size
SelectWithLock
Specifies that the row must be locked at the start of
transaction (pessimistic concurrency control).
Default: false.
Used in property: com.sybase.jaguar.component.selectWithLock
TimestampColumn
Specifies the timestamp column name.
There is no default value.
Used in property: com.sybase.jaguar.component.timestamp
UseTriggerNotification
Specifies the use of database triggers to notify
changes in the database and update the object
cache.
Default: false.
Used in property: com.sybase.jaguar.component.dn.triggers
Association extended attributes
The following extended attributes are available:
Extended attribute
Description
ConnectionCache
Specifies the connection cache name.
Default: the DefaultConnectionName of the model
or package.
Used in property: com.sybase.jaguar.component.storage
46
Chapter 3. Creating J2EE Applications for Sybase EAServer
Verifying the EAServer Configuration Descriptor
The EJB deployment descriptor defines commonly used EJB properties.
However, this is not enough for most application servers. For example, the
EJB deployment descriptor does not contain the O/R mapping. To address
this problem, each application server has its own deployment descriptor or
configuration descriptor for additional information.
Sybase EAServer uses a Configuration Descriptor, an XML file named
sybase-easerver-config.xml. This can be used to define all the property
values of each component in EAServer.
The Configuration Descriptor can be added in the EJB JAR file. When you
deploy an EJB JAR file into EAServer, all the properties will be set
including O/R mapping. You can also use the jagtool command to configure
EJBs with the Configuration Descriptor.
Before generating EJBs for EAServer, you can preview the Configuration
Descriptor to verify that it is properly defined.
v To preview the configuration descriptor
1. Open the properties of the package that contains the EJBs.
2. Click on the Preview tab. The first sub-tab shows the EJB Deployment
Descriptor:
47
Verifying the EAServer Configuration Descriptor
The second sub-tab shows the Sybase EAServer Configuration Descriptor:
48
Chapter 3. Creating J2EE Applications for Sybase EAServer
To change the Configuration Descriptor, you can change the O/R mapping
definition or the extended attributes.
You can also generate a jagant script (build.xml) to configure the properties
of EJBs. The jagant script is not necessary if you use the Configuration
Descriptor.
v To generate the jagant script
1. Open the model or package property sheet.
2. Click on the Preview tab.
3. Click on the Change Generation Options button.
4. Set the value of the “Generate jagant script to configure EJBs” option to
true:
49
Verifying the EAServer Configuration Descriptor
5. The Preview tab displays a new tab called EAServer.Jagant Script:
50
Chapter 3. Creating J2EE Applications for Sybase EAServer
Generating and Deploying EJBs, Servlets and
JSPs in EAServer
With PowerDesigner, you can:
♦ Generate EJB source code, EJB deployment descriptor
♦ Generate Servlet source code, Web application descriptor
♦ Generate EAServer configuration descriptor
♦ [optional] Generate EAServer jagant script
♦ Generate Javadoc
♦ Compile Java code and generate the EJB JAR file, Web Application WAR
file and the EAR file
♦ Run the J2EE verifier
♦ Deploy JAR, WAR or EAR file into EAServer directly from
PowerDesigner using jagtool
♦ Use Eclipse, JBuilder or Ant to compile, package and deploy into
EAServer
Generating, Building and Deploying EJBs, Servlets and JSPs from
PowerDesigner
You can generate EJBs, Servlets and JSPs and deploy in EAServer directly
from PowerDesigner:
v To generate from PowerDesigner
1. Select Language ä Generate Java Code.
2. Select the directory where you want to generate EJBs. Each package will
generate a subdirectory.
3. On the Targets tab, verify that Sybase EAServer is selected:
51
Generating and Deploying EJBs, Servlets and JSPs in EAServer
4. [optional] Click the Selection tab to select the packages, classes and
interfaces you want to generate.
5. [optional] Click the Options tab to change the generation options for both
EJB and EAServer:
52
Chapter 3. Creating J2EE Applications for Sybase EAServer
6. [optional] Click the Tasks tab to select the commands you need to
perform compilation and deployment.
You can compile Java code, create an EAR file and deploy the EAR file.
You can also create JAR and WAR files and deploy JAR and WAR files
separately.
Note: You can order the tasks by using the Move Up, Move Down
buttons.
7. Click OK to generate and deploy EJBs.
53
Generating and Deploying EJBs, Servlets and JSPs in EAServer
PowerDesigner generates all the Java source code and deployment
descriptors then shows the list of generated files.
You can use an editor to view the generated files:
8. Click Close to execute the commands.
PowerDesigner displays the generation result in the Output window. An
example result follows:
54
Chapter 3. Creating J2EE Applications for Sybase EAServer
Executing command(s)...
Java : Compile Java source codes...
d:\jdk1.3.1\bin\javac.exe CustomerBean.java OrderBean.java
CustomerPK.java OrderPK.java Customer.java
CustomerLocal.java CustomerHome.java
CustomerLocalHome.java Order.java OrderLocal.java
OrderHome.java OrderLocalHome.java
Java : Create JAR file for Java classes and deployment
descriptor...
d:\jdk1.3.1\bin\jar.exe cvf Order3.jar META-INF\*.xml
d:\jdk1.3.1\bin\jar.exe uvf Order3\Order3.jar Order3\*.class
Order3\*.java
Java : Run J2EE verifier on generated JARs...
cmd.exe /K d:\jdk1.3.1\bin\verifier.bat -oj2ee_verifier.log
Order3.jar
About to ValidateParse META-INF/ejb-jar.xml file.
Order3: No failed test.
Look in file "j2ee_verifier.log" for detailed results on test
assertions.
EAServer : Deploy an EJB JAR into EAServer...
Deploy the JAR file Order3.jar into EAServer...
jagtool.bat -host localhost -port 2000 -user jagadmin deploy
-type ejbjar -stubsandskels false -overwrite true verbose true -install false -strategy full Order3.jar
Deployed file Order3.jar
Deploying...
Deploying EJBs from bundle Order3
Deployment strategy is FULL
Deployed EJB Order
Deployed EJB Customer
Getting Relationships
Relationship = Customer-Order
Created Relationships
Resolving EJB References
Doing sybase-easerver-config.xml configuration
Configuration Description: Configure CMP EJBs defined in the
Order3 package
Component Order3/Customer was configured successfully
Component Order3/Order was configured successfully
Component Order3/Customer-Order was configured successfully
The configuration from file: Order3.jar was performed
successfully
Building and Deploying EJBs, Servlets and JSPs Using Eclipse
PowerDesigner can generate an Eclipse project that allows you to compile,
package and deploy using Eclipse.
55
Generating and Deploying EJBs, Servlets and JSPs in EAServer
v To build and deploy EJBs, Servlets and JSPs using Eclipse
1. Add the Eclipse Extended Model Definition in the PowerDesigner OOM.
2. In the General Options dialog box, display the Variables page and add a
variable ECLIPSE_HOME to indicate the home directory of Eclipse.
3. Generate all the Java code using Language ä Generate Java Code without
selecting any command task.
4. Launch Eclipse.
5. Import the generated Eclipse project.
6. Use the Rebuild command to compile and package.
7. Right click on the build.xml file and select Run Ant.
8. Select the deploy command to deploy the J2EE application into
EAServer.
Building and Deploying EJBs, Servlets and JSPs Using Borland JBuilder
Enterprise
PowerDesigner can generate a JBuilder Enterprise project file that contains:
♦ All Java files
♦ The EAR group
♦ The EJB groups
♦ The Web groups
♦ The EAServer configuration description containing O/R mapping
information
v To build and deploy EJBs, Servlets and JSPs using JBuilder Enterprise
1. Add the JBuilder Extended Model Definition in the PowerDesigner
OOM.
2. Generate all the Java code using Language ä Generate Java Code without
selecting any command task.
3. Launch JBuilder.
4. Open the generated JBuilder project file.
5. Use the Make command of the project to compile and package.
56
Chapter 3. Creating J2EE Applications for Sybase EAServer
6. Use the Deploy command of the .WAR, .JAR or .EAR to deploy in
EAServer.
You can also use the generated Ant script to compile, package and deploy
the J2EE application into EAServer.
For JBuilder 7, you need to install the EAServer plugin for JBuilder. You
can download it from http://www.sybase.com.
For more information, see the JBuilder chapter.
Building and Deploying EJBs, Servlets and JSPs Using Apache Ant
For general information about working with PowerDesigner and Ant, see the
Ant chapter.
The following EAServer-specific options are available:
Generation Option
Description
EASHost
Specifies the EAServer host name
Default: localhost
EASPort
Specifies the EAServer port number
Default: 2000
EASUser
Specifies the EAServer user name
Default: jagadmin
EASPassword
Specifies the EAServer password
Default: [N/A]
EASDeployGeneStubsAndSkels
Instructs PowerDesigner to generate
stubs and skeletons
Default: no
EASDeployOverwrite
Instructs PowerDesigner to overwrite
the existing package in EAServer
Default: yes
EASGenerateConfigurationDescriptor
Instructs PowerDesigner to generate
configuration descriptors to configure
EJBs
Default: yes
EASGenerateJagantScript
Instructs PowerDesigner to generate
jagant scripts to configure EJBs
Default: no
57
Generating and Deploying EJBs, Servlets and JSPs in EAServer
Generation Option
Description
EASGenerateQueryMap
Instructs PowerDesigner to generate
query mappings. If the query mapping
is in EJB-QL, it cannot be generated
in EJB deployment descriptor.
Default: no
EASDeployStrategy
Specifies the EAServer deployment
strategy
(full, incremental, optimistic)
Default: full
Verifying the Deployed EJBs in EAServer
You deploy EJBs in EAServer from PowerDesigner.
After deployment, you can verify that the EJBs are well deployed and the
O/R mapping and other properties are well defined.
In the Component property sheet, you need to verify that the general
properties of persistence:
. . . the Field Mapping:
58
Chapter 3. Creating J2EE Applications for Sybase EAServer
. . . the Query Mapping:
. . . the Table Mapping:
59
Generating and Deploying EJBs, Servlets and JSPs in EAServer
. . . and other properties are correct.
Using the Deployed EJBs
To use the deployed EJBs, you need to:
1. Generate stubs and skeletons if they were not generated at deployment
time.
2. Define roles for the EJBs in EAServer.
3. Install the package in a server.
4. Create a client program.
60
Chapter 3. Creating J2EE Applications for Sybase EAServer
Creating Web Services for EAServer
EAServer 6 supports Apache Axis for Web Services. Both Java classes and
Stateless Session Beans are supported.
PowerDesigner allows users to:
♦ Create Java classes for Web Service (Axis RPC component).
♦ Create Stateless Session Bean for Web Service (Axis EJB component).
♦ Compile, package, deploy and expose as Web Service from
PowerDesigner.
♦ Generate an Eclipse project, JBuilder project and Ant script to use
Eclipse, JBuilder or other IDEs to compile, package, deploy and expose
as Web Service.
Configuration
If you plan to compile, package and deploy using Eclipse, JBuilder or
another IDE, you need to install Apache Ant, and then:
♦ define an ANT_HOME variable in the Variables page of the General
Options dialog box
♦ add the Ant bin directory in the Windows Path environment variable
If you plan to use Eclipse to compile, package and deploy, you need to
install the EAServer 6 Eclipse plugin, and then:
♦ define an ECLIPSE_HOME variable in the Variables page of the General
Options dialog box
PowerDesigner uses jagtool to deploy a J2EE application and wstool to
deploy Java classes as Web Service and expose EJBs as Web Service.
You need to add the EAServer bin directory in the Windows Path
environment variable.
Using a Java class as Web Service
To use a Java class as a Web Service, you need to:
1. Create an OOM model for Java.
2. Add the EAServer 6 Extended Model Definition.
61
Creating Web Services for EAServer
3. Create a package and select the Archive stereotype.
Note: EAServer 6 requires that each Java class should be in a separate
package.
4. Open the diagram of the package.
5. Use the Web Service wizard to create a Web Service.
6. Select the Axis RPC implementation type.
7. Implement one or several Web Service methods.
8. Configure the Web Service component if necessary.
9. Generate the Java code and additional files.
Note: PowerDesigner generates a deploy.wsdd and an undeploy.wsdd files
for Axis.
Using a Stateless Session Bean as Web Service
To use a Stateless Session Bean as Web Service, you need to:
1. Create an OOM model for Java.
2. Add the EAServer 6 Extended Model Definition.
3. Create a package.
4. Open the diagram of the package.
5. Use the Web Service wizard to create a Web Service.
6. Select the Axis EJB implementation type.
A default WebMethod will be created. To rename it, you can use the
Operations tab of the Remote Interface properties.
7. Implement one or several Web Service methods.
8. Configure the Web Service component if necessary.
9. Generate the Java code and additional files.
Deploying Web Services
To deploy Web Services based on Java classes, PowerDesigner creates a
.JAR file for each archive package containing the Java classes and the
deploy.wsdd file, then uses the EAServer 6 wstool command to deploy the
Java classes as Web Services.
62
Chapter 3. Creating J2EE Applications for Sybase EAServer
To deploy Web Services based on Stateless Session Beans, PowerDesigner
deploys the J2EE application .EAR file first, then uses the EAServer 6
wstool command to expose the EJBs as Web Services.
Deploying Web Services from PowerDesigner
You can deploy Web Services directly from PowerDesigner or generate the
code from PowerDesigner then use an IDE to compile, package and deploy.
v To deploy Web Services from PowerDesigner
1. Create an OOM with Web Services based on Java classes and/or Stateless
Session Beans.
2. Start the Jaguar server.
3. Select Language ä Generate Java Code.
4. In the generation options window, enter the server name, port, user name
and password.
5. In the Tasks page, select the following tasks in this order:
♦ ”Java: Package J2EE application in an EAR file”,
♦ ”EAServer: Deploy J2EE application EAR file in EAServer”,
♦ ”EAServer: Expose Java classes or EJBs as Web Service in EAServer”
6. Click OK.
Using Eclipse to Develop and Deploy Web Services
63
Creating Web Services for EAServer
v To use Eclipse to develop and deploy Web Services
1. Create an OOM with Web Services based on Java classes and/or Stateless
Session Beans.
2. Add the Eclipse Extended Model Definition.
3. Select Language ä Generate Java Code.
4. Enter an output directory. It could be a subdirectory of the Eclipse
workspace directory.
5. In the generation options window, enter the server name, port, user name
and password.
6. Do not select any task in the Tasks page.
7. Click OK.
8. Start Eclipse.
9. Import the generated project.
10. Modify the Java classes or the EJBs if necessary.
11. Rebuild the project.
12. Right-click the build.xml file, and select Run Ant.
64
Chapter 3. Creating J2EE Applications for Sybase EAServer
13. Run the deployExpose tasks.
Using JBuilder to Develop and Deploy Web Services
v To use JBuilder 9 or higher to develop and deploy Web Services
1. Create an OOM with Web Services based on Java classes and/or Stateless
Session Beans.
2. Add the JBuilder Extended Model Definition.
3. Select Language ä Generate Java Code.
4. Enter an output directory.
5. In the generation options window, enter the server name, port, user name
and password.
6. Do not select any task in the Tasks page.
7. Click OK.
8. Start JBuilder.
9. Open the generated project.
10. Modify the Java classes or the EJBs if necessary.
11. Right-click the project and select Make to build the project.
12. Expand the build.xml file node.
13. Right-click the deployExpose tasks and select Make.
65
Creating Web Services for EAServer
Testing Deployed Web Services
The easiest way to test Web Services deployed in EAServer 6 is using the
EAServer 6 Eclipse plugin.
You can directly invoke the Web Service methods or generate a JSP client.
66
Chapter 3. Creating J2EE Applications for Sybase EAServer
Customizing EAServer Support
The EAServer support in PowerDesigner is defined in the EAServer
extended model definition.
v To customize the EAServer support
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. Double-click Sybase EAServer in the List of Extended Model
Definitions.
3. Use the Extended Model Definition Editor to modify the Configuration
Descriptor template:
67
Customizing EAServer Support
4. You can also modify the extended attributes, the options and the
commands:
68
CHAPTER 4
Deploying Web Applications in Apache
Tomcat
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with
Apache Tomcat.
Topic:
page
Introduction
70
Creating a Web Application
71
Generating the Ant Build Script
74
Building, Packaging and Deploying the Web Application Using
Ant
77
Running the Web Application
78
69
Introduction
Introduction
PowerDesigner supports many features for J2EE applications like
Object/Relational mapping (O/R mapping), Enterprise JavaBeanTM
(EJBTM), servlets, JSPs generation, deployment, and Web Services for Java.
This chapter explains how to use PowerDesigner to create, generate and
deploy Web applications including servlets, JSPs and Web Services in
Apache Tomcat 5.0 or higher.
Configuration
To follow this chapter, you will need:
♦ Apache Tomcat 5.0 or higher
♦ JDK Standard Edition 1.4 or higher
♦ A Java IDE or a text editor
Overview
This section discusses PowerDesigner support for specific constructs:
♦ Servlet - a Java component for Web Applications.
Servlets can be used to render dynamic web contents, generate web pages
based on the results returned by an EJB, or implement Web Services.
PowerDesigner supports servlet creation, generation and deployment.
♦ Java Server Page (JSP) - an HTML page with Java source code and JSP
specific tags.
A JSP is easier to edit and modify and, it is transformed into a servlet
when it is deployed to a server.
PowerDesigner supports JSP creation, generation and deployment.
♦ Web Services - can be implemented in different ways. For Apache
Tomcat, PowerDesigner supports the JAXM model and the JAX-RPC
model. The JAXM model uses a special servlet model to implement a
Web Service. The JAX-RPC model converts a normal Java class into a
servlet.
♦ Apache Tomcat - a Java based open source JSP/Servlet container.
The latest version of Tomcat supports Web Services: JAXM, JAX-RPC
and AXIS.
Apache Tomcat is widely used because it supports JSP/Servlet, and Web
Services, it is free, fast and easy to manage.
70
Chapter 4. Deploying Web Applications in Apache Tomcat
Creating a Web Application
The following procedures describe how to create the various elements of a
web application with PowerDesigner.
v To create a servlet
1. Create an Object-Oriented Model (OOM) with the Java language.
2. Select Tools ä Create Servlet wizard.
3. Enter the name of the servlet, click Next.
4. Select the type of servlet (the superclass of the servlet), and click Next.
5. [optional] Select an existing class as the Servlet class.
6. [optional] Create a component diagram and a component symbol.
Alternatively, if you already have a class and want to transform it into a
servlet, you can right-click it and select Create Servlet.
For more details about how to create servlets, see the OOM User’s Guide.
v To create a JSP
1. Create an Object-Oriented Model (OOM) with the Java language.
2. Select Tools ä Create JSP wizard.
3. Enter the name of the JSP, and click Next.
4. Select a JSP template, and click Next.
5. [optional] Create a component diagram and a component symbol.
Alternatively, if you already have a file and want to transform it into a JSP,
you can select it and then click Tools ä Create JSP.
To define the JSP contents, you can double-click the file object associated
with the JSP component or open the file property sheet and click on the
Content tab.
For more details about how to create JSPs, see the OOM User’s Guide.
71
Creating a Web Application
v To create a Web Service component
1. Create an Object-Oriented Model (OOM) with the Java language.
2. Select Tools ä Create Web Service Component wizard.
3. Enter the name of the Web Service, and click Next.
4. Select the Web Service type (implementation) and the Implementation
type (Standard or Servlet). The Standard implementation type uses the
JAX-RPC model. The servlet implementation model uses the JAXM
model.
5. [optional] Create a component diagram and a component symbol.
If you already have a class and you want to transform the class into a Web
Service, you can right-click on the class and select Create Web Service
Component.
For more details about how to create Web Service components, see the
OOM User’s Guide.
Adding Apache Tomcat Support
You can use the Ant build script to compile, package and deploy to Tomcat.
PowerDesigner can also use the Ant build script to deploy to Tomcat.
For more details about the Ant build script generation, see the Ant chapter.
PowerDesigner uses extended model definitions to support additional targets
like an application server, O/R mapping tool, IDE workspace, etc. An
extended model definition (XEM) defines stereotypes, extended attributes,
code generation templates, commands, and options. It can add new code
templates or override the templates of an object language (Java, XML, and
so on); it can also be independent from the object language. The code
generation templates use code templates and macros.
The Tomcat XEM defines:
♦ An Ant build script for deploying Web Applications in Tomcat.
♦ Command tasks for deploying Web Applications from PowerDesigner.
v To add Tomcat support
1. Verify that the current model has the object language Java.
2. Select Model ä Extended Model Definitions.
72
Chapter 4. Deploying Web Applications in Apache Tomcat
3. Click on the Import tool in the List of Extended Model Definitions
4. Select Apache Tomcat 5 from the list
5. Click OK. The XEM is imported into the current model
73
Generating the Ant Build Script
Generating the Ant Build Script
To generate the Ant build script, you need to create an Object-Oriented
Model (OOM) for the Java object language, and then enable the Ant build
script generation.
Enabling Ant build script generation
By default, the Ant build script generation is disabled.
v To enable Ant build script generation
1. Select Language ä Generate Java Code.
2. Click the Options tab.
3. Set the value of the option “ANT: Generate Ant build.xml file” to true:
4. Click Apply to save the settings.
5. Click OK to close the window.
Verifying the Ant Build Script
You can preview the Ant build.xml file to be generated.
74
Chapter 4. Deploying Web Applications in Apache Tomcat
v To preview the Ant build.xml file
1. Open the model property sheet.
2. Click the Preview tab.
3. Click the Ant build.xml tab to preview the Ant build.xml file.
Generating Servlets, JSPs and the Ant Build Script
v To generate servlets, JSPs and the Ant build script
1. Select Language ä Generate Java Code.
2. Specify the directory where you want to generate the code.
3. On the Targets tab, verify that Apache Tomcat 5 is selected.
4. [optional] Click the Selection tab to select the packages, classes and
interfaces you want to generate.
5. [optional] Click the Options tab, and enter the default host name, port
number, user name and password for login into Tomcat:
You can overwrite these default options using the –D option on the Ant
command line.
6. Click the Tasks tab to specify deployment tasks. You don’t need to select
any option if you plan to use Ant to build and deploy the Web
application. If you want to deploy the Web application directly from
PowerDesigner, you should start Apache Tomcat server , and then select
the following tasks:
75
Generating the Ant Build Script
♦ Tomcat: Install web applications in Apache Tomcat using Ant, or
♦ Tomcat: Deploy web applications in Apache Tomcat using Ant
7. Click OK to generate the servlet, JSPs and Ant build script.
76
Chapter 4. Deploying Web Applications in Apache Tomcat
Building, Packaging and Deploying the Web
Application Using Ant
To run the Ant build script, you can use the command:
ant [-buildfile <filename>.xml] [<targetName>]
Customizing the Tomcat Ant Build Script
The Tomcat Ant build script support in PowerDesigner is defined in the
Tomcat extended model definition. You can customize it if necessary.
v To customize the Tomcat Ant script
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. Double-click on Apache Tomcat in the List of Extended Model
Definitions.
3. Use the Extended Model Definition Editor to modify the Ant script
template.
77
Running the Web Application
Running the Web Application
To run the deployed Web Application:
1. Start the Apache Tomcat server.
2. Open a Web browser and enter the URL:
♦ http://<hostname>:8080/<ModelCode>/<JSPName>.jsp for a JSP
♦ http://<hostname>:8080/<ModelCode>/<ServletName> for a
Servlet
Where <hostname> is the host name of Apache Tomcat, <ModelCode>
is the code of model, <JSPName> is the JSP class code and
<ServletName> is the Servlet class code.
78
CHAPTER 5
Creating J2EE Applications for BEA
WebLogic
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with BEA
WebLogic.
Topic:
page
Introduction
80
Creating Enterprise Java Beans
83
Adding WebLogic Server Support
87
Parameterizing WebLogic EJB Container in PowerDesigner
89
Configuring WebLogic Persistence Services in PowerDesigner
94
Generating and Deploying EJBs in WebLogic server
100
Extended Attributes for WebLogic Server
104
79
Introduction
Introduction
To follow this chapter, you need:
♦ JDK 1.3
♦ A Java IDE or a text editor, for example JBuilder
♦ WebLogic Server 7.0 or higher
Overview
PowerDesigner supports features like Object/Relational mapping (O/R
mapping), UML Component Diagrams, and Enterprise Java Bean (EJB)
generation.
There are several types of EJBs: Entity Beans, Session Beans and
Message-Driven Beans.
Entity Beans are used for persistent objects. There are two types of
persistence management: Container Managed Persistence (CMP) and Bean
Managed Persistence (BMP). In CMP mode, the application server handles
the persistence. An EJB deployer can define the O/R mapping information to
tell the application server how to manage the persistence. In BMP mode, the
persistence management code is defined in the EJB implementation class.
J2EE 1.3 has a new EJB 2.0 component model. The EJB 2.0 specification
introduces a number of improvements: a better definition for CMP, local
interfaces, an EJB Query Language (EJB-QL) and ejbSelect methods.
PowerDesigner supports UML object modeling and data modeling, allowing
you to use the same tool to define objects, database schemas, O/R mappings
and to generate EJBs. PowerDesigner adds O/R mapping definition and EJB
generation. It fully supports the EJB 2.0 specification, and can support any
application server supporting EJB 2.0.
With PowerDesigner, you can:
♦ Define EJBs using the UML Class Diagram and Component Diagram
♦ Generate or reverse engineer database using the Physical Data Model
(PDM)
♦ Define O/R mapping
♦ Create CMP EJBs, BMP EJBs, Session Beans and Message Driven Beans
♦ Generate EJB source code and deployment descriptors
♦ Generate application server-specific descriptors
80
Chapter 5. Creating J2EE Applications for BEA WebLogic
♦ Compile Java code and generate the EJB JAR file
♦ Run the J2EE verifier
♦ Deploy EJBs into an application server
♦ Customize the EJB code generator and the application server support
WebLogic Server 7.0 from BEA fully supports the EJB 2.0 specification. It
is able to manage EJB persistence through their containers (CMP). It is
usually preferable to let it manage the persistence because this tool provides
optimized persistent management and better performance for large-scale
applications.
Since PowerDesigner already has the O/R mapping metadata, we provide a
way to export the metadata into a WebLogic server to make customers lives
easier and to optimize persistence management for EJBs.
With PowerDesigner, you can:
♦ Define WebLogic specific O/R mappings
♦ Define WebLogic specific Extended Attributes
♦ Generate WebLogic descriptors including O/R mappings
(weblogic-ejb-jar & weblogic-cmp-rdbms)
♦ Deploy EJBs into WebLogic Servers
This chapter describes PowerDesigner support for BEA WebLogic Server
7.0.
Introducing BEA WebLogic Server - Architecture Overview
BEA WebLogic Server implements the J2EE platform specification, which
includes Servlets, Java Server Pages (JSPs), Enterprise JavaBeans (EJBs),
Java Messaging Service (JMS), and other platform services.
81
Introduction
J2EE services provide access to standard network protocols, databases, and
messaging systems. When developing applications, developers can create,
assemble, and deploy components that use these services.
Web components provide the presentation logic for browser-based and
wireless applications, while EJB components encapsulate business objects
and processes. Components run on J2EE application services, such as Java
Database Connection (JDBC), JMS, and Java Transaction API (JTA), and
are executed in either the WebLogic Web container or EJB container.
Containers provide lifecycle support and services defined by the J2EE
specifications so that developers do not have to be concerned with many of
the details of transactions, security, database connectivity, and other
underlying system infrastructure.
82
Chapter 5. Creating J2EE Applications for BEA WebLogic
Creating Enterprise Java Beans
To create EJBs, you need to:
♦ Define classes using a Class Diagram
♦ Define the database schema using a PDM
♦ Define the O/R mapping
♦ Convert classes to EJBs or create EJBs
♦ Define EJB properties
For more details about how to use the Class Diagram, how to design
database, how to define O/R mappings and how to create EJBs, refer to the
PowerDesigner online documentation.
Defining Classes and Database Schemas
If you have an existing database, you can reverse-engineer it and create a
PDM, generate an Object-Oriented Model (OOM) from the PDM and
generate the default O/R mapping, then convert the classes to EJBs.
For a new application, you can create a Class Diagram in an OOM, generate
the PDM from the OOM and generate the default O/R mapping, then convert
the classes to EJBs.
If you already have a database schema and an object model but they don’t
match, you can manually define the O/R mapping, then convert classes to
EJBs.
The following diagrams show an example PDM and an OOM generated
from it. The name of classes and attributes can be changed to respect Java
naming conventions.
83
Creating Enterprise Java Beans
Defining O/R Mappings
When you generate an OOM from a PDM or a PDM from an OOM, the
default O/R mapping can be generated and saved in the OOM. You can also
manually define complex O/R mappings. The following screenshot shows
the Attribute Mapping of the Customer class, generated from the PDM.
For O/R mappings, PowerDesigner supports:
♦ Mapping a class to one or several tables or views
♦ Mapping an attribute to a column or an expression
♦ Select, insert, update and delete queries for a class
♦ Query for an operation
♦ Mapping an association to a table or reference
♦ Select, insert and delete queries for an association
♦ Stored-procedures
The SQL queries and stored-procedure syntaxes may vary for each
application server.
84
Chapter 5. Creating J2EE Applications for BEA WebLogic
Converting Classes to EJBs
To convert a class into an EJB, you can use the Tools ä Create Enterprise
JavaBean command. The create EJB wizard creates a Component to
represent the EJB:
It transforms a persistent class into a bean class:
It adds a primary key class, adds a remote home interface, a remote
interface, a local home interface, local interface, and creates an EJB-specific
Class Diagram.
Since an EJB has several classes and interfaces, PowerDesigner uses a
Component to represent an EJB:
85
Creating Enterprise Java Beans
It uses a Class Diagram for the definition of classes and interfaces:
You can also create a new EJB using the Component Diagram.
Defining EJB-QL
You can define EJB-QL for finders and ejbSelect methods.
For CMP EJBs, finders are only defined in remote home and local home
interfaces. ejbSelect methods are defined in bean classes.
v To define EJB-QL
1. Create a finder method or an ejbSelect method
2. Open the property sheet of the finder method or the ejbSelect method
3. Define the list of parameters of the method
4. Click on the Implementation tab
5. You can enter EJB-QL in the EJB-QL tab
86
Chapter 5. Creating J2EE Applications for BEA WebLogic
Adding WebLogic Server Support
PowerDesigner can generate standard CMP or BMP EJBs and application
server specific descriptors.
PowerDesigner uses extended model definitions to support additional targets
like an application server, O/R mapping tool, IDE workspace, etc. An
extended model definition (XEM) defines stereotypes, extended attributes,
code generation templates, commands, and options. It can add new code
templates or override the templates of an object language (Java, XML, and
so on); it can also be independent from the object language. The code
generation templates use code templates and macros.
The WebLogic Server Extended Model Definition defines:
♦ WebLogic Server Extended Attributes
♦ WebLogic Server generation templates for EJB descriptors
♦ WebLogic Server deployment commands
♦ WebLogic Server options
v To add WebLogic Server support
1. Ensure that the current model has the Java target language
2. Choose Model ä Extended Model Definitions
3. In the list of Extended Model Definitions, click on the Import button:
4. Select BEA WebLogic Server from the list:
87
Adding WebLogic Server Support
88
Chapter 5. Creating J2EE Applications for BEA WebLogic
Parameterizing WebLogic EJB Container in
PowerDesigner
This section summarizes the PowerDesigner extended attributes that you can
specify to parameterize the deployment of an EJB in WebLogic Server.
All of these extended attributes are used to generate elements in the
deployment descriptor weblogic-ejb-jar.xml. In order to classify them, we
enumerate them under their parent elements in the deployment descriptor.
Extended attributes available for all Enterprise Java Beans
You can define the following extended attributes for every type of Enterprise
Java Bean.
♦ Transaction Descriptor - The transaction-descriptor specifies properties
relating to transactions.
• trans-timeout-seconds (Component extended attribute)
♦ Reference Descriptor - The reference-descriptor specifies a list of
resource-descriptions that describe the resources used in the bean.
♦ Resource Description - The resource-description element is used to map a
resource-ref, declared in the ejb-jar.xml deployment descriptor, to the
JNDI name of the server resource factory it represents.
• res-ref-name (Component extended attribute)
• jndi-name (Component extended attribute)
♦ Resource Environment Description - The resource-env-description
element is used to map a resource-env-ref, declared in the ejb-jar.xml
deployment descriptor, to the JNDI name of the server resource it
represents.
• res-env-ref-name (Component extended attribute)
• jndi-name (Component extended attribute)
♦ EJB Reference Description - The ejb-reference-description is used to
map the JNDI name in the WebLogic server of an EJB that is referenced
by the bean in an ejb-reference.
• jndi-name (Remote Interface extended attribute)
♦ EJB Local Reference Description - The ejb-local-reference-description is
used to map the JNDI name in the WebLogic server of an EJB that is
referenced by the bean in an ejb-local-ref.
• jndi-name (Local Interface extended attribute)
89
Parameterizing WebLogic EJB Container in PowerDesigner
♦ WebLogic Enterprise Bean - The weblogic-enterprise-bean element
contains the deployment information for a bean that is specific to the
WebLogic Server:
• enable-call-by-reference (Component extended attribute)
• run-as-identity-principal (Component extended attribute)
• jndi-name (Remote Home Interface extended attribute)
• local-jndi-name (Local Home Interface extended attribute)
Entity Bean extended attributes
You can define the following extended attributes for entity beans.
♦ Free Pool: The pool element is used to specify various options for
instance pooling.
♦ Entity Cache: The entity-cache element is used to specify various options
for the caching of an entity bean.
• max-beans-in-cache (Component extended attribute)
• idle-timeout-seconds (Component extended attribute)
• read-timeout-seconds (Component extended attribute)
• concurrency-strategy (Component extended attribute)
• cache-between-transaction (Component extended attribute)
♦ Life Cycle: The lifecycle element is used to specify various options for
the management of the lifecycle of entity beans.
• passivation-strategy (Component extended attribute)
♦ Persistence: The persistence element is used to specify persistence
options.
• is-modified-method-name (Component extended attribute)
• delay-updates-until-end-of-tx (Component extended attribute)
• finders-load-bean (Component extended attribute)
♦ Persistence Use: The persistence-use tag stores an identifier of the
Persistence Type to be used for this particular bean.
• type-identifier (Component extended attribute)
• type-version (Component extended attribute)
• type-storage (Component extended attribute)
♦ Entity Clustering: The entity-clustering element is used to specify various
options for how an entity bean will be replicated in a WebLogic cluster.
• home-is-clusterable (Component extended attribute)
90
Chapter 5. Creating J2EE Applications for BEA WebLogic
• home-load-algorithm (Component extended attribute)
• home-call-router-class-name (Component extended attribute)
♦ Invalidation Target: The invalidation-target element specifies a
Read-Only entity EJB that should be invalidated when this
container-managed persistence entity EJB had been modified.
• invalidation-target (Component extended attribute)
♦ Enable Dynamic Queries: The enable-dynamic-queries element must be
present for Dynamic Queries to be enabled for the EJB. Dynamic Queries
are only available for EJB 2.0 CMP beans.
• enable-dynamic-queries (Component extended attribute)
Session Bean extended attributes
There are separate extended attributes for stateful and stateless beans
Stateful Session Bean
The following extended attributes are available for stateful session beans:
♦ Stateful session Cache - The stateful-session-cache element is used to
specify various options for the caching of a stateful session bean.
• max-beans-in-cache (Component extended attribute)
• idle-timeout-seconds (Component extended attribute)
• cache-type (Component extended attribute)
♦ Lifecycle - The lifecycle element is used to specify various options for
the management of the lifecycle of stateful beans.
• passivation-strategy (Component extended attribute)
♦ Persistent store directory - The persistent-store-dir specifies the directory
in the server’s file system where the state of passivated stateful session
beans is to be stored.
• persistent-store-dir (Component extended attribute)
♦ Allow concurrent calls - The allow-concurrent-calls specifies whether a
stateful session bean instance will allow concurrent method calls.
• allow-concurrent-calls (Component extended attribute)
♦ Stateful session clustering: The stateful-session-clustering element is
used to specify various options for how a stateful session bean will be
replicated in a WebLogic cluster.
• home-is-clusterable (Component extended attribute)
• home-load-algorithm (Component extended attribute)
91
Parameterizing WebLogic EJB Container in PowerDesigner
• home-call-router-class-name (Component extended attribute)
• replication-type (Component extended attribute)
Stateless Session Bean
The following extended attributes are available for stateless session beans:
♦ Free pool: The pool element is used to specify various options for
instance pooling.
• max-beans-in-free-pool (Component extended attribute)
• initial-beans-in-free-pool (Component extended attribute)
♦ Stateless clustering: The stateless-clustering element is used to specify
various options for how a stateless session bean will be replicated in a
WebLogic cluster.
• stateless-bean-is-clusterable (Component extended attribute)
• stateless-bean-load-algorithm (Component extended attribute)
• stateless-bean-call-router-class-name (Component extended attribute)
• stateless-bean-methods-are-idempotent (Component extended
attribute)
Message Driven Bean Extended attributes
A message-driven bean is a special kind of EJB that acts as a message
consumer in the WebLogic JMS messaging system. As with standard JMS
message consumers, message-driven beans receive messages from a JMS
Queue or Topic, and perform business logic based on the message contents.
EJB deployers create listeners to a Queue or Topic at deployment time, and
WebLogic Server automatically creates and removes message-driven bean
instances as needed to process incoming messages.
♦ Free pool: The pool element is used to specify various options for
instance pooling
• max-beans-in-free-pool (Component extended attribute)
• initial-beans-in-free-pool (Component extended attribute)
♦ Destination jndi name: The destination-jndi-name element specifies the
JNDI name used to associate a message-driven bean with an actual JMS
Queue or Topic deployed in the in WebLogic Server JNDI tree.
• destination-jndi-name (Component extended attribute)
92
Chapter 5. Creating J2EE Applications for BEA WebLogic
♦ Initial context factory: The initial-context-factory element specifies the
initial contextFactory that the container will use to create its connection
factories. If initial-context-factory is not specified, the default will be
weblogic.jndi.WLInitialContextFactory.
• initial-context-factory (Component extended attribute)
♦ Provider url: The provider-url element specifies the URL provider to be
used by the InitialContext. Typically, this is the host : port and used in
conjunction with initial-context-factory and
connection-factory-jndi-name.
• provider-url (Component extended attribute)
♦ Connection factory jndi name: The connection-factory-jndi-name
element specifies the JNDI name of the JMS ConnectionFactory that the
Message Driven Bean should look up to create its queues and topics. If
this element is not specified, the default will be the
weblogic.jms.MessageDrivenBeanConnectionFactory in config.xml.
• connection-factory-jndi-name (Component extended attribute)
♦ JMS messaging system:
• jms-polling-interval-seconds (Component extended attribute)
• jms-client-id (Component extended attribute)
93
Configuring WebLogic Persistence Services in PowerDesigner
Configuring WebLogic Persistence Services in
PowerDesigner
This section summarizes the PowerDesigner extended attributes that you can
use to configure the deployment of a CMP (Container Manage Persistence)
Entity Bean in WebLogic Server.
Configuring persistence properties for a Component
♦ Automatic Key Generation - WebLogic Server supports an automatic
primary key generation feature for container-managed-persistence
(CMP). By default, PowerDesigner uses DBMS primary key generation
when columns mapped to attributes are auto-incremented, but it lets you
override this by updating the following extended attributes:
• generator-type (Component extended attribute)
• generator-name (Component extended attribute)
• key-cache-size (Component extended attribute)
For more information on WebLogic automatic key generation, see
Automatic Primary Key Generation.
♦ Delay Database Insert Until - The delay-database-insert-until extended
attribute specifies the precise time when a new bean that uses RDBMS
CMP is inserted into the database.
It is advisable to delay the database insert until after the ejbPostCreate
method modifies the persistent fields of the bean. This can yield better
performance by avoiding an unnecessary store operation.
For maximum flexibility, you should avoid creating related beans in your
ejbPostCreate method. This may cause the delay database insert
impossible if database constraints prevent related beans from referring to
a bean that has not yet been created.
• delay-database-insert-until (Component extended attribute)
Specifying Data Sources
A PowerDesigner Data Source is used to identify where the object data is
stored. Usually a Data Source corresponds to a Database. Database schemas
are defined through Physical Data Models. So a Data Source has a list of
Physical Data Models which represents a database schema, where data
handled by objects are stored:
94
Chapter 5. Creating J2EE Applications for BEA WebLogic
A Data Source contains information about the connection to its
corresponding database. By default, the connection is made using ODBC but
Jconnect or JDBC can be used by specifying a connection string.
A default login and password can be specified to fully predefine a
connection to the database.
It is not necessary to predefine a login, a password or a connection in
PowerDesigner using WebLogic persistence services.
An Object Oriented Model can have several Data Sources i.e. several
databases as sources.
PowerDesigner Data Sources correspond to WebLogic JDBC Data sources.
You can redefine the name of a WebLogic Data Source using the
data-source-name extended attribute.
By default, PowerDesigner uses the code of its Data Sources as the
WebLogic data source name.
Note: A PowerDesigner Data Source is required before defining a mapping.
95
Configuring WebLogic Persistence Services in PowerDesigner
Defining a mapping for a Bean
PowerDesigner supports simple O/R mapping and complex O/R mapping.
♦ Simple O/R mapping uses a one-to-one mapping. For example, a class
maps to a table and an attribute maps to a column.
♦ Complex O/R mapping can map a class to several tables and an attribute
to a query.
WebLogic Server can manage persistence of entity beans at the container
level only in the case of simple O/R mapping (i.e. a class maps to only one
table and a class attribute maps to only one table column).
The O/R mapping in the case of Enterprise Java Beans is specified in the
Mapping tab of the Bean Class of the EJB Component. It is used to generate
an O/R mapping descriptor (a XML file) for CMP EJBs in BEA WebLogic
Server, or to generate BMP EJBs.
The Mapping tab describes where and how class instances are stored into the
database (i.e. Data Source). A Data Source specifies the mappings for a
class.
Once a Data Source is selected, the Mapping tab of the Bean class property
sheet contains the following tabbed pages:
♦ Class Sources - composed of a list of source tables or views. It allows
you to select a table or a view from Physical models specified in the data
source.
WebLogic Server supports only one table for each bean class, so there
can only be one table in this list.
♦ Attributes Mapping - Once a table is added in the Class Sources sub-tab,
you can define a mapping for each attribute of the Bean Class and can
map the attribute to a column of the selected table.
96
Chapter 5. Creating J2EE Applications for BEA WebLogic
Specific case for Oracle BLOB or CLOB: For an Oracle database, if the
mapped column is a BLOB or a CLOB, we need to specify a value in the
dbms-column-type extended attribute of the class attribute. This value
can be either Oracle BLOB or Oracle CLOB.
♦ Operation Mapping - Operation mapping allows the user to associate a
SQL query with a class operation for a Data Source. Usually this SQL
query is a select statement used to retrieve an instance, or instances of the
current class according to the operation parameters.
In the Enterprise Java Bean context, SQL queries attached to operations
are used to implement finder or select methods.
In the case of WebLogic server, it is not required to specify a mapping for
operations. But we can define the following extended attributes for finder
or select methods (i.e PowerDesigner Operations):
• weblogic-ql (Operation extended attribute) (see also Using EJB 2.0
WebLogic QL Extension for EJB QL)
• group-name (Operation extended attribute) (see Groups)
• max-elements (Operation extended attribute)
• include-updates (Operation extended attribute) (see Flushing the CMP
Cache)
♦ Criteria - Additional criteria can be specified for the class mapping in
order to define conditions for selecting, updating or deleting class
instances using SQL queries.
Note: This criteria is not used for WebLogic.
♦ Select – The SQL select statement is used to retrieve attribute values of a
class instance from the database using its identifying attributes.
Note: This statement is not used for WebLogic.
♦ Insert – The SQL insert statement is used to create an instance of the
class and saved all of its attributes
Note: This statement is not used for WebLogic.
♦ Update – The SQL update statement is used to update attribute values of
a class instance (note: you cannot update values of identifying attributes)
Note: This statement is not used for WebLogic.
♦ Delete – The SQL delete statement is used to delete a class instance in the
database using its identifying attributes.
Note: This statement is not used for WebLogic.
97
Configuring WebLogic Persistence Services in PowerDesigner
Defining a mapping for a Relationship
Relationships between Entity Beans are represented in PowerDesigner as
associations between Bean classes.
An association mapping defines the navigation between its classes from a
database perspective. A Data Source identifies association mappings. An
Association Mapping contains a list of source references, tables or views.
Usually in case of one-to-one or one-to-many relationships, associations
have a reference as source. In case of many-to-many relationships,
associations have an associative table as source.
From an association mapping, up to six SQL queries are automatically
computed to show how associated class instances can be retrieved from, or
modified in the database. These six SQL queries are respectively:
♦ A select statement for the role A: to retrieve related class A instances for
the role A defined on the class B from the database.
♦ An insert statement for the role A: to associate an instance of the class A
with the class B.
♦ A delete statement for the role A: to delete from the class B the
association with a class A.
♦ A select statement for the role B: to retrieve related class B instances for
the role B defined on the class A from the database.
♦ An insert statement for the role B: to associate an instance of the class B
with the class A.
♦ A delete statement for the role B: to delete from the class A the
association with the class B.
These SQL queries are computed only when their corresponding roles are
navigable. Insert and Delete queries for each role are only computed when
an associative table is defined as source for the association.
As for class mappings, these queries are not used for WebLogic.
For WebLogic, the following extended attributes are available for
associations in order to perform optimizations on relationships between
beans:
♦ group-name-roleA
♦ group-name-roleB
98
Chapter 5. Creating J2EE Applications for BEA WebLogic
Automatic creation of DBMS schemas by WebLogic Server
WebLogic Server supports a feature that allows you to automatically create
tables based on the descriptions in the deployment files and the bean class, if
the table does not already exist.
To let WebLogic create the DBMS schema, you need to define the
create_default_dbms_tables extended attribute in the model properties.
99
Generating and Deploying EJBs in WebLogic server
Generating and Deploying EJBs in WebLogic
server
With PowerDesigner, you can:
♦ Generate EJB source code and EJB deployment descriptors
♦ Generate WebLogic deployment descriptors (weblogic-ejb-jar.xml)
♦ Generate WebLogic RBMS persistence descriptors
(weblogic-cmp-rdbms-jar.xml)
♦ Generate Javadocs
♦ Compile Java code and generate the EJB JAR file
♦ Run the J2EE verifier
♦ Deploy EJBs into a BEA WebLogic server
100
Chapter 5. Creating J2EE Applications for BEA WebLogic
v To generate and deploy EJBs in a BEA WebLogic server
1. Choose Language ä Generate Java Code. . .
2. Specify the directory where you want to generate EJBs. Each package
will generate a subdirectory.
3. On the Targets tab, verify that BEA WebLogic server is selected.
4. [optional] Click the Selection tab to select the model or the packages you
want to generate.
5. Click the Options tab to change the generation options for both EJB and
WebLogic Server. You must specify at least a user name and a password
to establish a connection to the WebLogic Server.
101
Generating and Deploying EJBs in WebLogic server
6. Click the Tasks tab, and select “Build EJB components, Create EJB JAR,
Run J2EE verifier” to create the EJB JAR file and verify that the EJBs are
well defined. In addition, select “Compile container manage persistence
classes, create an EJB JAR file and deploy it into WebLogic Server” to
generate and compile persistence classes and deploy the EJBs in
WebLogic Server.
7. Reorganize the tasks using the up & down arrow buttons to build EJB
components before deploying them in the WebLogic Server.
8. Click on the OK button to generate and deploy EJBs.
9. PowerDesigner generates all the Java source code and deployment
descriptors then shows the list of generated files. You can use an editor to
view the generated files.
102
Chapter 5. Creating J2EE Applications for BEA WebLogic
10. Click on the Close button to execute the commands.
103
Extended Attributes for WebLogic Server
Extended Attributes for WebLogic Server
The following sections list the extended attributes by type
Model and Packages Extended Attributes
This table lists the model and package extended attributes:
Name
Description
deployment-unitname
Identifies the name of the EJB deployment unit. This
name can be specified at deployment time, either with
deploy or console utilities.
Default: the code of the model or the package
Usage: Deployment command
create-defaultdbms-tables
Specifies that, for each CMP Bean listed in the jar at
Deployment time, if there is no Table in the Database
for the Bean, the Container will attempt to CREATE the
Table based on information found in the deployment
files and in the Bean Class.
If TABLE CREATION fails,’a ‘Table Not Found’ Error
will be thrown, and the TABLE must be created by
hand.
This feature should only be used for convenience during
development and prototyping as the Table Schema in
the DBMS CREATE used will be the Containers best
approximation, and a production environment may
require a more precise schema definition.
Default: False
Usage: weblogic-rdbms-jar
database-type
Specifies the database type of the underlying DBMS as
one of the following:
DB2
INFORMIX
ORACLE
SQL_SERVER
SYBASE
POINTBASE
Usage: weblogic-rdbms-jar
104
Chapter 5. Creating J2EE Applications for BEA WebLogic
Data Source Extended Attributes
This table lists the data source extended attributes:
Name
Description
data-source-name
Specifies the JDBC data source name to be used for all
database connectivity for this bean.
Usage: data-source-name
Component Extended Attributes
This table lists the component extended attributes:
Name
Description
allow-concurrentcalls
Specifies that a stateful session bean instance will allow concurrent method calls. When a stateful session
bean instance is currently in a method call, and another
(concurrent) method call arrives on the server, the EJB
specification requires that the server throw a RemoteException. By default, allow-concurrent-calls are false,
and the EJB container will follow the EJB specification.
When this value is set to true, the EJB container will
block the concurrent method call and allow it to proceed
when the previous call has completed.
Default: False
Usage: stateful-session-descriptor
cache-type
Specifies the type of cache:
♦ NRU [default]
♦ LRU
Usage: stateful-session-cache
concurrencystrategy
Specifies how the container should manage concurrent
access to an entity bean.
Usage: entity-cache
105
Extended Attributes for WebLogic Server
Name
Description
cache-betweentransaction
Specifies whether to cache the persistent data of an
entity bean across (between) transactions.
When ‘true’ is specified, caching between transactions
is enabled and long term caching of data is performed.
If ‘false’ is specified, (the default) short term caching
is done, which means that data is only cached during
an individual transaction. The value ‘true’ is only
allowed if the concurrency-strategy for a bean is either
Exclusive, ReadOnly, or Optimistic.
A ReadOnly bean simply ignores the value of the cachebetween-transactions element since long term caching
of readonly data is always performed.
When long term caching is enabled for Exclusive
concurrency, the EJB container must have exclusive
update access to the underlying data, i.e. the data must
not be updated by another application outside of the
EJB container. If an Exclusive bean is deployed in a
cluster, long term caching is disabled automatically
because any node in the cluster may update the data,
making long term caching impossible. (Note: In
releases prior to WLS 7.0, this feature was controlled
using the db-is-shared element.)
When long term caching is enabled for Optimistic
concurrency, the EJB container reuses cached values
from previous transactions, but ensures that updates are
transactionally consistent by checking for optimistic
conflicts at the end of the transaction. In addition,
notifications for updates of optimistic data are broadcast
to other cluster members to help avoid optimistic
conflicts.
Default: False
Usage: entity-cache
connectionfactory-jndi-name
Specifies the JNDI name of the JMS ConnectionFactory
that the Message Driven Bean should look up to create
its Queues and Topics.
Default: (must be declared in config.xml) weblogic.jms.MessageDrivenBeanConnectionFactory
Usage: message-driven-descriptor
106
Chapter 5. Creating J2EE Applications for BEA WebLogic
Name
Description
delay-databaseinsert-until
Specifies the precise time at which a new bean that uses
RDBMS CMP is inserted into the database. By default,
the database insert is done after ejbPostCreate.
Delaying the database insert until after ejbPostCreate
is required when a cmr-field is mapped to a foreignkey column that doesn’t allow null values. In this
case, the cmr-field must be set to a non-null value
in ejbPostCreate before the bean is inserted into the
database. Note that cmr-fields may not be set during
ejbCreate, before the primary key of the bean is known.
It is also generally advisable to delay the database insert
until after ejbPostCreate if the ejbPostCreate method
modifies the persistent fields of the bean. This can yield
better performance by avoiding an unnecessary store
operation.
For maximum flexibility, developers should avoid
creating related beans in their ejbPostCreate method.
This may cause the delay database insert impossible
if database constraints prevent related beans from
referring to a bean that has not yet been created.
Allowed values:
ejbCreate - perform database insert immediately after
ejbCreate
ejbPostCreate - perform insert immediately after ejbPostCreate [default]
Usage: weblogic-rdbms-bean
delay-updatesuntil-end-of-tx
Applicable to entity beans only (both container- and
bean-managed). This optional optimization affects
when changes to a bean’s state are propagated to the
persistent store. If this is set to “True” (which is the
default) updates of the persistent store of all beans in
the transaction will be performed just before the end of
the transaction.
If this is set to “False”, the store update of a bean will
be performed at the conclusion of each method invoke.
Usage: Persistence
destination-jndiname
The destination-jndi-name element is used to associate
a message-driven bean with a JMS Queue or Topic that
has been deployed in the WebLogic JNDI tree.
Usage: message-driven-descriptor
107
Extended Attributes for WebLogic Server
Name
Description
enable-call-byreference
Pass by value is always necessary when the EJB is
called remotely (not from within the server). By setting
enable-call-by-reference to “True”, EJB methods called
from within the same server will pass arguments by
reference. This increases the performance of method
invocation since parameters are not copied.
Usage: weblogic-enterprise-bean
finders-load-bean
Applicable to CMP entity beans only. This optional
optimization affects whether the beans returned by a
finder (or ejbSelect method) are loaded immediately
into the cache before the finder method returns.
If this is set to “True”, the beans will immediately be
loaded into the cache by the finder. If this is set to
“False”, the beans will not be loaded into the cache
until the first invocation of the bean.
The default value is “True”, which generally provides
the best performance.
Usage: Persistence
generator-name
If this is DBMS Key Generation, then this may be
used to specify the Name of the Generator, e.g. for
<generator-type>ORACLE:
<generator-name> would be the name of the ORACLE
SEQUENCE to use. The SEQUENCE is assumed to
already exist in the Database.
If this is <generator-type>NAMED_SEQUENCE_TABLE Key Generation:
Then this would be used to specify the name of the
SEQUENCE TABLE to use.
The NAMED_SEQUENCE_TABLE is assumed to
already exist in the Database with one row.
Usage: automatic-key-generation
108
Chapter 5. Creating J2EE Applications for BEA WebLogic
Name
Description
generator-type
Specifies the Key Generation Method that will be
employed:
‘ORACLE’: use Oracle’s SEQUENCE
‘SQL_SERVER’: use SQL SERVER’s IDENTITY
column
‘NAMED_SEQUENCE_TABLE’: use USER designated SEQUENCE TABLE. User specifies the name of
a DBMS Table with the schema (sequence INT) which
will be used to hold sequence values
Usage: automatic-key-generation
home-call-routerclass-name
Specifies a custom class to be used for routing home
method calls. This class must implement weblogic.rmi.cluster.CallRouter. If specified, an instance of this class
will be called before each method call and be given the
opportunity to choose a server to route to based on the
method parameters. It either returns a server name or
null indicating that the current load algorithm should be
used to pick the server.
Usage: entity-clustering, stateful-session-clustering
home-isclusterable
The valid values of the home-is-clusterable parameter
are “True” and “False.”
If “True,” this bean can be deployed from multiple
servers in a cluster. Calls to the home stub will be
load-balanced between the servers on which this bean
is deployed, and if a server hosting the bean is unreachable, the call will automatically failover to another
server hosting the bean.
Usage: entity-clustering, stateful-session-clustering
home-loadalgorithm
Specifies the algorithm to use for load-balancing between replicas of this home. If this property is not
specified, the algorithm specified by the server property
weblogic.cluster.defaultLoadAlgorithm will be used.
The value of this element must be one of the following:
RoundRobin
Random
Usage: entity-clustering, stateful-session-clustering
109
Extended Attributes for WebLogic Server
Name
Description
idle-timeoutseconds
The cache (see “max-beans-in-cache” above) is
scrubbed of inactive objects after at least this many
seconds. Objects scrubbed are passivated.
Usage: entity-cache, stateful-session-cache
initial-beans-infree-pool
WebLogic EJB maintains a free pool of beans for every
bean class.
This property decides the initial size of the pool
Usage: entity-descriptor\pool, stateless-sessiondescriptor\pool, message-driven-descriptor\pool
initial-contextfactory
Specifies the initial ContextFactory that the container will use to create its connection factories.
If not specified, it will default to weblogic.jndi.WLInitialContextFactory.
Usage: message-driven-descriptor
invalidation-target
Specifies a Read-Only Entity EJB that should be invalidated when this Container-Managed Persistence Entity
EJB has been modified.
Usage: invalidation-target
enable-dynamicqueries
This optional element must be present for Dynamic
Queries to be enabled for the EJB. Dynamic Queries
are only available for EJB 2.0 CMP beans.
Usage: entity-descriptor
is-modifiedmethod-name
Applies to bean managed persistence or EJB 1.1
container-managed persistence entity EJBs. EJB 2.0
entity beans do not need to implement an is-modifiedmethod. The EJB container can automatically detect
which fields were modified in a transaction.
This parameter declares the name of an EJB method
that tells the container whether the bean data has been
modified. The method is called when the bean managed
EJB is stored. If a method is not specified, WebLogic
always assumes that the EJB has been modified and
saves it. Providing a method and setting it as appropriate
will improve performance.
Usage: Persistence
110
Chapter 5. Creating J2EE Applications for BEA WebLogic
Name
Description
jms-client-id
The JMS specification allows JMS consumers to specify
an associated id. This id is necessary for durable
subscriptions to JMS topics.
Usage: message-driven-descriptor
jms-pollinginterval-seconds
Each Message-Driven EJB listens on an associated
JMS destination. If the JMS destination is located on
another WebLogic Server instance or a foreign JMS
provider, it is possible that the JMS destination will
become unreachable. In this case, the EJB container
automatically attempts to reconnect to the JMS Server.
Once the JMS Server is up again, the Message-Driven
EJB can receive JMS messages.
The jms-polling-interval-seconds determines the number of seconds between each attempt to reconnect to the
JMS destination
Usage: message-driven-descriptor
jndi-name
Specifies a jndi-name for a bean, resource or reference.
Usage: resource-description, resource-env-description
key-cache-size
Optional size of key cache.
For <generator-type>ORACLE , this value MUST
match the Oracle SEQUENCE INCREMENT value. If
there is a mismatch between this value and the Oracle
SEQUENCE INCREMENT value, then there will likely
be duplicate key problems.
For <generator-type>NAMED_SEQUENCE_TABLE
, this tells how many keys the Container will fetch in a
single DBMS call
For <generator-type>SQL_SERVER, this value is
ignored
Usage: automatic-key-generation
max-beans-incache
Maximum number of objects of this class that are
allowed in memory.
Objects are kept in an LRU chain, and the ones dropped
from the end of the chain are passivated.
Usage: entity-cache, stateful-session-cache
111
Extended Attributes for WebLogic Server
Name
Description
max-beans-in-freepool
WebLogic EJB maintains a free pool of beans for every
bean class.
This property decides the maximum size of the pool.
Usage: entity-descriptor\pool, stateless-sessiondescriptor\pool, message-driven-descriptor\pool
passivationstrategy
The passivation-strategy can be either “default” or
“transaction”. With the default setting the container
will attempt to keep a working set of beans in the
cache. With the “transaction” setting, the container will
passivate the bean after every transaction (or method
call for a non-transactional invocation).
Usage: entity-descriptor
persistent-store-dir
Specifies the directory in the server’s file system where
the state of passivated stateful session beans is to be
stored.
Usage: stateful-session-descriptor
provider-url
Specifies the URL provider to be put in the Properties
used by the InitialContext. It is typically host:port and
used in conjunction with initial-context-factory and
connection-factory-jndi-name.
Usage: message-driven-descriptor
read-timeoutseconds
Specifies the number of seconds between ejbLoad calls
on a Read-Only entity bean. If read-timeout-seconds is
0, ejbLoad will only be called when the bean is brought
into the cache
Usage: entity-cache
replication-type
Specifies how to replicate stateful session beans in a
cluster. The legal values are:
”InMemory”: The bean will be replicated in memory
across the cluster
”None”: The bean will not be replicated.
Usage: stateful-session-clustering
res-env-ref-name
Specifies the name of a resource environment reference
Usage: resource-env-description
res-ref-name
Specifies the name of a resource factory reference
Usage: resource-description
112
Chapter 5. Creating J2EE Applications for BEA WebLogic
Name
Description
run-as-identityprincipal
Specifies which security principal is to be used for the
run-as identity. This tag is necessary if the role specified in the run-as element of the ejb-jar.xml descriptor
does not map to a single security principal representing
a User in the security realm. This could be true in
two cases. One case is where the role maps to multiple security principals (see security-role-assignment
element). In this case, the run-as-identity-principal
element must be used to specify which of the security
principals you would like to be used. The other case is
where the role maps to a single security principal that
represents a Group in the security realm. In this case
the run-as-identity-principal element must be used to
specify a particular User in the security realm
Usage: weblogic-enterprise-bean
stateless-bean-callrouter-class-name
Specifies a custom class to be used for routing bean
method calls. This class must implement weblogic.rmi.cluster.CallRouter. If specified, an instance of this
class will be called before each method call and be
given the opportunity to choose a server to route to
based on the method parameters. It either returns a
server name or null, indicating that the current load
algorithm should be used to pick the server.
Usage: stateless-clustering
stateless-bean-isclusterable
The valid values of the stateless-bean-is-clusterable
parameter are “True” and “False.”The parameter is applicable only to session beans with a session-type value
of “Stateless” (see ejb-jar.dtd).If home-is-clusterable
is “True” and this parameter is also “true”, calls to
this bean stub will be load-balanced between all the
servers on which this bean is deployed, and if a server
hosting the bean becomes unreachable, the call will
automatically failover to another server hosting the
bean.
Usage: stateless-clustering
113
Extended Attributes for WebLogic Server
Name
Description
stateless-beanload-algorithm
Specifies the algorithm to use for load-balancing between replicas of this bean. If this property is not
specified, the algorithm specified by the server property
weblogic.cluster.defaultLoadAlgorithm will be used.
The legal values of stateless-bean-load-algorithm are:
RoundRobin
Random
WeightBased
Usage: stateless-clustering
stateless-beanmethods-areidempotent
The value of the stateless-bean-methods-are-idempotent
must be either “True” or “False.”
This parameter is applicable only to session beans with
a session-type of “Stateless” (see ejb-jar.dtd).
The value should be set to “True” only if the bean is
written such that repeated calls to the same method
with the same arguments has exactly the same effect
as a single call. This allows the failover handler to
retry a failed call without knowing whether the call
actually completed on the failed server. Setting this
property to “true” makes it possible for the bean stub
to automatically recover from any failure as long as
another server hosting the bean can be reached.
Usage: stateless-clustering
trans-timeoutseconds
Specifies the default timeout for container-initiated
transactions for this bean. If a transaction’s duration is
longer than this value, it will be rolled back.
Usage: transaction-descriptor
type-identifier
Stores the identifier of the Persistence Type that this tag
describes.
Usage: persistence-type
type-storage
Specifies a file (path relative within the ejb-jar file)
which stores data specific to this Persistence Type
Usage: persistence-type
114
Chapter 5. Creating J2EE Applications for BEA WebLogic
Name
Description
type-version
Specifies the version of the Persistence Type to be used
for this particular bean. Most useful when a server
deployment has multiple compatible versions of the
same Persistence Type installed, as the Persistence
Type identifier is not unique between versions
Usage: persistence-type
Association Extended Attributes
This table lists the association extended attributes:
Name
Description
group-name-roleA
Specifies the name of a field group for the role A.
Usage: weblogic-relationship-role
group-name-roleB
Specifies the name of a field group for the role B.
Usage: Weblogic-relationship-role
Interface Extended Attributes
This table lists the interface extended attributes:
Name
Description
jndi-name
Specifies a jndi-name for a bean reference.
This name can be specified on the Remote Home
Interface or Local Home Interface of each deployed
beans.
Usage: ejb-reference-description, ejb-local-referencedescription
Identifier Extended Attributes
This table lists the identifier extended attributes:
Name
Description
group-name
Specifies the name of a field group.
Usage: field-group
115
Extended Attributes for WebLogic Server
Attribute Extended Attributes
This table lists the attribute extended attributes:
Name
Description
dbms-column-type
Can be either OracleBlob or Oracle Clob. This will map
the current field to a Blob or Clob in an Oracle database
(DBMS specific).
Usage: field-map
Operation Extended Attributes
This table lists the model and package extended attributes:
Name
Description
group-name
A field-group name corresponds to a class identifier.
The weblogic-query element is used to associate a fieldgroup with the query if the query retrieves an entity
bean that should be pre-loaded into the cache by the
query.
Usage: weblogic-query
include-updates
Specifies that updates made during the current transaction must be reflected in the result of a query.
If include-updates is set to ‘True’, the container will
flush all changes made by the current transaction to disk
before executing the query. The default value is ‘False’,
which provides the best performance.
Usage: weblogic-query
max-elements
Specifies the maximum number of elements that should
be returned by a multi-valued query. This option is
similar to the maxRows feature of JDBC.
Usage: weblogic-query
weblogic-ql
Specifies a query that contains a WebLogic specific
extension to the ejb-ql language. You should specify queries that only use standard EJB-QL language
features in the ejb-jar.xml deployment descriptor.
Usage: weblogic-query
116
CHAPTER 6
Creating J2EE Applications for IBM
WebSphere 5.0
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with IBM
WebSphere 5.0.
Topic:
page
Introduction
118
Creating EJBs
121
Adding WebSphere 5.0 Support
125
Customizing the O/R Mapping
128
Customizing WebSphere Application Server Generation
130
Customizing WebSphere Application Developer Generation
135
Verifying WebSphere Descriptors
137
Generating WebSphere Application Developer Projects
139
Building and Deploying J2EE Applications Without WSAD
144
Customizing WebSphere Support
147
117
Introduction
Introduction
PowerDesigner supports many features for J2EE applications like Enterprise
JavaBeans (EJBs), Object/Relational mapping (O/R mapping), Servlets,
JSPs, and Web Services for Java.
This chapter explains how to use PowerDesigner to create and generate
EJBs, Servlets and JSPs, use IBM WebSphere Application Developer 5.0
(WSAD) to complete the definition, compile and deploy into IBM
WebSphere Application Server 5.0 (WAS).
Configuration
To follow this chapter, you need:
♦ IBM WebSphere Application Server 5.0 or higher.
♦ IBM WebSphere Application Developer 5.0, a Java IDE or a text editor.
♦ J2EE 1.3 (JDK Standard Edition and Enterprise Edition 1.3.1.01 or
higher).
PowerDesigner
PowerDesigner supports UML object modeling and data modeling. It is
useful for developers to use the same tool to define objects, database
schema, O/R mapping and to generate EJBs. PowerDesigner supports O/R
mapping definition and EJB generation. It supports the EJB 2.0
specification, and can support any application server supporting EJB 2.0.
With PowerDesigner, you can:
♦ Define EJBs using UML class diagrams and component diagrams.
♦ Generate or reverse engineer a database using a Physical Data Model
(PDM).
♦ Define O/R mapping.
♦ Create CMP EJBs, BMP EJBs, Session Beans and Message Driven
Beans.
♦ Generate EJB source code, deployment descriptors.
♦ Generate application server specific descriptors.
♦ Compile Java code and generate the EJB JAR file.
♦ Deploy EJBs into an application server.
118
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
♦ Use an IDE to compile and deploy.
♦ Customize the EJB code generator and the application server support.
Enterprise JavaBeans
Enterprise JavaBean (EJB) is a component model for Java.
There are several types of EJBs: Entity Bean, Session Bean, and Message
Driven Bean.
Entity Bean is used for persistent objects. There are two types of persistence
management:
♦ Container Managed Persistence (CMP) - the persistence is handled by the
application server. An EJB deployer has to define the O/R mapping
information to allow the application server to manage the persistence.
♦ Bean Managed Persistence (BMP) - the persistence management code is
defined in the EJB implementation class.
J2EE 1.3 has a new EJB 2.0 component model. The EJB 2.0 specification
introduces a number of improvements: better definition for CMP, local
interfaces, EJB Query Language (EJB-QL), and ejbSelect methods.
Servlets
A servlet is a Java component for Web Applications.
A servlet can be used to render dynamic web contents, generate web pages
based on the results returned by an EJB or implement Web Services.
PowerDesigner supports servlet creation, generation and deployment.
Java Server Pages
Java Server Pages (JSPs) are HTML pages with Java source code and JSP
specific tags. These are easier to edit and modify than servlets.
When a JSP is deployed into a server, it is transformed into a servlet.
PowerDesigner supports JSP creation, generation and deployment.
IBM WebSphere Application Server 5.0
IBM WebSphere Application Server 5.0 is a J2EE 1.3 compliant application
server. It supports EJB 2.0, Servlets and JSPs.
PowerDesigner provides complete support for IBM WebSphere Application
Server 5.0.
119
Introduction
With PowerDesigner, you can:
♦ Define WebSphere Application Server-specific O/R mapping descriptors.
♦ Define WebSphere Application Server-specific extended attributes.
♦ Generate WebSphere Application Server-specific descriptors including
O/R mapping.
♦ Generate WSAD project files for compiling a J2EE application.
♦ Generate an Ant build.xml file to compile and deploy.
♦ Generate JBuilder project files to compile and deploy.
♦ Compile and deploy a J2EE application directly from PowerDesigner.
IBM WebSphere Application Developer 5.0
IBM WebSphere Application Developer 5.0 (WSAD) is a Java IDE based on
Eclipse. It is designed for creating and deploying J2EE applications for
WebSphere Application Server.
PowerDesigner provides complete support for IBM WebSphere Application
Developer 5.0.
With PowerDesigner, you can:
♦ Generate WSAD EJB projects, Web projects and EAR projects
♦ Generate WSAD project files, classpath files and Struts files
♦ Use WSAD to compile the generated J2EE application and deploy it into
the WebSphere Application Server.
120
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Creating EJBs
To create EJBs, you need to:
♦ Define classes using class diagrams.
♦ Define a database schema using a Physical Data Model (PDM).
♦ Define the O/R mapping.
♦ Convert classes to EJBs or new EJBs.
♦ Define EJB properties.
For more information about how to use class diagrams, how to design a
database, how to define O/R mapping and how to create EJBs, refer to the
core PowerDesigner documentation.
Defining Classes and Database Schema
If you have an existing database, you can reverse engineer the database to
create a Physical Data Model (PDM), generate an Object-Oriented Model
(OOM) from the PDM and generate the default O/R mapping, then convert
classes to EJBs.
For a new application, you can create a class diagram in an OOM, generate
the PDM from the OOM and generate the default O/R mapping, then convert
classes to EJBs.
If you already have a database schema and an Object Model but they do not
match, you can manually define the O/R mapping, then convert classes to
EJBs.
The following diagram shows an example of PDM:
The following diagram shows the OOM generated from the PDM.
121
Creating EJBs
The class and attribute names can be changed to respect Java naming
conventions. When you rename classes, attributes, tables or columns, the
O/R mapping is automatically updated if it is not user-defined.
Note: We recommend that you first create a package in the OOM, then
define classes inside the package. The package is used to create the JAR and
WAR files. Without a package, you may not be able to deploy EJBs into
WebSphere Application Server.
Defining O/R Mapping
When you generate an OOM from a PDM or a PDM from an OOM, the
default O/R mapping can be generated and saved in the OOM. You can also
manually define complex O/R mapping.
For O/R mapping, PowerDesigner supports:
♦ Mapping of a class to one or several tables or views.
♦ Mapping of an attribute to a column or an expression.
♦ Select, insert, update and delete queries for a class.
122
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
♦ Query for an operation.
♦ Mapping of an association to a table or a reference.
♦ Select, insert and delete queries for an association.
♦ Stored-procedures
The syntax of SQL queries and stored-procedures may vary depending on
the application server. For WebSphere Application Server, PowerDesigner
generates WebSphere Application Server specific SQL statements.
Converting classes to EJBs
To convert a class to an EJB, right-click it, and then select the Create
Enterprise JavaBean command or use the Tools ä Create Enterprise
JavaBean command. The create EJB wizard creates a component to
represent the EJB.
It transforms a persistent class into a bean class:
It adds a primary key class, remote home interface, remote interface, local
home interface, local interface, and creates an EJB-specific class diagram.
123
Creating EJBs
Since an EJB has several classes and interfaces, PowerDesigner uses a
component to represent the EJB and a class diagram for the definition of the
EJB related classes and interfaces. The following diagram shows the UML
component diagram:
The following diagram shows the Customer EJB specific class diagram:
You can also create a new EJB using the component diagram.
124
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Adding WebSphere 5.0 Support
PowerDesigner can generate standard CMP or BMP EJBs, Servlets, JSPs,
and application server specific descriptors.
Adding WebSphere 5.0 Profile
PowerDesigner uses an Extended Model Definition file (.xem) to support
additional targets, such as an application server, O/R mapping tool, IDE, etc.
An Extended Model Definition defines stereotypes, extended attributes, code
generation templates, commands and options. It can add new code templates
or override the templates of an object language (Java, XML, and so on); it
can also be independent from the object language. The code generation
templates use code templates and macros.
The WebSphere 5.0 profile defines:
♦ Templates for WebSphere Application Server specific descriptors.
♦ Templates for WebSphere Application Developer project files.
♦ Extended attributes for customizing the generation.
♦ Generation options.
♦ Command tasks for deployment from PowerDesigner.
v To add WebSphere 5.0 support
1. Verify that the current model is targeted for Java.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click on the Import tool
125
Adding WebSphere 5.0 Support
4. Select IBM WebSphere 5.0 from the list:
5. Click OK. The profile is imported into the current model.
Defining WebSphere Environment Variables
If you plan to use WebSphere Application Developer 5.0 to compile and
deploy J2EE applications, you should define the WSAD_HOME
environment variable to indicate the WSAD home directory. You can define
it as a Windows environment variable or as a PowerDesigner variable. If you
define a Windows environment variable, you will have to restart
PowerDesigner for this change to take effect.
The WSAD_HOME variable should not end with a \. For example, use
C:\WebSphereStudio instead of C:\WebSphereStudio\.
v To define WSAD_HOME as a PowerDesigner variable
1. Select Tools ä General Options.
2. Select the Variables category.
3. Add a WSAD_HOME variable.
4. In the WSAD_HOME variable value box, enter the WSAD home
directory.
If you plan to compile and deploy using another IDE or PowerDesigner, you
should define the WebSphere Application Server home directory
environment variable WAS_HOME as a Windows environment variable or
as a PowerDesigner variable. If you define it as a Windows environment
variable, you will have to restart PowerDesigner for this change to take
effect.
126
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
v To define WAS_HOME as a PowerDesigner variable
1. Select Tools ä General Options.
2. Select the Variables category.
3. Add a WAS_HOME variable.
4. In the WAS_HOME variable value box, enter the WAS home directory.
Activating WSAD Project Files Generation
If you plan to use WebSphere Application Developer 5.0 to compile and
deploy J2EE applications, you must activate the WSAD project files
generation.
v To activate the WSAD project files generation
1. Select Language ä Generate Java Code.
2. Click the Options tab and set the value of the “Generate WebSphere
Application Developer 5.0 project files” option to true.
3. Click Apply to save this option.
4. Click Cancel to close the window.
127
Customizing the O/R Mapping
Customizing the O/R Mapping
Each application server may use a different syntax for O/R mapping SQL
queries, variables and stored-procedures.
WebSphere Application Server supports simple one-to-one mapping. You
cannot define complex mapping or your own select, insert, update and delete
queries.
v To verify the O/R mapping
1. Open the property sheet of a bean class.
2. Click on the Mapping tab.
3. Verify the class mapping and attributes mapping
Defining EJB-QL
You can define EJB-QL for finders and ejbSelect methods.
For CMP EJBs, finders are only defined in remote home and local home
interfaces. ejbSelect methods are defined in bean classes.
v To define EJB-QL
1. Create a finder method or an ejbSelect method in the remote home
interface or the local home interface.
2. Open the property sheet of the finder method or the ejbSelect method.
3. Define the list of parameters of the method.
128
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
4. Click on the Implementation tab, and select the EJB-QL sub-tab:
5. You can type EJB-QL on this tab.
129
Customizing WebSphere Application Server Generation
Customizing WebSphere Application Server
Generation
PowerDesigner generates all the WebSphere server specific files for
WebSphere Application Server:
♦ META-INF\application.xml - J2EE application descriptor file with
modules IDREF
♦ META-INF\ejb-jar.xml - EJB deployment descriptor with objects Ids
♦ WEB-INF\web.xml - web application descriptor with objects Ids
♦ META-INF\ibm-ejb-jar-bnd.xml - EJB binding file
♦ META-INF\Table.ddl - DDL for database creation
♦ META-INF\backends\%DBMSID%\%databaseName%.dbxmi Database definition file
♦ META-INF\backends\%DBMSID%\%databaseName%_
%schemaName%.schxmi - Database schema definition file
♦ META-INF\backends\%DBMSID%\%databaseName%_
%schemaName%_%tableCode%.tblxmi - Table definition file
♦ META-INF\backends\%DBMSID%\Map.mapxmi - O/R mapping
descriptor
♦ META-INF\backends\%DBMSID%\Table.ddl - DDL for creating the
database
Where:
♦ %DBMSID% ID of the back-end DBMS. For example,
DB2UDBNT_V72_1
♦ %databaseName% - Database name
♦ %schemaName% - Schema name
♦ %tableCode% - Table name
Customizing Database Support
WebSphere Application Server supports the following databases:
♦ DB2UDBNT_V61, DB2UDBNT_V71, DB2UDBNT_V72,
DB2UDBNT_V8
130
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
♦ DB2UDBOS390_V6, DB2UDBOS390_V7
♦ DB2UDBAS400_V4, DB2UDBAS400_V5
♦ DB2FAMILY
♦ INFORMIX_V73, INFORMIX_V92, INFORMIX_V93
♦ SYBASE_V1192, SYBASE_V12, SYBASE_V125
♦ ORACLE_V8, ORACLE_V9
♦ MSSQLSERVER_V7, MSSQLSERVER_V70
♦ MYSQL_V323
♦ CLOUDSCAPE_V50
♦ INSTANTDB_V326
SQL92, SQL99
PowerDesigner does not support the following databases:
♦ CLOUDSCAPE_V50
♦ INSTANTDB_V326
v To define the type, name, and schema name of the target
database
1. Select Model ä Data Sources.
2. Open the property sheet of the first data source.
3. Click the Extended Attributes tab, and then click the WebSphere sub-tab
at the bottom of the list.
131
Customizing WebSphere Application Server Generation
4. Enter values for the following properties:
Extended Attribute
Description
DatabaseName
Specifies the database name.
Default value: PDM Code or the PDM database object
Code
DatabaseType
Specifies the database type.
Default value: <Default>.
If you do not select the database type, PowerDesigner tries
to determine it using the DBMS type of the PDM.
SchemaName
Specifies the database schema name.
Default value: NULLID
Customizing Deployment Descriptors Generation
You can use Extended Attributes to customize WebSphere server descriptors
generation for:
♦ Jar file name
♦ War file name
♦ Ear file name
♦ EJB JNDI name
♦ JMS message acknowledge mode
♦ JMS destination type
♦ JMS message selector
♦ JMS subscription durability
♦ JMS listner port name
Model Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
EarFileName
Specifies the J2EE application .EAR file name.
Default Value: %Code%.ear
132
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Package Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
JarFileName
Specifies the EJB .JAR file name.
Default value: %Code%.jar
WarFileName
Specifies the web application .WAR file name.
Default value: %Code%.war
contextRoot
Specifies the relative context path within the web
server for the web application (servlets and JSPs).
distributable
Specifies that the web application is to be deployed
into a distributed servlet container.
sessionTimeout
Specifies the default session timeout interval for all
sessions created in the web application.
Default value: 0
Component Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
JNDIName
Specifies the EJB JNDI name.
Default value:
ejb/%PackageCode%/%RemoteHomeCode%
JMSAcknowledgeMode
Specifies the JMS message acknowledge mode
JMSDestinationType
Specifies the JMS destination type
JMSMessageSelector
Specifies the JMS message selector
JMSSubscriptionDurability
Specifies the JMS subscription durability
JMSListnerPortName
Specifies the JMS listner port name
The following screen shows extended attributes for a Message-Driven Bean:
133
Customizing WebSphere Application Server Generation
The following screen shows extended attributes for a WebSphere
Application Server:
134
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Customizing WebSphere Application Developer
Generation
PowerDesigner generates all the WSAD specific project files for WebSphere
Application Developer:
♦ .project file - for EJB project
♦ .classpath file - for EJB project
♦ .project file for - Web project
♦ .classpath file for - Web project
♦ .websettings file for - Web project
♦ Web Content\theme\Master.css - Master style sheet
♦ Web Content\WEB-INF\lib\*.jar - Related JAR files
♦ Web Content\WEB-INF\ibm-web-bnd.xmi - Web binding file
♦ Web Content\WEB-INF\ibm-web-ext.xmi - Web extension file
♦ Web Content\WEB-INF\struts-bean.tld - Struts bean file
♦ Web Content\WEB-INF\struts-config.xml - Struts configuration file
♦ Web Content\WEB-INF\struts-html.tld - Struts HTML file
♦ Web Content\WEB-INF\struts-logic.tld - Struts logic file
♦ Web Content\WEB-INF\struts-template.tld - Struts template file
♦ .project - for EAR project
PowerDesigner generates a WSAD project for each EJB, Web and EAR
archive.
You can use the generated WSAD projects to edit Java code descriptors,
compile the code, generate deployment code and deploy the application into
a server.
Customizing WSAD Project Files Generation
You can use extended attributes to customize WSAD project files generation
for:
♦ EJB project name
135
Customizing WebSphere Application Developer Generation
♦ Web project name
♦ EAR project name
♦ Use Struts
Model Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
WSAD_EARProjectName
Specifies the WSAD enterprise application
project name.
Default value: Model code. If the model contains both EJBs and Web components, the
project name will have an EAR suffix
Model Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
WSAD_EJBProjectName
Specifies the WSAD EJB project name.
Default value: Package or Model code. If the
same model or package contains both EJBs and
Web components, the project name will have an
EJB suffix
WSAD_WebProjectName
Specifies the WSAD Web project name.
Default value: Package or Model code. If the
same model or package contains both EJBs and
Web components, the project name will have a
Web suffix
WSAD_UseStruts
Specifies the use of Apache Struts in Servlets or
JSPs.
Default value: false
Note: By default, a single .jar file and a single .war file will be generated per
OOM model. You can decide which package should generate a separate .jar
or .war file by assigning the archive stereotype to this package.
If you decide to use Apache Struts for JSPs or Servlets, you must set the
WSAD_UseStruts extended attribute to true for the model or the package
that will generate a .war file.
136
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Verifying WebSphere Descriptors
In addition to the standard J2EE application, EJB and web descriptors,
WebSphere Application Server and WSAD use many other descriptors, all
of which are in XML format.
Before generating the code for WebSphere Application Server and WSAD,
you can preview the most important descriptors to verify that they are
properly defined.
v To preview the descriptors
1. Open the property sheet of the package or the model that defines an
archive.
2. Click the Preview tab, where you can verify the J2EE application
descriptor and the EJB deployment descriptor:
or the Web application deployment descriptor and the O/R mapping
descriptor:
137
Verifying WebSphere Descriptors
138
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Generating WebSphere Application Developer
Projects
With PowerDesigner, you can:
♦ Generate EJBs, Servlets and JSPs source code and deployment
descriptors.
♦ Generate WebSphere Application Server descriptors.
♦ Generate WebSphere Application Developer projects.
You can use WSAD to complete the components definition, compile the
code, generate deployment code and deploy the application into WebSphere
server.
Generating the Java Code and WSAD Projects
v To generate the Java code and WSAD projects from PowerDesigner
1. Select Language ä Generate Java Code.
2. Specify the directory where you want to generate the WSAD projects.
Each WSAD project will be a subdirectory of this directory
3. Click the Targets tab, and verify that IBM WebSphere 5.0 is selected.
4. [optional] Click the Selection tab, and select all the packages, classes and
interfaces you want to generate.
5. Click the Options tab, and ensure that the value of the “Generate
WebSphere Application Developer 5.0 project files” option is set to true:
139
Generating WebSphere Application Developer Projects
6. Click on OK to generate the Java code and WSAD projects.
PowerDesigner generates all the Java source code, deployment descriptors
and WSAD project files, and then displays the list of generated files. You
can use an external editor to view the generated files:
Importing Generated WSAD Projects
140
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
v To import a generated WSAD project into the WSAD workspace
1. Start WSAD.
2. Select File ä Import to run the import wizard.
3. Select “Existing Project into Workspace” as the import source.
4. Click the Next button.
5. In the Import Project page, use the browse window to select a generated
WSAD project (a subdirectory in the generation directory).
6. Click Finish to import the project:
You need to import all the EJB, Web and EAR projects.
Building an EJB Project
For an EJB project, you can use WSAD to edit the Java code, and edit the
deployment descriptors (add security roles, etc).
You do not need to modify the O/R mapping definition since PowerDesigner
generates all the O/R mapping metadata from the OOM and PDM models
and can generate an optimized database from the PDM. If you use WSAD to
generate the default O/R mapping and the database creation DDL, you will
only have a default database schema that may not be optimized.
141
Generating WebSphere Application Developer Projects
v To build the EJB project
1. Right-click the EJB project.
2. Select Build Project or Rebuild Project.
v To validate the EJB project
1. Right-click the EJB project.
2. Select Run Validation.
Prior to the deployment, you will need to generate WebSphere server side
code for EJBs implementation.
v To generate server side code
1. Right-click the EJB project.
2. Select Generate ä Deploy and RMIC Code.
This command will run the validation, generate all the server side code
and compile the code.
To deploy an EJB project, you need to use the J2EE EAR project to deploy
the application.
Building a Web Application Project
For a Web project, you can use WSAD to edit the Java code, modify the JSP
pages, and edit the deployment descriptors.
v To build a Web project
1. Right-click the Web project.
2. Select Build Project or Rebuild Project.
v To validate a Web project
1. Right-click the Web project.
2. Select Run Validation.
To deploy a Web project, you need to use the J2EE EAR project to deploy
the application.
Building a J2EE Application Project
Instead of building EJB and Web projects one-by-one , you can build them at
once by using the J2EE application project.
142
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
v To build a J2EE application project
1. Right-click the J2EE application project.
2. Select Build Project or Rebuild Project.
v To validate a J2EE application project
1. Right-click the J2EE application project.
2. Select Run Validation.
Prior to the deployment, you need to generate WebSphere server side code
for EJBs implementation.
v To generate the server side code
1. Right-click the J2EE application project.
2. Select Generate Deploy Code.
This command will run the validation, generate all the server side code
and compile the code.
Deploying a J2EE Application
Before deploying an application, you need to configure one or several
WebSphere servers.
v To deploy a J2EE application
1. Open the Server Perspective.
2. In the Server Configuration view, right-click the server.
3. Select the Add popup menu.
4. In the popup menu, select the name of the J2EE application.
5. In the Servers view, right-click the server.
6. Select Publish.
For more information about deploying the application, see the WSAD
documentation.
143
Building and Deploying J2EE Applications Without WSAD
Building and Deploying J2EE Applications
Without WSAD
If you do not have WSAD or you cannot use WSAD, you can use Eclipse,
an IDE that supports Ant or PowerDesigner to build, package and deploy
J2EE application into WebSphere server.
Building and Deploying J2EE Applications Using Eclipse
You can use Eclipse to build, package and deploy a J2EE application into
WebSphere server.
You will need to download and install the latest version of the Eclipse
runtime and the JDT from the www.eclipse.org web site.
v To generate Eclipse project files
1. Add the Eclipse profile to your environment by importing the Eclipse
extended model definition into your OOM.
2. Ensure that the WAS_HOME environment variable is defined to indicate
the WebSphere server home directory.
3. Ensure that the ECLIPSE_HOME environment variable is defined to
indicate the Eclipse home directory.
4. Ensure that the ANT_HOME environment variable is defined to indicate
the Apache Ant home directory.
5. Select Language ä Generate Java Code.
An Eclipse project file and an Ant build.xml will be generated together with
the Java source code, and descriptors. You can import the generated project
into Eclipse, then use the Eclipse JDT to develop and compile Java files and
use the Ant build.xml file to deploy the J2EE application into WebSphere
server.
Building and Deploying J2EE Applications Using Ant
You can use an IDE or text editor to modify the Java source code, and then
use the generated Ant build.xml to build, package and deploy J2EE
application into WebSphere server.
144
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
v To generate an Ant build.xml file
1. Ensure that the WAS_HOME environment variable is defined to indicate
the WebSphere server home directory.
2. Ensure that the ANT_HOME environment variable is defined to indicate
the Apache Ant home directory.
3. Select Language ä Generate Java Code.
4. In the Options tab, enable Ant generation.
When you generate the Java code, an Ant build.xml file will be generated.
You can use an IDE or text editor to modify the Java source code then use
the Ant build.xml file to build, package and deploy into WebSphere server.
For more information on how to generate the Ant build.xml file, see the Ant
chapter.
Generating and Deploying J2EE Applications from PowerDesigner
You can generate the Java code, compile the code, package and deploy into
WebSphere server from PowerDesigner.
v To deploy a J2EE application into WebSphere server from PowerDesigner
1. Ensure that the WAS_HOME environment variable is defined to indicate
the WebSphere server home directory.
2. Select Language ä Generate Java Code.
3. Click the Options tab, and disable the “Generate WebSphere Application
Developer 5.0 project files” option.
4. Click the Tasks tab, and select the “Java: Build components, Create EJB
JARs, Web Application WARs and EAR” and “WebSphere: Deploy the
EAR file in WebSphere Application Server” tasks. The deploy task
should come after the build task:
145
Building and Deploying J2EE Applications Without WSAD
PowerDesigner will use the ejbdeploy.bat command to generate the
server side code and the wsadmin.bat to deploy the J2EE application.
146
Chapter 6. Creating J2EE Applications for IBM WebSphere 5.0
Customizing WebSphere Support
The WebSphere Application Server and WebSphere Application Developer
support in PowerDesigner is defined in the WebSphere profile. You can
customize it if necessary.
v To customize WebSphere support
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. Double-click IBM WebSphere 5.0 in the List of Extended Model
Definitions.
3. Use the Extended Model Definition Editor to modify the file generation
templates, the extended attributes, the options and the commands:
147
Customizing WebSphere Support
148
CHAPTER 7
O/R Mapping Modeling
About this chapter
Contents
This chapter explains how to use PowerDesigner to support standard O/R
mapping technology.
Topic:
page
Overview
150
Applying Top-Down Approach
151
Applying Bottom-Up Approach
169
Meet in the Middle
172
149
Overview
Overview
PowerDesigner not only supports object-oriented modeling and data
modeling, but also supports O/R Mapping modeling between OOM and
PDM objects.
The following table lists object mappings in these two model types:
OOM Element
PDM Element
Domain
Domain
Class (only if the Persistent and
Generate checkboxes are selected
in the class property sheet)
Table
Attribute Column (only if the
Persistent checkbox is selected in
the attribute property sheet)
Column
Identifier
Identifier
Association
Reference or table
Association class
Table with two associations between
the end points of the association class
Generalization
Reference
You can define mappings between these two model types in any of the
following ways:
♦ Top-down approach – define classes, generate database schema and O/R
mapping
♦ Bottom-up approach – reverse engineer a database or define new database
schema, generate classes and O/R mapping
♦ Meet-in-the-middle – manually define O/R mapping using the visual
mapping editor
150
Chapter 7. O/R Mapping Modeling
Applying Top-Down Approach
In order to apply well-defined O/R Mapping strategies, PowerDesigner
provides default transformation rules for model generation. We will
introduce these rules in detail in the following sections. You can also
customize transformation using persistence settings and generation options.
v To generate a PDM from an OOM
1. Create the OOM, defining object-oriented model elements, persistent
classes, inheritance links and associations etc, to describe the static
features of your model domain.
2. Define transformation settings to apply transformation rules. See “Basic
transformation” on page 152s.
3. Define generation options.
4. On the General tab, specify the DBMS type, the name and code of the
generated PDM. You can also click the Update existing Physical Data
Model radio button to update the existing PDM. This option allows you
to do round trip generation.
5. On the Detail tab, click the O/R Mapping checkbox, in order for
PowerDesigner to automatically generate O/R Mapping between the
151
Applying Top-Down Approach
PDM and the OOM. You can also specify table prefix that will apply to
all the generated tables.
6. Select the OOM objects that you want to transform into PDM objects on
the Selection tab.
Basic transformation
There are two types of classes:
♦ Entity classes, that have their own database identity, mapping definition
and life cycle
♦ Value type classes that depend on entity classes. They are also called
component classes
Entity class transformation
You can transform a class into a table. To do so you first must select the
Persistent option in the Detail tab of the class property sheet. Then, you can
define the persistent type in the Persistent groupbox:
152
Chapter 7. O/R Mapping Modeling
Persistent groupbox
Property
Description
Generate table
The class is generated in a separate table
Migrate columns
The class is not generated ; its attributes and associations are migrated to the generated parent or child
table
Generate ADT
The class is generated as an abstract data type, a
user-defined data type that can encapsulate a range
of data values and functions. This option is not used
when you define O/R Mapping.
Value type
No separate table will be generated for the class;
its persistent attributes will be transformed into
columns that are embedded in other table(s)
Persistent classes are classes with one of the following persistent types:
♦ Generate table. Classes with this persistent type are called Entity classes.
♦ Migrate column. Classes with this persistent type are called Entity
classes.
♦ Value type. Classes with this persistent type are called Value type classes.
153
Applying Top-Down Approach
Entity classes with Generate table persistent type will be transformed into
separate tables. No separate table will be generated for Entity classes with
Migrate columns persistent type. This persistent type is just used in
inheritance transformation.
Only one table can be generated for each entity class with Generate table
persistence type. However, you can map an entity class to multiple tables.
For more information about mapping an entity class to multiple tables, see
“Defining entity class mapping” on page 173.
You can also customize the code of the generated tables in the Code box in
the Persistent groupbox. Class mapping will be generated for the persistent
class.
Attribute transformation
You can transform an attribute into a column. To do so you must select the
Persistent option in the Detail tab of the attribute property sheet.
Persistent attributes can have simple data types or complex data types.
Simple data type
154
The simple data type is based on standard data types, such as int, float,
String, Date etc. Each persistent attribute is transformed into one column. Its
data type is converted into an internal standard data type. The internal
Chapter 7. O/R Mapping Modeling
standard data type is then mapped to a specific data type of the physical
database.
The following table list the correspondence between simple data types
supported Java and internal standard data types.
Java data type
Standard data type
Description
String
VA254
Variable character with 254
max length
Date
DT
Date time
Object
ANY
Default data type
Boolean
BL
Two opposing values
(true/false; yes/no; 1/0)
Integer
I
32 bit integer
Short
SI
16 bit integer
Long
LI
64 bit integer
Float
F
32 floating point numbers
Double
N
Numbers with a fixed decimal
point
Character
A1
Character with 1 length
Byte
BT
256 values
Number
N
Numbers with a fixed decimal
point
StringBuffer
TXT
Character strings
Thread
ANY
Default data type
ThreadGroup
ANY
Default data type
Process
ANY
Default data type
The following table list the correspondence between simple data types
supported C# and internal standard data types.
C# data type
Standard data type
Description
Array
ANY
Default data type
155
Applying Top-Down Approach
C# data type
Standard data type
Description
Boolean
BL
Two opposing values
(true/false; yes/no; 1/0)
Byte
BT
256 values
Char
TXT
Character strings
DateTime
DT
Date time
TimeSpan
T
Time
Decimal
DC
Decimal
Double
LF
64 floating point numbers with
double precision
Int16
SI
16 bit integer
Int32
I
32 bit integer
Int64
LI
64 bit integer
Object
ANY
Default data type
SByte
BT
256 values
Single
F
32 floating point numbers
String
VA254
Variable character string with
254 max length
UInt16
SI
16 bit integer
UInt32
I
32 bit integer
UInt64
LI
64 bit integer
These standard data types will be translated into data types supported by the
DBMS of your PDM. You can refer to the database definition for the
translation rules.
156
Chapter 7. O/R Mapping Modeling
You can also customize the code of the generated data types in the Code box
of the Persistent groupbox. You can also customize the code of the generated
columns.
Attribute mapping will be generated for the attribute.
Complex data type
The complex data type is based on a classifier. The transformation depends
on the persistent settings of the classifier. The classifier is generally used as a
value type class. For more information, see “Value type transformation” on
page 157.
Identifier transformation
Identifiers of persistent classes, which generation type is not set to Value
type are transformed into table keys.
Primary identifiers are transformed into primary keys or part of primary
keys. Persistent attributes contained in primary identifiers are transformed
into columns of primary keys.
+ For more information about the different types of primary identifier
mappings, see the “Defining primary identifier mapping” on page 177
section.
Value type transformation
PowerDesigner supports fine-grained persistence model. Multiple classes
157
Applying Top-Down Approach
can be transformed into single table.
Given two classes, Person and Address . The class Person owes one
attribute address whose data type is Address :
These classes can be transformed into one table if the transformation type of
Class Address is set to Value type. The columns transformed from persistent
attributes of the class Address are embedded into the table transformed from
the class Person .
Association transformation
Association defined between entity classes will be transformed into
reference keys or reference tables. Associations with Value type classes as
target or source will be ignored.
Transformation rules differ according to the type of the association:
158
Chapter 7. O/R Mapping Modeling
♦ One-to-one
♦ One-to-many
♦ Many-to-many
One-to-one association transformation
For each unidirectional one-to-one association, one foreign key will be
generated with the same direction as the association. The primary key of
parent table will also migrate into child table as its foreign key.
Given two entity classes, Person and Account , and a one-to-one
association defined between them. The association is unidirectional and
navigates from Person to Account :
The generated reference key will be the following:
The generated foreign key has the same direction as the association
direction.
159
Applying Top-Down Approach
If the association is bidirectional (can navigate in two ways), two foreign
keys with both directions will be generated since PowerDesigner do not
know which one of the generated table is the parent table or the child table.
You need to delete one manually.
One-to-many association transformation
Unlike one-to-one associations, just one foreign key will be generated for
each one-to-many association, whatever its direction (bidirectional or
unidirectional). The reference key navigates from the table generated from
the entity class on multiple-valued side to the table generated from the entity
class on single-valued side.
Given a one-to-many association defined between the class Customer and
the class Order :
The generated foreign key will be the following:
PowerDesigner can generate a primary key of a parent table as part of the
primary key of the child table.
160
Chapter 7. O/R Mapping Modeling
To do so, you need to define the association as composition with the class on
single-valued side containing the class on multiple-valued side:
The association is defined as composition association with the class
Customer containing the class Order . The association looks like the
following:
161
Applying Top-Down Approach
The generated tables and reference look like the following:
The primary key of the table Customer migrates into the table Order as part
of its primary key.
For most O/R Mapping frameworks, one unidirectional one-to-many
association will usually be mapped to a middle table and two references
navigating from the middle table to the tables mapped by the two entity
classes.
+ For more information, see the “Defining one-to-many association
mapping” on page 183 section.
Many-to-many association transformation
Each many-to-many association will be transformed into one middle table
and two reference keys that navigate from the middle table to the tables
generated from the two entity classes.
Given the many-to-many association defined between the class Employee
and the class Title :
162
Chapter 7. O/R Mapping Modeling
The generated middle table and reference keys will look like the following:
Association class transformation
Associations can have association classes.
Regarding O/R Mapping, association class is only meaningful for
many-to-many associations. Persistent attributes in the association entity
class will be transformed into columns of the middle table.
Given the example listed in the Many-to-many transformation section; we
now define one association class to hold ultra information for the association:
163
Applying Top-Down Approach
The generated middle table and reference keys will be the following:
Other transformation settings
There are some other settings that can affect association transformation.
The minimal multiplicity of association ends can affect the Mandatory
property of the generated reference keys.
For one-to-one associations if the minimal multiplicity of side that is
transformed to parent table is more than one, the generated foreign key will
be mandatory.
For one-to-many associations, if the minimal multiplicity on single-valued
side is more than one, the generated foreign key will be mandatory.
Inheritance transformation
PowerDesigner supports three mapping strategies for inheritance
persistence:
♦ Table per class hierarchy. All the classes in a hierarchy are mapped to a
single table. The table has a column that serves as a “discriminator
164
Chapter 7. O/R Mapping Modeling
column”. The value of this column identifies the specific subclass to
which the instance that is represented by the row belongs.
♦ Joined subclass. The root class of the class hierarchy is represented by a
single table. Each subclass is represented by a separate table. This table
contains the fields that are specific to the subclass (not inherited from its
super class), as well as the column(s) that represent its primary key. The
primary key column(s) of the subclass table serves as a foreign key to the
primary key of the super class table.
♦ Table per class. Each class is mapped to a separate table. All properties
of the class, including inherited properties, are mapped to columns of the
table for the class.
Each strategy has its pros and cons. You can select the one to apply
according to your own needs. You can also apply mixed strategies. But you
should be aware that mixed strategy is not well supported by persistence
frameworks.
Given the following inheritance hierarchy:
We will describe in the following sections how to apply these mapping
strategies in transformation.
Applying table per class hierarchy strategy
In order to apply this kind of strategy, you should set transformation type of
the root class to Generate table and the transformation type of other classes
in the class hierarchy to Migrate column .
For each class hierarchy, a discriminator is needed to distinguish between
different class instances. You need to select one of the attributes of the root
class in the Specifying Attribute list located in the property sheet of one of
165
Applying Top-Down Approach
the children inheritance links of the root class. The attribute will be
transformed into a discriminator column. In the following example, we
define one extra attribute shapeType in Shape and select it as discriminator
attribute:
The generated table will look like the following:
166
Chapter 7. O/R Mapping Modeling
Applying joined subclass strategy
In order to apply this kind of strategy, you should set the transformation type
of all the classes to Generate table . You can also define discriminator for
this type of strategy. However, it is optional.
The generated tables will look like the following:
Applying table per class strategy
In order to apply this kind of strategy, you should set the transformation type
of leaf classes to Generate table and the transformation type of the other
classes in the hierarchy to Migrate column .
PowerDesigner will only generate the tables for leaf classes. If you want to
map other classes to tables, you need to create them manually.
Applying mixed strategy
You can apply more than one strategy in the same inheritance hierarchy.
The transformation of entity classes with the Generate table transformation
167
Applying Top-Down Approach
type will not change. But transformation of entity classes with Migrate
column transformation type will be slightly different. If entity classes with
this kind of transformation type have both their super-class and sub-classes
with the Generate table transformation type, the columns transformed from
their persistent attributes will be migrated into tables transformed from
sub-classes. The migration to sub-classes has higher priority.
168
Chapter 7. O/R Mapping Modeling
Applying Bottom-Up Approach
Bottom-up approach is much more like top-down approach, except that
transformation happens in reverse direction.
The following limitations exist when you transform an object-oriented
model into a data model:
♦ One table just can be transformed into one class.
♦ Reference keys just can be transformed into bidirectional associations.
♦ You cannot generate inheritance links from reference keys and tables.
So you have to customize the generated OOM to meet your needs. You
should define some mappings manually by following the instructions in the
Meet-in-the-middle section.
There are no transformation settings for PDM elements.
v To generate an OOM from a PDM
1. Create a new PDM from scratch or by reverse engineering an existing
database.
2. On the General tab define generation options: object language, name and
code for the target OOM.
169
Applying Bottom-Up Approach
3. Select the O/R Mapping option on the Detail tab.
4. Select the PDM elements in which OOM objects will be transformed on
the Selection tab.
Basic transformation
Selected tables are transformed into persistent entity classes.
Columns are transformed into persistent attributes.
Keys are transformed into identifiers.
Primary keys are transformed into primary identifiers.
There are no transformation settings for this kind of transformation.
Reference key transformation
Reference keys are transformed into associations.
Generated associations are all bidirectional. You have to customize them
according to your own needs.
Unlike associations, reference keys have no multiplicity on their ends. They
just have cardinality. The default value is 0..*. You have to customize it in
order to generate different kinds of association.
170
Chapter 7. O/R Mapping Modeling
Generating many-to-many association is just the reverse process of
transforming many-to-many association. You just need to:
♦ Define tables and references as those generated from many-to-many
associations.
♦ Leave cardinality of the reference keys as they are.
If your database reference keys cannot be transformed into many-to-many
associations, they will be transformed into one-to-many associations. If you
want to generate one-to-one association, you need to set the maximum
cardinality to 1 (cardinality 0..1 or 1..1).
If the reference key is mandatory, the minimal multiplicity of one side of the
generated association will be 1.
171
Meet in the Middle
Meet in the Middle
If you have existing OOM and PDM, you can also define mapping between
them manually. The O/R Mapping models in PowerDesigner are platform
independent.
There is not any constraint on the way you map your persistent classes.
However, there are some well-defined mapping strategies, which are
supported by most of O/R Mapping technologies. You should follow these
strategies in order to build correct O/R Mapping models. However, minor
differences still reside between them which we will raise when necessary.
Note: when your O/R Mapping models are related with a specific
technology, for example when you add an EJB 3.0 persistence extended
model definition to your model, there will be some constraints and we
provide model checks to help you check the syntax of the mappings you
have defined.
Defining basic mapping
In order to define basic mapping, you have to define a data source for your
OOM. Then you can define the mapping using the Mapping tab of the OOM
object you want to map to a PDM object or using the Mapping Editor.
v To define mapping manually
1. In the OOM, select Model ä Data Sources to open the corresponding list.
2. Click the Add a row tool to create a data source.
You can create multiple data sources in the model.
3. Double-click the data source in the list to open its property sheet.
4. On the Models tab, click the Add Models tool to select one or more
PDMs from the available open PDM as source models for the data source.
172
Chapter 7. O/R Mapping Modeling
5. Define mappings using the Mapping tab or the Mapping Editor.
The Mapping Editor is more convenient to use as you can define all the
mappings in one place just by some drag and drop actions. However, it is
easy to understand the correspondence between OOM elements and PDM
elements by using the Mapping tab in objects property sheet. So we will
introduce you how to use Mapping definition tab to define mappings in
the following sections.
When you are familiar with O/R Mapping concepts, you can use the
Mapping Editor.
Defining entity class mapping
In order to define mapping for entity classes, you have to:
♦ Open the Mapping tab of a class property sheet
♦ Click the Create Mapping to create a new class mapping
♦ In the Select an object dialog box, add a data model element as mapping
source
You can also click the Add objects tool in the Class Sources sub-tab of the
Mapping tab after you created the class mapping.
173
Meet in the Middle
You can add tables, views and references as mapping sources. There are
some constraints on views as mapping sources, as some views cannot be
updated. When you add references as mapping sources, tables at the two
ends will also be added.
You can add multiple tables as mapping sources. Usually, the first table you
add is called the primary table. Other tables are called secondary tables.
Each secondary table should have reference key referring to primary table,
which is joined on its primary key.
Given the following class Customer :
174
Chapter 7. O/R Mapping Modeling
It can be mapped to two tables:
The Customer table is the primary table. The CutomerInfo table is the
secondary table and it has one reference key referring to the primary table,
which is joined on its primary key.
With the Mapping Editor, you just have to drag the two tables and drop them
to class Customer to define class mappings.
175
Meet in the Middle
Defining attribute mapping
After you have defined class mapping, you can define attribute mappings for
the class in the Attributes Mapping sub-tab of the Mapping tab.
PowerDesigner will generate some attribute mappings by matching their
names with the column names. Click the Add Mappings tool and select the
attributes you want to be mapped from the list.
For each attribute, you can select the column to which it is mapped from the
list in the Mapped to column. Usually you just have to map each attribute to
one column. However, you may need to map the attribute to multiple
columns when you define attribute mappings for Value type class for
example. In this case, you can open the attribute mappings property sheet
and select the Sources tab to add multiple columns.
176
Chapter 7. O/R Mapping Modeling
You can also map the attribute to a formula expression by defining it in the
Mapped to box in the General tab. You can construct the formula using the
SQL editor.
When an attribute has a Value type class as type, you do not need to define
attribute mappings for it. You should instead define mapping for the Value
type class.
Defining primary identifier mapping
Columns of primary keys should be mapped to persistent attributes. Like
primary keys for tables, you need to set these persistent attributes as primary
identifiers of entity classes. The mapped primary keys should be primary
keys of primary tables.
There are three types of primary identifier mapping:
♦ Simple primary identifier mapping which means a primary key with only
one column. The mapped primary identifier just has one persistent
attribute mapped to the column.
♦ Composite primary identifier mapping which means a primary key is
comprised of more than one column. The mapped primary identifier can
have the same number of persistent attributes mapped to the columns.
♦ Component primary identifier mapping, which is a special case of
composite primary identifier mapping. Multiple persistent attributes are
177
Meet in the Middle
encapsulated into Value type class. The mapped primary identifier
contains one attribute whose type is the Value type class.
Primary identifier mapping is mandatory for entity classes.
v To define simple primary identifier mapping
1. Set one persistent attribute as primary identifier.
2. Define attribute mapping for the attribute.
v To define composite primary identifier mapping
1. Set multiple persistent attributes as primary identifier.
2. Define attribute mapping for each of these attributes.
Column(s) of primary keys can be mapped to association. They are migrated
from primary keys of other tables.
+ For more information, see the “One-to-many association
transformation” on page 160 section.
v To define component primary identifier mapping
1. Define one persistent attribute as primary identifier.
2. Define the type as Value type class.
3. Define attribute mappings for the Value type class.
Attributes of value type classes are mapped to columns, which are embedded
in primary tables mapped by other entity classes. So you have to add primary
tables of the containing classes as value type classes’ mapping sources. If
the value type class is used in more than one entity class, you should map
each of its persistent attributes to multiple columns of tables of these classes.
For example, Value type class Address is used as attribute type for two
classes, Product and Customer .
178
Chapter 7. O/R Mapping Modeling
The attributes of the Value type class Address can be mapped to columns of
two tables, Company table and Customer table.
The mapping is easier to visualize in the Mapping Editor.
179
Meet in the Middle
Defining association mapping
You can define association mapping in the Mapping tab of the association
property sheet and select the Add Objects tool to add mapping sources.
180
Chapter 7. O/R Mapping Modeling
Associations defined between entity classes can be mapped to reference keys
or tables. In order to define association mapping, you have to add the
references keys or tables as mapping sources. When you add reference keys,
the tables on their ends will also be added.
Associations can be classified as one-to-one, one-to-many and
many-to-many according to multiplicities of ends. And associations can be
classified as unidirectional and bi-directional according to navigability of
both ends. Associations of different types should be mapped in different
ways. We will introduce them in detail in the following sections.
Defining one-to-one association mapping
You can map each unidirectional one-to-one association to a reference key.
The foreign key should have the same direction as the association. Suppose
that we have two entity classes, Person and Account , and a one-to-one
association between them.
181
Meet in the Middle
The association is unidirectional and navigates from the entity class Person
to the entity class Account .
The association and the reference key are linked in the Mapping Editor.
182
Chapter 7. O/R Mapping Modeling
For a bi-directional one-to-one association, you also just can map it to one
reference key. But the reference can navigate in either direction.
Defining one-to-many association mapping
Each unidirectional many-to-one association should be mapped to a
reference that has the same direction as the association.
Suppose that we have a unidirectional many-to-one association defined
between the class Customer and the class Order :
The unidirectional association should be mapped to the reference key:
183
Meet in the Middle
Each unidirectional one-to-many association should be mapped to a middle
table and two references that refer to tables mapped by the entity classes on
both ends.
In the following example, the association defined between Customer and
Order is a unidirectional one-to-many association:
This association should be mapped to middle table and reference keys:
You can map a bi-directional one-to-many association as unidirectional
many-to-one association. The reference just can navigate from primary table
of class on multiple-valued side to primary table of class on single-valued
side.
Sometimes we want to make the primary key of parent table be part of
primary key of the child table and reference key join on the migrated
column(s). For example we can map Customer , Order and bi-directional
one-to-many association to tables and reference key as follows:
184
Chapter 7. O/R Mapping Modeling
In order to define such type of association mapping, you have to define the
association as composition with the class on single-valued side containing
the class on multiple-valued side first.
The association is the following:
185
Meet in the Middle
Then add the reference as mapping sources. You just can define the same
way association mapping for bi-directional one-to-many association.
Defining many-to-many association mapping
Each many-to-many association should be mapped to a middle table and two
reference keys that refer to tables mapped by entity classes on the two ends.
Given the following many-to-many association defined between the class
Employee and the class Title :
This association should be mapped to a middle table and references:
Defining inheritance mapping
Inheritance can be mapped in different ways.
+ For more information about this type of mapping, see “Inheritance
186
Chapter 7. O/R Mapping Modeling
transformation” on page 164.
You can apply those three inheritance mapping strategies or even mix
strategies. You should define primary identifier on the entity class that is the
root of the entity hierarchy.
Given the following inheritance hierarchy:
We will describe in detail how to define inheritance mapping applying these
mapping strategies.
Applying table per class hierarchy strategy
The whole class hierarchy should be mapped to one table. There should be
one discriminator column defined to distinguish instances of difference
classes in the hierarchy. The column can have character based type or
integer type.
187
Meet in the Middle
v To apply table per class hierarchy strategy
1. Define class mappings for each class in the hierarchy.
All the classes have the same primary table. They can also be mapped to
other secondary tables.
2. 2 Define identifier mapping in the root class.
3. 3 Define attribute mappings or association mappings for each class.
4. 4 Define discriminator column in the root class.
For each class hierarchy, a discriminator is needed to distinguish between
different class instances. You have to select one of the attributes in the root
class, in the Specifying Attribute list of the property sheet of one of the
children inheritance links of the root class. The attribute will be transformed
into a discriminator column. In the following example, we define one extra
attribute shapeType in Shape and select it as discriminator attribute:
188
Chapter 7. O/R Mapping Modeling
♦ 5 Define persistence generation type for each class. Define the
persistence generation type of the root class as Generate table and all the
other classes as Migrate columns .
Applying joined subclass strategy
Each entity class should be mapped to its own primary table. Each primary
table has a reference key referring to a primary table of its parent class
except for the primary table of the root class. The reference key should join
on the primary key of the primary table.
189
Meet in the Middle
v To apply joined subclass strategy
1. Define class mappings for each class in the hierarchy. Each class is
mapped to its own primary table.
2. Define identifier mapping in the root class.
3. Define attribute mappings or association mappings for each class.
4. Define persistence generation type for each class.
5. Define persistence generation type of all the classes as Generate table.
Applying table per class strategy
Each class should be mapped to its own primary table. All persistent
attributes of the class, including inherited persistent attributes, are mapped to
columns of the table for the class. Given the following example:
190
Chapter 7. O/R Mapping Modeling
Super classes can be also mapped to primary tables of subclasses if inherited
persistent attributes are mapped in different ways for subclasses, for example
to different columns. The other primary table can just be secondary tables.
PowerDesigner will generate these secondary tables for super classes.
For this kind of strategy, some super classes can have no table mapped.
These classes are used to define state and mapping information that can be
inherited by their subclasses.
191
Meet in the Middle
v To apply table per class strategy
1. Define entity class mappings for each class in the hierarchy.
Each class is mapped to its own primary table.
2. Define attribute mappings and association mappings for each class.
3. Define identifier mapping in the root class.
4. Define persistence generation type for each class.
5. Define persistence generation type of leaf classes as Generate table and
all the other classes as Migrate columns .
192
CHAPTER 8
Generating Persistent Objects for Java
and JSF Pages
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with JBoss
Hibernate.
Topic:
page
Generating Hibernate Persistent Objects
194
Generating EJB 3 Persistent Objects
219
Generating JavaServer Faces (JSF) for Hibernate
241
193
Generating Hibernate Persistent Objects
Generating Hibernate Persistent Objects
Hibernate is an open source project developed by JBoss, which provides a
powerful, high performance and transparent object/relational persistence and
query solution for Java.
Hibernate lets you develop persistent objects using POJO (Plain Old Java
Object). All the common Java idioms, including association, inheritance,
polymorphism, composition, and the Java collections framework are
supported. Hibernate allows you to express queries in its own portable SQL
extension (HQL), as well as in native SQL, or with Java-based Criteria and
Example objects.
PowerDesigner supports the design of Java classes, database schema and
Object/Relational mapping (O/R mapping). Using these metadata,
PowerDesigner can generate Hibernate persistent objects including:
♦ Persistent Java classes (domain specific objects)
♦ Configuration file
♦ O/R mapping files
♦ DAO factory
♦ Data Access Objects (DAO)
♦ Unit test classes for automated test
Adding Hibernate Support
PowerDesigner uses a Hibernate Extended Model Definition (or profile) to
generate Hibernate files.
v To add Hibernate support
1. Verify that the current model has the target language Java or Java 5.0
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click on the Import tool.
4. Select Hibernate in the O/R Mapping tab and click OK.
You can also select the Hibernate Extended Model Definition when creating
an OOM.
Hibernate has a lot of options for O/R mapping support.
194
Chapter 8. Generating Persistent Objects for Java and JSF Pages
To generate Hibernate O/R mapping files that fit in your needs, you need to
defined Hibernate specific options.
Defining the Hibernate default options
You can define these options in the model or a package property sheet.
v To define Hibernate default options
1. Open the model or a package property sheet, and click the Hibernate tab:
2. Define the model or package level default options.
Option
Description
Auto import
Specifies that users may use an unqualified class
name in queries.
Default access
Specifies the default class attribute access type.
Specifies the default
cascade
Specifies the default cascade type.
Schema name
Specifies the default database schema name.
Catalog name
Specifies the default database catalog name.
Defining the Hibernate database configuration parameters
Hibernate can support multiple databases. You need to define database
configuration parameters. The database configuration parameters are stored
in the configuration file, hibernate.cfg.xml .
195
Generating Hibernate Persistent Objects
v To define Hibernate configuration parameters
1. Open the model property sheet and click the Hibernate Configuration tab:
2. Define the type of database, JDBC driver, connection URL, JDBC driver
jar file path, user name, password, etc.
Option
Description
Dialect
Specifies the dialect, and hence the type of database.
Hibert Tag: dialect
JDBC driver
class
Specifies the JDBC driver class.
Connection
URL
Specifies the JDBC connection URL string.
JDBC driver
jar
Specifies the JDBC driver jar file path.
User name
Specifies the database user name.
Hibert Tag: connection.driver_class
Hibert Tag: connection.url
Hibert Tag: N/A
Hibert Tag: connection.username
Password
Specifies the database user password.
Hibert Tag: connection.password
Show SQL
Specifies that SQL statements should be shown in the log.
Hibert Tag: show_sql
196
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Option
Description
Auto schema
export
Specifies the mode of creation from tables.
Package prefix
Specifies a namespace prefix for all the packages in the
model.
Hibert Tag: hbm2ddl.auto
Hibert Tag: N/A
Connection
pool size
Specifies the maximum number of pooled connections.
Hibert Tag: connection.pool_size
You can verify the configuration parameters in the Preview tab.
Defining Hibernate Basic O/R Mappings
There are two kinds of classes in Hibernate, entity classes and value type
classes. Entity classes have their own database identities, mapping files and
life cycles, while value type classes don’t have. Value type classes depend
on entity classes. Value type classes are also called component classes.
Hibernate uses mapping files to define the mapping metadata. Each mapping
file <Class>.hbm.xml can contain metadata for one or many classes.
PowerDesigner uses the following grouping strategy:
♦ A separate mapping file is generated for each single entity class that is
not in an inheritance hierarchy.
♦ A separate mapping file is generated for each inheritance hierarchy that
has a unique mapping strategy. All mappings of subclasses are defined in
the mapping file. The mapping file is generated for the root class of the
hierarchy. See ““Defining Hibernate Inheritance Mappings” on
page 210” for details about how the mapping strategy is determined.
♦ No mapping file is generated for a single value type class that is not in an
inheritance hierarchy. Its mapping is defined in its owner’s mapping file.
Defining Hibernate Class Mapping Options
Classes can be mapped to tables or views. Since views have many
constraints and limited functionality (for example they do not have primary
keys and reference keys), some views cannot be updated, and the mappings
may not work properly in some cases.
There are some conditions that need to be met in order to generate mapping
for a specific class:
197
Generating Hibernate Persistent Objects
♦ The Java source can be generated. This may not be possible if, for
example, the visibility of the class is private.
♦ The class is persistent.
♦ The generation mode is not set to Generate ADT (abstract data type).
♦ If the class is an inner class, it must be static, and have public visibility.
Hibernate should then be able to create instances of the class.
Hibernate-specific class mapping options can be defined in the Hibernate tab
of the class property sheet:
Option
Description
Dynamic insert
Specifies that INSERT SQL should be generated at
runtime and will contain only the columns whose
values are not null.
Hibernate Tag: dynamic-insert
198
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Option
Description
Dynamic update
Specifies that UPDATE SQL should be generated at
runtime and will contain only the columns whose
values have changed.
Hibernate Tag: dynamic-update
Select before update
Specifies that Hibernate should never perform a SQL
UPDATE unless it is certain that an object is actually
modified.
Hibernate Tag: select-before-update
Default cascade
type
Specifies the default cascade style.
Default access type
Specifies the default access type (field or property)
Hibernate Tag: default-cascade
Hibernate Tag: default-access
Proxy name
Specifies an interface to use for lazy initializing proxies.
Hibernate Tag: proxy
Batch size
Specifies a “batch size” for fetching instances of this
class by identifier.
Hibernate Tag: batch-size
Check
Specifies a SQL expression used to generate a multi-row
check constraint for automatic schema generation.
Hibernate Tag: check
Polymorphism
Specifies whether implicit or explicit query polymorphism is used.
Hibernate Tag: polymorphism
Schema name
Specifies the name of the database schema.
Hibernate Tag: schema
Catalog name
Specifies the name of the database catalog.
Hibernate Tag: catalog
Row id
Specifies that Hibernate can use the ROWID column on
databases which support it (for example, Oracle).
Hibernate Tag: rowed
Persister class
name
Specifies a custom persistence class.
Hibernate Tag: persister
199
Generating Hibernate Persistent Objects
Option
Description
Lazy
Specifies that the class should be lazy fetching.
Hibernate Tag: lazy
Mutable
Specifies that instances of the class are mutable.
Hibernate Tag: mutable
Abstract class
Specifies that the class is abstract.
Hibernate Tag: abstract
Auto import
Specifies that an unqualified class name can be used in
a query
Hibernate Tag: Auto-import
Discriminator column
Specifies the discriminator column or formula for
polymorphic behavior in a one table per hierarchy
mapping strategy.
Hibernate Tag: discriminator
Discriminator
value
Specifies a value that distinguishes individual subclasses, which are used for polymorphic behavior.
Hibernate Tag: discriminator-value
Discriminator type
Specifies the discriminator type.
Hibernate Tag: type
Force usage of
discriminator
Forces Hibernate to specify allowed discriminator
values even when retrieving all instances of the root
class.
Hibernate Tag: force
Do not use discriminator in insert
Forces Hibernate to not include the column in SQL
INSERTs
Hibernate Tag: insert
Optimistic lock
type
Specifies an optimistic locking strategy.
Optimistic lock
column name
Specifies the column used for optimistic locking. A
field is also generated if this option is set.
Hibernate Tag: optimistic-lock
Hibernate Tag: version/ timestamp
Optimistic lock
unsaved value
200
Specifies whether an unsaved value is null or undefined.
Hibernate Tag: unsaved-value
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Defining primary identifier mappings
Primary identifier mapping is mandatory in Hibernate. Primary identifiers of
classes are mapped to primary keys of master tables in data sources. If not
defined, a default primary identifier mapping will be generated, but this may
not work properly.
There are three kinds of primary identifier mapping in Hibernate:
♦ Simple identifier mapping
♦ Composite identifier mapping
♦ Component identifier mapping
Mapped classes must declare the primary key column of the database table.
Most classes will also have a Java-Beans-style property holding the unique
identifier of an instance.
Simple identifier mapping When a primary key is attached to a single column, only one attribute in the
primary identifier can be mapped. This kind of primary key can be generated
automatically. You can define the generator class and parameters. There are
many generator class types, such as increment, identity, sequence, etc. Each
type of generator class may have parameters that are meaningful to it. See
your Hibernate documentation for detailed information.
You can define the generator class and parameters in the Hibernate tab of the
primary identifier property sheet. The parameters take the form of
param1=value1; param2=value2.
201
Generating Hibernate Persistent Objects
v To define an identifier mapping
1. Open the class property sheet and click the Attributes tab.
2. Create an attribute and set it as the Primary identifier.
3. Click the Identifiers tab and double-click the entry to open its property
sheet.
4. Click the Hibernate tab, select a generator class and define its parameters.
Example parameters:
♦ Select hilo in the Generator class list
♦ Enter “table=hi_value,column=next_value,max_lo=10000” in the
Generator params box. You should use commas to separate the
parameters.
5. You can check the code in the Preview tab:
Note that, if there are several Primary identifier attributes, the generator is
not used.
Composite identifier
mapping
202
If a primary key comprises more than one column, the primary identifier can
have multiple attributes mapped to these columns. In some cases, the
primary key column could also be the foreign key column.
Chapter 8. Generating Persistent Objects for Java and JSF Pages
v To define a composite identifier mapping
1. Define association mappings.
2. Migrate navigable roles of associations.
3. Add these migrated attributes in primary identifier. The migrated
attributes need not to be mapped.
In the above example, the Assignment class has a primary identifier with
three attributes: one basic type attribute and two migrated attributes. The
primary identifier mapping is as follows:
<composite-id>
<key-property name="type">
<column name="type" sql-type="smallint"
not-null="true"/>
</key-property>
<key-many-to-one name="title">
</key-many-to-one>
<key-many-to-one name="worker">
</key-many-to-one>
</composite-id>
Component primary
identifier mapping
For more convenience, a composite identifier can be implemented as a
separate value type class. The primary identifier has just one attribute with
the class type. The separate class should be defined as a value type class.
Component class mapping will be generated then.
v To define component primary identifier mapping
1. Define a primary identifier attribute.
2. Define the type of the attribute as a value type class.
3. Set the Class generation property of the primary identifier attribute to
Embedded.
4. Set the ValueType of the primary identifier class to true.
5. Define a mapping for the primary identifier class.
203
Generating Hibernate Persistent Objects
In the example above, three name attributes are grouped into one separate
class Name. It is mapped to the same table as Person class. The generated
primary identifier is as follows:
<composite-id name="name" class="identifier.Name">
<key-property name="firstName">
<column name="name_firstName"
sql-type="text"/>
</key-property>
<key-property name="middleName">
<column name="name_middleName"
sql-type="text"/>
</key-property>
<key-property name="lastName">
<column name="name_lastName"
sql-type="text"/>
</key-property>
</composite-id>
Note: The value type class must implement the java.io.Serializable interface,
which implements the equals() and hashCode() methods.
Defining attribute mappings
Attributes can be migrated attributes or ordinary attributes. Ordinary
attributes can be mapped to columns or formulas. Migrated attributes do not
require attribute mapping.
The following types of mapping are possible:
♦ Map attribute to formula - When mapping an attribute to a formula, you
should ensure that the syntax is correct. There is no column in the source
table of the attribute mapping.
♦ Component attribute mapping - A component class can define the
attribute mapping as for other classes, except that there is no primary
identifier.
♦ Discriminator mapping - In inheritance mapping with a
one-table-per-hierarchy strategy, the discriminator needs to be specified
204
Chapter 8. Generating Persistent Objects for Java and JSF Pages
in the root class. You can define the discriminator in the Hibernate tab of
the class property sheet.
Hibernate-specific attribute mapping options are defined in the Hibernate tab
of the Attribute property sheet.
Option
Description
Generate finder
function
Generates a finder function for the attribute.
Hibernate type
Specifies a name that indicates the Hibernate type.
Property access
Specifies the strategy that Hibernate should use for
accessing the property value.
Id unsaved value
Specifies the value of an unsaved id.
Insert
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Update
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Optimistic lock
Specifies that updates to this property require acquisition
of the optimistic lock.
Lazy
Specifies that this property should be fetched lazily when
the instance variable is first accessed (requires build-time
byte code instrumentation).
205
Generating Hibernate Persistent Objects
Hibernate Association Mappings
Hibernate supports one-one, one-to-many/many-to-one, and many-to-many
association mappings. The mapping modeling is same with standard O/R
Mapping Modeling. However, Hibernate provides special options to define
its association mappings, which will be saved into <Class>.hbm.xml
mapping file. PowerDesigner allows you to define standard association
attributes like Container Type implementation class, role navigability, array
size and specific extended attributes for Hibernate association mappings.
Defining Hibernate Association Mapping Options
v To define the Hibernate association mapping options
1. Open the Association property sheet and click the Hibernate Collection
tab.
2. Define the collection management options (see ““Collection management
options” on page 207”).
3. Select the Hibernate Persistence tab. Define persistence options (see
““Persistence options” on page 208”).
206
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Collection management options
The following options are available:
Field
Description
Sort
Specifies a sorted collection with natural sort order, or a
given comparator class.
Hibernate Tag: sort
Order by
Specifies a table column (or columns) that define the
iteration order of the Set or bag, together with an optional
asc or desc.
Hibernate Tag: order-by
Access
Specifies the strategy Hibernate should use for accessing
the property value.
Hibernate Tag: access
Cascade
Specifies which operations should be cascaded from the
parent object to the associated object.
Hibernate Tag: cascade
207
Generating Hibernate Persistent Objects
Field
Description
Collection type
Specifies a name that indicates the Hibernate type.
Hibernate Tag: type
Batch size
Specifies the batch load size.
Hibernate Tag: batch-size
Not found
Specifies how foreign keys that reference missing rows
will be handled: ignore will treat a missing row as a null
association.
Hibernate Tag: not-found
Inverse collection
Specifies that the role is the inverse relation of the opposite
role.
Hibernate Tag: inverse
Persistence options
The following options are available:
Field
Description
Schema
Specifies the name of the schema.
Hibernate Tag: schema
Catalog
Specifies the name of the catalog.
Hibernate Tag: catalog
Where clause
Specifies an arbitrary SQL WHERE condition to be used
when retrieving objects of this class.
Hibernate Tag: where
Check
Specifies a SQL expression used to generate a multi-row
check constraint for automatic schema generation.
Hibernate Tag: check
Fetch type
Specifies outer-join or sequential select fetching.
Hibernate Tag: fetch
Persister class
Specifies a custom persistence class.
Hibernate Tag: persister
Subselect
Specifies an immutable and read-only entity to a database
subselect.
Hibernate Tag: subselect
208
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Field
Description
Index column
Specifies the column name if users use list or array collection type.
Hibernate Tag: index
Insert
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Hibernate Tag: insert
Update
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Hibernate Tag: update
Lazy
Specifies that this property should be fetched lazily when
the instance variable is first accessed.
Hibernate Tag: lazy
Optimistic
lock
Specifies that a version increment should occur when this
property is dirty.
Hibernate Tag: optimistic-lock
Outer join
Specifies to use an outer-join.
Hibernate Tag: outer-join
Mapping collections of value types
If there is a value type class on the navigable role side of an association with
a multiplicity of one, PowerDesigner will embed the value type in the entity
type as a composite attribute.
v To map collections of value type
1. Create an entity type class.
2. Create another class for value type.
3. Open the property sheet of the class, click the Detail tab, and select the
Value type radio button.
4. Create an association between the value type class and an entity type
class. On the value type side, set the multiplicity to one and the
navigability to true.
209
Generating Hibernate Persistent Objects
5. Generate the PDM with O/R mapping.
6. Open the property sheet of the entity class and click the Preview tab.
7. Verify the mapping file.
A composite entity class may contain components, using the
<nested-composite-element> declaration.
v To define association collection type for one-to-many or many-tomany associations
1. Open the association property sheet and click the Detail tab.
2. Specify a Multiplicity on both sides.
3. Specify either unidirectional or bi-directional navigability.
4. Specify role names if necessary.
5. If one role of the association is navigable and the multiplicity is many,
you can set the collection container type and batch loading size.
6. If you select java.util.List or <none>, it implies that you want to use an
array or list-indexed collection type. Then you should define an index
column to preserve the objects collection order in the database.
Note: The Java collection container type conditions the Hibernate collection
type.
Collection Container Type
Hibernate Collection Type
<None>
array
java.util.Collection
bag or idbag (many-to-many)
java.util.List
list
java.util.Set
set
Defining Hibernate Inheritance Mappings
Hibernate supports the three basic inheritance mapping strategies:
♦ Table per class hierarchy
210
Chapter 8. Generating Persistent Objects for Java and JSF Pages
♦ Table per subclass
♦ Table per concrete class
♦ There are not any special different from standard inheritance mapping
definition in O/R Mapping Modeling. However, a separate mapping file
is generated for each inheritance hierarchy that has a unique mapping
strategy. All mappings of subclasses are defined in the mapping file. The
mapping file is generated for the root class of the hierarchy.
Generating Code for Hibernate
Before generating code for Hibernate, you need to:
♦ Install Hibernate 3.0 or higher - you can download it from
www.hibernate.org.
♦ Check the model.
♦ Define generation options.
Checking the model
When you complete the definition of the model, you need to run the Check
Model function to verify if there are errors or warnings in the model. If there
are errors, you need to fix them before generating code.
Defining generation options
There are two types of generation options:
♦ Environment variables - to allow your Eclipse or Ant build script to find
the Hibernate library Jar files
♦ Generation options
211
Generating Hibernate Persistent Objects
v To define environment variables
1. Select Tools ä General Options
2. Select the Variables node.
3. Add a variable HIBERNATE_HOME and, in the value field, enter the
Hibernate home directory path. For example, D:\Hibernate-3.0.
212
Chapter 8. Generating Persistent Objects for Java and JSF Pages
v To define generation options
1. Select Language ä Generate Java Code.
2. Specify the root directory where you want to generate the code.
3. Click the Options tab.
4. [optional] To use DAO, set the Generate DAO sources option to true.
5. [optional] To use Eclipse to compile and test the Java classes, set the
Generate Eclipse project artifacts option to true.
6. [optional] To use unit test classes to test the Hibernate persistent objects,
set the Generate unit test sources option to true.
7. Click on OK to generate code immediately or Apply and then Cancel to
save your changes for later.
Generating code for Hibernate
Once you have completed your model, checked it, and defined your
generation options, you can generate the code for Hibernate.
213
Generating Hibernate Persistent Objects
v To generate code for Hibernate
1. Select Language ä Generate Java Code
2. [optional] Click the Select tab to change the object selection.
3. [optional] Click the Options tab to change the Hibernate and Java
generation options.
4. [optional] Click the Generated Files tab to review all the files that will be
generated.
5. Click OK.
You can use an IDE like Eclipse to modify the generated code, compile, run
the unit test and develop your application.
Using the Generated Hibernate Code
To use Eclipse, you need to download the Eclipse SDK from
www.eclipse.org and install it.
Importing the generated project into Eclipse
If you have selected the Generate Eclipse project artifacts generation option,
you can import the generated project into Eclipse and use Eclipse to modify,
compile and run the tests.
If you use the PowerDesigner Eclipse plugin then, after the code generation,
the project is automatically imported or refreshed in Eclipse.
214
Chapter 8. Generating Persistent Objects for Java and JSF Pages
If you use the standalone version of PowerDesigner, you need to import the
generated project as follows:
1. In Eclipse, select File ä Import
2. In the import list, select Existing Projects into Workspace. Eclipse will
automatically compile all the Java classes. If there are errors, you should
check:
♦ That all the required Jar files are included in the .classpath file.
♦ That the JDK version is the right one. If you use Java 5.0 as the
language in OOM, you need to use the JDK 5.0 to compile the code.
Performing the unit tests
If the generated Java classes are compiled without error, you can run the unit
tests within Eclipse or using Ant.
The unit tests generate random data to create and update objects.
After creating, updating, deleting or finding objects, a test asserts that the
result is as expected.
If the result is as expected, the test succeeds; otherwise it fails.
Before running the unit tests, you need to:
1. Create the database file.
2. Define an ODBC connection.
3. Generate the database from the PDM using the ODBC connection.
4. Give the test user the permission to connect to the database.
5. Start the database.
Running unit tests in Eclipse
Eclipse integrates JUnit. The JUnit Jar files and JUnit user-interface are
provided.
215
Generating Hibernate Persistent Objects
v To run a single test case
1. Open the Java perspective
2. In the Package Navigator, expand the test package
3. Right-click on a test case (for example, CustomerTest.java) and select
Run As ä JUnit Test
4. Select the JUnit view to verify the result:
If there are 0 errors, then the test has succeeded. If there are errors, you
need to check the Console view to locate the sources of them. The
problem could be:
216
Chapter 8. Generating Persistent Objects for Java and JSF Pages
♦ The database is not started.
♦ The user name or password is wrong.
♦ The database is not generated.
♦ The mapping is wrong.
v To run the test suite
1. Open the Java perspective
2. In the Package Navigator, expand the test package
3. Right-click on the AllTests.java test suite and select Run As ä JUnit Test
from the contextual menu
4. Select the JUnit view to verify the result
Running unit tests with Ant
To generate the Ant build.xml file, you need to select the Generate Ant
build.xml file in the Java code generation window.
To use Ant, you need to:
♦ Download it from www.apache.org and install it.
217
Generating Hibernate Persistent Objects
♦ Define an environment variable ANT_HOME and set it to your Ant
installation directory.
♦ Copy junit-3.8.1.jar from HIBERNATE_HOME/lib directory to
ANT_HOME/lib directory.
♦ Make sure that the Hibernate Jar files are defined in the build.xml file or
in the CLASSPATH environment variable.
♦ Make sure that the JDBC driver Jar file of your database is defined in the
build.xml file or in the CLASSPATH environment variable.
v To run unit tests with Ant from PowerDesigner
1. Select Language ä Generate Java Code
2. Select the Options tab.
3. Set the Generate Ant build.xml file option to true.
4. Select the Tasks tab.
5. Check the Hibernate: Run the generated unit tests task.
6. Click OK.
7. After you close the generation files list window, the JUnit task runs. You
can see the result in output window.
v To run unit tests with Ant from the command line
1. Open a command line window.
2. Go to the directory where you have generated the code.
3. Run the JUnit test task: Ant junit
4. Check the output result.
218
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Generating EJB 3 Persistent Objects
EJB 3.0 is the latest revision of the Enterprise Java Beans specification. One
of the principal goals of EJB 3.0 is:
”Simplification of object persistence by the definition of a light-weight
object/relational mapping facility based on the direct use of Java classes
rather than persistent components.”
One of the most significant changes in EJB 3.0 is the introduction of a
standard O/R mapping specification and the move to POJO based
persistence.
EJB 3.0 persistence provides a lightweight persistence solution for Java
applications. It supports powerful, high performance and transparent
object/relational persistence, which can be used both in container and out of
container.
EJB 3.0 persistence lets you develop persistent objects using POJO (Plain
Old Java Object). All the common Java idioms, including association,
inheritance, polymorphism, composition, and the Java collections
framework are supported. EJB 3.0 persistence allows you to express queries
in its own portable SQL extension (EJBQL), as well as in native SQL.
PowerDesigner supports the design of Java classes, database schema and
Object/Relational mapping (O/R mapping). Using these metadata,
PowerDesigner can generate codes for EJB 3 persistence, including:
♦ Persistent EJB Entities (domain specific objects)
♦ Configuration file
♦ O/R mapping files (Optional)
♦ DAO factory
♦ Data Access Objects (DAO)
♦ Unit test classes for automated test
v To generate entities for EJB 3.0
1. Create an OOM and a PDM, and then define your O/R mappings. For
detailed information, see the “O/R Mapping Modeling” chapter.
2. Define the EJB 3 persistence settings.
3. Generate Java code.
4. 5 Run unit tests.
219
Generating EJB 3 Persistent Objects
Adding EJB 3 Persistence Support
PowerDesigner uses an EJB 3.0 Extended Model Definition to generate EJB
3.0 persistence artifacts.
v To add EJB 3.0 persistence support
1. Select Model ä Extended Model Definitions.
2. 2 In the List of Extended Model Definitions click on the Import tool.
3. 3 Select EJB 3.0 in the O/R Mapping tab and click OK.
You can also select the EJB 3.0 Extended Model Definition when creating an
OOM by clicking the Extended Model Definitions tab in the New dialog,
clicking the O/R Mapping sub-tab, and selecting the EJB 3.0 checkbox.
Defining EJB 3 Basic O/R Mapping
There are three kinds of persistent classes in EJB 3:
♦ Entity classes
♦ Embeddable classes
♦ Mapped superclasses
The following requirements apply to persistent classes:
They must be defined as persistent classes (see “Class Transformation” in
the O/R Mapping Modeling chapter).
They must be top level classes (and not inner classes).
Entity classes and Mapped superclasses should carry the EJBEntity
stereotype.
Embeddable classes are Value type classes, i.e. persistent classes with a
Value type persistent type.
Classes that do not meet these requirements will be ignored.
Tip: You can set the stereotype and persistence of all the classes in a model
or package (and sub-packages) by right-clicking the model or package and
selecting Make Persistent from the contextual menu.
Defining Entity Mappings
Set the stereotype of persistent classes to make them EJB 3 Entity classes.
220
Chapter 8. Generating Persistent Objects for Java and JSF Pages
See the O/R Mapping Modeling chapter for information about defining
entity class mappings.
The Entity annotation is generated to specify that the class is an entity.
@Entity
@Table(name="EMPLOYEE")
public class Employee { ... }
EJB 3 Entity Mapping
Options
Mapping to Multiple
Tables
The following EJB3-specific mapping options can be set on the EJB 3
Persistence tab of the class property sheet.
Option
Description
Entity Name
Specifies that the class alias that can be used in EJB QL.
Access strategy
Specifies the default access type (FIELD or PROPERTY)
Schema name
Specifies the name of the database schema.
Catalog name
Specifies the name of the database catalog.
Mapping definition
type
Specifies what will be generated for mapping meta data,
the mapping file, annotations or both.
Discriminator
value
Specifies the discriminator value to distinguish instances of the class
In EJB 3, Entity classes can be mapped to multiple tables. See the O/R
Mapping Modeling chapter for information on how to map one Entity class
to multiple tables.
There is a check to guarantee that secondary tables have reference keys
referring to primary tables.
The SecondaryTable annotation is generated to specify a secondary table for
the annotated Entity class. The SecondaryTables annotation is used when
there are multiple secondary tables for an Entity.
Defining Primary
Identifier Mapping
Three kinds of primary identifier mapping are supported in EJB 3.0:
♦ Simple identifier mapping - This kind of primary key can be generated
automatically in EJB 3. You can define the generator class and
parameters. There are four generator class types, Identity, Sequence,
Table and Auto. Table generator and sequence generators require certain
parameters. See the EJB 3.0 persistence specification for details.
You can define the generator class and parameters in the EJB 3
persistence tab of primary identifiers’ property sheet. The parameters
take the form of param1=value1; param2=value2.
221
Generating EJB 3 Persistent Objects
The Id annotation generated specifies the primary key property or field of
an entity. The GeneratedValue annotation provides for the specification
of generation strategies for the values of primary keys:
@Id
@GeneratedValue(strategy=GenerationType.TABLE,
generator="customer_generator")
@TableGenerator(
name=" customer_generator",
table="Generator_Table",
pkColumnName="id",
valueColumnName="curr_value",
initialValue=4
)
@Column(name="cid", nullable=false)
♦ Composite identifier mapping - The IdClass annotation will be generated
for an entity class or a mapped superclass to specify a composite primary
key class that is mapped to multiple fields or properties of the entity:
@IdClass(com.acme.EmployeePK.class)
@Entity
public class Employee {
@Id String empName;
@Id Date birthDay;
...
}
♦ Embedded primary identifier mapping - corresponds to component
primary identifier mapping. The EmbeddedId annotation is generated for
a persistent field or property of an entity class or mapped superclass to
denote a composite primary key that is an embeddable class:
@EmbeddedId
protected EmployeePK empPK;
Defining Attribute
Mappings
Each persistent attribute with basic types can be mapped to one column.
Follow instructions to define attribute mappings for this kind of persistent
attributes.
The following EJB3-specific attribute mapping options are available on the
EJB 3 Persistence tab of each attribute’s property sheet:
222
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Option
Description
Version attribute
Specifies if attribute is mapped as version attribute
Insertable
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Updatable
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Fetch
Specify if attribute should be fetched lazily.
Generate finder
Generates a finder function for the attribute.
The Basic annotation is generated to specify fetch mode for the attribute or
property and whether the attribute or property is mandatory. The Column
annotation is generated to specify a mapped column for a persistent property
or field.
@Basic
@Column(name="DESC", nullable=false, length=512)
public String getDescription() { return description; }
Other Annotations can also be generated to specify the persistence type of an
attribute or property. A Temporal annotation specifies that a persistent
property or attribute should be persisted as a temporal type. There is also the
enumerated annotation for enumerated types and Lob for large object types.
Defining Versioning
Mapping
EJB 3.0 uses managed versioning to perform optimistic locking. If you want
to use this kind of feature, you need to set one mapped persistent attribute as
the Version attribute, by selecting the Version attribute option on the EJB 3
Persistence tab. The following types are supported for Version attribute: int,
Integer, short, Short, long, Long, Timestamp.
The Version attribute should be mapped to the primary table for the entity
class. Applications that map the Version property to a table other than the
primary table will not be portable. Only one Version attribute should be
defined for each Entity class.
The Version annotation is generated to specify the version attribute or
property of an entity class that serves as its optimistic lock value.
@Version
@Column(name="OPTLOCK")
protected int getVersionNum() { return versionNum; }
Defining Embeddable Class Mapping
Embeddable classes are simple Value type classes. Follow the instructions
for defining Value type class mappings to define Embeddable class mapping
223
Generating EJB 3 Persistent Objects
for EJB 3.
In EJB 3, Embeddable classes can contain only attribute mappings, and
these persistent attributes can have only basic types, i.e. Embeddable classes
cannot contain nested Embeddable classes.
Note: The Embeddable class must implement the java.io.Serializable
interface and overrides the equals() and hashCode() methods.
The Embeddable annotation is generated to specify a class whose instances
are stored as an intrinsic part of an owning entity and share the identity of
the entity.
@Embeddable
public class Address implements java.io.Serializable {
@Basic(optional=true)
@Column(name="address_country")
public String getCountry() {}
.....
}
Defining EJB 3 Association Mappings
EJB 3 persistence provides support for most of the association mapping
strategies described in the O/R Mapping Modeling chapter. We will just
address the differences here.
One association must be defined between two Entity classes or one Entity
class and one Mapped superclass before it can be mapped. Association
mapping with a Mapped superclass as the target will be ignored.
Embeddable classes can be either the source or the target of associations.
Mapping for associations with association class is not currently supported.
You must separate each kind of associations into two equivalent associations.
Mapping One-to-one Associations
EJB 3 persistence supports both bi-directional one-to-one association
mapping and unidirectional one-to-one association mapping (see the O/R
Mapping chapter).
The OneToOne annotation is generated to define a single-valued association
to another entity that has one-to-one multiplicity. For bi-directional
one-to-one associations, the generated annotations will resemble:
224
Chapter 8. Generating Persistent Objects for Java and JSF Pages
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn(name="aid", referencedColumnName="aid")
})
public Account getAccount() { ... }
@OneToOne(cascade=CascadeType.PERSIST, mappedBy="account")
public Person getPerson() { ... }
Generated annotations for unidirectional one-to-one associations are similar.
A model check is available to verify that mappings are correctly defined for
unidirectional one-to-one associations. One unidirectional association can
only be mapped to a reference that has the same direction as the association.
Mapping One-to-many Associations
EJB 3 persistence supports bi-directional one-to-many association mapping,
unidirectional one-to-one association mapping and unidirectional
one-to-many association mapping (see the O/R Mapping chapter).
A OneToMany annotation is generated to define a many-valued association
with one-to-many multiplicity. A ManyToOne annotation is generated to
define a single-valued association to another entity class that has
many-to-one multiplicity. The JoinColumn annotation is generated to
specify a join column for the reference associating the tables. For
bi-directional one-to-many associations, generated annotations will
resemble:
@OneToMany(fetch=FetchType.EAGER, mappedBy="customer")
public java.util.Collection<Order> getOrder() { ... }
@ManyToOne
@JoinColumns({
@JoinColumn(name="cid", referencedColumnName="cid")
})
public Customer getCustomer() { ... }
Generated annotations for unidirectional many-to-one associations are
similar. A model check is available to verify that mappings for bi-directional
one-to-many associations and unidirectional many-to-one associations are
correctly defined. The references can only navigate from primary tables of
classes on the multiple-valued side to primary tables of classes on the
single-valued side.
For unidirectional one-to-many association, the JoinTable annotation is
generated to define middle table and join columns for the two reference keys.
225
Generating EJB 3 Persistent Objects
@OneToMany(fetch=FetchType.EAGER)
@JoinTable(
name="Customer_Order",
joinColumns={
@JoinColumn(name="cid", referencedColumnName="cid")
},
inverseJoinColumns={
@JoinColumn(name="oid",
referencedColumnName="orderId")
}
)
public java.util.Collection<Order> getOrder() { ... }
A model check is available to verify that mappings for unidirectional
one-to-many associations are correctly defined. Middle tables are needed for
this kind of one-to-many association mapping.
One-to-many associations where the primary key is migrated are not
supported in EJB 3.
Mapping Many-to-many Associations
EJB 3 persistence supports both bi-directional many-to-many association
mapping and unidirectional many-to-many association mapping (see the
O/R Mapping chapter).
A ManyToMany annotation is generated to define a many-valued association
with many-to-many multiplicity.
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="Assignment",
joinColumns={
@JoinColumn(name="eid", referencedColumnName="eid")
},
inverseJoinColumns={
@JoinColumn(name="tid", referencedColumnName="tid")
}
)
public java.util.Collection<Title> getTitle() { ... }
A model check is available to verify that mappings are correctly defined for
many-to-many associations. Middle tables are needed for many-to-many
association mapping.
Defining EJB 3 Association Mapping Options
The following EJB 3-specific options for association mappings are available
on the EJB 3 Persistence tab of an association’s property sheet:
226
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Field
Description
Inverse side
Specifies which side is the inverse side.
Role A cascade
Specifies which cascade operation can be performed
on role A side.
Role B cascade
Specifies which cascade operation can be performed
on role B side.
Role A fetch
Specifies if role A side should be fetched eagerly.
Role B fetch
Specifies if role B side should be fetched eagerly.
Role A order by
Specifies the order clause for role A side.
Role A order by
Specifies the order clause for role B side.
Defining EJB 3 Inheritance Mappings
EJB 3 persistence supports all three popular inheritance mapping strategies
and also mixed strategies.
♦ Table per class hierarchy - SINGLE_TABLE
♦ Joined subclass - JOINED
♦ Table per concrete class - TABLE_PER_CLASS
All classes in the class hierarchy should be either Entity classes or Mapped
superclasses. For each class hierarchy, the primary identifier must be defined
on the Entity class that is the root of the hierarchy or on a mapped superclass
of the hierarchy.
You can optionally define a Version attribute on the entity that is the root of
the entity hierarchy or on a Mapped superclass of the entity hierarchy.
Mapped Superclasses
In EJB 3.0, Mapped superclasses are used to define state and mapping
information that is common to multiple entity classes. They are not mapped
to separate tables of their own. You cannot currently define Mapped
superclasses in PowerDesigner.
Table per Class Hierarchy Strategy
In this strategy, the whole class hierarchy is mapped to one table (see the
O/R Mapping chapter). You can optionally define discriminator values for
each Entity class in the hierarchy on the EJB 3 Persistence tab of the class
property sheet.
227
Generating EJB 3 Persistent Objects
Option
Description
Discriminator
value
Specifies a value that distinguishes individual this class
from other classes.
The Inheritance annotation with SINGLE_TABLE strategy is generated.
The DiscriminatorColumn annotation is generated to define the
discriminator column. The DiscriminatorValue annotation is generated to
specify the value of the discriminator column for entities of the given type if
you specify it for the class.
@Entity(name="Shape")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="shapeType",
discriminatorType=DiscriminatorType.STRING, length=100)
@Table(name="Shape")
public class Shape { ... }
@Entity(name="Rectangle")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("Rectangle")
@Table(name="Shape")
public class Rectangle extends Shape { ... }
A model check is available to verify that discriminator columns are correctly
defined.
Joined Subclass Strategy
In this strategy, each class is mapped to its own primary table. Primary
tables of child classes have reference keys referring to the primary tables of
the parent classes (see the O/R Mapping chapter).
An Inheritance annotation with JOINED strategy is generated. The
PrimaryKeyJoinColumn annotation is generated to define a join column that
joins the primary table of an Entity subclass to the primary table of its
superclass.
@Entity(name="Shape")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="shapeType")
@Table(name="Shape")
public class Shape { ... }
@Entity(name="Rectangle")
@Inheritance(strategy=InheritanceType.JOINED)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="sid", referencedColumnName="sid")
})
@Table(name="Rectangle")
public class Rectangle extends Shape { ... }
228
Chapter 8. Generating Persistent Objects for Java and JSF Pages
A model check is available to verify that primary tables of child classes have
reference keys referring to the primary tables of their parent classes.
Applying Table per Class Strategy
In this strategy, each class is mapped to a separate table. When transforming
an OOM to a PDM, PowerDesigner only generates tables for leaf classes,
and assumes that all other classes are not mapped to a table, even if you
manually define additional mappings. The MappedSuperclass annotations
are generated for those classes, and the Inheritance annotation will not be
generated for all the classes. You need to customize the generated
annotations and create additional tables if you want to map classes other
than leaf classes to tables.
@MappedSuperclass
public class Shape { .. }
@Entity(name="Rectangle")
@Table(name="Rectangle")
public class Rectangle extends Shape { ... }
Defining EJB 3 Persistence Default Options
The following default persistent options can be set at the model, package or
class level:
Option
Description
Default access
Specifies an access strategy.
Mapping definition type
Specifies the level of mapping metadata to be generated.
Catalog name
Specifies the catalog name for persistent classes.
Schema name
Specifies the schema name for persistent classes.
Defining EJB 3 Persistence Configuration
There are some persistence properties which are used for database
connection. You need to set them before run the generated application.
229
Generating EJB 3 Persistent Objects
v To define EJB 3 persistence configuration parameters
1. Open EJB 3 Persistence Configuration form from the model’s property
sheet.
2. Select persistence provider you use. You should refer to compliance
issues for some constraints with these persistence providers.
3. 3. Define JDBC driver class, connection URL, JDBC driver jar file path,
user name and password.
230
Option
Description
Persistence
provider
Specifies the persistence provider to be used.
Transaction
type
Specifies the transaction type to be used.
Data source
Specifies the data source name (if data source is used).
Add Dali support
Specifies that the generated project can be authored in
Dali. A special Eclipse project builder and nature will be
generated.
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Option
Description
JDBC driver
class
Specifies the JDBC driver class.
Connection
URL
Specifies the JDBC connection URL string.
JDBC driver
jar
Specifies the JDBC driver jar file path.
User name
Specifies the database user name.
Password
Specifies the database user password.
Cascade persist
Specifies whether to set the cascade style to PERSIST for
all relationships in the persistent unit.
You can verify the configuration parameters in the Preview tab. The
generated persistence configuration file looks like:
231
Generating EJB 3 Persistent Objects
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="EJB3_0Model" transactiontype="RESOURCE_LOCAL">
<description>
This is auto generated configuration for persistent unit
EJB3_0Model
</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- mapped files -->
<!--jar-file/-->
<!-- mapped classes -->
<class>com.company.orders.Customer</class>
<class>com.company.orders.Order</class>
<properties>
<property
name="hibernate.dialect">org.hibernate.dialect.SybaseDi
alect</property>
<property name="hibernate.connection.driver_
class">com.sybase.jdbc2.jdbc.SybDriver</property>
<property
name="hibernate.connection.url">jdbc:sybase:Tds:localho
st:5000/Production</property>
<property
name="hibernate.connection.username">sa</property>
<property
name="hibernate.connection.password"></property>
</properties>
</persistence-unit>
</persistence>
Checking the Model
To keep the model and mappings correct and consistent, you need to run a
model check. If there are errors, you need to fix them. You can also run
model checking before code generation.
Generating Code for EJB 3 Persistence
In order to generate code for EJB 3 persistence, you must.
♦ Download an EJB 3 persistence provider such as Hibernate Entity
Manager, Kodo, TopLink and GlassFish.
♦ Define an environment variable to specify the location of the persistence
library directory.
♦ Generate code - define model selection and generation options and
232
Chapter 8. Generating Persistent Objects for Java and JSF Pages
preview generated file list.
♦ Run unit test.
Defining the Environment Variable
PowerDesigner uses an environment variable to generate library
configuration for Eclipse project or Ant build script.
v To define the environment variable
1. Select Tools ä Generation Options
2. Select the Variables node
3. Add a variable EJB3PERSISTENCE_LIB and, in the value field, enter
directory path which you put your persistence provider libraries, for
example D:\EJB 3.0\Hibernate Entity Manager\lib.
You can also define this as a Windows system environment variable, but you
need to restart PowerDesigner to have it take effect.
Generate Code
To generate code, select Generate Java code on Language menu (Ctrl +
G).Specify the directory where you want to put your generated code. On the
Targets tab, make sure the O/R Mapping target is selected.
Select Model Elements
Select model elements to be generated on the Selection tab. The model
should be selected for there are some important artifacts generated on the
233
Generating EJB 3 Persistent Objects
model level, such as persistence configuration file, DAO factory classes,
DAO base classes etc.
Define Generation
Options
234
♦ Define generation options on the Options tab.
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Option
Description
Generate DAO sources
Specifies whether DAO sources should be
generated.
Generate Eclipse project
artifacts
Specifies whether Eclipse project file and classpath file should be generated.
Generate unit test sources
Specifies whether unit test sources should be
generated.
Java source directory
Specifies directory for Java sources.
Test source directory
Specifies directory for unit test sources.
Generate schema validation files
Specifies whether schema file and validation
script should be generated.
Generate Ant build.xml file
Specifies whether Ant build.xml file should be
generated.
235
Generating EJB 3 Persistent Objects
Preview Generated File
List
Specify Post Generation
Tasks
You can get a preview of generated file list on the Generated files tab.
There are some tasks that can be run after the generation. You can select
them on Tasks tab. The useful one is Run generated unit tests.
PowerDesigner will run unit tests by Ant script generated after generation if
you select the task. You can also run it on the command window. There are
some prerequisites before you can run the task. We will show you how to
run unit tests in the coming section.
Authoring in Dali Tools
Dali JPA Tools provide support for the definition, editing, and deployment of
Object-Relational (O/R) mappings for EJB 3.0 Entity Beans. It simplifies
mapping definition and editing through:
1. Creation and automated mapping wizards
2. Intelligent mapping assistance
3. Dynamic problem identification
You can import generated Eclipse project and do further editing in Dali tools
if you had selected Add Dali support in model’s property sheet.
Run Unit Tests
There are two ways you can run unit tests generated. One is running Ant
task. The other is running them in Eclipse.
236
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Running Unit Tests with
Ant
To generate the Ant build.xml file, you need to select the Generate Ant
build.xml file in the Java code generation options tab.
To use Ant, you need to:
♦ Download Ant from www.apache.org and install it.
♦ Define an environment variable ANT_HOME and set it to your Ant
installation directory.
♦ Download junit-3.8.1.jar if you don’t have it.
♦ Copy junit-3.8.1.jar to $ANT_HOME/lib directory.
♦ Make sure that you have defined database connection parameters and
JDBC driver jar correctly.
v To run unit tests with Ant from PowerDesigner
1. Select the Run unit tests task when generating code.
v To run unit tests with Ant from the command line
1. You can also run the task from command line.
2. Open a command line window.
3. Go to the directory where you have generated the code.
4. Run the JUnit test task by issuing command: Ant junit
5. Check the output result in ejb3-persistence.log and testout directory.
Running Unit Test in
Eclipse
To use Eclipse, you need to download the Eclipse SDK from
www.eclipse.org and install it.
If you have selected the Generate Eclipse project artifacts generation option,
you can import the generated project into Eclipse and use Eclipse to modify,
compile and run the tests.
If you use the PowerDesigner Eclipse plugin, after the code generation, the
project is automatically imported or refreshed in Eclipse.
You can run a single test case each time or run them as suite.
237
Generating EJB 3 Persistent Objects
v To run a single test case
1. Open the Java perspective
2. In the Package Navigator, expand the test package
3. Select a test case class, for example CustomerTest.java and run it as Unit
Test
4. Select the JUnit view to verify the result:
238
Chapter 8. Generating Persistent Objects for Java and JSF Pages
v To run the test suite
1. Select AllTests class under test package.
2. Run it as Application. All the tests will be run as suite.
Generated File List
The following files are generated:
♦ Eclipse Project Files - If you have selected the Generate Eclipse project
artifacts generation option, .project file and .classpath file are generated
by PowerDesigner. But if you are regenerating codes, these two files will
not be generated again.
♦ Persistent Java Classes - If mapping definition type specified includes
Annotation, Default, Annotation or Mapping File & Annotation,
annotations will be generated in Java sources.
♦ Primary Key Classes - Primary key classes are generated to ease
find-by-primary-key operation. It is also mandatory for composite
primary key.
♦ EJB 3 Configuration File - The EJB 3 persistence configuration file
persistence.xml is generated in META-INFO sub directory of Java source
directory.
♦ Log4J Configuration File - PowerDesigner uses Log4j as the default
logging framework to log messages. The Log4j properties file
log4j.properties is generated in Java source directory.
♦ Utility Class - The Util.java class contains some utility functions that are
used by unit tests, such as compare date by precision. It is defined in the
com.sybase.orm.util package.
♦ EJB 3 O/R Mapping Files - If mapping definition type specified includes
mapping file, Mapping File & Annotation or Mapping file, EJB 3 O/R
mapping files will be generated. These mapping files are generated in the
same directory with Java source.
♦ Factory and Data Access Objects - To help simplify the development of
your application, PowerDesigner generates DAO Factory and Data
Access Objects (DAO), using Factory and DAO design pattern.
♦ Unit Test Classes - generated to help user perform test to prove that:
• The mappings are correctly defined
• The CRUD (Create, Read, Update and Delete) work properly
239
Generating EJB 3 Persistent Objects
• The find methods work
• The navigations work
Unit test classes include:
• Test helper classes - provide some utility functions for unit test classes,
such as creating new instances, modifying state of instances, saving
instances etc.
• Unit Test Classes - For each persistent entity, PowerDesigner generates
a unit test class. The generated test cases are:
♦
♦
♦
♦
♦
♦
♦
♦
Insert test method - to test instance insert.
Update test method - to test instance update.
Delete test method - to test instance delete.
Property finder test methods - to test every property finder method
defined in Dao.
Get all instance list test method - to test get all instances method.
Navigation test method - to test association mapping.
Inheritance test method - to test inheritance mapping.
User defined operation test methods - skeleton test methods for user
defined functions.
♦ AllTest Class - a test suite that runs all the unit test cases.
♦ Ant Build File - PowerDesigner can generate an Ant build file to help you
to compile and run unit tests if you set the Generate Ant build.xml file
option to true in the Java code generation window. The Ant build.xml
contains customized elements for EJB 3:
• Custom properties - that specify directories and class path.
• Custom target definitions - to define JUnit tasks.
• Custom tasks - to run JUnit test or generate JUnit test reports.
240
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Generating JavaServer Faces (JSF) for Hibernate
JavaServer Faces (JSF) is a UI framework for Java Web applications. It is
designed to significantly ease the burden of writing and maintaining
applications that run on a Java application server and render their UIs back
to a target client.
PowerDesigner can generate JSF pages automatically according to the O/R
mapping persistent framework you select, such as Hibernate or EJB3.0. You
can quickly build Web application without writing repeated code because
PowerDesigner generates persistent classes, DAO, managed beans, page
navigation and JSF pages.
JSF generation can help you to test persistent objects using Web pages with
your own data.
JSF generation can also help you to generate default JSF Web application.
You can use an IDE to improve the generated JSF pages or change the
layout.
Adding JSF support
PowerDesigner uses a JSF profile (Extended Model Definition) to generate
JSF pages.
The JSF profile defines:
♦ Extended attributes
♦ Check Model
♦ JSP templates
♦ Invoker managed bean templates
♦ Face-configure templates
v To add JSF support
1. Verify that the current model has the target language Java or Java 5.0
2. Select Model(Extended Model Definitions.
3. In the List of Extended Model Definitions, click on the Import tool.
4. Select JavaServer Faces (JSF) in the User Interface tab and click OK.
241
Generating JavaServer Faces (JSF) for Hibernate
You can also select JSF Extended Model Definition when creating an OOM.
Note: JSF uses Data Access Objects (DAO) to access data from the
database. In order to generate JSF, you need to add a persistence
management Extended Model Definition such as Hibernate.
Defining global options
Each page could use a style sheet, a header file and a footer file to define its
standard presentation.
PowerDesigner provides default style sheet, header and footer files
Alternatively, you can specify your own files.
You can also define global default options like data format, time format, etc.
v To define global default JSF options
1. Open the model property sheet, and click the JSF tab:
2. Define style sheet, header and footer files.
3. Define the directory where the images used by style sheet, header and
footer.
242
Chapter 8. Generating Persistent Objects for Java and JSF Pages
4. Define the JSF library Jar files directory.
5. Define default options.
The following options are available:
Option
Description
JSF runtime
Specifies the JSF runtime.
It can be JSF Reference Implementation or Apache
My Faces.
Target IDE
Specifies the target IDE.
List/Default Values: Eclipse WTP, Sybase WorkSpace
Target runtime
Specifies the target runtime.
List/Default Values: Apache Tomcat v5.0, Sybase
EAServer v5.x, etc.
Dynamic Web
Module
Specifies the dynamic web module’s version
Stylesheet CSS File
Specifies the stylesheet file for JSF pages.
List/Default Values: 2.2, 2.3, and 2.4.
List/Default Values: %$_JSF%\stylesheet.css
Header JSP file
Specifies the header file for JSF pages.
List/Default Values: %$_JSF%\header.jsp
Footer JSP file
Specifies the footer file for JSF pages.
List/Default Values: %$_JSF%\footer.jsp
Picture library path
Specifies the path that contains pictures for JSF pages.
List/Default Values: %$_JSF%\images
Use resource bundle
Specifies to use a resource bundle.
Locale
Specifies the locale
Time zone
Specifies the time zone
Date format
Specifies the date format could be default, short,
medium, long, full
Default: short
Date display pattern
Specifies the date pattern
243
Generating JavaServer Faces (JSF) for Hibernate
Option
Description
Time format
Specifies the date format could be default, short,
medium, long, full
Default: short
Time display pattern
Specifies the time pattern
Date and time pattern
Specifies the date and time pattern
Currency code
Specifies the currency code
Currency symbol
Specifies the currency symbol
Form label width
Specifies the width of the control label in pixel in a
form
Default: 200
Form control width
Specifies the width of the control in pixel in a form
Default: 500
Table column width
Specifies the width of the control in pixel in a table
Default: 50
Table number rows
Specifies the number of rows that can be displayed in
a table
Default: 20
Defining attribute options
You can define attribute-level options for validation or presentation style.
244
Chapter 8. Generating Persistent Objects for Java and JSF Pages
v To define JSF Attribute Options
1. Open Attribute Property sheet, select JSF tab.
2. Define Attribute options.
Option
Description
Control type
Specifies the type of control.
Note: You should select the type that can support the
Attribute Java type.
♦ String - EditBox, MultilineEdit
♦ Boolean - CheckBox
♦ Date - Date, Time, DateTime, Year, Month, Day
♦ <Contains List of Value> - ListBox, ComboBox,
RadioButtons
Minimum length
Specifies the minimum number of characters
Maximum length
Specifies the maximum number of characters
Display format
pattern
Specifies the display format pattern for the attribute
Number of visible characters
Specifies the number of visible characters per line
Number of lines
Specifies the number of lines for multiline edit control
Default: 3
245
Generating JavaServer Faces (JSF) for Hibernate
Option
Description
List values
method
Specifies the method that provides the list of values for
ListBox, ComboBox or radioButtons.
CSS style
Specifies the CSS formatting style
Use the attribute
as foreign key
label
Specifies that the column associated to the attribute will
be used as the foreign key label for the foreign key
selection.
If no FK label column is defined, PowerDesigner will
choose the first not-PK and non FK column for the
default label column.
Default: False
Note: If the “Use the attribute as foreign key label” checkbox is not selected
and if there is a foreign key in the current table, PowerDesigner generates a
combo box by default to display the foreign key id. If you want to display
the value of another column (for example, the product name instead of the
product id), you can select the “Use the attribute as foreign key label” option
for product name attribute to indicate that it will be used as foreign key label.
Remember that if some attributes specify the choice to be true, we will
generate the foreign key label only according to the first attribute of them.
Derived attributes
To support derived attributes in PowerDesigner, you can:
246
Chapter 8. Generating Persistent Objects for Java and JSF Pages
1. Define an attribute, and indicate that it is not persistent, and is derived.
2. Generate and implement a getter.
When generating pages, PowerDesigner will automatically include the
derived attributes.
Attribute validation rules and default values
PowerDesigner can generate validation and default values for the edit boxes
in the Create and Edit pages.
v To define validation rules
1. Open the attribute property sheet, and click the Standard Checks tab.
2. You can define minimum value and maximum values to control the value
range.
3. You can define a default value. A string, must be enclosed in quotes. You
can also define the Initial value in the Details tab.
4. You can define a list of values that will be used in a listbox, combo box or
radio buttons.
Note: You can set a “list of values” on the Standard Checks tab of an
attribute property sheet, and PowerDesigner will generate a combo box that
includes the values. For validation rules, you can define the customized
domain as well, and then select the domain you want to apply in the
specified attribute.
You can also select which control style to use:
♦ Combobox
♦ Listbox
♦ Radio buttons (if the number of values is low) For example: Mr. Ms.
Defining Master-Detail pages
If two objects have a master-detail relationship, PowerDesigner renders them
(create, update, delete and find methods) in the same page. When you click
the detail link button column in the master table view, the detail page view in
the same page will change dynamically.
For example, there is a table Orders (Master table) and a table Orderline
(Detail table). The association is a composition. If you delete an order, the
order lines should be deleted. They will be shown on the same page:
247
Generating JavaServer Faces (JSF) for Hibernate
v To define a Master-Detail Page
1. Create a one-to-many association, where the one-to-many direction is
navigable.
2. Open the association property sheet, and click the JSF tab.
3. Select the “Use Master-Detail Page” checkbox:
The association type must be set to Composition or Aggregation, which
means that one side of association is a weak-reference to the master class.
The generated master-detail JSF page will resemble the following:
248
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Generating PageFlow Diagrams
In Java Server Faces, a configuration (xml) file is used to define navigation
rules between different web pages, which is called PageFlow. Power
Designer will provide a high level PageFlow diagram to abstract different
kinds of definition, and can generate navigation rules for JSF web
application and JSF page bean based on PageFlow diagram.
You can Generate PageFlow Diagram diagram in three levels, Model,
Package and Class. Next description will use the following example.
249
Generating JavaServer Faces (JSF) for Hibernate
v To generate a class level PageFlow diagram
1. Select one class in the ClassDiagram, e.g., Customer. Right click and
select the context menu “Generate PageFlow Diagram”.
2. A new PageFlow will be automatically generated, e.g.,
CustomerPageFlow.
v To generate a package level PageFlow diagram
1. Select one package, e.g., “Orders”. Right click it and select the context
menu “Generate PageFlow Diagram”.
2. The PageFlow will be generated for each class under this package and its
sub packages recursively, e.g., CustomerPageFlow, OrdersPageFlow,
ProductPageFlow, OrderLinePageFlow.
v To generate a model level PageFlow diagram
1. Right click on the model, e.g., “JSF”, and select the context menu
“Generate PageFlow Diagram”.
2. A model level PageFlow will be generated, e.g., “JSFPageFlow”
automatically. At the same time, the PageFlow will be generated for each
class under this package and its sub packages recursively, e.g.,
CustomerPageFlow, OrdersPageFlow, ProductPageFlow,
OrderLinePageFlow.
250
Chapter 8. Generating Persistent Objects for Java and JSF Pages
Modifing Default High Level PageFlow Diagram
After generating the default High Level PageFlow, you can define
customized pages and pageflows in the class level PageFlow.
All the pages in the default High Level PageFlow diagram have their
pre-defined stereotype, e.g., The stereotype for CustomerFind is “FindPage”,
CustomerEdit is “EditPage”, etc. You can add your customized Page.
You can also add new PageFlows to link the pages in the PageFlow diagram,
which is similar to adding a transition in a statechart diagram.
251
Generating JavaServer Faces (JSF) for Hibernate
v To add a new Page
1. Select the “State” from the palette, and drag it to the PageFlow diagram,
it will create a new Page with the default name.
2. You can change its name and change its stereotype to Page in its property
dialog, e.g., change the name to “Home”. This dialog is same with
general State.
After create a new Page, when the code generation, a default JSF page and
its page bean will be generated.
252
Chapter 8. Generating Persistent Objects for Java and JSF Pages
v To add a new PageFlow
1. Select “Transition” from Palette
2. Select the source state, e.g., “Home”, to the target state, e.g.,
“CustomerFind”. A default transition will be generated.
3. Double click the default transition, or right click the default transition and
select the context menu “Properties”, its property dialog will pop up.
1. Click “Create” button beside “Trigger Event” list, it will pop up Trigger
Event creation dialog. You can input the name, e.g., GoCustomer. Click
“OK” to finish the creation of Trigger Event.
253
Generating JavaServer Faces (JSF) for Hibernate
1. Click “OK” in the property dialog of Transition. A new PageFlow will be
created.
After you modify the default pageflow, and generate JSF codes, the
corresponding default JSF pages, page beans and faces-config file will be
updated.
Installing JSF runtime jar files
You can use an IDE like Eclipse WTP or Sybase WorkSpace to edit, deploy
254
Chapter 8. Generating Persistent Objects for Java and JSF Pages
and test JSF pages.
If the IDE does not include JSF runtime Jar files, you will need to download
a copy and install them.
You can use the following JSF runtimes:
JSF reference implementation
Apache My Faces
v To install the JSF reference implementation
1. Download the JSF reference implementation from the URL:
http://java.sun.com/j2ee/javaserverfaces/download.html
2. Unzip the downloaded file into a folder. This folder contains the required
library files:
♦ commons-beanutils.jar
♦ commons-collections.jar
♦ commons-digester.jar
♦ commons-logging.jar
♦ jsf-api.jar
♦ jsf-impl.jar
3. The JSF reference implementation requires an additional jar file:
♦ jstl.jar
You can download it from the URL:
http://cvs.apache.org/builds/jakarta-taglibs/nightly/ , select a zip file, for
example, jakarta-taglibs-20051115.zip.
Unzip the downloaded file, and there will be a folder
“jakarta-taglibs\standard\lib”. Then copy the jstl.jar file to the JSF
reference implementation lib folder.
4. Define a “JSF_LIB” variable in the PowerDesigner “General Options”
window, Variables tab to indicate the JSF reference implementation lib
folder path.
v To install the JSF reference implementation
1. Download the Apache MyFaces JSF implementation from the URL:
http://myfaces.apache.org/binary.cgi
Select the current release of Apache MyFaces, for example,
myfaces-1.1.1.zip.
255
Generating JavaServer Faces (JSF) for Hibernate
2. Unzip the downloaded file into a folder. This folder contains several jar
files:
♦ myfaces-all.jar
♦ myfaces-api.jar
♦ myfaces-impl.jar
Remove the myfaces-api.jar and myfacs-impl.jar files.
Download the dependency jar files from the myfaces examples at the
URL: http://myfaces.apache.org/binary.cgi , select a zip file, for example,
myfaces-1.1.1-examples.zip.
3. Copy the jar files of the folder myfaces-blank-example\WEB-INF\lib to
the Apache MyFaces lib folder. You should have the following jar files:
♦ commons-beanutils-1.6.1.jar
♦ commons-codec-1.2.jar
♦ commons-collections-3.0.jar
♦ commons-digester-1.5.jar
♦ commons-el.jar
♦ commons-logging.jar
♦ commons-validator.jar
♦ log4j-1.2.8.jar
4. Define a “JSF_LIB” variable in the PowerDesigner “General Options”
window, Variables tab to indicate the Apache MyFaces implementation
lib folder path.
Configuring for JSF generation
v To configure JSF generation
1. Select Tools ä General Options.
2. Select the Variables Category.
3. Add a new row in the Variables list:
♦ Name: JSF_LIB
♦ Value: Select JSF Jar file library folder.
4. Select the Named Paths Category.
5. If there is no _JSF named path, add a new row in the Named Paths list:
♦ Name: _JSF
256
Chapter 8. Generating Persistent Objects for Java and JSF Pages
♦ Value: Select the JSF folder where it contains JSF style sheets,
headers, footers and images.
Generating JSF pages
Before generation, make sure that you have attached the Hibernate Extended
Model Definition to the model, and checked the model for errors.
v To generate JSF files
1. Select Language ä Generate Java Code.
2. Specify a target directory.
3. Define generation options.
4. Click OK.
The generation produces the following files:
♦ Persistent files (persistent classes, DAO, . . . )
♦ Eclipse and Eclipse WTP project artifacts
♦ A home page
♦ JSF pages for persistent classes
♦ Managed beans
♦ Page flows (face configuration files)
For each persistent class, PowerDesigner generates:
♦ A find page for searching objects
♦ A list page for displaying find results
♦ A create page for creating new objects
♦ An edit page for updating objects
Testing JSF pages
You can deploy a JSF Web application in a Web server or an application
server that supports JSP. For example, Apache Tomcat, JBoss.
You can use an IDE like Eclipse to edit the generated Java classes, and use
the Eclipse WTP (Web Tools Project) to edit JSF pages and face config files.
257
Generating JavaServer Faces (JSF) for Hibernate
v To test JSF pages with Eclipse WTP
1. Install a Web server such as Tomcat or an application server such as
JBoss.
2. Generate Java code
3. Import the JSF project into Eclipse. The project is built.
4. Configure your Web server or application server.
5. Start the database.
6. Start the Web server or application server using the WTP Servers view.
7. Right-click the index.jsp under the webroot folder and select Run As(Run
on Server.
8. Select the server you want to use in the list.
v To test JSF pages with Apache Tomcat
1. Install a Web server such as Tomcat or an application server such as
JBoss.
2. Generate Java code
3. Import the JSF project into Eclipse. The project is built.
4. Copy the <ProjectName> folder under the .deployables folder into the
Apache Tomcat webapps folder. Where <ProjectName> is the Eclipse
project name.
5. Start the database.
6. Start Apache Tomcat server.
7. Run the Web application using the URL:
http://<hostname>:8080/<ProjectName>/index.jsp. If Apache Tomcat
is installed locally, <hostname> is localhost.
258
CHAPTER 9
Generating JDO Persistent Objects
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with JDO.
Topic:
page
Introduction
260
Creating JDO Persistent Objects
263
Generating Java Code and JDO Persistence Descriptor
272
Compiling Java Code and Running the JDO Enhancer
275
259
Introduction
Introduction
PowerDesigner supports the design of Java classes, database schema and
Object/Relational mapping (O/R mapping). Using these metadata,
PowerDesigner can also generate persistent objects using Java Data Objects
(JDO).
This chapter explains how to use PowerDesigner to define Java classes and
O/R mapping, generate JDO persistence descriptor and O/R mapping
extension and use an IDE to compile and enhance the Java classes.
Configuration
To follow this technical document, you need:
♦ An implementation of JDO, for example, Xcalia LiDO
♦ JDK 1.3 or higher
♦ Apache Ant 1.5 or higher
♦ A Java IDE (optional)
JDO
Java Data Objects (JDO) is a standard transparent persistence management
API for Java programs. It is developed as a Java Specification Request by
the Java Community Process. Application programmers can use JDO to
directly store their Java domain model object instances into persistent stores
such as a relational database, object database or files.
JDO provides transparent persistence management. It means that a Java
developer does not need to write any code for managing the persistence of
business objects.
v To define persistent objects for JDO
1. Create Java classes as usual. You can use interfaces, inheritances and
associations.
2. Define O/R mapping.
3. Define a JDO persistence descriptor.
4. Compile the Java classes.
5. Run the JDO enhancer to transform the Java classes into persistent
objects.
260
Chapter 9. Generating JDO Persistent Objects
v To use JDO persistent objects
1. Obtain a persistence manager.
2. Connect to a database.
3. Begin a transaction.
4. Work with the Java classes as usual (use JDOQL to find objects, create
new objects, modify objects, delete objects, etc.).
5. Commit the transaction.
JDO 1.0 does not specify a standard way of defining O/R mapping. Each
JDO implementation uses a different O/R mapping format. Most of the
products offer limited O/R mapping possibilities.
JDO supports inheritance and navigation between objects.
JDO and Entity Bean are complementary. If you plan to use persistent
objects locally without an application server or if you always access data
through Session Beans, it is better to use JDO. If you need to use remote
persistent objects or need better security support, you should use Entity
Beans.
There are several commercial implementations of JDO:
♦ Xcalia LiDO (http://www.xcalia.com)
♦ SolarMetric Inc. KODO (http://www.solarmetric.com)
♦ Hemisphere Technologies JDO Genie (http://www.hemtech.co.za)
There are also several open source projects:
♦ Apache OJB (http://db.apache.org/ojb/ )
♦ TriActive JDO (TJDO) (http://tjdo.sourceforge.net/ )
♦ XORM (http://xorm.sourceforge.net/ )
You can find more information on the web sites http://www.jdocentral.com,
http://java.sun.com/products/jdo/ .
PowerDesigner
PowerDesigner supports UML object modeling and data modeling. It is
useful for developers to use the same tool to define objects, database
schema, O/R mapping, and to generate the database schema, Java classes
and JDO persistence descriptor with O/R mapping definition.
261
Introduction
With PowerDesigner, you can:
♦ Define objects using UML class diagrams.
♦ Generate or reverse engineer a database using the Physical Data Model
(PDM).
♦ Generate O/R mapping when generating a PDM from OOM or an OOM
from PDM.
♦ Manually define complex O/R mapping.
♦ Generate and compile Java code.
♦ Generate JDO persistence descriptors with O/R mapping definition.
♦ Customize the O/R mapping generator.
♦ Generate an Ant build script for compiling and running the JDO enhancer.
♦ Integrate with JBuilder and Eclipse.
The recommended integration between PowerDesigner and a JDO product
is:
1. Define Java classes, database schema and O/R mapping in
PowerDesigner.
2. Generate Java classes, database and JDO persistence descriptor with O/R
mapping from PowerDesigner.
3. Compile and run the JDO enhancer from PowerDesigner, Ant, JBuilder
or Eclipse.
262
Chapter 9. Generating JDO Persistent Objects
Creating JDO Persistent Objects
The following sections describe how to create JDO Persistent Objects with
PowerDesigner.
Defining Java Classes
v To define JDO Java classes for your persistent business objects
1. Create a PowerDesigner Object-Oriented Model Class Diagram targeted
for Java.
2. Define Java classes using any UML Class Diagram concept
(generalization, association, interface, etc).
3. Define the O/R mapping.
If the JDO product you use does not support complex O/R mapping, you will
need to define Java classes that can be easily mapped to relational tables.
Defining O/R Mapping
v To define O/R mapping
1. Define classes using a Class Diagram.
2. Define the database schema using a Physical Data Model (PDM).
3. Define the O/R mapping.
For more information on how to use the Class Diagram, how to design a
database and how to define O/R mapping, see the core PowerDesigner
documentation.
Defining Classes and Database Schema
If you have an existing database, you can reverse engineer the database and
create a PDM, then generate an Object-Oriented Model (OOM) from the
PDM. PowerDesigner will generate the default O/R mapping.
For a new application, you can create a Class Diagram in an OOM, then
generate the PDM from the OOM. PowerDesigner will generate the default
O/R mapping.
If you already have a database schema and an OOM but they do not match,
you can manually define the O/R mapping.
263
Creating JDO Persistent Objects
For more information on O/R mapping, see the core PowerDesigner
documentation.
The following diagram shows an example of a PDM.
The following diagram shows the generated OOM from the PDM. The name
of the classes and their attributes can be modified to respect Java naming
conventions.
Defining O/R Mapping
When you generate an OOM from a PDM or a PDM from an OOM, the
default O/R mapping can be generated and saved in the OOM. You can also
manually define complex O/R mapping.
The following diagram shows the Attributes Mapping page of class
Customer. It was generated from a PDM.
264
Chapter 9. Generating JDO Persistent Objects
For O/R mapping, PowerDesigner supports:
♦ Mapping of a class to one or several tables or views
♦ Mapping of an attribute to a column or an expression
♦ Select, insert, update and delete queries for a class
♦ Query for an operation
♦ Mapping of an association to a table or a reference
♦ Select, insert and delete queries for an association
Customizing O/R Mapping
If necessary, you can customize the O/R mapping.
If the JDO product you are using supports complex O/R mapping, you can
also customize the select, insert, update, and delete queries.
Adding JDO Support
PowerDesigner uses a JDO profile (Extended Model Definition) to generate
JDO files.
A profile uses the extension mechanism to add additional features in
PowerDesigner such as extended attributes, custom symbols, and code
generation templates.
The JDO profile defines:
♦ Extended attributes
265
Creating JDO Persistent Objects
♦ Standard JDO persistence descriptor templates
♦ JDO products extensions
♦ Ant tasks
v To add JDO support
1. Verify that the current model has the target language Java.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click on the Import tool
4. Select Java Data Objects (JDO) from the list and click OK.
Defining Standard JDO Persistence Descriptors
To customize the generated JDO persistence descriptor and O/R mapping
extensions, PowerDesigner uses extended attributes for classes, attributes
and associations.
The standard JDO 1.0 persistence descriptor does not support O/R mapping.
To define O/R mapping, you must use a JDO product that provides an O/R
mapping extension.
266
Chapter 9. Generating JDO Persistent Objects
v To generate a standard JDO persistence descriptor without any
extension
1. Select Language ä Generate Java Code.
2. Click on the Options tab.
3. Set the “JDO provider” option to <Standard>
4. Click Apply to save this option.
5. Click Cancel to close the window.
By default, PowerDesigner generates a single metadata.jdo file.
v To generate a separate .jdo file for each package that contains
persistent objects
1. Select Language ä Generate Java Code.
2. Click on the Options tab.
3. Set the “Use a single JDO persistence descriptor for all packages” option
to false.
4. Click Apply to save this option.
5. Click Cancel to close the window.
If you want to generate a JDO persistence descriptor for a specific JDO
product, you still need to configure standard JDO extended attributes.
If a class has primary key attributes, PowerDesigner will generate an inner
class to implement the primary key class.
If you use inheritances, only the parent class can have primary key attributes.
Class Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
identity-type
Specifies the object identity type. The default value
is datastore.
Tag name: identity-type
objectid-class
Specifies the primary key class name.
Tag name: objectid-class
requires-extent
Specifies the requires extent.
Tag name: requires-extent
267
Creating JDO Persistent Objects
Attribute Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
default-fetch-group
Specifies that the attribute is managed as a group
with other attributes.
Tag name: default-fetch-group
embedded
Specifies that the attribute should be stored in the
instance instead of its own instance.
Tag name: embedded
null-value
Specifies the null value treatment. The default value
is none.
Tag name: null-value
persistence-modifier
Specifies the persistence modifier.
Tag name: persistence-modifier
Association Extended Attributes
The following extended attributes are available:
Extended Attribute
Description
roleA-default-fetchgroup
Specifies that roleA is managed as a group with
other attributes.
Tag name: default-fetch-group
roleA-embedded
Specifies that roleA should be stored in the instance
instead of its own instance.
Tag name: embedded
roleA-null-value
Specifies the null value treatment for roleA.
Tag name: null-value
roleA-persistencemodifier
Specifies the persistence type of roleA.
roleB-default-fetchgroup
Specifies that roleB is managed as a group with
other attributes.
Tag name: persistence-modifier
Tag name: default-fetch-group
268
Chapter 9. Generating JDO Persistent Objects
Extended Attribute
Description
roleB-embedded
Specifies that roleB should be stored in the instance
instead of its own instance.
Tag name: embedded
roleB-null-value
Specifies the null value treatment for roleB.
Tag name: null-value
roleB-persistencemodifier
Specifies the persistence type of roleB.
Tag name: persistence-modifier
Defining JDO Persistence Descriptor for Xcalia LiDO
Xcalia LiDO is a JDO product. It fully implements the JDO 1.0 standard. It
also provides complete O/R mapping extensions.
PowerDesigner supports LiDO 1.4. PowerDesigner can generate all LiDO
extensions.
To support LiDO, you need to:
♦ select LiDO as the JDO provider
♦ define the LiDO home directory
♦ define LiDO extended attributes for LiDO extensions
Configuring JDO Provider for LiDO
v To select LiDO as the JDO provider
1. Select Language ä Generate Java Code.
2. Click on the Options tab.
3. Set the “JDO provider” option to Xcalia LiDO
4. Click Apply to save this option.
5. Click Cancel to close the window.
By default, PowerDesigner generates a single metadata.jdo file. You do not
have to change this behavior for LiDO.
269
Creating JDO Persistent Objects
Configuring the LiDO Home Directory
To be able to run the LiDO JDO enhancer, you need to define the
LIDO_HOME variable in PowerDesigner or in the Windows environment
variables.
v To define the LIDO_HOME variable in PowerDesigner
1. Select Tools ä General Options.
2. Select the Variable category.
3. Add a LIDO_HOME variable.
4. In the value column of this variable, type the home directory of LiDO.
If you define the LIDO_HOME variable in the Windows environment
variables, you need to restart PowerDesigner for this to take effect.
Attribute Extended Attributes for LiDO
The following extended attributes are available:
Extended Attribute
Description
LiDO-BigDecimalLength
Specifies the LiDO BigDecimal length.
Extension name: sql-mapping
LiDO-BigIntegerLength
Specifies the LiDO BigInteger string format
length.
Extension name: sql-mapping
LiDO-CustomMapper
Specifies the LiDO custom mapper class name.
Extension name: custom-mapper
LiDO-DateFormat
Specifies the LiDO date format.
Extension name: sql-mapping
LiDO-IndexType
Specifies the column index type.
Extension name: sql-index
Verifying JDO Persistence Descriptor
Before generating the JDO persistence descriptor, you can preview the file to
make sure that it is properly defined.
270
Chapter 9. Generating JDO Persistent Objects
v To preview the JDO persistence descriptor
1. Open the property sheet of the model or package that contains the classes.
2. Click on the Preview tab.
3. Select the JDO.Persistence Descriptor tab:
271
Generating Java Code and JDO Persistence Descriptor
Generating Java Code and JDO Persistence
Descriptor
To run the JDO enhancer, an Ant build.xml file is used.
Generating Java Code and the JDO Persistence Descriptor
v To generate Java code and the JDO persistence descriptor
1. Select Language ä Generate Java Code
2. Specify the directory where you want to generate the files.
3. Click the Targets tab and verify that JDO is selected.
4. [optional] Click the Selection tab and select the packages, classes and
interfaces you want to generate.
5. Click the Options tab and set the “ANT: Generate Ant build.xml file”
option to true
272
Chapter 9. Generating JDO Persistent Objects
6. [optional] If you want to compile Java classes and run the JDO enhancer
from PowerDesigner, click the Tasks tab and select the “JDO: Compile
Java sources, Run JDO Enhancer” commands.
7. Click OK to generate the Java classes and the JDO persistence descriptor.
PowerDesigner generates all the Java source code and the JDO
persistence descriptor. You can use an editor to view the generated files
273
Generating Java Code and JDO Persistence Descriptor
274
Chapter 9. Generating JDO Persistent Objects
Compiling Java Code and Running the JDO
Enhancer
Before you can use the persistent JDO Java classes, you need to compile
them and run the JDO enhancer.
To compile and run the JDO enhancer, you can use JBuilder, Eclipse,
Apache Ant, PowerDesigner or any IDE that supports Ant.
Using JBuilder
To compile Java classes and run JDO enhancer with JBuilder, you need to
add the JBuilder profile before you generate the Java code and JDO
persistence descriptor.
v To add the JBuilder profile
1. Select Model ä Extended Model Definitions.
2. In the List of Extended Model Definitions, click on the Import tool.
3. Click on the IDE category.
4. Select JBuilder 9.
Once you have added the JBuilder profile, you can generate the Java code.
PowerDesigner will also generate a JBuilder project file and an Ant build
script.
v To compile and run the JDO enhancer
1. Start JBuilder.
2. Open the generate JBuilder project file in the generation directory.
3. Right-click the project node in the browser.
4. Select Make. JBuilder will compile the Java classes.
5. Expand the Ant build.xml file.
6. Right-click on the Enhance task.
7. Select Make. JBuilder will run the JDO enhancer using Ant.
275
Compiling Java Code and Running the JDO Enhancer
For more information on JBuilder support, see the JBuilder support technical
document from the Help ä Product Documentation menu.
Using Eclipse
To compile Java classes and run JDO enhancer with Eclipse, you need to add
the Eclipse profile before you generate the Java code and JDO persistence
descriptor.
v To add the Eclipse profile
1. Select Model ä Extended Model Definitions.
2. In the List of Extended Model Definitions, click on the Import tool.
3. Click on the IDE category.
4. Select Eclipse.
Once you have added the Eclipse profile, you can generate the Java code.
PowerDesigner will also generate an Eclipse project file and an Ant build
script.
v To compile and run the JDO enhancer
1. Start Eclipse.
2. Import the generated project if it is a new project or refresh the project if
it is an existing project. Eclipse will automatically compile the project.
276
Chapter 9. Generating JDO Persistent Objects
3. Right-click the Ant build.xml file.
4. Select Run Ant
5. In the list of tasks, select the enhance task
6. Click Finish. Eclipse will run the JDO enhancer.
Using Ant
To compile Java classes and run the JDO enhancer with Apache Ant, you
need to enable the Ant build.xml file generation before you generate the Java
277
Compiling Java Code and Running the JDO Enhancer
code and JDO persistence descriptor.
Once you have enabled the Ant build.xml file generation, you can generate
the Java code. PowerDesigner will also generate an Ant build script.
You can use an IDE or a text editor to edit Java source code.
v To compile and enhance JDO classes
1. Open a DOS prompt window.
2. Go to the directory where you have generated the Java code.
3. Enter: ant enhance
Using PowerDesigner
v To compile and run JDO enhancer using PowerDesigner
1. Select Language ä Generate Java Code.
2. Click the Tasks tab and select the “JDO: Compile Java sources, Run JDO
Enhancer” command..
3. Click OK.
Customizing JDO Support
The JDO support in PowerDesigner is entirely defined in the JDO Extended
Model Definition. You can customize it if necessary. You can also add the
support for other JDO products.
278
Chapter 9. Generating JDO Persistent Objects
v To customize the JDO support
1. Select Tools ä Resources ä Extended Model Definitions ä
Object-Oriented Models.
2. In the List of Extended Model Definitions, select Java Data Objects
(JDO)
3. Click the Properties tool on the toolbar.
4. Use the Extended Model Definition Editor to modify the O/R Mapping
template and the extended attributes.
279
CHAPTER 10
Generating .NET 2.0 Persistent Objects
and Windows Applications
About this chapter
Contents
This chapter explains how to use PowerDesigner in conjunction with
ADO.NET, NHibernate, Unit Test and .NET Window Application
Topic:
page
Introducing the .NET and .NET CF Frameworks
282
Generating ADO.NET and ADO.NET CF Persistent Objects
285
Generating NHibernate Persistent Objects
295
Configuring Connection Strings
314
Generating Unit Tests
317
Generating Windows or Smart Device Applications
323
281
Introducing the .NET and .NET CF Frameworks
Introducing the .NET and .NET CF Frameworks
PowerDesigner follows the best practices and design patterns to produce
n-tier architecture enterprise applications for the .NET framework, as shown
in the following figure:
PowerDesigner can be used to generate all these layers:
♦ Domain Model - contains persistent POCOs (Plain Old CLR Objects),
which are similar to Java’s POJOs. These act as information holders for
the application and do not contain any business logic. A primary key
class is generated for each persistent class in order to help the
“find-by-primary-key” function, especially when the class has a
composite primary identifier.
♦ Data Access Layer - follows the standard DAO pattern, and provides
typical CRUD methods for each class. This layer is divided into two
parts, one of which contains interfaces for DAL, while the other contains
the implementation for these interfaces, using ADO.NET technology to
access databases.
The DAL Helper provides common features used by all the DAL
implementations, such as connection and transaction management, and
282
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
the supply of SQL command parameters. Some common classes, such as
Session, Criteria, and Exception, are also defined.
PowerDesigner supports two kinds of DAL implementation:
• ADO.NET (see “Generating ADO.NET and ADO.NET CF Persistent
Objects” on page 285)
• Nhibernate (see “Generating NHibernate Persistent Objects” on
page 295)
♦ Business Logic Layer - contains the typical user-defined business logic.
This is a wrapper for the DAL, exposing CRUD functionalities provided
by the DAL underneath. You can customize this layer according to your
needs.
♦ Windows Application - the Composite UI Application Block, or CAB
layer helps you build complex user interface applications that run in
Windows. It provides an architecture and implementation that assists
with building applications by using the common patterns found in
line-of-business client applications.
PowerDesigner can generate data-centric windows applications based on
the CAB (see “Generating Windows or Smart Device Applications” on
page 323).
The .NET CF (Compact Framework) has a similar organization, but with a
configuration utility class that provides the capability to load and parse
configuration used in different layers, e.g., data source configuration, log and
exception configuration, etc:
283
Introducing the .NET and .NET CF Frameworks
PowerDesigner supports the ADO.NET DAL implementation for the .NET
CF (see “Generating ADO.NET and ADO.NET CF Persistent Objects” on
page 285)
284
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Generating ADO.NET and ADO.NET CF Persistent
Objects
Microsoft ADO.NET and ADO.NET CF are database-neutral APIs.
PowerDesigner provides enhancements to them to support:
♦ Cascade Association: one-to-one, one-to-many, many-to-one, and
complex many-to-many associations.
♦ Inheritance: table per class , table per subclass, and table per concrete
class hierarchies.
♦ Value Types
♦ SQL statements: including complex SQL statement like Join according to
OOM model and PDM model.
PowerDesigner also supports the design of .NET classes, database schema
and Object/Relational mapping (O/R mapping), and can use these metadata,
to generate ADO.NET and ADO.NET CF persistent objects including:
♦ Persistent .NET classes (POCOs)
♦ ADO.NET O/R mapping classes (ADODALHelper)
♦ DAL factory
♦ Data Access Objects (DAL)
Adding ADO.NET or ADO.NET CF support
PowerDesigner provides an ADO.NET and ADO. Net CF extended model
definitions to generate persistent files for these frameworks.
v To add ADO.NET or ADO.NET CF support
1. Verify that the current model has the target language C# 2.0 or Visual
Basic 2005, and select Model ä Extended Model Definitions.
2. In the List of Extended Model Definitions, click the Import tool.
3. Click the O/R Mapping sub-tab, select ADO.NET or ADO.NET Compact
Framework, and click OK to attach the framework to the model.
4. Double-click the model name in the browser to open its property sheet,
and click the ADO.NET or ADO.NET CF tab:
285
Generating ADO.NET and ADO.NET CF Persistent Objects
5. Define the database connection parameters and other options. For more
information, see “ADO.NET and ADO.NET CF options” on page 286.
6. Click OK to return to the model.
You can also select the ADO.NET or ADO.NET CF Extended Model
Definition when creating an OOM by clicking the Extended Model
Definitions tab in the New dialog, clicking the O/R Mapping sub-tab, and
selecting the ADO.NET or ADO.NET CF checkbox.
ADO.NET and ADO.NET CF options
The following options are available on the ADO.NET and ADO.NET CF
tabs:
286
Option
Description
Target Device
[ADO.NET CF only] Specifies the operating system on
which the application will be deployed.
Output file
folder
[ADO.NET CF only] Specifies the location on the device
to which the application will be deployed. Click the
ellipsis button to the right of this field to edit the root
location and add any appropriate sub-directories.
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Data Provider
Specifies which data provider you want to use. For ADO.NET, you can choose between:
♦ OleDB
♦ SqlClient
♦ ODBC
♦ Oracle
For ADO.NET CF, you can choose between:
♦ Microsoft SQL Server 2005 Mobile Edition
♦ Sybase ASA Mobile Edition
Connection
String
Specifies the connection string. You can enter this by
hand or click the ellipsis tool to the right of the field to
use a custom dialog. For information about the providerspecific parameters used to build the connection string, see
“Configuring Connection Strings” on page 314.
Default access
Specifies the default class attribute access type. This and
the other package options, are valid for the whole model
You can fine-tune these options for an individual package
through its property sheet.
Default cascade
Specifies the default cascade type.
Default command type
Specifies the default command type, which can be overridden by concrete class.
DALContainer
Specifies the collection type returned from database. You
can choose between Generic List Collection and System.Collections.ArrayList.
Logging Type
[ADO.NET only] The common logging component is
Log4Net, but you can reuse it as well if you have your own
logging framework. By default, the value of logging type
is Console type, but PowerDesigner also supports “None”
or Log4Net
Class mappings
There are two kinds of classes in ADO.NET and ADO.NET CF:
♦ Entity classes - have their own database identities, mapping files and life
cycles
287
Generating ADO.NET and ADO.NET CF Persistent Objects
♦ Value type classes - depend on entity classes. Also known as component
classes
Framework-specific class mapping options are defined on the ADO.NET or
ADO.NET CF tab of the class property sheet:
288
Option
Description
Default cascade
Specifies the default cascade style.
Default access
Specifies the default access type (field or property)
Default command
type
Specifies command type, currently we supply Text and
StoreProcedure to users.
Lazy
Specifies that the class should be lazy fetching.
Abstract class
Specifies that the class is abstract.
Discriminator column
Specifies the discriminator column or formula for polymorphic behavior in a one table per hierarchy mapping
strategy.
Discriminator
value
Specifies a value that distinguishes individual subclasses, which are used for polymorphic behavior.
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Discriminator
type
Specifies the discriminator type.
Primary identifier mappings
Primary identifier mapping is mandatory in ADO.NET and ADO.NET CF.
Primary identifiers of entity classes are mapped to primary keys of master
tables in data sources. If not defined, a default primary identifier mapping
will be generated, but this may not work properly.
Mapped classes must declare the primary key column of the database table.
Most classes will also have a property holding the unique identifier of an
instance.
There are three kinds of primary identifier mapping in ADO.NET and
ADO.NET CF:
♦ Simple identifier mapping - When a primary key is attached to a single
column, only one attribute in the primary identifier can be mapped. This
kind of primary key can be generated automatically. You can define
increment, identity, sequence, etc., on the corresponding column in PDM.
♦ Composite identifier mapping - If a primary key comprises more than one
column, the primary identifier can have multiple attributes mapped to
these columns. In some cases, the primary key column could also be the
foreign key column. In the following example, the Assignment class has
a primary identifier with three attributes: one basic type attribute and two
migrated attributes:
♦ Component identifier mapping - For more convenience, a composite
identifier can be implemented as a separate value type class. The primary
identifier has just one attribute with the class type. The separate class
289
Generating ADO.NET and ADO.NET CF Persistent Objects
should be defined as a value type class. Component class mapping will be
generated then. In the example below, three name attributes are grouped
into one separate class Name, which is mapped to the same table as the
Person class.
Attribute mappings
Attributes can be migrated attributes or ordinary attributes. Ordinary
attributes can be mapped to columns or formulas. Migrated attributes do not
require attribute mapping.
The following types of mapping are possible:
♦ Component attribute mapping - A component class can define the
attribute mapping as for other classes, except that there is no primary
identifier.
♦ Discriminator mapping - In inheritance mapping with a
one-table-per-hierarchy strategy, the discriminator needs to be specified
in the root class. You can define the discriminator in the ADO.NET or
ADO.NET CF tab of the class property sheet.
Framework-specific attribute mapping options are defined in the ADO.NET
or ADO.NET CF tab of the Attribute property sheet.
290
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Generate finder
function
Generates a finder function for the attribute.
Insert
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Update
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Lazy
Specifies that this property should be fetched lazily when
the instance variable is first accessed (requires build-time
byte code instrumentation).
Property access
Specifies the strategy used for accessing the property
value.
Defining association mappings
ADO.NET and ADO.NET CF support one-to-one,
one-to-many/many-to-one, and many-to-many association mappings.
PowerDesigner allows you to define standard association attributes like
Container Type class, role navigability, array size and specific extended
291
Generating ADO.NET and ADO.NET CF Persistent Objects
attributes for association mappings.
v To define ADO.NET or ADO.NET CF association mapping options
1. Open the Association property sheet and click the ADO.NET or
ADO.NET CF Collection tab.
1. Define the appropriate options and then click OK.
The following options are available on this tab:
292
Option
Description
Order by
Specifies a table column (or columns) that define the
iteration order of the Set or bag, together with an optional
asc or desc.
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Cascade
Specifies which operations should be cascaded from the
parent object to the associated object.
Batch size
Specifies the batch load size.
Not found
Specifies how foreign keys that reference missing rows
will be handled: ignore will treat a missing row as a null
association.
Insert
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Update
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Lazy
Specifies that this property should be fetched lazily when
the instance variable is first accessed.
Many-to-Many
operation side
Specifies the entry point when operating data in bidirectional many-to-many association. No matter the
choice is RoleA or RoleB, the results are the same.
Defining inheritance mappings
ADO.NET and ADO.NET CF support the three basic inheritance mapping
strategies:
♦ Table per class hierarchy
♦ Table per subclass
♦ Table per concrete class
♦ These strategies all follow the standard inheritance mapping definitions.
Generating code for ADO.NET or ADO.NET CF
In order to generate code for ADO.NET or ADO.NET CF, you must have
the .NET Framework 2.0 Visual Studio.NET 2005 or above installed:
v To generate ADO.NET or ADO.NET CF code
1. Select Tools ä Check Model to verify if there are errors or warnings in
the model. If there are errors, fix them before continuing with code
generation.
293
Generating ADO.NET and ADO.NET CF Persistent Objects
2. Select Language ä Generate C# 2 Code or Generate Visual Basic 2005
Code to open the Generation dialog box:
3. Specify the root directory where you want to generate the code and then
click the Options tab:
4. [optional] To use DAL, set the Generate DAL sources option to true. For
information about the standard C# and VB.NET generation options, see
the OOM User’s Guide .
5. Click OK to generate code immediately or Apply and then Cancel to save
your changes for later.
Once generation is complete, you can use an IDE such as Visual Studio.NET
2005 to modify the code, compile, and develop your application.
294
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Generating NHibernate Persistent Objects
NHibernate is a port of the Hibernate Core for Java to the .NET Framework.
It handles persistent POCOs (Plain Old CLR Objects) to and from an
underlying relational database.
All the common .NET idioms, including association, inheritance,
polymorphism, composition, and the collections framework are supported.
NHibernate allows you to express queries in its own portable SQL extension
(HQL), as well as in native SQL, or with Criteria and Example objects.
PowerDesigner supports the design of .NET classes, database schema, and
Object/Relational mapping (O/R mapping). Using these metadata,
PowerDesigner can generate NHibernate persistent objects including:
♦ Persistent .NET classes (domain specific objects)
♦ NHibernate Configuration file
♦ NHibernate O/R mapping files
♦ DAL factory
♦ Data Access Objects (DAL)
Adding NHibernate Support
PowerDesigner provides a NHibernate Extended Model Definition to
generate NHibernate persistent files.
v To add NHibernate support
1. Verify that the current model has the target language C# 2.0 or Visual
Basic 2005
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click the Import tool.
4. Select NHibernate in the O/R Mapping sub-tab and click OK to return to
the model.
5. Double-click the model name in the browser to open its property sheet,
and click the NHibernate tab:
295
Generating NHibernate Persistent Objects
6. Define the database connection parameters and other options. For more
information, see “NHibernate options” on page 296.
7. Click OK to return to the model.
You can also select the NHibernate Extended Model Definition when
creating an OOM by clicking the Extended Model Definitions tab in the
New dialog, clicking the O/R Mapping sub-tab, and selecting the
NHibernate checkbox.
NHibernate options
The following options are available on this tab:
Option
Description
Dialect
Specifies the dialect, and hence the type of database.
NHibernate Tag: dialect
Driver class
Specifies the driver class.
NHibernate Tag: connection.driver_class
296
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Connection
String
Specifies the connection string. You can enter this by
hand or click the ellipsis tool to the right of the field to
use a custom dialog. For information about the providerspecific parameters used to build the connection string, see
“Configuring Connection Strings” on page 314.
NHibernate Tag: connection.url
Auto import
Specifies that users may use an unqualified class name in
queries.
Default access
Specifies the default class attribute access type. This and
the other package options, are valid for the whole model
You can fine-tune these options for an individual package
through its property sheet.
Specifies the
default cascade
Specifies the default cascade type.
Schema name
Specifies the default database schema name.
Catalog name
Specifies the default database catalog name.
Show SQL
Specifies that SQL statements should be shown in the log.
NHibernate Tag: show_sql
Auto schema
export
Specifies the mode of creation from tables.
NHibernate Tag: hbm2ddl.auto
Defining Class Mappings
There are two kinds of classes in NHibernate:
♦ Entity classes - have their own database identities, mapping files and life
cycles
♦ Value type classes - depend on entity classes. Also known as component
classes
NHibernate uses mapping XML files to define the mapping metadata. Each
mapping file can contain metadata for one or many classes. PowerDesigner
uses the following grouping strategy:
♦ A separate mapping file is generated for each single entity class that is
not in an inheritance hierarchy.
297
Generating NHibernate Persistent Objects
♦ A separate mapping file is generated for each inheritance hierarchy that
has a unique mapping strategy. All mappings of subclasses are defined in
the mapping file. The mapping file is generated for the root class of the
hierarchy.
♦ No mapping file is generated for a single value type class that is not in an
inheritance hierarchy. Its mapping is defined in its owner’s mapping file.
Classes can be mapped to tables or views. Since views have many
constraints and limited functionality (for example they do not have primary
keys and reference keys), some views cannot be updated, and the mappings
may not work properly in some cases.
There are some conditions that need to be met in order to generate mapping
for a specific class:
♦ The source can be generated. This may not be possible if, for example,
the visibility of the class is private.
♦ The class is persistent.
♦ The generation mode is not set to Generate ADT (abstract data type) and
Value Type.
♦ If the class is an inner class, it must be static, and have public visibility.
NHibernate should then be able to create instances of the class.
NHibernate specific class mapping options are defined in the NHibernate tab
of the class property sheet:
298
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Dynamic insert
Specifies that INSERT SQL should be generated at runtime
and will contain only the columns whose values are not
null.
NHibernate Tag: dynamic-insert
Dynamic update
Specifies that UPDATE SQL should be generated at runtime
and will contain only the columns whose values have
changed.
NHibernate Tag: dynamic-update
Select before
update
Specifies that NHibernate should never perform a SQL
UPDATE unless it is certain that an object is actually
modified.
NHibernate Tag: select-before-update
Default cascade
Specifies the default cascade style.
NHibernate Tag: default-cascade
299
Generating NHibernate Persistent Objects
Option
Description
Default access
Specifies the default access type (field or property)
NHibernate Tag: default-access
Proxy name
Specifies an interface to use for lazy initializing proxies.
NHibernate Tag: proxy
Batch size
Specifies a “batch size” for fetching instances of this class
by identifier.
NHibernate Tag: batch-size
Check
Specifies a SQL expression used to generate a multi-row
check constraint for automatic schema generation.
NHibernate Tag: check
Polymorphism
Specifies whether implicit or explicit query polymorphism
is used.
NHibernate Tag: polymorphism
Schema name
Specifies the name of the database schema.
NHibernate Tag: schema
Catalog name
Specifies the name of the database catalog.
NHibernate Tag: catalog
Row id
Specifies that NHibernate can use the ROWID column on
databases which support it (for example, Oracle).
NHibernate Tag: rowed
Persister class
name
Specifies a custom persistence class.
Lazy
Specifies that the class should be lazy fetching.
NHibernate Tag: persister
NHibernate Tag: lazy
Mutable
Specifies that instances of the class are mutable.
NHibernate Tag: mutable
Abstract class
Specifies that the class is abstract.
NHibernate Tag: abstract
Auto import
Specifies that an unqualified class name can be used in a
query
NHibernate Tag: Auto-import
300
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Discriminator
column
Specifies the discriminator column or formula for polymorphic behavior in a one table per hierarchy mapping
strategy.
NHibernate Tag: discriminator
Discriminator
value
Specifies a value that distinguishes individual subclasses,
which are used for polymorphic behavior.
NHibernate Tag: discriminator-value
Discriminator
type
Specifies the discriminator type.
Force usage of
discriminator
Forces NHibernate to specify allowed discriminator values
even when retrieving all instances of the root class.
NHibernate Tag: type
NHibernate Tag: force
Do not use
discriminator
in insert
Forces NHibernate to not include the column in SQL
INSERTs
Optimistic
lock type
Specifies an optimistic locking strategy.
Optimistic
lock column
name
Specifies the column used for optimistic locking. A field is
also generated if this option is set.
Optimistic
lock unsaved
value
Specifies whether an unsaved value is null or undefined.
NHibernate Tag: insert
NHibernate Tag: optimistic-lock
NHibernate Tag: version/ timestamp
NHibernate Tag: unsaved-value
Primary identifier mappings
Primary identifier mapping is mandatory in NHibernate. Primary identifiers
of entity classes are mapped to primary keys of master tables in data sources.
If not defined, a default primary identifier mapping will be generated, but
this may not work properly.
There are three kinds of primary identifier mapping in NHibernate:
♦ Simple identifier mapping ♦ Composite identifier mapping
♦ Component identifier mapping
301
Generating NHibernate Persistent Objects
Mapped classes must declare the primary key column of the database table.
Most classes will also have a property holding the unique identifier of an
instance.
Simple identifier mapping When a primary key is attached to a single column, only one attribute in the
primary identifier can be mapped. This kind of primary key can be generated
automatically. You can define the generator class and parameters. There are
many generator class types, such as increment, identity, sequence, etc. Each
type of generator class may have parameters that are meaningful to it. See
your NHibernate documentation for detailed information.
You can define the generator class and parameters in the NHibernate tab of
the primary identifier property sheet. The parameters take the form of
param1=value1; param2=value2.
v To define an identifier mapping
1. Open the class property sheet and click the Identifiers tab. Double-click
the entry to open its property sheet.
2. Click the NHibernate tab, select a generator class and define its
parameters.
Example parameters:
♦ Select hilo in the Generator class list
302
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
♦ Enter “table=hi_value,column=next_value,max_lo=10000” in the
Generator params box. You should use commas to separate the
parameters.
3. You can check the code in the Preview tab:
Note that, if there are several Primary identifier attributes, the generator is
not used.
Composite identifier
mapping
If a primary key comprises more than one column, the primary identifier can
have multiple attributes mapped to these columns. In some cases, the
primary key column could also be the foreign key column.
303
Generating NHibernate Persistent Objects
In the above example, the Assignment class has a primary identifier with
three attributes: one basic type attribute and two migrated attributes. The
primary identifier mapping is as follows:
<composite-id>
< key-property name="Type" access="property">
< column name="Type" sql-type="integer"
not-null="true"/>
</key-property>
<key-many-to-one name="title" access="property">
</key-many-to-one>
<key-many-to-one name="worker" access="property">
</key-many-to-one>
</composite-id>
Component primary
identifier mapping
For more convenience, a composite identifier can be implemented as a
separate value type class. The primary identifier has just one attribute with
the class type. The separate class should be defined as a value type class.
Component class mapping will be generated then.
In the example above, three name attributes are grouped into one separate
class Name. It is mapped to the same table as Person class. The generated
primary identifier is as follows:
<composite-id name="name" class="identifier.Name">
<key-property name="firstName">
<column name="name_firstName"
sql-type="text"/>
</key-property>
<key-property name="middleName">
<column name="name_middleName"
sql-type="text"/>
</key-property>
<key-property name="lastName">
<column name="name_lastName"
sql-type="text"/>
</key-property>
</composite-id>
Note: The value type class must implement the java.io.Serializable interface,
which implements the equals() and hashCode() methods.
Attribute mappings
Attributes can be migrated attributes or ordinary attributes. Ordinary
attributes can be mapped to columns or formulas. Migrated attributes do not
304
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
require attribute mapping.
The following types of mapping are possible:
♦ Map attribute to formula - When mapping an attribute to a formula, you
should ensure that the syntax is correct. There is no column in the source
table of the attribute mapping.
♦ Component attribute mapping - A component class can define the
attribute mapping as for other classes, except that there is no primary
identifier.
♦ Discriminator mapping - In inheritance mapping with a
one-table-per-hierarchy strategy, the discriminator needs to be specified
in the root class. You can define the discriminator in the NHibernate tab
of the class property sheet.
NHibernate-specific attribute mapping options are defined in the NHibernate
tab of the Attribute property sheet.
Option
Description
Generate finder
function
Generates a finder function for the attribute.
305
Generating NHibernate Persistent Objects
Option
Description
NHibernate type
Specifies a name that indicates the NHibernate type.
Property access
Specifies the strategy that NHibernate should use for
accessing the property value.
Id unsaved value
Specifies the value of an unsaved id.
Insert
Specifies that the mapped columns should be included in
any SQL INSERT statements.
Update
Specifies that the mapped columns should be included in
any SQL UPDATE statements.
Optimistic lock
Specifies that updates to this property require acquisition
of the optimistic lock.
Lazy
Specifies that this property should be fetched lazily when
the instance variable is first accessed (requires build-time
byte code instrumentation).
Defining Association Mappings
NHibernate supports one-one, one-to-many/many-to-one, and many-to-many
association mappings. The mapping modeling is same with standard O/R
Mapping Modeling. However, NHibernate provides special options to define
its association mappings, which will be saved into <Class>.hbm.xml
mapping file. PowerDesigner allows you to define standard association
attributes like Container Type class, role navigability, array size and specific
extended attributes for NHibernate association mappings.
306
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
v To define the NHibernate association mapping options
1. Open the Association property sheet and click the NHibernate Collection
tab.
2. Define the collection management options (see “Defining NHibernate
Collection options” on page 308).
3. Select the NHibernate Persistence tab, and define the persistence options
(see “Defining NHibernate Persistence options” on page 309).
307
Generating NHibernate Persistent Objects
Defining NHibernate Collection options
The following options are available:
Option
Description
Sort
Specifies a sorted collection with natural sort order, or a
given comparator class.
NHibernate Tag: sort
Order by
Specifies a table column (or columns) that define the iteration
order of the Set or bag, together with an optional asc or desc.
NHibernate Tag: order-by
Access
Specifies the strategy Nhibernate should use for accessing
the property value.
NHibernate Tag: access
308
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Cascade
Specifies which operations should be cascaded from the
parent object to the associated object.
NHibernate Tag: cascade
Collection
type
Specifies a name that indicates the NHibernate type.
Batch size
Specifies the batch load size.
NHibernate Tag: type
NHibernate Tag: batch-size
Not found
Specifies how foreign keys that reference missing rows
will be handled: ignore will treat a missing row as a null
association.
NHibernate Tag: not-found
Inverse collection
Specifies that the role is the inverse relation of the opposite
role.
NHibernate Tag: inverse
Mapping type
Specifies the collection mapping type
NHibernate Tag: Set, Array, Map, or List.
Defining NHibernate Persistence options
The following options are available:
Option
Description
Schema
Specifies the name of the schema.
NHibernate Tag: schema
Catalog
Specifies the name of the catalog.
NHibernate Tag: catalog
Where
clause
Specifies an arbitrary SQL WHERE condition to be used when
retrieving objects of this class.
NHibernate Tag: where
Check
Specifies a SQL expression used to generate a multi-row check
constraint for automatic schema generation.
NHibernate Tag: check
Fetch type
Specifies outer-join or sequential select fetching.
NHibernate Tag: fetch
309
Generating NHibernate Persistent Objects
Option
Description
Persister
class
Specifies a custom persistence class.
Subselect
Specifies an immutable and read-only entity to a database
subselect.
NHibernate Tag: persister
NHibernate Tag: subselect
Index column
Specifies the column name if users use list or array collection
type.
NHibernate Tag: index
Insert
Specifies that the mapped columns should be included in any
SQL INSERT statements.
NHibernate Tag: insert
Update
Specifies that the mapped columns should be included in any
SQL UPDATE statements.
NHibernate Tag: update
Lazy
Specifies that this property should be fetched lazily when the
instance variable is first accessed.
NHibernate Tag: lazy
Optimistic
lock
Specifies that a version increment should occur when this
property is dirty.
NHibernate Tag: optimistic-lock
Outer join
Specifies to use an outer-join.
NHibernate Tag: outer-join
Defining NHibernate Collection Container Type
NHibernate supports Set, Bag, List, Array, and Map mapping type, it
restricts the container type. PowerDesigner does not support Map mapping
type.
310
Collection Mapping Type
Collection Container Type
Set
Iesi.Collections.ISet
Bag
System.Collections.IList
List
System.Collections.IList
Array
<None>
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
You can input the container type manually, or select the needed mapping
type, and PowerDesigner will automatically select the correct container type.
Defining inheritance mappings
NHibernate supports the two basic inheritance mapping strategies:
♦ Table per class hierarchy
♦ Table per subclass
♦ It does not support the “Table per concrete class” mapping strategy.
♦ These strategies all follow the standard inheritance mapping definitions.
However, a separate mapping file is generated for each inheritance
hierarchy that has a unique mapping strategy. All mappings of subclasses
are defined in the mapping file. The mapping file is generated for the root
class of the hierarchy.
Generating Code for NHibernate
Before generating code for NHibernate, you must have NHibernate 1.0.2 or
higher installed (available at www.NHibernate.org).
311
Generating NHibernate Persistent Objects
v To generate Nhibernate code
1. Select Tools ä Check Model to verify if there are errors or warnings in
the model. If there are errors, fix them before continuing with code
generation.
2. Select Tools ä General Options, and click the Variables node.
3. Add a variable NHIBERNATE_HOME and, in the value field, enter the
NHibernate home directory path. For example, D:\nhibernate-1.0.2.0\bin.
4. Select Language ä Generate C# 2 Code or Generate Visual Basic 2005
Code to open the Generation dialog box:
5. Specify the root directory where you want to generate the code, and then
click the Options tab:
312
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
6. [optional] To use DAL, set the Generate DAL sources option to true. For
information about the standard C# and VB.NET generation options, see
the OOM User’s Guide .
7. Click OK to generate code immediately or Apply and then Cancel to save
your changes for later.
Once generation is complete, you can use an IDE such as Visual Studio.NET
2005 to modify the code, compile, and develop your application.
313
Configuring Connection Strings
Configuring Connection Strings
PowerDesigner supports multiple types of database connection with each of
the .NET frameworks.
Each connection requires a different set of parameters, which can be entered
by hand in the Connection String field of the ADO.NET or NHibernate tab,
or through custom dialogs accessible via the ellipsis tool to the right of this
field.
v To configure a connection string from the ADO.NET or ADO.NET
CF tab
1. Select a data provider.
2. Click the ellipsis button to open a provider-specific connection string
dialog.
3. [ADO.NET only] Enter the necessary parameters and click Test
Connection to validate them.
4. Click Apply to Connection String and then Close to return to the
ADO.NET or ADO.NET CF tab.
v To configure a connection string from the NHibernate tab
1. Select a dialect and driver class.
2. Click the ellipsis button to open a provider-specific connection string
dialog.
3. Enter the necessary parameters and click Test Connection to validate
them.
4. Once the connection tests correctly, click Close to return to the
NHibernate tab.
OLEDB connection string parameters
♦ The following parameters are required to configure an OLEDB
connection string:
314
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Option
Description
Data provider
Specifies the data provider from the list
Server or file name
Specifies the database server or file name.
User name
Specifies the database user name.
Password
Specifies the database user password.
Use Windows NT
integrated security
Specifies to use Windows NT integrated security.
Allow saving password
Specifies whether to allow saving password or
not
Initial catalog
Specifies database’s initial catalog.
ODBC connection string parameters
♦ The following parameters are required to configure an ODBC connection
string:
Option
Description
ODBC source name
Specifies the ODBC source name
User name
Specifies the database user name.
Password
Specifies the database user password.
Microsoft SQL Server and Microsoft SQL Server Mobile Edition
connection string parameters
♦ The following parameters are required to configure a Microsoft SQL
Server and Microsoft SQL Server Mobile Edition connection string:
315
Configuring Connection Strings
Option
Description
Server name
Specifies the server name.
User name
Specifies the database user name.
Password
Specifies the database user password.
Authentication type
Specifies authentication type, Use SQL Server
Authentication, or Use Windows Authentication
Database name
Specifies the database name
Database file name
Specifies the database’s file name.
Logical name
Specifies the logical name for the database file.
Oracle connection string parameters
♦ The following parameters are required to configure an Oracle connection
string:
316
Option
Description
Server name
Specifies the server name.
User name
Specifies the database user name.
Password
Specifies the database user password.
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Generating Unit Tests
If there are many persistent classes, it can be difficult to test them all to
prove that:
♦ The mappings are correctly defined
♦ The CRUD (Create, Read, Update, Delete) options work
♦ The find methods work
♦ The navigations work
Usually, developers have to develop unit tests or user-interfaces in order to
test these objects. PowerDesigner can automate this time-consuming process
by using the NUnit or Visual Studio Test System (VSTS) to generate the unit
test classes.
Some conditions must be met to unit test for a class:
♦ Mapping of the class should be defined.
♦ The class can be instantiated. Unit test classes cannot be generated for
abstract classes.
♦ The class is not a value type.
♦ The Mutable property is set to true. If Mutable is set to false, the class
can not be updated or deleted.
♦ The class has no unfulfilled foreign key constraints. If any foreign key is
mandatory, the parent class should be reachable (navigable on the parent
class side) for testing.
You can run the tests using NUnit or Visual Studio Test System.
Add Unit Test Support
PowerDesigner provides a UnitTest.NET Extended Model Definition to
generate unit test files.
v To add UnitTest support
1. Verify that the current model has the target language C# 2.0 or Visual
Basic 2005, and includes an extended model definition for either
ADO.NET, ADO.NET CF, or Nhibernate.
2. Select Model ä Extended Model Definitions.
317
Generating Unit Tests
3. In the List of Extended Model Definitions, click the Import tool.
4. Select UnitTest.NET or UnitTest.NET CF in the Unit Test sub-tab, and
then click OK to return to the model.
You can also select the UnitTest.NET (UnitTest.NET CF) or Extended
Model Definition when creating an OOM by clicking the Extended Model
Definitions tab in the New dialog, clicking the Unit Test sub-tab, and
selecting the appropriate checkbox.
Generating Code for Unit Testing
Before generating code for UnitTest, you must have NUnit 2.2.3 or higher
installed (available at www.nunit.org).
v To generate UnitTest code
1. Select Tools ä Check Model to verify if there are errors or warnings in
the model. If there are errors, fix them before continuing with code
generation.
2. Select Tools ä General Options, and click the Variables node.
3. Add a variable NUNIT_HOME and, in the value field, enter the NUnit
home directory path. For example, D:\NUnit2.2.3\bin. Add a variable
LOG4NET_HOME in the same way if log4net is going to be used for
logging.
318
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
4. Select Language ä Generate C# 2 Code or Generate Visual Basic 2005
Code to open the Generation dialog box.
5. Specify the root directory where you want to generate the code, and then
click the Options tab:
6. Select a UnitTest framework in “Unit test framework”. You can choose
between Nunit or Visual Studio Team Test.
7. Click on OK to generate code immediately or Apply, and then Cancel to
save your changes for later.
Differences Between NUnit and Visual Studio Team Test (VSTS)
Most code generated for these two UnitTest frameworks is very similar. The
main differences are:
♦ Team Test use different attributes with NUnit in test class, such as
[TestClass()] to [TestFixture] and [TestMethod()] to [Test] etc.
♦ AllTests file is not generated because all tests will be run in Visual Studio
gui or command prompt.
♦ Log4net is replaced by test result .trx file that can be opened in Test
Result window in Visual Studio.
319
Generating Unit Tests
Running NUnit Unit Tests
After generating your test code, you can run it in one of three ways:
♦ Run in Nunit - NUnit has two different ways to run your test cases. The
console runner, nunit-console.exe, is the fastest to launch, but is not
interactive. The GUI runner, nunit-gui.exe, is a Windows Forms
application that allows you to work selectively with your test cases and
provides graphical feedback.
NUnit also provide Category attribute, which provides an alternative to
suites for dealing with groups of tests. Either individual test cases or
fixtures may be identified as belonging to a particular category. Both the
GUI and console test runners allow specifying a list of categories to be
included in or excluded from the run. When categories are used, only the
tests in the selected categories will be run. Those tests in categories that
are not selected are not reported at all.
♦ Nunit GUI - The nunit-gui.exe program is a graphical runner. It shows
the tests in an explorer-like browser window and provides a visual
indication of the success or failure of the tests. It allows you to selectively
run single tests or suites and reloads automatically as you modify and
re-compile your code.
As you can see, the tests that were not run are marked with a grey circle,
while those that were run successfully are colored green. If any tests had
failed, they would be marked red.
320
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
♦ Nunit Console - The nunit-console.exe program is a text-based runner
and can be used when you want to run all your tests and don’t need a
red/yellow/green indication of success or failure. It is useful for
automation of tests and integration into other systems. It automatically
saves its results in XML format, allowing you to produce reports or
otherwise process the results.
Running Visual Studio Test System Unit Tests
The Visual Studio Team System Team Test tools offer a number of ways to
run tests, both from the Visual Studio integrated development environment
(IDE) and from a command prompt.
v To run tests in Visual Studio.NET 2005 IDE
1. Use the Test Manager or Test View window. You can also rerun tests
from the Test Result window.
2. In the Test Manager window, select tests by selecting the check boxes in
the test’s row, and then either click Run Tests on the Test Manager
toolbar or right-click the selected tests and then click Run Checked Tests.
3. In the Test View window, select the tests you want to run and then click
Run Tests on the Test View toolbar, or right-click, and select Run
Selection.
321
Generating Unit Tests
v To run tests from the command line
1. Open the Visual Studio command prompt
2. Either navigate to your solution folder directory or, when you run the
MSTest.exe program in step, specify a full or relative path to the metadata
file or to the test container.
3. Run the MSTest.exe program
322
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
Generating Windows or Smart Device Applications
The Composite UI Application Block (CAB) helps you build complex user
interface applications that run in Windows. It provides an architecture and
implementation that assists with building applications by using the common
patterns found in line-of-business client applications. The current version of
the Composite UI Application Block is aimed at Windows Forms
applications that run with the Microsoft .NET Framework 2.0.
PowerDesigner can automatically generate UI files based on CAB according
to the persistent framework you select, such as NHibernate or ADO.NET.
With persistent classes, DAL, BLL and UI files based on CAB generated by
PowerDesigner, you can quickly build Windows application without writing
repetitive code.
Using this Windows application, you can test persistent objects with your
own data. You can also improve the generated files and change the layout as
you like in Visual Studio .NET 2005.
Adding Windows or Smart Device Application Support
PowerDesigner provides both Windows Application and Smart Device
Application Extended Model Definitions, which allow you to generate UI
files.
v To add Windows Application support
1. Verify that the current model has the target language C# 2.0 or Visual
Basic 2005, and includes an extended model definition for either
ADO.NET or Nhibernate.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click the Import tool.
4. Select Windows Application in the User Interface sub-tab and click OK
to return to the model.
You can also select the Windows Application Extended Model Definition
when creating an OOM by clicking the Extended Model Definitions tab in
the New dialog, clicking the User Interface sub-tab, and selecting the
Windows Application checkbox.
323
Generating Windows or Smart Device Applications
v To add Smart Device Application support
1. Verify that the current model has the target language C# 2.0 or Visual
Basic 2005, and includes an extended model definition for ADO.NET CF.
2. Select Model ä Extended Model Definitions.
3. In the List of Extended Model Definitions, click the Import tool.
4. Select Smart Device Application in the User Interface sub-tab and click
OK to return to the model.
You can also select the Smart Device Application Extended Model
Definition when creating an OOM by clicking the Extended Model
Definitions tab in the New dialog, clicking the User Interface sub-tab, and
selecting the Windows Application checkbox.
Specifying an image library
Your forms will probably use some images as icons. PowerDesigner
provides a default image library, which it uses by default for Windows
applications. You can also specify your own image library.
v To specify an image library
1. Open the model property sheet, and click the Window Application tab.
2. Specify a path to your image library, and then click OK to return to the
model.
Controlling the Data Grid View
You can specify the length of your ADO.NET CF datagrid views.
v To specify the length of datagrid views
1. Open the model property sheet, and click the Smart Device Application
tab.
2. Specify the number of rows, and then click OK to return to the model.
Defining Attributes Display Options
You can define attribute-level options for presentation style.
324
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
v To define Attribute Options
1. Open Attribute Property sheet, and select the Windows Application tab.
2. Set the appropriate options and then click OK
The following options are available:
Option
Description
Control Type
You can choose TextBox or ComoboBox as input control
Display as
foreign key
label
Specifies to display the current attribute as a foreign key label
in combo boxes, instead of the foreign key. For example,
select this option for the product name attribute to use it as
foreign key label instead of the product id.
Defining Attribute Validation Rules and Default Values
PowerDesigner provides validation and default values for the edit boxes in
the Create, Find, ListView, and DetailView forms.
v To define Validation Rules
1. Open the attribute property sheet, and click the Standard Checks tab.
2. [optional] Define minimum value and maximum values to control the
value range.
3. [optional] Define a default value. A string value must be enclosed in
quotes. You can also define the Initial value in the Details tab.
4. [optional] Define a list of values. PowerDesigner will automatically
generate a combo box that includes these values.
5. Click OK to return to the model.
Generating Code for a Windows Application
Before generating code for Windows Application, you need to install CAB
(available from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/cab.asp) . Check for the following
required files in your installation directory:
♦ Microsoft.Practices.CompositeUI.dll
♦ Microsoft.Practices.CompositeUI.WinForms.dll
♦ Microsoft.Practices.ObjectBuilder.dll
325
Generating Windows or Smart Device Applications
v To generate UnitTest code
1. Select Tools ä Check Model to verify if there are errors or warnings in
the model. If there are errors, fix them before continuing with code
generation.
2. Select Tools ä General Options, and click the Variables node.
3. Add a variable CAB_PATH with the value of your installation directory
4. Select Language ä Generate C# 2.0 Code or Generate Visual Basic 2005
Code to open the Generation dialog box.
5. Specify a target directory, and then click OK to begin generation.
The following files will be generated:
♦ Domain files (persistent classes, mapping files)
♦ DAL files (database connection file and data access files)
♦ A solution file and project files
♦ A login dialog
♦ Forms for persistent classes
♦ Controller files
For each persistent class, PowerDesigner generates:
♦ A find dialog for searching objects
♦ A list view form for displaying find results
♦ A detail view form for displaying object’s detailed information
♦ A create view form for creating new objects
You can deploy or edit a Windows application in an IDE, such as Visual
Studio .NET 2005.
Generating Code for a Smart Device Application
Before generating a smart device application, you must:
♦ Ensure that you have attached the ADO.NET Compact Framework (and,
if you want to generate unit tests, UnitTest.NET Compact Framework)
extended model definitions (see “Adding ADO.NET or ADO.NET CF
support” on page 285).
♦ Set any appropriate model properties on the ADO.NET CF and
Application tabs, including a functioning connection string (see
“ADO.NET and ADO.NET CF options” on page 286).
326
Chapter 10. Generating .NET 2.0 Persistent Objects and Windows
Applications
♦ Specify appropriate values for the following variables (select Tools ä
General Options, and click the Variables category):
• CFUT_HOME – if using Microsoft Mobile Client Software Factory
CFUnitTester
• ASANET_HOME – if using Sybase ASA. Specifies the location of
iAnywhere.Data.AsaClient.dll.
• SQLSERVERMOBILENET_HOME – if using Microsoft SQL Server
Mobile Edition. Specifies the location of System.Data.SqlServerCe.dll
• ULTRALITENETCE_HOME – if using Sybase UltraLite. Specifies
the location of ulnet10.dll
• ULTRALITENET_HOME – if using Sybase UltraLite. Specifies the
location of iAnywhere.Data.UltraLite.dll and
en\iAnywhere.Data.UltraLite.resources.dll
v To generate code
1. Select Tools ä Check Model to verify that there are no errors in the
model. If there are errors, fix them before continuing with code
generation.
2. Select Language ä Generate C#2 Code or Generate Visual Basic 2005 to
open the Generation dialog box.
3. Specify the root directory where you want to generate the code and then
click the Options tab.
4. Specify any appropriate options and then click OK to generate code
immediately or Apply and then Cancel to save your changes for later.
Once you have generated your code, you can deploy it:
v To deploy code to a smart device
1. Compile your generated code in Visual Studio.
2. Deploy the start up project, i.e. the <model>Test project or User
Interface project
3. Deploy the SystemFramework project separately with the database file
and required DLLs (such as ulnet10.dll for UltraLite support).
327
Generating Windows or Smart Device Applications
v To test the application on the device
1. If you have generated and deployed the user interface projects to the
device, you can run them and test the application by inputting some data.
2. If you have generated for ‘Microsoft Mobile Client Software Factory’,
you can run the unit tests by clicking GuiTestRunner.exe in the
deployment folder in the device. The exe file and its references can be
copied from the Microsoft Mobile Client Software Factory installation
folder.
328
Index
A
ADO.NET
association mapping
attribute mapping
component primary identifier mapping
composite identifier mapping
database connection strings
extended model definition
generating code
inheritance mapping
introduction
O/R mapping
ODBC connection string
OLEDB connection string
options
Oracle connection string
simple identifier mapping
SQL Server connection string
ADO.NET CF
extended model definition
options
Ant
build file preview
build script generation
customizing build script generation
generating Java code
installing
PowerDesigner support for
running build script
server support
targets
association class transformation
association mapping
association transformation
attribute
complex data type
simple data type
transformation
attribute mapping
composite primary identifier mapping
291
290
289
289
314
285
293
293
285
287
315
314
286
316
289
315
285
286
6
4
10
7
9
2
9
5
9
163
180
158
154
154
154
176
C
component primary identifier mapping
177
177
D
data grid view
data source
define mapping
324
172
172
E
EAServer
creating EJBs
creating web services
customizing PowerDesigner support for
defining classes
defining database schema
extended attributes
extended model definition
generating and deploying Java code
O/R mapping
PowerDesigner support for
using Apache Ant
using Borland JBuilder Enterprise
using Eclipse
using EJBs
verifying configuration descriptor
verifying EJBs
EAServer web services
deploying
testing
using Eclipse
using Java classes
using JBuilder
using stateless session beans
entity class
entity class mapping
entity class transformation
33
61
67
33
33
44
37
51
34, 39
30
57
56
55
60
47
58
62
66
63
61
65
62
152
173
152
H
Hibernate
database configuration parameters
default options
entity type classes
195
195
197
329
Index
extended model definition
generating code
generation options
PowerDesigner support for
using Ant
using Eclipse
value type classes
Hibernate JavaServer Faces
attribute options
attribute validation rules
computed attributes
default values
generating
global page options
JSF runtime environments
master-detail pages
testing
Hibernate O/R mapping
association mapping
attribute mapping
basic
collections of value types
component primary identifier mapping
composite identifier mapping
inheritance mapping
options
simple identifier mapping
194
211
211
194
217
214
197
244
247
246
247
257
242
254
247
257
206
204
197
209
203
202
210, 227
198
201
I
identifier transformation
inheritance
joined subclass
table per class
table per class hierarchy
transformation
inheritance mapping
157
164
164
164
164
186
J
JBuilder
building and deploying application
extended model definition
generating code
PowerDesigner support for
project file generation
supported servers
using BEA WebLogic
using Sybase EAServer
330
23
16
21
14
16
17
18
18
verifying files
JDO
compiling code
creating an OOM for
defining classes and database schema
defining Java classes
defining O/R mapping
extended model definition
generating code
persistence descriptor
PowerDesigner support for
running JDO enhancer
using Ant
using Eclipse
using JBuilder
using PowerDesigner
Xcalia LiDO
joined subclass
20
275
263
263
263
263, 264
265
272
266
261
275
277
276
275
278
269
189
M
many-to-many association mapping
many-to-many association transformation
186
162
N
NHibernate
association mapping
attribute mapping
component primary identifier mapping
composite identifier mapping
database connection strings
extended model definition
generating code
inheritance mapping
introduction
O/R mapping
ODBC connection string
OLEDB connection string
options
Oracle connection string
simple identifier mapping
SQL Server connection string
NUnit
running
306
304
304
303
314
295
311
311
295
297
315
314
296
316
301
315
320
O
O/R mapping
150
Index
ODBC
connection string
OLEDB
connection string
one-to-many association mapping
one-to-many association transformation
one-to-one association mapping
one-to-one association transformation
OOM
generate PDM
Oracle
connection string
315
314
183
160
181
159
151, 169
316
P
PDM
generate from OOM
PowerDesigner
Ant support
customizing JDO support
customizing support for EAServer
EAServer support
JBuilder support
JDO support
support for Hibernate
Tomcat support
WebLogic support
WebSphere support
primary identifier mapping
151, 169
2
278
67
30
14
261
194
70
80
118
177
R
reference key transformation
170
S
simple primary identifier mapping
Smart Device Application
generating code
Smart Device applications
data grid view
SQL Server
connection string
177
326
324
315
T
table per class
table per class hierarchy
Tomcat
Ant build script
190
187
74
creating JSPs
creating servlets
creating web service components
customizing Ant build script
extended model definition
PowerDesigner support for
running a web application
typographic conventions
71
71
71
77
72
70
78
vi
U
Unit Tests
extended model definition
generating code
introduction
Nunit vs VSTS
317
318
317
319
V
value type class
value type transformation
VSTS
running
152
157
321
W
WebLogic
component persistence properties
94
converting classes to EJBs
85
creating EJBs
83
defining a mapping for a bean
96
defining a mapping for a relationship
98
defining classes and database schemas
83
defining EJB-QL
86
defining O/R mappings
84
extended attributes
89, 92, 104
extended model definition
87
generating code
100
PowerDesigner support for
80
specifying data sources
94
WebSphere
application developer generation
135
application developer projects
139
application server generation
130
building a J2EE application project
142
building a web application project
142
building an EJB project
141
converting classes to EJBs
123
creating EJBs
121
331
Index
customizing database support
customizing O/R mapping
defining classes and database schema
defining EJB-QL
defining O/R mapping
environment variables
extended attributes
extended model definition
PowerDesigner support for
using Ant
using Eclipse
using PowerDesigner
verifying descriptors
WSAD project files
Windows applications
attribute display options
attribute validation rules
extended model definition
generating code
image library
introduction
332
130
128
121
128
122
126
132, 136
125, 147
118
144
144
145
137
127
324
325
323
325
324
323
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement