Upload
colin-pierce
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
SOEN 343Software Design
Section H Fall 2006
Dr Greg Butlerhttp://www.cs.concordia.ca/~gregb/home/soen343h-f06.html
Outline• Data Gateways
– GetByLastNameEA
• Enterprise Applications:– SoenEA framework and samples.
• Controller patterns– Focus: Page Controller
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion
Active Record
Enterprise Application Patterns
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Active Record
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion Data Source Patterns
Row Data Gateway
• An object that acts as a single record in the data source– There is one instance per row
• Fowler RDG combines two rolesClass …Finder with find(id):Gateway method
which returns the ‘object’
Class …Gateway which is the ‘object’
• Our PersGradeRDG (next slide) combines
Row Data Gateway
PersGradeRDG- name : String
- grade : int
+ PersGradeRDG(name, grade)
+ find(name) : PersGradeRDG
+ insert() : void
+ update() : void
+ delete() : void
+ … getters and setters …
Row Data Gateway: Find Code
Row Data Gateway
• Code sample for Fowler’s PersonRDG
• Note ‘find’ method is static– it is class method
GetByLastName Example
Simple web application toInput a student’s last name
Fetch database record
Output student’s full name
GetByLastName
Will look atRow Data Gateway
PageController
Transaction Script
Row Data Gateway
• StudInfoRDG– Represents record in DB of student
• StudInfoFinder– Finds student record based on lastName– Returns the StudInfoRDG– Locates DB using DBRegistry
Outline
• Enterprise Applications:– SoenEA framework and samples
– Simple sample: GetByLastName
– Builds on HelloWeb
Package structure
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion
Active Record
Enterprise Application Patterns
Transaction Script
Fowler: A TS organizes the business logic primarily as a single procedure where each procedure handles a single request from the presentation.
The TS may make calls directly to the DB or through a thin DB wrapper.
Think of a script for:a use case or business transaction.
Implementation can be– shared among subroutines.– Subroutines can be used by more than one script
Transaction Script
• … is essentially a procedure that takes the– input from the presentation,– processes it with validations and calculations,– stores data in the database,– (invokes any operations from other systems, and)– replies with more data to the presentation perhaps
doing more calculation to help organize and format the reply data.
(Fowler)
GetByLastName
Will look atRow Data Gateway
PageController
Transaction Script
Do-it-all Transaction Script
A TS that does all the work itselfWithout a Finder
Without a RDG
Directly calls DB
Do-it-all Servlet or Script, Class
public class DoItAll extends javax.servlet.http.HttpServlet
{protected void doGet(
HttpServletRequest request,HttpServletResponse response)throws ... //
{…}
}
Do-it-all Transaction Script, doGet()
String lastName = request.getParameter(“…"); Connection dbc = DbRegistry.getDbConnection();String findSql = "SELECT * from … where LastName = ?”;PreparedStatement dbQuery = dbc.prepareStatement(findSql);
dbQuery.setString(1, lastName);ResultSet rs = dbQuery.executeQuery();rs.next();String firstName = rs.getString("FirstName");lastName = lastName.toUpperCase();PrintWriter out = response.getWriter();response.setContentType("text/html");out.println("<h1>Hello "+firstName+" "+lastName+"</h1>");
Outline
• Controller patterns– Focus: Page Controller
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Active Record
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion Controller Patterns
Page Controller
Fowler:A Page Controller is an object that handles a
request for a specific page or action on a web site.
There is one input controller for each logical page of the web site.
Page Controller handles the http get and post
Decides which model and view to use
Page Controller
Responsibilities:– Decode the URL, extract any form data, decide action– Create and invoke any model objects
• All relevant data from the html request should be passed to the model, so the model does not need any connection to html request
– Determine which view should display the result page• Forward model information to it
Helper objects can be created/used to perform tasks that are shared
Page ControllerFowler Example:
display info about a recording artist– ActionServlet implements common ‘forward’ task– ArtistController implements doGet()
• Checks artist name is ok• Creates a new ArtistHelper object with Artist as attribute• Adds helper information to html request• Forwards request to Artist.jsp
– Artist.jsp is a TemplateView which gets information to display from helper object (which it gets from request)
Page Controller
GetByLastName
Will look atRow Data Gateway
PageController
Transaction Script
Page ControllerSOEN EA sample:display info about a student
– PageController implements doGet()• Delegates to transaction script
Note:does not follow Fowler’s use of .jspdelegates rather than forwardsno explicit helper object
(really StudInfoRDG is helper)