+ All Categories
Home > Documents > SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

Date post: 19-Jun-2015
Category:
Upload: stephan-h-wissel
View: 4,110 times
Download: 5 times
Share this document with a friend
Popular Tags:
478
© 2011 IBM Corporation SHOW107 The Data Source Session: Take XPages data boldly where no XPages data has been taken before Jim Quill | XPages Developer | IBM Ireland Stephan H. Wissel | LTPA | IBM Singapore
Transcript
Page 1: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

SHOW107 The Data Source Session: Take XPages data boldly where no XPages data has been taken before

Jim Quill | XPages Developer | IBM IrelandStephan H. Wissel | LTPA | IBM Singapore

Page 2: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 2

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●Simple CSV file Data Source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 3: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Built-in DataSources─ Domino® View─ Domino® Document─

● SeverSide JavaScript─ Write custom Java™ code to connect any data source and return that data

as an object, array, List, ResultSet, or DataModel will enable XPages controls to consume that data.

● Any control that holds data, for display or editing can be bound to an item of data, a field in a Domino document or a property of a Managed Bean, for example.

● Container controls, i.e. DataTable, Repeat, and View Panel can be bound to a single item or a collection of items and will iterate over the data

Page 4: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Demo 1─ Create an array─ Put it into view

scope─ Reference data

using EL expression

Page 5: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Built-in DataSources Benefits─

─ declaratively add and reuse custom data sources to an XPage,─

─ computed properties ─

─ easy access the data souce in SSJS─

─ nest DataSources so contents of one data source can be bound to computed properties of another data source defined on an inner panel that is in a Repeat control

─ control behavoiur via URL parameters─

─ add your own query/postSaveEvents, and more

Page 6: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Objectives for todays session─

─ Write a data source that reads a CSV file from the local filesystem

─ Write a data source that reads data from an RDBMS by executing SQL via JDBC

Page 7: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 7

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 8: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● For the two core storage artifacts, View and Documents, XPages provides a convenient mechanism to declaratively add these two data sources to your application without any coding

─ All properties can be computed using JavaScript or an EL expression─ Tight integration with a set of easy to use Simple Actions for working with

Documents and View─ Ability to specify request parameters to control and influence the behavior

of the data source

● Within the XPages framework, data sources are based on two key classes─ com.ibm.xsp.model.AbstractDataSource─ com.ibm.xsp.model.AbstractDataContainer─

Page 9: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

AbstractDataSource AbstractDataContainer

ComponentBindingObject ValueBindingObject

DataPublishingObject

StateHolder

DataSource

DataContainer

Externalizable

Page 10: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● AbstractDataSource Responsibilities─ Data source id management

– BeanId– UniqueId

─ RuntimeProperty management– Computed properties can be saved as runtime property so its values

doesn't have to be repeatedly calculated─ State Management

– Base properties var, scope, ignoreRequestParams, requestParamPrefix

– Property accessors for state of component to be recreated─ Data Container Management─ DataPublishing

– pushData, popData – publishes the DataModel to request scope using the specified var attribute as the key

Page 11: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● Data Container Responsibilities─ Externalizable support─ Manages the life cycle of the data – if it doesn't continuously store the data

between requests, it knows how to retrieve it.─

Page 12: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 12

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 13: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Setting up your development environment

● What you need─ IBM® Lotus Domino® Designer 8.5.2─ IBM® Lotus Domino® 8.5.2─ IBM® DB2® ─

● What you should have to hand:─ Javadoc

– XPages Extensibility API Documentation– http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPages_Extensibility_API_Document

ation─

─ Wiki– XPages Extensibility API Developers Guide– http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Master_Table_of_Contents_for_XPag

es_Extensibility_APIs_Developer_Guide

Page 14: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 14

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●Simple CSV File Data Source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 15: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a New Application─ Menu > File > New

Page 16: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Overview ─ Create a New Application─ Project setup─ Extend AbstractDataSource

– Manages the DataSource properties─ Extend AbstractDataContainer

– Manages the Data life cycle, caching, refreshing─ Create an xsp-config file that describes the DataSource so it can integrate

with Lotus Domino® Designer and the Xpages Framework

Page 17: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Application Setup─ Grant Anonymous Manager access level File > Application > Access Control...─ Specify oneuiv2 as the Web theme. File > Application > Properties > Xpages─ CTRL-S to save changes

Page 18: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Switch to the Java™ perspective─ Window > Open Perspective > Java

● Shortcut─ CTRL-F8

● A virtual file system for the NSF─ organized like a WAR

Page 19: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a new Source Folder─ Select the application NSF (ls2011.nsf)─ Right-Click > New > Source Folder─

● Do not use Local as the source folder─ Java files stored here are actually located on the

local workstation file system in the IBM® Lotus Domino® Designer workspace and are not inside the NSF file.

─ When XPages are compiled to Java classes, the intermediate Java source file is written to here.

– Can be useful to examine these source files to

Page 20: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a new Source Folder─ In the Folder name: field enter src ─ Select Finish

Page 21: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Appropriate Java Build Path is automatically configured

● Select src folder─ Right-Click >

Build Path > Configure Build Path...

─ Select Libraries tab

Page 22: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Verify the src folder will generate the class files into the expected location (ls2011.nsf/WebContent/WEB-INF/classes)

● Select src folder─ Right-Click > Build

Path > Configure Output Folder...

● Note: To see the classes folder use the Navigator view

─ Menu > Window > Show Eclipse Views > Navigator

Page 23: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create the a new Class file─ Select the src folder─ Right-Click > New > Class

Page 24: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Enter the New Java Class details─

─ Package:– demo.ls2011.csv

─ Name:– CSVDataSource

─ Superclass:– com.ibm.xsp.model.AbstractDataSource

─ Interfaces:– com.ibm.xsp.model.DataSource

─ Leave inherit abstract methods checked.

● Select Finish

Page 25: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● The CSV File Data Source has 4 properties

─ csvFilePath– location on the

local file system─ separator

– field delimiter–

─ firstLineIsHeader– treat the first line

of the CSV file as column headers.

─ trimWhiteSpace– Postprocessing

the data, could be anything you like

Page 26: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Theory: Literal values compared to Computed values─

─ Property setter called for Literal values– getter will simply return the set value–

─ SetValueBinding called for Computed values– Getter has to evaluate the corresponding value expression to– AbstractDataSource.RuntimeProperties help optimize reading these values

Page 27: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● AbstractDataSource.RuntimeProperties─

● Optimization to save recalculating computed properties

Page 28: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Java Bean property accessors─ Always follow this general structure

– If set directly, return the value– Otherwise check for a computed value

● Specifies the location of the target CSV file

Page 29: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Property accessors continued

● Allows developer specify the field delimiter

Page 30: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Use this property to label columns─ #{item.column2}─

● With no header must specify column position

─ #{item[1]}

Page 31: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Can specify any other properties required

─ Manipulation, transformation, etc.

Page 32: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● UniqueId─ Using a combination of the Data Source

properties, than can be repeatedly calculated, construct an id to identity the data souce, such that any property changes that would effect the data would generate a new id.

● Bean Id─ The key used to store the DataContainer for the

DataSource─ AbstractDataSource calculates beanId,

DataSource developer specified how to compose the uniqueId

─ Default scope for DataSources is View Scope─ If data shared

– scope = session– scope = application

─ Then beanId = uniqueId

Page 33: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Abstract methods─ Called by the XPages Framework to get the data from a data source─

Page 34: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Support changing functionality via request parameters

● http://server/app.nsf/csv.xsp?separator=:&firstLineIsHeader=false─

●● PrefixRequestParam

─ Enable request parameters to be specified for individual data sources

● Save is called by XPages Framework if Submit event was triggered

Page 35: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● State Management

● StateHolder is a JSF interface that must be implemented by components that need to save their state between requests

● Saving and restoring is done as a Serializable object─ Must have a public no-args constructor─

● Component tree is built for the initial request, and then restoring for subsequent postbacks

● If it is not done right, components behave differently and data disappears in subsequent POST requests after the initial GET

Page 36: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● State Management

● Must be Objects

● Care needed for primitive types

● Ctrl-S to Save

Page 37: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData─ Represents a row of data

● Implement DataObject─ XPages Property Resolver knows about this

type─ For EL expression like item.name instead of

calling getName() as is typical for Java Beans the Property Resolver will call getValue(“name”)

