Presentation is loading. Please wait.

Presentation is loading. Please wait.

An XML Based JDBC Connector Servlet Framework By Narasimhan Rengaswamy.

Similar presentations


Presentation on theme: "An XML Based JDBC Connector Servlet Framework By Narasimhan Rengaswamy."— Presentation transcript:

1 An XML Based JDBC Connector Servlet Framework By Narasimhan Rengaswamy

2 What is a JDBC Connector Servlet(JCS)? A Java servlet that provides an XML based scripting interface to JDBC data sources Allows JSP and servlet developers to achieve a separation between server side presentation logic and their data access(SQL) logic

3 Brief Idea about JDBC An API used to write database clients(from applets to servlets, EJBs), connect to a relational database, execute SQL statements and process the results extracted Database connectivity is not just connecting to database and executing statements but also optimizing network resources using connection pooling and distributed transactions(e.g.WebLogic Enterprise CORBA Java and WebLogic Enterprise EJB applications)

4 Servlet A Java servlet contains the application code that executes on the server in response to an event. A servlet receives events from the web application page, performs the appropriate actions, and then subsequently outputs data dynamically to the application's presentation layout model by invoking a Java Server Page (JSP)

5 Servlets(Contd.) Are Http request handlers which provide full access to Java APIs and endow web programmers with a powerful tool for creating dynamic Web pages A servlet is a Java component that can be plugged into a Java-enabled web server to provide custom services

6 A little about XML XML, the Extensible Markup Language, is the universal syntax for describing and structuring data, independent from application logic. XML is a method for putting structured data in a text file

7 Case Study Two Sections 1. Implementing the JDBC Connector Servlet 2. Using the JDBC Connector Servlet

8 Implementing the JDBC Connector Servlet Determine Framework’s Functional Requirements Design a High Level Architecture Design the tool’s scripting Framework Design and develop the Java classes that implement the scripting framework Design and develop other artifacts to deploy framework to J2EE containers

9 (Contd…) Package the framework’s binaries for deployment to servlet engines and application servers that support J2EE Deploy JCS to a J2EE web container

10 Framework’s Functional Requirements JCS should provide mechanism to Query a Database and return the result back to the browser.The output can be a XML document. Allow to view in a WAP device in a WML format JCS must be able to execute INSERT,UPDATE and DELETE statements

11 (Contd…) Must allow HTML form,CGI and custom variables in JCS query files Allow HTTP GET or POST between the HTML form and a JCS Query Support SSI(Server Side Includes) e.g. Library files

12 (Contd…) Must accommodate default content to send to the browser e.g. if the select statements does not return the result Support Exception and redirecting of pages when error occurs Should allow JCS queries within JSP applications by providing a bean interface and custom tag Must provide tags to generate unique Ids (e.g. primary key)

13 The JCS Architecture HTTP Appropriate Connector Web Clients Web Server(Apache,IIS) Servlet Engine(Tomcat, various J2EE App Servers) JDBC Connector Servlet jcs Engine JSP Custom Tag Java Server Pages Relational Databases

14 (Contd…) Step 1: Remote Browser requests URL for the XML based queries. Step 2: Servlet Engine dispatch it to JDBC Connector Servlet Step 3: JDBC Connector Servlet Instantiates JCS engine and parse the query and get back the result

15 JCS Scripting Framework JCS provides a scripting framework to write web-based JDBC queries JDBC queries are XML documents with special tags containing database connection parameters, SQL code and output Design of this XML schema is done by first creating a jcs namespace

16 Snapshot of a JCS Query

17 (contd…) SELECT * FROM guestbook WHERE ID = “#FORM.id#”

18 (Contd…)

19 JCS Query Tags Database connectivity parameter tags The SQL tag Output definition tags Special function tags Template-specific tags

20 Database Connectivity Tags Contains parameters to connect to what database, which JDBC driver to use and support authentication Tag names jcs:jdbc_driver jcs:jdbc_url jcs:jdbc_uid jcs:jdbc_pwd

21 The SQL Tag Contains tag

22 Output Definition Tags Jcs:mime_type Jcs:redirect_url Jcs:template Jcs:empty_resultset_output Jcs:error_page Jcs:maxrows

