ATG教程-DEV1 Chapter 5: Configuring SQL Repositories

Chapter 5: Configuring SQL Repositories

Catching Up

If you were unable to complete the exercises from the previous chapter

1. Complete the “Catching Up” section from Chapter 4

2. Copy the properties files in solutions\chapter04 to <ATG9.1dir>\Dynamusic\config\dynamusic.

3. Copy the JSPs in solutions\chapter04 to <ATG9.1dir>\Dynamusic\j2ee-apps\dynamusic-j2ee\dynamusic-web.war.

Exercise 1: Configuring and using SQL Repositories

Exercise Objective

After completing this exercise, you will be able to create and configure a SQL repository.

Problem Statement

In this exercise, you will create an Events Repository which contains venue and concert information. The SQL database tables associated with venues and concerts have already been created in the SOLID database. These tables are currently empty – you will populate them with repository items as part of this exercise.

( 2个数据库表已经在solid数据库中创建了,不过他们的内容当前还是空的,所以我们必须在这个练习中用repository item的项来填充之)

For help with the syntax of the repository definition file, refer to the lecture notes, the DAS reference in the appendix to this course, or the “SQL Repository Reference” chapter in the Repository Guide.

The SQL definitions of the Events (venues and concerts) tables follow:

CREATE TABLE dynamusic_venue (

id VARCHAR(32) not null,

name VARCHAR(100) null,

description LONG VARCHAR null,

street1 VARCHAR(100) null,

street2 VARCHAR(100) null,

state VARCHAR(32) null,

city VARCHAR(50) null,

zip VARCHAR(10) null,

phone VARCHAR(20) null,

image VARCHAR(100) null,

url VARCHAR(100) null,

primary key(id)

);

CREATE TABLE dynamusic_concert (

id VARCHAR(32) not null,

name VARCHAR(100) null,

description LONG VARCHAR null,

venue VARCHAR(32) null

references dynamusic_venue(id),

image VARCHAR(100) null,

event_date TIMESTAMP null,

primary key(id)

);

CREATE TABLE dynamusic_concert_artists (

concert_id VARCHAR(32) not null

references dynamusic_concert(id),

artist_id VARCHAR(32) not null

references dynamusic_artist(id),

primary key(concert_id, artist_id)

);

19-May-11
Guided Instruction
Create the Events Repository

1. Copy the starter file events.xml from <atgdir>/training/DEV1/src/chapter05/ to <ATG9.1Dir>/Dynamusic/config/dynamusic. (This file contains the basic outline of a repository definition file. You will edit it later.)

(是的,这个文件是一个提纲文件,里面基本没有任何实质性的内容)

2. Create a new generic component based on the atg.adapter.gsa.GSARepository class called EventsRepository in the dynamusic folder.

(当基于一个类来创建组件的时候,这个类的类名必须是全限定名)

3. In the EventsRepository component, configure the four standard properties by linking them to the other components and as shown below:

Property
Value

dataSource

/atg/dynamo/service/jdbc/JTDataSource

idGenerator

/atg/dynamo/service/IdGenerator

transactionManager

/atg/dynamo/transaction/TransactionManager

XMLToolsFactory

/atg/dynamo/service/xml/XMLToolsFactory

创建组件的同时必须制定这个组件的repository definition file(这个是最重要的,否则无法读取相应的repository file的内容,所以就会出错了)【【【【【【 这个太重要了,十分容易攻错,我们要切记,切记,不小心就出错了】】】】】】】

4. Configure the definitionFiles property to point to the repository definition file for this repository: /dynamusic/events.xml. (This value will be typed in, not linked, as you are not linking to a component, but specifying a file.(自己给出他的名字,因为这是我们自创的,见第一步,是我们copy过去的)) In the previous step, you copied this file to <ATG9.1dir>/Dynamusic/config/dynamusic/events.xml. When you specify the value for this property, the value entered is the location of this file relative to the CONFIGPATH; because the CONFIGPATH for this module is <ATG9.1dir>/Dynamusic/config, you need only enter /dynamusic/events.xml to refer to the file.

Define the property mappings for the Events Repository

5. Edit the events.xml file you previously copied. The repository will define two repository items, one of type venue and one of type concert, as discussed below.

For details on the syntax of the repository definition file, refer to the slides for this chapter, and to the ATG reference in the Appendix of your course book. If you get stuck, you may also wish to review the definition for the Songs Repository (Dynamusic-base/config/dynamusic/songs.xml).