─ Is also implemented for DominoDocument─ Similar to ViewRowData Interface used for row

data items in a Domino View.─ Documentation Bug

– Interface com.ibm.xsp.model.DataObject is not published.

Page 38: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData─ Create a new Java Class─

─ Package– demo.ls2011.scv–

─ Name– CSVRowData

─ Interfaces– com.ibm.xsp.model.

DataObject– java.io.Serializable

Page 39: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData

● SerialVersionUID─ not requied─ added to remove warning

Page 40: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Object

● GetValue()─ #{item.name}

– gets the value for the field labeled “name”–

─ #{item[2]}– gets the value for the second field– useful if CSV file doesn't use the first row to

specify column names–

Page 41: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● DataObject─

─ Data is stored in a Map of key-value pairs

● CTRL-S to save─

Page 42: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● In the Package Navigator, Select the src folder, Right-Click > New > Class to create a New Java Class for the Data Container

─ Package– demo.ls2011.csv–

─ Name:– CSVDataContainer–

─ Superclass:– com.ibm.xsp.model.

AbstractDataContainer

● Select Finish

Page 43: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container─

● Data is a List of CSVRowObjects

Page 44: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● Externalizable─

Page 45: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● The actual implementation to get the data

Page 46: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container─

Page 47: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● Accessor methods to finish off the Class

Page 48: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create the xsp-config file

● ─

Page 49: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● New File─ File name:

– csvDataSource.xsp-config–

Page 50: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Complex Types in the xsp-config file─

─ Used to specify non-primative types in Xpages– Objects

─ Represented using their own tags─ Can specify a Class or Interface

Page 51: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Declare the namespace

● Descriptive information that wil be used by Domino® Designer

● The class the implements the functionality and property support

● Group-type-ref─ Base data source

properties ─

Page 52: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Specify the required properties

Page 53: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Properties─

Page 54: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2─ Create the following test CSV files in the C: \temp directory

Page 55: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● Switch to the Domino Designer perspective─ CTRL-F8 > Domino Designer

● Create a new Xpage called xpDemo1 ─ XPages > New Xpage...─ Name is xpDemo1─ Select on the blank XPage design canvas so

the XPage design Properties tab appears

● In the XPage Properties tab─ Open the Data section─ Click Add and you will see CSV Data Source

in the drop down list─

Page 56: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● Declaratively configure the new data source

Page 57: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2─

Page 58: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● 2 single row tables with a repeat control

Page 59: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Create XPage with CSV Data Source─

─ test3.csv─ #SEP#

Page 60: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Create a Panel with a Repeat Control

● Create another Panel within the Repeat

● Configure a Data Source for this Panel

Page 61: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3─

● Properties for the inner Panel are computed based on values read from the Data Source on the XPage.

Page 62: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3─ Inner Repeat Iterates over a table row

Page 63: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Button performs partial refresh on outer Panel when clicked.

─ Useful for testing data source State Management

─ If is is wrong, data will disappear after completion of the POST request

Page 64: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 64

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 65: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Overview─

─ Enable Java debugging on IBM® Lotus Domino®

─ Create a Debug Configuration─

Page 66: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Enable Java debugging on IBM® Lotus Domino® by adding the following lines to notes.ini

─ JavaEnableDebug=1─ JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8

000

Page 67: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Restart IBM® Lotus Domino® and verify that debugging has been enabled by checking the server console for the following message:

– > Listening for transport dt_socket at address: 8000– 1/01/2011 17:08:45 JVM: Java Virtual Machine initialized.– 1/01/2011 17:08:45 HTTP Server: Java Virtual Machine loaded

Page 68: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Instead of switching perspectives, stay in the Domino Designer perspective and open the Navigator and Package Explorer views.

─ Window > Show Eclipse Views > Other...─ Select Navigator (under General)─ Click OK─

Page 69: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● The Navigator opens be default beside the Control palette and the Data palette

● One benefit of the Navigator over the Package Explorer is that the Navigator show then compiled Java classes for the application

● However it does not have the Right-Click context menus for configuring the Java build path

Page 70: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● To open the Package Explorer view:─ Window > Show Eclipse Views > Other...─ Select Package (under Java)─ Click OK─

Page 71: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● In Package Explorer, double-click on the class you are interested in debugging to open it.

● Set a breakpoint in your code by double-clicking on the line number for the method you want to debug.

● Notice a small circle icon will appear beside the line. ─

Page 72: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Create a Debug Configuration

● Select ─ Remote

Java Application

─ Click New─

─ Enter– Name:–

─ Leave all other default values

Page 73: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Add your source path to the debug environment for source code to open for breakpoints

● Select the source tab

● Click Add─

Page 74: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Choose─ Java Project─

● Select your project─

Page 75: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Click Apply─ to save the

changes ─

● Click Debug to launch the debugger

Page 76: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Run the demo XPage application again─

Page 77: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● The Java Debug perspective will open with the code stopped on the breakpoint

Page 78: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Summary

● Being able to debug custom code in an XPages application will be vital for data source development

Page 79: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 79

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 80: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a read only Data Source that allows a developer to declaratively specify JDBC connection information and an SQL query that retrieves the appropriate data

Page 81: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Install DB2®─ Include the sample databases─ Assumes user is db2admin with password as password─

● Locate the JDBC Type 4 driver─ db2jcc.jar─ db2jcc_license.jar─ will need them later─

Page 82: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a simple helper class that will be used to create database connections

Page 83: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Only supports DB2® driver protocol

Page 84: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Code to load the JDBC driver

Page 85: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Test the connection and configuration─

Page 86: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Simple test application─

Page 87: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● SSJS to call the static test method─

Page 88: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Expected ClassNotFoundException

● Add the JDBC Driver to the NSF─

Page 89: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● In the Java perspective, open the Navigator

● Expand the WebContent/WEB-INF folder

● Notice there is no lib folder

● Select WEB-INF

● Right-Click > New > Folder─

Page 90: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Folder name:─ lib

● Click Finish─

Page 91: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Select the lib folder under WebContent/WEB-INF─

● Right-Click > Import...

Page 92: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Select File System

● Click Next─

Page 93: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Browse to the folder that contains the JDBC driver

● Select ─ db2jcc.jar─ db2jcc_license.jar─

● Click FInish─

Page 94: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Driver should be on the XPages Classpath

● Run the test again

● Oooops...─

Page 95: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Check the logs

● Security Exception─ checkPropertiesAccess() is not managed by AgentSecurityManager─ Doesn't check if unrestriced users can perform the operation─

● Need to move JDBC drivers to trusted location (since call is wrapped by AccessController.doPrivileged() )

Page 96: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● C:\Domino\jvm\lib\security\java.policy

● Choices:

─ Store JARs under C:\Domino\xsp\shared– it is a trusted location– XPages ClassLoader will search for JARs here when runtime starts

─ Trust the specific NSF application as a location

Page 97: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Restart the HTTP task to pick up changes to java.policy─ tell http quit─ load http─

─ Rerun test– success

Page 98: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create the

─ JDBC Query Data Source class─

─ JDBC Query Data Container class─

─ JDBC Query Data Source xsp-config configuration file─

Page 99: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create new class

● Extend AbstractDataSource─

Page 100: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ComposeUniqueId()─ Based on data source properties─

● getDataObject()─ return the data

● isReadOnly()

● ReadRequestParams()─ data source specific options

● load()─ Called by the XPages framework

● Save()─ Called by the XPages framework─

Page 101: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Define the properties the Data Source is going to support

Page 102: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Support Parameters - declared in the xsp-config which then appear in the data source property panel

Page 103: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● State Management for primitive types

● Can't return null - need to decide on value to be returned when port is not set

Page 104: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● If using RuntimeProperties, check here

Page 105: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● queryString holds the SQL

● In a form that will be parsed by a JDBC PreparedStatement

Page 106: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● More property accessors

● KeyColumn could be used to identify the Primary Key column in the the table the SQL query is based upon

Page 107: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Override abstract methods

● Connection information and SQL query.

─ Changing the sort order, which still reads the data from the same data source could change the UniqueId, triggering the DataContainer to refresh any cached data

● getDataObject gets the data from the DataContainer

Page 108: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● load()─ Called by

XPages framework

● save()─ Return false

since read only

Page 109: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● State management─

Page 110: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● Create a new class

● Extend AbstractDataContainer