23 Special function tags Jcs:encode_sql Doubles up single quote characters to replace them with two consecutive single quote characters Jcs:line_break_character to handle carriage return and line feed characters in data retrieved from database(currently supports HTML only but future enhancement would be an XHTML)

24 Template specific tags loops through the rows of data returned from the query creates a server-side include reference within a JCS output template

25 Variable Types JCS supports variable types to access dynamic data.Variable names are case sensitive Form Variables Resultset Field Variables CGI Variables System Variables Custom Variables Variables take the form #form.variablename#

26 Form Variables Variables passed by client to the server via HTTP GET and POST method Sample JCS query form handler named guestbook_add.jcs jdbc:odbc:guestbook INSERT INTO guestbook (“ID”, “fname”, “lname”, “comments”, “host”, “date”) VALUES (‘#SYSTEM.UID#’,’#form.fname#’, ’#form.lname#’, ’#form.lname#’, ’#form.comments#’,’CGI.REMOTE_ADDR#’,NOW())

27 Resultset Field Variables It takes the form #fieldname# Used in output templates to reference values of a given record’s fields Sample code templates\header.inc #fname# #lname#’s Guestbook Entry Comments: #comments# Date entered: #date# Originating Host: #host# Delete this entry templates\footer.inc

28 CGI Variables Uses form variables in #cgi.variablename# format Variable names #CGI.REMOTE_ADDR# #CGI.SERVER_PROTOCOL# #CGI.QUERY_STRING# #CGI.REMOTE_USER# #CGI.SERVER_NAME# #CGI.SERVER_PORT# #CGI.REMOTE_HOST#

29 System Variables # system.date# Servers current date #system.UID# Generates a unique id

30 Java Classes that implement JCS Grouped into three Classes providing functionality to reuse in other applications 1) FunctionLib class from com.jresources.util package 2) XMLSerializableResultset class from com.jresources.jdbc package

31 Core JCS functionality classes jcsRuntimeException class jcsQuery class jcsTemplateParser class jcsEngine class from com.jresources.jcs package

32 Classes providing server-side presentation services jcsCustomTag class jcsCustomTagOutput class JDBCConnectorServlet class

33 Functionality of FunctionLib class Unique Id generation XML parsing and file I/O Methods used are generateUID() OpenFile() getCDATASection() to parse jcs:template and jcs:empty_resultset_output tags HTMLLineBreak() replaces a carriage return character with an HTML tag

34 XMLSerializableResultSet class Serializes a JDBC resultset as a XML document Method used is getXML()

35 Core JCS functionality classes jcsRuntimeException class Method: jcsRuntimeException()

36 (Contd…) jcsQuery class How it works: 1)Constants DEFAULT_JDBC_DRIVER (set to ODBC-JDBC bridge) and DEFAULT_MIME_TYPE (set to text/html) are declared 2)Instantiate the class using default constructor setJCSQueryContent() to parse the JCS query and initialize the instance variables CODE: package com.jresources.jcs; import com.resources.util.FunctionLib; public class jcsQuery { //constants public static final String DEFAULT_JDBC_DRIVER = “sun.jdbc.odbc.JdbcOdbcDriver” ; public static final String DEFAULT_MIME_TYPE = “ text/html ” ;

37 (Contd…) //the JCS Query raw XML private String jcsQueryContent; //”Read-only” instance variables private String strMIMEType = this.DEFAULT_MIME_TYPE; private String JDBCDriver = this.DEFAULT_JDBC_DRIVER; private String JDBCURL; private String UID; private String PWD; private String SQL; private String qrydoc; private String templateDoc; private String redirectURL; private String errorPage; private String emptyResultsetOutput; private int maxRows = -1 ; private boolean htmlLineBreakFlag = false;

38 jcsTemplateParser Class Has two constructors parseTemplate() setFilename() setTagname() setTemplate()

39 Class JCSEngine Uses processRequest() processSSI() executeUpdate() executeQuery()

40 Class jcsCustomTag Provides functionality for custom JSP tag Allows pages written in JSP 1.1. to execute JCS queries Tag has two attributes url outputvariable

41 Class jcsCustomTagOutput Provides an interface to the host JSP page to access the contents of output variable Method: getVariableInfo()


Download ppt "An XML Based JDBC Connector Servlet Framework By Narasimhan Rengaswamy."

Similar presentations


Ads by Google