Click here to load reader

SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler gregb/home/soen343h-f06.html

  • View
    212

  • Download
    0

Embed Size (px)

Text of SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler gregb/home/soen343h-f06.html

  • Slide 1
  • SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/soen343h-f06.html
  • Slide 2
  • Outline Data Gateways GetByLastNameEA Enterprise Applications: SoenEA framework and samples. Controller patterns Focus: Page Controller
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 6
  • Row Data Gateway PersGradeRDG - name : String - grade : int + PersGradeRDG(name, grade) + find(name) : PersGradeRDG + insert() : void + update() : void + delete() : void + getters and setters
  • Slide 7
  • Row Data Gateway: Find Code
  • Slide 8
  • Row Data Gateway Code sample for Fowlers PersonRDG Note find method is static it is class method
  • Slide 9
  • GetByLastName Example Simple web application to Input a students last name Fetch database record Output students full name
  • Slide 10
  • GetByLastName Will look at Row Data Gateway PageController Transaction Script
  • Slide 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
  • Slide 12
  • Outline Enterprise Applications: SoenEA framework and samples Simple sample: GetByLastName Builds on HelloWeb
  • Slide 13
  • Package structure
  • Slide 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
  • Slide 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
  • Slide 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)
  • Slide 17
  • GetByLastName Will look at Row Data Gateway PageController Transaction Script
  • Slide 18
  • Do-it-all Transaction Script A TS that does all the work itself Without a Finder Without a RDG Directly calls DB
  • Slide 19
  • Do-it-all Servlet or Script, Class public class DoItAll extends javax.servlet.http.HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws... // { }
  • Slide 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+" " );
  • Slide 21
  • Outline Controller patterns Focus: Page Controller
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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)
  • Slide 26
  • Page Controller
  • Slide 27
  • GetByLastName Will look at Row Data Gateway PageController Transaction Script
  • Slide 28
  • Page Controller SOEN EA sample: display info about a student PageController implements doGet() Delegates to transaction script Note: does not follow Fowlers use of.jsp delegates rather than forwards no explicit helper object (really StudInfoRDG is helper)

Search related