Page 111: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● DataContainers are not stored with the DataSource in the view

● The are managed by a scope Bean Manager and are identified by their beanId

Page 112: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● Get the data

● Other stragegy is to get the data as part of the DataSource and just have container manage its lifecycle

─ Can it be cached ─ Does it need to be refereshed─ Resource pooling─

Page 113: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─

● JDBC code using ResultSet─

─ Could consider RowSets and have it handle disconnected mode

Page 114: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─ Leverage FacesContextListener to manage the lifecycle of the data and

caching stratagies– beforeRenderingPhase()– beforeContextReleased()

Page 115: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─

─ Implements Externalizable─

─ Class handles serialization of each property itself

─ Optimization to avoid the serialization code having to intropsect and figure out all the datatypes.

Page 116: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create ResultSetModelEx

─ Extends TabularDataModel– better integration with

XPages Pager control for ResultSets

─ Delegates to ResultSetDataModel

Page 117: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Some properties and constructors

● Wraps a ResultSetDataModel to which it delegates most methods, except getRowCount() as we don't want to return the standard -1 (prevents us working with the pager controls. DataModels that have an unknown count can extend TabularDataModel

Page 118: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Pager estimates number rows and ask data model if it knows if rowCount is bigger than current maxCount

● For the current page, always return the current page range + 1 – causes the Pager to indicate that there are more rows

Page 119: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Delegated methods─

Page 120: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx─

─ If isRowAvailable returns false from the delegated ResultSetDataModel then we know we have found a potential value for the actual row count

─ HasMoreRows() will start using this value and since it will be less than the current deduced max in the pager, it will readjust based on this value.

Page 121: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create JDBC xsp-config

● Select WEB-INF, Right-Click > New > File

● File name:─ jdbcQuertDataSource.xsp-config

Page 122: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC xsp-config

● Key property─ complex-extension

– dataInterface–

● If xsp-config file not immediately recognised as XML, close and reopen.

Page 123: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Query Data Source Properties

● Server

● Port

● Database

Page 124: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Query Data Source Properties

● User

● Password

● SQL query

Page 125: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Demo 4─ Create XPage

Page 126: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

Page 127: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

Page 128: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

● Want to build this

Page 129: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a DataTable

● Bind using EL

Page 130: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● DataTable collection is called item

● Computed fields can bind to the data using EL expression

Page 131: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Pager tries to deduce last page

● ...Next indicates more pages

● Keeps increasing until no row is found, then Pages adjusts last page

● Next indicates a max count found

Page 132: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 132

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS (Part 2: CRUD)

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 133: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Courtesy of XKCD.com ( http://xkcd.com/327/ )

Page 134: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a JDBC Data Source that supports working with individual rows in a table. Should support operations such as:

─ (C) inserting a new row─ (R) selecting a specific row─ (U) updating an existing row ─ (D) deleting a row─

● Like a DominoView -> DominoDocument, Master -> Detail type relationship

─ JDBCQueryDataSource– works with several rows–

─ JDBCRecordDataSource– works with a single row

Page 135: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 136: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 137: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class─ Select the ls2011 package─ Right-Click, select

– New > Class ─

● Use CTRL-F8 to switch perspectives (if necessary)

Page 138: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package─ demo.ls2011.jdbc4─

● Name:─ JDBCConstants

Page 139: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Constants─ Not all used in current

implementation─

─ JDBC Driver properties─

─ Standard XPages (Domino oriented URL parameters

─ Actions– New, Open, Edit

Page 140: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 141: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● A class with helpful convenience methods for working with JDBC, e.g. open/close connections, getting column information, setting types, etc.

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCUtil

Page 142: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Open JDBC Connection─

─ via Properties object─

─ via basic properties– server – port – database – User– password

Page 143: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Code that actually loads the JDBC driver

● Close a connection

Page 144: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More utility methods─

─ Get a single ─

─ Get an empty ResultSet to retirence the ResultSet meta data to get column information

Page 145: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Utility method to for setting the appropriate type for the columns when setting parameters for a JDBC PreparedStatement

─ not all types covered– Numbers– Characters

Page 146: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 147: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Note─ Use CTRL-Space to get─ 'hints' on packages and

classes available in the application package hierarchy

Page 148: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCAbstractDataSource

● Modifiers:─ public abstract─

● Superclass:─ com.ibm.xsp.model.Abstract

DataSource

Page 149: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Imports that can be added as the abstract data source class is developed

● Has the abstract modifier

● This class will be extended later on with a concrete class that will implement the row oriented specifics of the data source

Page 150: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Specify member variables that represent properties for the JDBC-based data source

─ server─ port─ database, etc─

● parameters is as List─ used to store name-value

(com.ibm.xsp.Paramster) pairs that can be used to pass information to the data source.

Page 151: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create property accessor methods─ server─ port ─

● Follow the standard 'template' for getters

─ 1) check if instance variable is set─ 2) check for a corresponding value

binding (if value can be computed)─ 3) retrun null or default for primitive

(int etc.) types

● action─ 'read only' property─ set via request parameter

– action=newDocument

Page 152: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More property accessors─ database─ user

● If RuntimeProperties is implmemented, get it here.

● Extend the standard 'template' for getters

─ 1) if using RuntimeProperties, get it from there

─ 2) check if instance member variable is set

─ 3) check for a corresponding value binding (if the value can be computed)

─ 4) retrun null or default for primitive (int etc.) types

Page 153: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties─ password─ selectString

● selectString─ idea was that whether one row is

indented to be returned (JDBCRecordDataSource), or several (JDBCQueryDataSource).

─ oth have a SQL select statement in common, so property is in abstract class

– then decided to modify/override with concurrency column info (not fully implemented)

Page 154: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties─ keyColumn

– primary key–

─ tableName– used for getting

database metadata–

─ SortOrder– not implemented.

● Optimize – collect metadata during Connection/Data Source definition

Page 155: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● UniqueId─ An identifier that distinguishes

this JDBC data source from other JDBC data sources

– can be repeatedly re-constructed form the data source properties

─ used as the name for storing data in scope (if shared)

─ connection information + request parameter info + select statement

Page 156: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Read general request parameters

─ action─ sortOrder

● Abstract methods sub-classes must implement

─ isReadOnly()─ getDataObject()─ load()─ save()

● Helper methods for connection URL and opening the JDBC connection

Page 157: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● State Management for all the properties

─ Handy StateHolderUtil method for working with List objects

Page 158: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 159: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● create a helper class JDBCConcurrencyInfo

─ Not really used. Keep in mind that it (or this feature) will be required for taking this sample further for production use.

Page 160: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 161: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Concurrency─ Pessimistic

– RDBMS specific─

─ Optimistic– which column provides

the 'timestamp' that can be compared for row updates

─ Force – Last Writer Wins– Not really a good idea

Page 162: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 163: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create a concrete class that implements DataObject

─ JDBCRecord

● Purpose─ Enables the data that are returned to

be simply referenced with an EL expression using the data field/column name

Page 164: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Name:─ JDBCRecord

● Interfaces─ com.ibm.xsp.model.

DataObject– Known interface by the

XPages PropertyResolver, calls getValue(“<prop>”)

─ java.io.Serializable

Page 165: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● When the XPages Framework calls

─ DataSource.getDataObject()─ which in turn calls─ DataContainer.getRecord()

● This is the returned object

● Is essentially the BackingBean for the part of the UI that displays the data from the Data Source

● wrappedData ─ JDBC ResultSet─ transient - not serializable

need to be managed

Page 166: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Constructor─ ResultSet

– wrapped─ UniqueId

– Primary Key Column for the record

─ Should be a List<String>─

● Get the Column Types for each of the Columns based on the ResultSet meta data

● selectSQL ─ used to recreate the ResultSet

as necessary

Page 167: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Implements the DataObject methods:

─ getType(key)─ getValue(key)─ setValue(key,value)─ isReadOnly()

Page 168: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● The DataContainer implementation will callback to the JDBCRecord before and after the de/serialized to give JDBC an opportunity to do anything it needs

Page 169: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● discardWrappedObject─ ResultSet is closed before

serialization.─

● Several other methods not yet fully implemented that will be useful in the future:

─ CheckRecordValidity()– row may been deleted

between requests─

Page 170: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 171: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create a concrete class that extends AbstractDataContainer

─ JDBCRecordDataContainer

