Download presentation
Presentation is loading. Please wait.
Published byColin Pierce Modified over 9 years ago
1
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/soen343h-f06.html
2
Outline Data Gateways –GetByLastNameEA Enterprise Applications: –SoenEA framework and samples. Controller patterns –Focus: Page Controller
3
Domain Data Source Table Data Gateway Transaction Script Domain Model Data Mapper Row Data Gateway Front Controller Template View Transform View Page Controller Presentation Active Record Enterprise Application Patterns
4
Domain Data Source Table Data Gateway Transaction Script Domain Model Data Mapper Row Data Gateway Active Record Front Controller Template View Transform View Page Controller Presentation Data Source Patterns
5
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 roles Class …Finder with find(id):Gateway method which returns the ‘object’ Class …Gateway which is the ‘object’ Our PersGradeRDG (next slide) combines
6
Row Data Gateway PersGradeRDG - name : String - grade : int + PersGradeRDG(name, grade) + find(name) : PersGradeRDG + insert() : void + update() : void + delete() : void + … getters and setters …
7
Row Data Gateway: Find Code
8
Row Data Gateway Code sample for Fowler’s PersonRDG Note ‘find’ method is static –it is class method
9
GetByLastName Example Simple web application to Input a student’s last name Fetch database record Output student’s full name
10
GetByLastName Will look at Row Data Gateway PageController Transaction Script
11
Row Data Gateway StudInfoRDG –Represents record in DB of student StudInfoFinder –Finds student record based on lastName –Returns the StudInfoRDG –Locates DB using DBRegistry
12
Outline Enterprise Applications: –SoenEA framework and samples –Simple sample: GetByLastName –Builds on HelloWeb
13
Package structure
14
Domain Data Source Table Data Gateway Transaction Script Domain Model Data Mapper Row Data Gateway Front Controller Template View Transform View Page Controller Presentation Active Record Enterprise Application Patterns
15
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
16
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)
17
GetByLastName Will look at Row Data Gateway PageController Transaction Script
18
Do-it-all Transaction Script A TS that does all the work itself Without a Finder Without a RDG Directly calls DB
19
Do-it-all Servlet or Script, Class public class DoItAll extends javax.servlet.http.HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws... // { … }
20
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( " Hello "+firstName+" "+lastName+" " );
21
Outline Controller patterns –Focus: Page Controller
22
Domain Data Source Table Data Gateway Transaction Script Domain Model Data Mapper Row Data Gateway Active Record Front Controller Template View Transform View Page Controller Presentation Controller Patterns
23
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
24
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
25
Page Controller Fowler 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)
26
Page Controller
27
GetByLastName Will look at Row Data Gateway PageController Transaction Script
28
Page Controller SOEN EA sample: display info about a student –PageController implements doGet() Delegates to transaction script Note: does not follow Fowler’s use of.jsp delegates rather than forwards no explicit helper object (really StudInfoRDG is helper)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.