6. Create the venue item type, including the following properties:

Table: dynamusic_venue

Type: primary

Id Column: id

Property Name
Type
Column Name

id

string

id

name

string

name

description

string

description

street1

string

street1

street2

string

street2

city

string

city

state

string

state

zip

string

zip

phone

string

phone

url

string

url

imageURL

string

image

Use name as the display property for the item descriptor.

7. Test your work using startSQLRepository. Open a cmd prompt window, change directory to <ATG9.1dir>/home, and enter the following command:

bin\startSQLRepository -m Dynamusic -repository /dynamusic/EventsRepository

Resolve any errors before proceeding. (Hint: syntax errors are largely inevitable the first time through; if you got no errors, make sure your repository component is configured correctly to find the definition file; startSQLRepository will not complain if it cannot find a definition file.) [所以我们需要细心]

8. Add the concert item-type to the descriptor file. Unlike the venue item-type, the concert item type will have properties in two tables. The main (primary) table includes all the single-value properties, while the second (multi) table links concert items to a set of artists.

Table: dynamusic_concert

Type: primary

Id Column: id

Property Name
Type
Column Name

id

string

id

name

string

name

description

string

description

imageURL

string

image

venue

venue (item type)

venue

date

timestamp

event_date

Table: dynamusic_concert_artists

Type: multi

Id Column: concert_id

Property Name
Data Type
Component Item type
Column
Repository

artists

set

artist

artist_id

/dynamusic/SongsRepository

Note that the artists property is a set of artist item types, yet the artist item is defined in a separate repository (/dynamusic/SongsRepository). We need to “link” this property to the definition of the artist item, which is defined in the repository descriptor file associated with the SongsRepository.

Use name as the display property for the item descriptor.

9. Test your repository again by running startSQLRepository.

10. In order to manage the Events Repository via the ACC, you need to add it to the list of “initial” repositories defined by the /atg/registry/ContentRepositories component. To modify this component in the ACC, right click on the component and select Open Component (unlike most component, double-clicking will display the “children” of the component as it would with a folder, rather than opening it in the component editor) . Modify /atg/registry/ContentRepositories by adding /dynamusic/EventsRepository to the initialRepositories property.

(一旦把某个我们新创建的repository添加到了ContentRepositoies组件的initialRepositories的属性中,那么这个repository将会出现在ACC控制台的ContentRepository栏目中,你可以看到我们创建的这个EventRepository)

11. Restart ATG.

12. Use the ACC to add several venue and concert items. Select Content > EventsRepository, and the click the new item button. Begin by creating items of type venue, and then create a few concerts for each venue.

Import pre-defined items into the Events Repository

To save you some time, several predefined venue and concert items are provided for you in repository <add-item> xml format. All you have to do is run startSQLRepository to import the pre-defined items.

13. Copy events-data.xml from the <atgdir>\Training\DEV1\src\chapter05\ folder to the <ATG9.1dir>\Dynamusic\config\dynamusic\ folder.

14. From a cmd prompt window, change directory to <A6dir>/home, and enter the following command:

bin\startSQLRepository -m Dynamusic -import ..\Dynamusic\config\dynamusic\events-data.xml -repository /dynamusic/EventsRepository

15. Use the ACC to list venue and concert items. Verify the pre-defined items have been added to the repository.

Display a list of venues

16. Create VenueLookupDroplet and ConcertLookupDroplet components (in the dynamusic folder) based on the atg.repository.servlet.ItemLookupDroplet class, for venue and concert items in the Events Repository, just a you did for artists and albums in the Songs Repository. Be sure to set the repository and itemDescriptor properties correctly. (Review the exercises in Chapter 4 if necessary.)

17. You have been provided with “drill-down” pages for the Events Repository. If your repository is configured correctly as described, and you have created the lookup droplets, these pages should work for you. (venues.jsp, venueDetails.jsp and concertDetails.jsp.) Load the Venues page, select a venue and verify your changes.

18. Optional: create “drill-down” pages for Events Repository from scratch, rather than using the pre-provided ones. The steps will be very similar to those required for setting up the artists.jsp, artistDetails.jsp and albumDetails.jsp pages in the previous chapter.

posted on 2011-05-19 12:58  Eason Jiang  阅读(435)  评论(0编辑  收藏  举报

导航