● Purpose─ Manages the life-cycle of the data in a

stateless request response environment

─ Good place for implementing a caching strategy

Page 172: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCRecordDataContainer─

● Superclass:─ com.ibm.xsp.model.Abstract

DataContainer

Page 173: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● com.ibm.xsp.model.AbstractDataContainer

─ contains some basic support for making the data source Externalizable

● Need to implement the required serialize and deserialize methods

Page 174: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● JDBCRecord─ the data object

● FaceContectListener─ used to discard

resources at the end of the request

● In this implementation the DataSource creates the JDBCRecord and passes it into the Constructor

Page 175: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● FacesContextListener─ Can use this listener to

manage the data through the various phases of the JSF Lifecycle

● getRecord()

● Called from DataSource.getDataObject()

– Xpages Framework entry point for Data Source data

Page 176: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Externalizable

─ For Serialization when the data to be serialized is complex – since the datatype are known can use the API to specify the type avoid the introspection

– readBoolean()– readChar()– readObject()– ...–

Page 177: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 178: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● create a concrete implementation that extends JDBCAbstractDataSource

● that will work with a single row of data in a table

● It will support operations to─ (C)reate -> Insert ─ (R)ead -> Select─ (U)pdate -> Update─ (D)elete-> Delete

Page 179: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name─ JDBCRecordDataSource

● Superclass:─ demo.ls2011.jdbc4.

JDBCAbstractDataSource

Page 180: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Required imports

● JDBCRecordDataSource specifies the SQL required for manipulating the data

● MethodBinding─ Support actions that can be

called before and after saving row

Page 181: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Property setter and getters

● Check if the value has been set, otherwise check for a computed value

Page 182: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties...

Page 183: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties...

● recordId is the PK

● isReadOnly()─

● isNewRecord()─ Depends on the action

– newDocument

Page 184: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● If no action is specified, assumes newDocument

● Whenever the XPages component tree is being constructed or traversed any data controls are 'published'

● DataPublisher() calls getDataObject()

● getDataContainer() is implemented in AbstractDataSource

─ checks uniqueId()─ calls load()

Page 185: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Save is triggered by the XspCommandButton

─ save=true─

● invoke preSave─ false prevents save

● doSave

● Invoke postSave

Page 186: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Invoke the Data Source Action─ push()─ invoke()─ pop()

● If it's a new document, then beforehand, for example, queryNewDocument, there is no record/document, so no data to push to request scope, so in this case, record would be null.

Page 187: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Read JDBCRecordDataSource specific request parameters

● JDBCConstants─ URL_PARAM_ID

– documentId

● DataSource will be published using the var attribute

─ record1

● Can publish the data using several identifiers,

─ currentDocument─

Page 188: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (C)reate

● an 'empty' result set for the column meta data

● returns a JDBCDataContainer

● Concurrency not yet implemented

Page 189: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (R)ead

● JDBC PreparedStatement

● If documentId not set in URL, or ignoring request parameters for this data source look into the supplied Parameters

● If asked to read a row, but no PK specified, default to Create/Insert a new row

Page 190: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (R)ead........

● JDBC code - execute the select statement

Page 191: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (D)elete

Page 192: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (U)pdate─ if openDocument ─

● (C)reate─ if newDocument

● work with the JDBCRecord

Page 193: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● SQL INSERT or UPDATE statement needed?

● Specify the Prepared Statement parameters using the appropriate type of each column

Page 194: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● For UPDATE, the PK value should be specified in the WHERE clause

● executeUpdate()─ should update/insert 1 row

● If it was INSERT – get the PK value so it can be stored in the JDBCRecord

Page 195: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Handle any SQLExceptions

● OK? return true

Page 196: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● StateManagement─ as always!─

● Note the StateHolderUtil helper mehtods

─ saveMethodBinding()─ restoreMethodBinding()

Page 197: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● ...... almost there ......

Page 198: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create an XPages .xsp-config file that defines the properties and Domino Designer integration.

Page 199: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

AbstractDataSource

JDBCAbstractDataSource

JDBCRecordDataSource

com.ibm.xsp.model.group.DataSource

jdbcAbstractDataSource.xsp-config

jdbcRecordDataSource.xsp-config

Page 200: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Still in the Java Perspective

● Under─ WebContent /

– WEB-INF

Page 201: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New File

Page 202: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New File

● File name:─ jdbcAbstractDataSource.

xsp-config

Page 203: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Define a <group>─ idenfifed by <group-type>─

● specify all the properties declared in JDBCAbstractDataSource

─ server─ port─ database─

Page 204: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties.....

─ user─ password─ selectString─ tableName─

Page 205: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties.....

─ keyColumn─ parameters

– <property-class>● ArrayList

– <collection-property>● true

Page 206: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create .xsp-config for JDBCRecordDataSource

Page 207: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● <complex-type>─ specifes an Object with

properties

● <display-name>─ will be shown in Domino

Designer

● <complex-id>─ identifier─

● <complex-class>─ fully qualified implementing

class

Page 208: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties....

● <property-class>─ javax.faces.el.MethodBinding─

● <property-extension>─ DominoDesigner directive─ <method-binding-property>

– true

Page 209: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● <group-type-ref>─ to include properties from

other .xsp-config definition files

● <complex-extension>─ <tag-name>

– jdbcRecordDataSource─ <base-complex-id>

– dataInterface

Page 210: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next.........almost there........honest.....

Page 211: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Demo 5

● Create a new XPage

● CTRL-F8

Page 212: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a new XPage

● Name:─ xpDemo5

Page 213: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 214: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

Page 215: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Should look like this......

Page 216: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Data source events can be added

─ Although they show up in the Data Events tab

─ add them as a property of the Data Source

Page 217: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Simply reference the data source in SSJS

Page 218: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Use EL expressions to bind EditBoxes to row data columns

Page 219: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

Page 220: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Save Button─ Submit─ Visible only

when row is editable

Page 221: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 222: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Navigation─ result = saved ? XSP_SUCCESS : XSP_FAILURE;

Page 223: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Update xpDemo4 to include command link and command button to open xpDemo5 with row details

Page 224: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Can use the Document Simple Actions

─ no programming!

Page 225: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Will add the request parameters─ action=openDocument&documentId=<item.empno>

Page 226: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Click New to open xpDemo5

Page 227: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Open, ReadOnly, Edit, QuerySave Event, Edit, Save

Page 228: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 228

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 229: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to non relational data sources

● XML

● Web Services (REST/SOAP)

● etc

● Same approach as two previous examples

● Extend AbstractDataSource to define what properties the data source has

● Extend AbstractDataContainer to manage the life-cycle of the data in the context of a disconnected web application where the data is only live for the duration of the request

Page 230: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 230

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 231: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Deploying your data source

● To create a sharable library (OSGi Plugin), see─

─ http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Creating_an_XPages_Library

● For deployment on Lotus Domino® and Lotus Notes® Client, see─

─ http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Deploying_XPage_Libraries

Page 232: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 232

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 233: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A for General XPages Development

● blog.sequill.com ─ connect to development, general Xpages developemnt

Page 234: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation234

Mastering XPages

● Factoids ...

─ Comprehensive 7 Part, 785 page volume

─ IBM Press publication

─ Authored by lead members of XPages development team

─ Features contributions from other key community members

─ Covers all aspects of XPages application development

─ Example-driven approach focusing on practical problems

─ Includes sample NSF downloads

● Available now @ Lotusphere bookstore

● Available online

─ www.ibmpressbooks.com/bookstore/product.asp?isbn=0132486482

─ www.amazon.com/Mastering-XPages-Step-Step-Application/dp/0132486318

Page 235: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A

●We ask you answer!

Page 236: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

My Question:

Do you want MORE?

Page 237: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

My Answer:

bleedyellow.com

Page 238: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A

●Now it is your turn!

Page 239: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 239

Legal Disclaimer© IBM Corporation 2011. All Rights Reserved.

The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.

References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.

IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both. Unyte is a trademark of WebDialogs, Inc., in the United States, other countries, or both.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

Page 240: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

SHOW107 The Data Source Session: Take XPages data boldly where no XPages data has been taken before

Jim Quill | XPages Developer | IBM IrelandStephan H. Wissel | LTPA | IBM Singapore

Page 241: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 2

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●Simple CSV file Data Source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 242: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Built-in DataSources─ Domino® View─ Domino® Document─

