DEV1-Ch04-Data Anywhere Architecture
DEV1-Ch04-Data Anywhere Architecture
Part I
Chapter 4 • Data Anywhere Architecture
a Repository
— Use the ACC to browse and query a
Repository
4-2
ATG Data Anywhere Architecture
Overview
4-3
The Problem
Dynamusic.com
LDAP Employee
Directory newsfeed (XML)
Images
Customer Data
Song Data
4-4
The Solution
Dynamusic.com
LDAP Employee
Directory Customer Data Song Data Images newsfeed (XML)
4-5
The ATG Data Anywhere Architecture (1)
• The ATG Data Anywhere Architecture provides
Repositories, which connect to various data
sources
— SQL relational database
— LDAP directory
4-6
The ATG Data Anywhere Architecture (2)
• Includes
— Servlet Beans for displaying data in a page
data
4-7
Why the Data Anywhere Architecture?
etc.)
4-9
Repository Architecture
4-10
Dynamusic.com Repositories
/atg
/dynamusic/ /userprofiling/ /dynamusic/
SongsRepository ProfileAdapterRe EventsRepository
pository
Albums
Venues
Users
Artists
Concerts
Songs Playlists
4-11
Repository Items (1)
RepositoryItem
id
title
album
artist
songList
...
Songs
Albums
Reposi
RepositoryItem tory Artists
id
Songs
artist
name
description
photoURL
...
4-12
Repository Items (2)
• Each RepositoryItem has
— a repositoryId property
itemDescriptor
+ title (String)
artist (artist)
album artist
4-13
Item Relationships
RepositoryItem
RepositoryItem
id=200023 id=610153
title=Abbey Road title=Here Comes
songs song the Sun
album
artist downloadURL
coverURL artist
RepositoryItem
id=200194 MP3
name=The Beatles
artist
descr="The 'Fab Four'
started in Liverpool as…"
photoURL
4-14
Demo: Repositories and the ACC
4-15
Using Repositories:
Repository Servlet Beans
4-16
Using Repositories with Dynamic Pages
• The most common use of repositories is to
display and manipulate data in dynamic pages
— Form Handlers
4-17
Repository Servlet Beans
• When you know the item ID and want to display
the item
— ItemLookupDroplet
— RQLQueryRange
4-18
Using an Item Lookup Droplet (1)
• Create and configure new component based on
the ItemLookupDroplet class
ConcertLookup
Droplet Events
repository Repository venue
id
name
concert
description
venue
artists
4-19
Using an Item Lookup Droplet (2)
• Call from a page, passing in the id parameter
<dsp:droplet name="/dynamusic/ConcertLookupDroplet">
<dsp:param name="id" param="itemId"/>
<dsp:oparam name="output">
Name: <dsp:valueof param="element.name"/> <br>
Venue: <dsp:valueof param="element.venue.name"/>
<br>
Date: <dsp:valueof param="element.date" date="MMM
dd,yyyy"/> <br>
</dsp:oparam>
<dsp:oparam name="empty">
No such concert found.
</dsp:oparam>
</dsp:droplet>
4-20
Querying a Repository
4-21
Repository Query Servlet Beans
• For cases when the id of the item(s) is unknown, the
Data Anywhere Architecture includes query Servlet
Beans
— RQLQueryForEach – displays each item found by a
query
— RQLQueryRange – displays a subset of result items
• Queries can:
— Match patterns in text
— Query through collections
— Query through complex values
— Specify the order to present the results
4-22
Using RQL Servlet Beans
• Input parameters
— repository – the repository to query
• Oparam
— output – rendered once the query has been executed
matched
4-23
Repository Query Language (RQL)
• Textual query syntax, similar to SQL
— RQL describes conditions to match items of a
repository items
• Higher level than SQL
4-24
RQL Statements
• RQL statements are built using the RQL syntax
around a specified item type descriptor
• Example:
— item type: song
— repository: /dynamusic/SongsRepository
— RQL statement: genre = "jazz"
means "find all song items whose genre property is
jazz"
4-25
RQL Query Conditions
• Return all items: ALL
• Comparison: =, !=, <, <=, >, >=
— Example: age > 18
4-26
RQL Queries with Item References
• If a property refers to another repository item,
you can drill down:
— Single value properties
address.zip starts with "02"
— Multi value properties
favoriteArtists INCLUDES ITEM (name
STARTS WITH "B")
4-27
RQL Collection Queries
• INCLUDES ANY
For example:
prefGenres INCLUDES ANY { "jazz", "blues" }
is equivalent to:
(prefGenres INCLUDES "jazz") OR
(prefGenres INCLUDES "blues")
• INCLUDES ALL
For example:
prefGenres INCLUDES ALL { "jazz", "blues" }
is equivalent to:
(prefGenres INCLUDES "jazz") AND
(prefGenres INCLUDES "blues")
4-28
Parameterized RQL Queries
• Queries have access to page parameters
— genre = :paramname
• The parameters you want to use must be in
scope when the Servlet Bean is rendered
• Parameters may be
— passed in from an enclosing page
4-29
Example: RQLQueryRange (1)
4-30
Example: RQLQueryRange (2)
1 <dsp:droplet name="/atg/dynamo/droplet/ForEach">
<dsp:param bean="Profile.prefGenres" name="array"/>
<dsp:oparam name="output">
2 <dsp:setvalue param="prefgenre" paramvalue="element"/>
<h3><dsp:valueof param="prefgenre"/> songs: </h3><ul>
<dsp:droplet name="/atg/dynamo/droplet/RQLQueryRange">
3 <dsp:param name="itemDescriptor" value="song"/>
<dsp:param name="repository"
value="/dynamusic/SongsRepository"/>
<dsp:param name="howMany" value="4"/>
4 <dsp:param name="queryRQL" value="genre = :prefgenre"/>
<dsp:oparam name="output">
<li><dsp:valueof param="element.title"/> (by
<dsp:valueof param="element.artist.name"/>)
</dsp:oparam>
</dsp:droplet>
</ul>
</dsp:oparam> genresongs.jsp
</dsp:droplet>
4-31
RQL Query and Item Lookup Together(1)
… <dsp:oparam name="output">
<li><dsp:a href="song.jsp">
<dsp:param name="itemId" param="element.id"/>
genresongs.jsp <dsp:valueof param="element.title"/> (by
<dsp:valueof param="element.artist.name"/>)
</dsp:a>
</dsp:oparam> …
4-32
RQL Query and Item Lookup Together(2)
song.jsp
<dsp:droplet name="/dynamusic/SongLookupDroplet">
<dsp:param name="id" param="itemId"/>
<dsp:oparam name="output">
…
Song: <dsp:valueof param="element.title"/>
…
</dsp:oparam>
</dsp:droplet>
4-33
Dynamic Beans:
The Magic Behind
<dsp:valueof
param="element.property">
4-34
Repository Item Properties
• How can objects of the same class have different
properties?
• The RepositoryItem class uses
— a Map to store values
— get/setPropertyValue(String
4-35
Property Mapping (1)
• ATG normally retrieves/modifies properties by
calling the get/set methods of beans
Page.jsp
<dsp:droplet name="ForEach">
...
mycompany.someClass
<dsp:valueof param="element.someProp"/>
... String getSomeProp()
4-36
Property Mapping (2)
• Each Dynamic Bean class (such as
RepositoryItem) has an associated Dynamic
Property Mapper object that tells ATG how to get
and set properties
Dynamic
Property
Mapper
Page.jsp RepositoryItem
<dsp:droplet name="Repository">
…
<dsp:valueof param="element.title"/> getPropertyValue("title")
…
</dsp:droplet>
4-37
Dynamic Beans and JSTL
• JSTL "dot" notation for accessing JavaBean
properties doesn't work for Dynamic Beans
<c:out value=
"${element.title}"/>
4-38
Summary
In this chapter, you learned that
• The Data Anywhere Architecture frees the
the repository by ID
• RQL Servlet Beans query the repository
4-39
For More Information
• Repository Guide
• Page Developer's Guide
— "Dynamo Servlet Beans" appendix
4-40
Exercises
• Use the ACC the browse the Songs Repository
• Create "drill-down pages" to list artists, albums
and songs from the Songs Repository
4-41