● SeverSide JavaScript─ Write custom Java™ code to connect any data source and return that data

as an object, array, List, ResultSet, or DataModel will enable XPages controls to consume that data.

● Any control that holds data, for display or editing can be bound to an item of data, a field in a Domino document or a property of a Managed Bean, for example.

● Container controls, i.e. DataTable, Repeat, and View Panel can be bound to a single item or a collection of items and will iterate over the data

Page 243: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Demo 1─ Create an array─ Put it into view

scope─ Reference data

using EL expression

Page 244: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Built-in DataSources Benefits─

─ declaratively add and reuse custom data sources to an XPage,─

─ computed properties ─

─ easy access the data souce in SSJS─

─ nest DataSources so contents of one data source can be bound to computed properties of another data source defined on an inner panel that is in a Repeat control

─ control behavoiur via URL parameters─

─ add your own query/postSaveEvents, and more

Page 245: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Overview – options to connect to data

● Objectives for todays session─

─ Write a data source that reads a CSV file from the local filesystem

─ Write a data source that reads data from an RDBMS by executing SQL via JDBC

Page 246: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 7

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 247: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● For the two core storage artifacts, View and Documents, XPages provides a convenient mechanism to declaratively add these two data sources to your application without any coding

─ All properties can be computed using JavaScript or an EL expression─ Tight integration with a set of easy to use Simple Actions for working with

Documents and View─ Ability to specify request parameters to control and influence the behavior

of the data source

● Within the XPages framework, data sources are based on two key classes─ com.ibm.xsp.model.AbstractDataSource─ com.ibm.xsp.model.AbstractDataContainer─

Page 248: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

AbstractDataSource AbstractDataContainer

ComponentBindingObject ValueBindingObject

DataPublishingObject

StateHolder

DataSource

DataContainer

Externalizable

Page 249: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● AbstractDataSource Responsibilities─ Data source id management

– BeanId– UniqueId

─ RuntimeProperty management– Computed properties can be saved as runtime property so its values

doesn't have to be repeatedly calculated─ State Management

– Base properties var, scope, ignoreRequestParams, requestParamPrefix

– Property accessors for state of component to be recreated─ Data Container Management─ DataPublishing

– pushData, popData – publishes the DataModel to request scope using the specified var attribute as the key

Page 250: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The Data Source Object Model

● Data Container Responsibilities─ Externalizable support─ Manages the life cycle of the data – if it doesn't continuously store the data

between requests, it knows how to retrieve it.─

Page 251: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 12

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 252: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Setting up your development environment

● What you need─ IBM® Lotus Domino® Designer 8.5.2─ IBM® Lotus Domino® 8.5.2─ IBM® DB2® ─

● What you should have to hand:─ Javadoc

– XPages Extensibility API Documentation– http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPages_Extensibility_API_Document

ation─

─ Wiki– XPages Extensibility API Developers Guide– http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Master_Table_of_Contents_for_XPag

es_Extensibility_APIs_Developer_Guide

Page 253: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 14

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●Simple CSV File Data Source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 254: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a New Application─ Menu > File > New

Page 255: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Overview ─ Create a New Application─ Project setup─ Extend AbstractDataSource

– Manages the DataSource properties─ Extend AbstractDataContainer

– Manages the Data life cycle, caching, refreshing─ Create an xsp-config file that describes the DataSource so it can integrate

with Lotus Domino® Designer and the Xpages Framework

Page 256: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Application Setup─ Grant Anonymous Manager access level File > Application > Access Control...─ Specify oneuiv2 as the Web theme. File > Application > Properties > Xpages─ CTRL-S to save changes

Page 257: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Switch to the Java™ perspective─ Window > Open Perspective > Java

● Shortcut─ CTRL-F8

● A virtual file system for the NSF─ organized like a WAR

Page 258: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a new Source Folder─ Select the application NSF (ls2011.nsf)─ Right-Click > New > Source Folder─

● Do not use Local as the source folder─ Java files stored here are actually located on the

local workstation file system in the IBM® Lotus Domino® Designer workspace and are not inside the NSF file.

─ When XPages are compiled to Java classes, the intermediate Java source file is written to here.

– Can be useful to examine these source files to

Page 259: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create a new Source Folder─ In the Folder name: field enter src ─ Select Finish

Page 260: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Appropriate Java Build Path is automatically configured

● Select src folder─ Right-Click >

Build Path > Configure Build Path...

─ Select Libraries tab

Page 261: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Verify the src folder will generate the class files into the expected location (ls2011.nsf/WebContent/WEB-INF/classes)

● Select src folder─ Right-Click > Build

Path > Configure Output Folder...

● Note: To see the classes folder use the Navigator view

─ Menu > Window > Show Eclipse Views > Navigator

Page 262: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create the a new Class file─ Select the src folder─ Right-Click > New > Class

Page 263: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Enter the New Java Class details─

─ Package:– demo.ls2011.csv

─ Name:– CSVDataSource

─ Superclass:– com.ibm.xsp.model.AbstractDataSource

─ Interfaces:– com.ibm.xsp.model.DataSource

─ Leave inherit abstract methods checked.

● Select Finish

Page 264: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● The CSV File Data Source has 4 properties

─ csvFilePath– location on the

local file system─ separator

– field delimiter–

─ firstLineIsHeader– treat the first line

of the CSV file as column headers.

─ trimWhiteSpace– Postprocessing

the data, could be anything you like

Page 265: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Theory: Literal values compared to Computed values─

─ Property setter called for Literal values– getter will simply return the set value–

─ SetValueBinding called for Computed values– Getter has to evaluate the corresponding value expression to– AbstractDataSource.RuntimeProperties help optimize reading these values

Page 266: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● AbstractDataSource.RuntimeProperties─

● Optimization to save recalculating computed properties

Page 267: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Java Bean property accessors─ Always follow this general structure

– If set directly, return the value– Otherwise check for a computed value

● Specifies the location of the target CSV file

Page 268: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Property accessors continued

● Allows developer specify the field delimiter

Page 269: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Use this property to label columns─ #{item.column2}─

● With no header must specify column position

─ #{item[1]}

Page 270: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Can specify any other properties required

─ Manipulation, transformation, etc.

Page 271: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● UniqueId─ Using a combination of the Data Source

properties, than can be repeatedly calculated, construct an id to identity the data souce, such that any property changes that would effect the data would generate a new id.

● Bean Id─ The key used to store the DataContainer for the

DataSource─ AbstractDataSource calculates beanId,

DataSource developer specified how to compose the uniqueId

─ Default scope for DataSources is View Scope─ If data shared

– scope = session– scope = application

─ Then beanId = uniqueId

Page 272: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Abstract methods─ Called by the XPages Framework to get the data from a data source─

Page 273: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Support changing functionality via request parameters

● http://server/app.nsf/csv.xsp?separator=:&firstLineIsHeader=false─

●● PrefixRequestParam

─ Enable request parameters to be specified for individual data sources

● Save is called by XPages Framework if Submit event was triggered

Page 274: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● State Management

● StateHolder is a JSF interface that must be implemented by components that need to save their state between requests

● Saving and restoring is done as a Serializable object─ Must have a public no-args constructor─

● Component tree is built for the initial request, and then restoring for subsequent postbacks

● If it is not done right, components behave differently and data disappears in subsequent POST requests after the initial GET

Page 275: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● State Management

● Must be Objects

● Care needed for primitive types

● Ctrl-S to Save

Page 276: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData─ Represents a row of data

● Implement DataObject─ XPages Property Resolver knows about this

type─ For EL expression like item.name instead of

calling getName() as is typical for Java Beans the Property Resolver will call getValue(“name”)

─ Is also implemented for DominoDocument─ Similar to ViewRowData Interface used for row

data items in a Domino View.─ Documentation Bug

– Interface com.ibm.xsp.model.DataObject is not published.

Page 277: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData─ Create a new Java Class─

─ Package– demo.ls2011.scv–

─ Name– CSVRowData

─ Interfaces– com.ibm.xsp.model.

DataObject– java.io.Serializable

Page 278: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● CSVRowData

● SerialVersionUID─ not requied─ added to remove warning

Page 279: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Object

● GetValue()─ #{item.name}

– gets the value for the field labeled “name”–

─ #{item[2]}– gets the value for the second field– useful if CSV file doesn't use the first row to

specify column names–

Page 280: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● DataObject─

─ Data is stored in a Map of key-value pairs

● CTRL-S to save─

Page 281: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● In the Package Navigator, Select the src folder, Right-Click > New > Class to create a New Java Class for the Data Container

─ Package– demo.ls2011.csv–

─ Name:– CSVDataContainer–

─ Superclass:– com.ibm.xsp.model.

AbstractDataContainer

● Select Finish

Page 282: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container─

● Data is a List of CSVRowObjects

Page 283: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● Externalizable─

Page 284: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● The actual implementation to get the data

Page 285: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container─

Page 286: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Data Container

● Accessor methods to finish off the Class

Page 287: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Create the xsp-config file

● ─

Page 288: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● New File─ File name:

– csvDataSource.xsp-config–

Page 289: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Complex Types in the xsp-config file─

─ Used to specify non-primative types in Xpages– Objects

─ Represented using their own tags─ Can specify a Class or Interface

Page 290: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Declare the namespace

● Descriptive information that wil be used by Domino® Designer

● The class the implements the functionality and property support

● Group-type-ref─ Base data source

properties ─

Page 291: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Specify the required properties

Page 292: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● xsp-config

● Properties─

Page 293: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2─ Create the following test CSV files in the C: \temp directory

Page 294: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● Switch to the Domino Designer perspective─ CTRL-F8 > Domino Designer

● Create a new Xpage called xpDemo1 ─ XPages > New Xpage...─ Name is xpDemo1─ Select on the blank XPage design canvas so

the XPage design Properties tab appears

● In the XPage Properties tab─ Open the Data section─ Click Add and you will see CSV Data Source

in the drop down list─

Page 295: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● Declaratively configure the new data source

Page 296: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2─

Page 297: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 2

● 2 single row tables with a repeat control

Page 298: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Create XPage with CSV Data Source─

─ test3.csv─ #SEP#

Page 299: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Create a Panel with a Repeat Control

● Create another Panel within the Repeat

● Configure a Data Source for this Panel

Page 300: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3─

● Properties for the inner Panel are computed based on values read from the Data Source on the XPage.

Page 301: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3─ Inner Repeat Iterates over a table row

Page 302: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Simple CSV Data Source

● Demo 3

● Button performs partial refresh on outer Panel when clicked.

─ Useful for testing data source State Management

─ If is is wrong, data will disappear after completion of the POST request

Page 303: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 64

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 304: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Overview─

─ Enable Java debugging on IBM® Lotus Domino®

─ Create a Debug Configuration─

Page 305: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Enable Java debugging on IBM® Lotus Domino® by adding the following lines to notes.ini

─ JavaEnableDebug=1─ JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8

000

Page 306: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Restart IBM® Lotus Domino® and verify that debugging has been enabled by checking the server console for the following message:

– > Listening for transport dt_socket at address: 8000– 1/01/2011 17:08:45 JVM: Java Virtual Machine initialized.– 1/01/2011 17:08:45 HTTP Server: Java Virtual Machine loaded

Page 307: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Instead of switching perspectives, stay in the Domino Designer perspective and open the Navigator and Package Explorer views.

─ Window > Show Eclipse Views > Other...─ Select Navigator (under General)─ Click OK─

Page 308: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● The Navigator opens be default beside the Control palette and the Data palette

● One benefit of the Navigator over the Package Explorer is that the Navigator show then compiled Java classes for the application

● However it does not have the Right-Click context menus for configuring the Java build path

Page 309: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● To open the Package Explorer view:─ Window > Show Eclipse Views > Other...─ Select Package (under Java)─ Click OK─

Page 310: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● In Package Explorer, double-click on the class you are interested in debugging to open it.

● Set a breakpoint in your code by double-clicking on the line number for the method you want to debug.

● Notice a small circle icon will appear beside the line. ─

Page 311: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Create a Debug Configuration

● Select ─ Remote

Java Application

─ Click New─

─ Enter– Name:–

─ Leave all other default values

Page 312: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Add your source path to the debug environment for source code to open for breakpoints

● Select the source tab

● Click Add─

Page 313: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Choose─ Java Project─

● Select your project─

Page 314: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Click Apply─ to save the

changes ─

● Click Debug to launch the debugger

Page 315: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● Run the demo XPage application again─

Page 316: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Debugging you code

● The Java Debug perspective will open with the code stopped on the breakpoint

Page 317: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Summary

● Being able to debug custom code in an XPages application will be vital for data source development

Page 318: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 79

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 319: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a read only Data Source that allows a developer to declaratively specify JDBC connection information and an SQL query that retrieves the appropriate data

Page 320: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Install DB2®─ Include the sample databases─ Assumes user is db2admin with password as password─

● Locate the JDBC Type 4 driver─ db2jcc.jar─ db2jcc_license.jar─ will need them later─

Page 321: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a simple helper class that will be used to create database connections

Page 322: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Only supports DB2® driver protocol

Page 323: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Code to load the JDBC driver

Page 324: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Test the connection and configuration─

Page 325: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Simple test application─

Page 326: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● SSJS to call the static test method─

Page 327: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Expected ClassNotFoundException

● Add the JDBC Driver to the NSF─

Page 328: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● In the Java perspective, open the Navigator

● Expand the WebContent/WEB-INF folder

● Notice there is no lib folder

● Select WEB-INF

● Right-Click > New > Folder─

Page 329: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Folder name:─ lib

● Click Finish─

Page 330: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Select the lib folder under WebContent/WEB-INF─

● Right-Click > Import...

Page 331: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Select File System

● Click Next─

Page 332: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Browse to the folder that contains the JDBC driver

● Select ─ db2jcc.jar─ db2jcc_license.jar─

● Click FInish─

Page 333: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Driver should be on the XPages Classpath

● Run the test again

● Oooops...─

Page 334: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Check the logs

● Security Exception─ checkPropertiesAccess() is not managed by AgentSecurityManager─ Doesn't check if unrestriced users can perform the operation─

● Need to move JDBC drivers to trusted location (since call is wrapped by AccessController.doPrivileged() )

Page 335: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● C:\Domino\jvm\lib\security\java.policy

● Choices:

─ Store JARs under C:\Domino\xsp\shared– it is a trusted location– XPages ClassLoader will search for JARs here when runtime starts

─ Trust the specific NSF application as a location

Page 336: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Restart the HTTP task to pick up changes to java.policy─ tell http quit─ load http─

─ Rerun test– success

Page 337: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create the

─ JDBC Query Data Source class─

─ JDBC Query Data Container class─

─ JDBC Query Data Source xsp-config configuration file─

Page 338: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create new class

● Extend AbstractDataSource─

Page 339: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ComposeUniqueId()─ Based on data source properties─

● getDataObject()─ return the data

● isReadOnly()

● ReadRequestParams()─ data source specific options

● load()─ Called by the XPages framework

● Save()─ Called by the XPages framework─

Page 340: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Define the properties the Data Source is going to support

Page 341: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Support Parameters - declared in the xsp-config which then appear in the data source property panel

Page 342: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● State Management for primitive types

● Can't return null - need to decide on value to be returned when port is not set

Page 343: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● If using RuntimeProperties, check here

Page 344: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● queryString holds the SQL

● In a form that will be parsed by a JDBC PreparedStatement

Page 345: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● More property accessors

● KeyColumn could be used to identify the Primary Key column in the the table the SQL query is based upon

Page 346: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Override abstract methods

● Connection information and SQL query.

─ Changing the sort order, which still reads the data from the same data source could change the UniqueId, triggering the DataContainer to refresh any cached data

● getDataObject gets the data from the DataContainer

Page 347: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● load()─ Called by

XPages framework

● save()─ Return false

since read only

Page 348: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● State management─

Page 349: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● Create a new class

● Extend AbstractDataContainer

Page 350: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● DataContainers are not stored with the DataSource in the view

● The are managed by a scope Bean Manager and are identified by their beanId

Page 351: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container

● Get the data

● Other stragegy is to get the data as part of the DataSource and just have container manage its lifecycle

─ Can it be cached ─ Does it need to be refereshed─ Resource pooling─

Page 352: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─

● JDBC code using ResultSet─

─ Could consider RowSets and have it handle disconnected mode

Page 353: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─ Leverage FacesContextListener to manage the lifecycle of the data and

caching stratagies– beforeRenderingPhase()– beforeContextReleased()

Page 354: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Data Container─

─ Implements Externalizable─

─ Class handles serialization of each property itself

─ Optimization to avoid the serialization code having to intropsect and figure out all the datatypes.

Page 355: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create ResultSetModelEx

─ Extends TabularDataModel– better integration with

XPages Pager control for ResultSets

─ Delegates to ResultSetDataModel

Page 356: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Some properties and constructors

● Wraps a ResultSetDataModel to which it delegates most methods, except getRowCount() as we don't want to return the standard -1 (prevents us working with the pager controls. DataModels that have an unknown count can extend TabularDataModel

Page 357: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Pager estimates number rows and ask data model if it knows if rowCount is bigger than current maxCount

● For the current page, always return the current page range + 1 – causes the Pager to indicate that there are more rows

Page 358: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx

● Delegated methods─

Page 359: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● ResultSetModelEx─

─ If isRowAvailable returns false from the delegated ResultSetDataModel then we know we have found a potential value for the actual row count

─ HasMoreRows() will start using this value and since it will be less than the current deduced max in the pager, it will readjust based on this value.

Page 360: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create JDBC xsp-config

● Select WEB-INF, Right-Click > New > File

● File name:─ jdbcQuertDataSource.xsp-config

Page 361: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC xsp-config

● Key property─ complex-extension

– dataInterface–

● If xsp-config file not immediately recognised as XML, close and reopen.

Page 362: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Query Data Source Properties

● Server

● Port

● Database

Page 363: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC Query Data Source Properties

● User

● Password

● SQL query

Page 364: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Demo 4─ Create XPage

Page 365: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

Page 366: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

Page 367: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● JDBC

● Want to build this

Page 368: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Create a DataTable

● Bind using EL

Page 369: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● DataTable collection is called item

● Computed fields can bind to the data using EL expression

Page 370: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS

● Pager tries to deduce last page

● ...Next indicates more pages

● Keeps increasing until no row is found, then Pages adjusts last page

● Next indicates a max count found

Page 371: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 132

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS (Part 2: CRUD)

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 372: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Courtesy of XKCD.com ( http://xkcd.com/327/ )

Page 373: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a JDBC Data Source that supports working with individual rows in a table. Should support operations such as:

─ (C) inserting a new row─ (R) selecting a specific row─ (U) updating an existing row ─ (D) deleting a row─

● Like a DominoView -> DominoDocument, Master -> Detail type relationship

─ JDBCQueryDataSource– works with several rows–

─ JDBCRecordDataSource– works with a single row

Page 374: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 375: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 376: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class─ Select the ls2011 package─ Right-Click, select

– New > Class ─

● Use CTRL-F8 to switch perspectives (if necessary)

Page 377: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package─ demo.ls2011.jdbc4─

● Name:─ JDBCConstants

Page 378: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Constants─ Not all used in current

implementation─

─ JDBC Driver properties─

─ Standard XPages (Domino oriented URL parameters

─ Actions– New, Open, Edit

Page 379: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 380: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● A class with helpful convenience methods for working with JDBC, e.g. open/close connections, getting column information, setting types, etc.

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCUtil

Page 381: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Open JDBC Connection─

─ via Properties object─

─ via basic properties– server – port – database – User– password

Page 382: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Code that actually loads the JDBC driver

● Close a connection

Page 383: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More utility methods─

─ Get a single ─

─ Get an empty ResultSet to retirence the ResultSet meta data to get column information

Page 384: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Utility method to for setting the appropriate type for the columns when setting parameters for a JDBC PreparedStatement

─ not all types covered– Numbers– Characters

Page 385: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 386: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Note─ Use CTRL-Space to get─ 'hints' on packages and

classes available in the application package hierarchy

Page 387: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCAbstractDataSource

● Modifiers:─ public abstract─

● Superclass:─ com.ibm.xsp.model.Abstract

DataSource

Page 388: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Imports that can be added as the abstract data source class is developed

● Has the abstract modifier

● This class will be extended later on with a concrete class that will implement the row oriented specifics of the data source

Page 389: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Specify member variables that represent properties for the JDBC-based data source

─ server─ port─ database, etc─

● parameters is as List─ used to store name-value

(com.ibm.xsp.Paramster) pairs that can be used to pass information to the data source.

Page 390: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create property accessor methods─ server─ port ─

● Follow the standard 'template' for getters

─ 1) check if instance variable is set─ 2) check for a corresponding value

binding (if value can be computed)─ 3) retrun null or default for primitive

(int etc.) types

● action─ 'read only' property─ set via request parameter

– action=newDocument

Page 391: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More property accessors─ database─ user

● If RuntimeProperties is implmemented, get it here.

● Extend the standard 'template' for getters

─ 1) if using RuntimeProperties, get it from there

─ 2) check if instance member variable is set

─ 3) check for a corresponding value binding (if the value can be computed)

─ 4) retrun null or default for primitive (int etc.) types

Page 392: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties─ password─ selectString

● selectString─ idea was that whether one row is

indented to be returned (JDBCRecordDataSource), or several (JDBCQueryDataSource).

─ oth have a SQL select statement in common, so property is in abstract class

– then decided to modify/override with concurrency column info (not fully implemented)

Page 393: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties─ keyColumn

– primary key–

─ tableName– used for getting

database metadata–

─ SortOrder– not implemented.

● Optimize – collect metadata during Connection/Data Source definition

Page 394: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● UniqueId─ An identifier that distinguishes

this JDBC data source from other JDBC data sources

– can be repeatedly re-constructed form the data source properties

─ used as the name for storing data in scope (if shared)

─ connection information + request parameter info + select statement

Page 395: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Read general request parameters

─ action─ sortOrder

● Abstract methods sub-classes must implement

─ isReadOnly()─ getDataObject()─ load()─ save()

● Helper methods for connection URL and opening the JDBC connection

Page 396: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● State Management for all the properties

─ Handy StateHolderUtil method for working with List objects

Page 397: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 398: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● create a helper class JDBCConcurrencyInfo

─ Not really used. Keep in mind that it (or this feature) will be required for taking this sample further for production use.

Page 399: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 400: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Concurrency─ Pessimistic

– RDBMS specific─

─ Optimistic– which column provides

the 'timestamp' that can be compared for row updates

─ Force – Last Writer Wins– Not really a good idea

Page 401: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 402: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create a concrete class that implements DataObject

─ JDBCRecord

● Purpose─ Enables the data that are returned to

be simply referenced with an EL expression using the data field/column name

Page 403: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Name:─ JDBCRecord

● Interfaces─ com.ibm.xsp.model.

DataObject– Known interface by the

XPages PropertyResolver, calls getValue(“<prop>”)

─ java.io.Serializable

Page 404: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● When the XPages Framework calls

─ DataSource.getDataObject()─ which in turn calls─ DataContainer.getRecord()

● This is the returned object

● Is essentially the BackingBean for the part of the UI that displays the data from the Data Source

● wrappedData ─ JDBC ResultSet─ transient - not serializable

need to be managed

Page 405: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Constructor─ ResultSet

– wrapped─ UniqueId

– Primary Key Column for the record

─ Should be a List<String>─

● Get the Column Types for each of the Columns based on the ResultSet meta data

● selectSQL ─ used to recreate the ResultSet

as necessary

Page 406: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Implements the DataObject methods:

─ getType(key)─ getValue(key)─ setValue(key,value)─ isReadOnly()

Page 407: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● The DataContainer implementation will callback to the JDBCRecord before and after the de/serialized to give JDBC an opportunity to do anything it needs

Page 408: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● discardWrappedObject─ ResultSet is closed before

serialization.─

● Several other methods not yet fully implemented that will be useful in the future:

─ CheckRecordValidity()– row may been deleted

between requests─

Page 409: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 410: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create a concrete class that extends AbstractDataContainer

─ JDBCRecordDataContainer

● Purpose─ Manages the life-cycle of the data in a

stateless request response environment

─ Good place for implementing a caching strategy

Page 411: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name:─ JDBCRecordDataContainer─

● Superclass:─ com.ibm.xsp.model.Abstract

DataContainer

Page 412: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● com.ibm.xsp.model.AbstractDataContainer

─ contains some basic support for making the data source Externalizable

● Need to implement the required serialize and deserialize methods

Page 413: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● JDBCRecord─ the data object

● FaceContectListener─ used to discard

resources at the end of the request

● In this implementation the DataSource creates the JDBCRecord and passes it into the Constructor

Page 414: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● FacesContextListener─ Can use this listener to

manage the data through the various phases of the JSF Lifecycle

● getRecord()

● Called from DataSource.getDataObject()

– Xpages Framework entry point for Data Source data

Page 415: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Externalizable

─ For Serialization when the data to be serialized is complex – since the datatype are known can use the API to specify the type avoid the introspection

– readBoolean()– readChar()– readObject()– ...–

Page 416: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

The JDBC Data Source Object Model

– AbstractDataSource

JDBCUtil

JDBCConcurrencyInfo

JDBCRecord

JDBCAbstractDataSource

JDBCRecordDataSource

JDBCRecordDataContainer

JDBCConstants

AbstractDataContainer

Page 417: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● create a concrete implementation that extends JDBCAbstractDataSource

● that will work with a single row of data in a table

● It will support operations to─ (C)reate -> Insert ─ (R)ead -> Select─ (U)pdate -> Update─ (D)elete-> Delete

Page 418: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

● Package:─ demo.ls2011.jdbc4─

● Name─ JDBCRecordDataSource

● Superclass:─ demo.ls2011.jdbc4.

JDBCAbstractDataSource

Page 419: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Required imports

● JDBCRecordDataSource specifies the SQL required for manipulating the data

● MethodBinding─ Support actions that can be

called before and after saving row

Page 420: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Property setter and getters

● Check if the value has been set, otherwise check for a computed value

Page 421: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties...

Page 422: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties...

● recordId is the PK

● isReadOnly()─

● isNewRecord()─ Depends on the action

– newDocument

Page 423: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● If no action is specified, assumes newDocument

● Whenever the XPages component tree is being constructed or traversed any data controls are 'published'

● DataPublisher() calls getDataObject()

● getDataContainer() is implemented in AbstractDataSource

─ checks uniqueId()─ calls load()

Page 424: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Save is triggered by the XspCommandButton

─ save=true─

● invoke preSave─ false prevents save

● doSave

● Invoke postSave

Page 425: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Invoke the Data Source Action─ push()─ invoke()─ pop()

● If it's a new document, then beforehand, for example, queryNewDocument, there is no record/document, so no data to push to request scope, so in this case, record would be null.

Page 426: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Read JDBCRecordDataSource specific request parameters

● JDBCConstants─ URL_PARAM_ID

– documentId

● DataSource will be published using the var attribute

─ record1

● Can publish the data using several identifiers,

─ currentDocument─

Page 427: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (C)reate

● an 'empty' result set for the column meta data

● returns a JDBCDataContainer

● Concurrency not yet implemented

Page 428: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (R)ead

● JDBC PreparedStatement

● If documentId not set in URL, or ignoring request parameters for this data source look into the supplied Parameters

● If asked to read a row, but no PK specified, default to Create/Insert a new row

Page 429: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (R)ead........

● JDBC code - execute the select statement

Page 430: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (D)elete

Page 431: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● (U)pdate─ if openDocument ─

● (C)reate─ if newDocument

● work with the JDBCRecord

Page 432: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● SQL INSERT or UPDATE statement needed?

● Specify the Prepared Statement parameters using the appropriate type of each column

Page 433: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● For UPDATE, the PK value should be specified in the WHERE clause

● executeUpdate()─ should update/insert 1 row

● If it was INSERT – get the PK value so it can be stored in the JDBCRecord

Page 434: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Handle any SQLExceptions

● OK? return true

Page 435: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● StateManagement─ as always!─

● Note the StateHolderUtil helper mehtods

─ saveMethodBinding()─ restoreMethodBinding()

Page 436: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● ...... almost there ......

Page 437: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next...

● Create an XPages .xsp-config file that defines the properties and Domino Designer integration.

Page 438: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

AbstractDataSource

JDBCAbstractDataSource

JDBCRecordDataSource

com.ibm.xsp.model.group.DataSource

jdbcAbstractDataSource.xsp-config

jdbcRecordDataSource.xsp-config

Page 439: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Still in the Java Perspective

● Under─ WebContent /

– WEB-INF

Page 440: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New File

Page 441: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New File

● File name:─ jdbcAbstractDataSource.

xsp-config

Page 442: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Define a <group>─ idenfifed by <group-type>─

● specify all the properties declared in JDBCAbstractDataSource

─ server─ port─ database─

Page 443: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties.....

─ user─ password─ selectString─ tableName─

Page 444: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties.....

─ keyColumn─ parameters

– <property-class>● ArrayList

– <collection-property>● true

Page 445: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create .xsp-config for JDBCRecordDataSource

Page 446: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● <complex-type>─ specifes an Object with

properties

● <display-name>─ will be shown in Domino

Designer

● <complex-id>─ identifier─

● <complex-class>─ fully qualified implementing

class

Page 447: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● More properties....

● <property-class>─ javax.faces.el.MethodBinding─

● <property-extension>─ DominoDesigner directive─ <method-binding-property>

– true

Page 448: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● <group-type-ref>─ to include properties from

other .xsp-config definition files

● <complex-extension>─ <tag-name>

– jdbcRecordDataSource─ <base-complex-id>

– dataInterface

Page 449: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Next.........almost there........honest.....

Page 450: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Demo 5

● Create a new XPage

● CTRL-F8

Page 451: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a new XPage

● Name:─ xpDemo5

Page 452: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 453: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

Page 454: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Should look like this......

Page 455: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Data source events can be added

─ Although they show up in the Data Events tab

─ add them as a property of the Data Source

Page 456: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Simply reference the data source in SSJS

Page 457: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Use EL expressions to bind EditBoxes to row data columns

Page 458: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

Page 459: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Save Button─ Submit─ Visible only

when row is editable

Page 460: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Create a New Java Class

Page 461: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Navigation─ result = saved ? XSP_SUCCESS : XSP_FAILURE;

Page 462: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Update xpDemo4 to include command link and command button to open xpDemo5 with row details

Page 463: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Can use the Document Simple Actions

─ no programming!

Page 464: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Will add the request parameters─ action=openDocument&documentId=<item.empno>

Page 465: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Click New to open xpDemo5

Page 466: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to RDBMS(2)

● Open, ReadOnly, Edit, QuerySave Event, Edit, Save

Page 467: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 228

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 468: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Connecting to non relational data sources

● XML

● Web Services (REST/SOAP)

● etc

● Same approach as two previous examples

● Extend AbstractDataSource to define what properties the data source has

● Extend AbstractDataContainer to manage the life-cycle of the data in the context of a disconnected web application where the data is only live for the duration of the request

Page 469: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 230

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 470: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Deploying your data source

● To create a sharable library (OSGi Plugin), see─

─ http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Creating_an_XPages_Library

● For deployment on Lotus Domino® and Lotus Notes® Client, see─

─ http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Deploying_XPage_Libraries

Page 471: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 232

Agenda

●Overview – options to connect to data

●The Data Source object model

●Setting up your development environment

●The first data source

●Debugging your code

●Connecting to RDBMS

●Connecting to Non relational data sources

●Deploying your data source

●Q & A

Page 472: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A for General XPages Development

● blog.sequill.com ─ connect to development, general Xpages developemnt

Page 473: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation234

Mastering XPages

● Factoids ...

─ Comprehensive 7 Part, 785 page volume

─ IBM Press publication

─ Authored by lead members of XPages development team

─ Features contributions from other key community members

─ Covers all aspects of XPages application development

─ Example-driven approach focusing on practical problems

─ Includes sample NSF downloads

● Available now @ Lotusphere bookstore

● Available online

─ www.ibmpressbooks.com/bookstore/product.asp?isbn=0132486482

─ www.amazon.com/Mastering-XPages-Step-Step-Application/dp/0132486318

Page 474: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A

●We ask you answer!

Page 475: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

My Question:

Do you want MORE?

Page 476: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

My Answer:

bleedyellow.com

Page 477: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation

Q&A

●Now it is your turn!

Page 478: SHOW107: The DataSource Session: Take XPages data boldly where no XPages data has been taken before

© 2011 IBM Corporation 239

Legal Disclaimer© IBM Corporation 2011. All Rights Reserved.

The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.

References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.

IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, and Lotusphere are trademarks of International Business Machines Corporation in the United States, other countries, or both. Unyte is a trademark of WebDialogs, Inc., in the United States, other countries, or both.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.


Recommended