Enterprise Applications Development & Integration Andrew Stratton Hibernate Case Study.

Slides:



Advertisements
Similar presentations
Using EBSCOs Search Box Builder Tool Tutorial. Would you like to promote your EBSCOhost resources by adding an easy-to-use search box to your website?
Advertisements

JSP and web applications
A Toolbox for Blackboard Tim Roberts
Java Script Session1 INTRODUCTION.
Apache Struts Technology
beas WEB App Installation
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Web MVC-2: Apache Struts Rimon Mikhaiel
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Tutorial: Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Tomcat Configuration A Very, Very, Very Brief Overview.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
JSP and Servlets Lecture notes by Theodoros Anagnostopoulos.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Fresher Technology Specific - JAVA Stream Hibernate Framework
This presentation will guide you though the initial stages of installation, through to producing your first report Click your mouse to advance the presentation.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Sage CRM Developers Course
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
WaveMaker Visual AJAX Studio 4.0 Training Troubleshooting.
Classroom User Training June 29, 2005 Presented by:
Eclipse Overview Introduction to Web Programming Kirkwood Continuing Education Fred McClurg © Copyright 2015, Fred McClurg, All Rights Reserved.
CSE 305 Theory of Database Tutorial on Connecting with Sybase from Java program and Developing GUI Jalal Mahmud, TA, CSE 305.
Creating a Web Site to Gather Data and Conduct Research.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Plug-in Development Environment. Session Outline Tools Installation Configuration New Project Basic Debugging Remote Debugging.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Simple MVC. An example: join.jsp
Chapter 6 Server-side Programming: Java Servlets
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Topic Java EE installation (Eclipse, glassfish, etc.) Eclipse configuration for EE Creating a Java Web Dynamic Project Creating your first servlet.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Sakai code exercises Aaron Zeckoski.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Apache Struts Technology A MVC Framework for Java Web Applications.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Open Software Integrators, LLC 1 Spring Roo - IDE Research ● Basics of Spring Roo (Installation and Roo shell) ● Spring Roo, Maven, Tomcat works! ● Front.
Don't run late! Get Calendar and Schedule up and running 'on-time' in 'no-time'.
Persistence – Iteration 4 Vancouver Bootcamp
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Presentation transcript:

Enterprise Applications Development & Integration Andrew Stratton Hibernate Case Study

Hibernate for Enterprise Java Only a small part of a solution... Often paired with Spring (framework) in Java Example focuses on ASP based presentation, which could alternately be: ● Application (i.e. WinForms) ● XML/SOAP (i.e. Web Service) ● WAP/WML (Mobile service) Tier overview: JSP Browser or App Presentation Business logic Database connection Database UserJava Hibernate

Case Study : Kitchen Worktop offcuts A large DIY retailer wishes to sell offcuts of kitchen worktops. Kitchen worktops typically come in three metre lengths. Most stores offer an in house cutting service, which can leave offcuts that the customer does not need or want. The justification for the system is: To reduce wasted warehouse space To (potentially) allow reductions in costs for customer needing ‘just a couple more feet’ of worktop For green credentials, i.e. to recycle/reduce waste To increase income for the (charged for) cutting service In order to accomplish this, an enterprise system is to be developed for use in house and (later) available externally as a web service

Methodologies and Technologies An Agile like approach is to be used, with sprints and incremental functionality Test Driven Development is to be used, particularly for Web Services JUnit is to be used for unit testing Hibernate is to be used for ORM mapping

Case Study : Phase 1 Detail The first phase is to provide the following solution: A JSP based web site for use in house, that display details of all offcuts available These details to include: Name: This is the short identifier for the type of worktop, e.g. ‘Shiny Light Grey Marble’. Description : this is a free form area that records any extra details. Length : in metric and imperial, typically up to 3m, down to 0.6m Depth and Height : typically 60cm deep (default) and 2.5cm high Contact details : free form, of the store and preferably person or role to speak with

Case Study : Phase 1, Sprint 1 The focus of this sprint is the presentation layer, supported by the minimum required business logic/data objects

Presentation tier Following a ‘front end first’ approach N.B. We are first concentrating on the presentation tier and implementing whatever we need for the JSP to be complete ● Create jsp and html pages to allow you to: 1.enter a name for a worktop in a form 2.submit the form contents to a createWorktop.jsp page oe.g. you could call the page with rble oAn example page is: o oName entered is o 3.Next add fields for Description, Length, Height, Depth 4.check the form submission and display of parameters

Business Logic 1 Next we add some business logic 1.Add a WorktopManager class, e.g. package com.worktops; public class WorktopManager { public void createWorktop(String name, String description, String length, String height, String depth) { System.out.println("Request to create Worktop with" + "\nName=" + name + "\ndescription=" + description + "\nlength=" + length + "mm" + "\nheight=" + height + "mm" + "\ndepth=" + depth + "mm"); }

Business Logic 2 Integrate this with the createWorktop.jsp, e.g. Not much to say... <% worktopManager.createWorktop( request.getParameter("name"), request.getParameter("description"), request.getParameter("length"), request.getParameter("height"), request.getParameter("depth") ); %>

Stop check What have we gained? + Separation of presentation from (business) logic / rules + Business focused functionality (not yet implemented!) - spaghetti? - code dependencies - run time incompatibilities (i.e. loss of compile time checking)

Business Logic Implementation 1 We need to separate out the Worktop POJO (Plain Old Java Object) from the manager - 1.Create Worktop class package com.worktops; import java.io.Serializable; public class Worktop { private String name; } oIn the package explorer - right click name - Source -> Generate getters and setters...OK 2.Add the other properties: odescription, length, height, depth 3.Generate getters and setters (use Ctrl-right click to select multiple properties) Now we have a JavaBean...

Business Logic Implementation 2 Now we update the WorktopManager.createWorktop method, similar to: And the jsp: Run it again and check the output... public void createWorktop(Worktop worktop) { System.out.println("Request to create Worktop with" + "\nName=" + worktop.getName() <% Worktop worktop = new Worktop(); worktop.setName(request.getParameter("name"));... also set the other properties worktopManager.createWorktop(worktop); %>

Stop Check What have we gained? + Separation of data object from (business) logic / rules + Data focused class/objects - more spaghetti? - code dependencies - Java beans do not impose compile time constructor checking

Install Hibernate – at last Download ● Hibernate-3_2min.zip from blackboard ● hsqldb.jar from blackboard (simple database – or use access) Unzip hibernate to directory ● e.g. F:\Hibernate3.2 Copy hsqldb.jar into directory ● e.g. F:\hsqldb Create a new project ‘Worktops’ in Eclipse ● Import all the jars in F:\Hibernate3.2\lib to WEB-INF/lib ● import hsqldb.jar as well (or use access) ● import F:\Hibernate3.2\hibernate3.jar as well ● under build path choose add jar and pick all the lib jars

Worktop class Modify the Worktop class:... import java.io.Serializable; public class Worktop implements Serializable { private Long id; // and add getter/setter... Note: Serializable makes the class able to be sent through a stream, e.g. file, http, ftp, etc., without using RMI. Hibernate uses it for storing ‘persistent’ copies of objects.

Hibernate configuration file This tells hibernate where to look for mapping files - this is a one off creation of file ‘hibernate.cfg.xml’ in the WEB-INF/src directory: <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" " org.hsqldb.jdbcDriver jdbc:hsqldb:data/test sa org.hibernate.dialect.HSQLDialect true org.hibernate.transaction.JDBCTransactionFactory org.hibernate.cache.HashtableCacheProvider update

Adding a mapping file Now we need a worktop.hbm.xml mapping file (in WEB- INF/src/com/worktops directory): <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" " mapping-3.0.dtd"> o

Logger configuration While we’re at it, create the logger configuration file in log4j.properties in the WEB-INF/src directory: log4j.rootCategory=INFO, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-5p - Now update the jsp... Trying... <% boolean success = false; try{ Worktop worktop = new Worktop();... success = true; } catch (Exception e) { e.printStackTrace(); } if (success) { %> It worked!!! <% } else {%> Some problems....

Updating Business Logic The hibernate code needs to be added. Amend the WorktopManager: Now run it - and look in the console in eclipse for logging information: Hibernate: select max(id) from worktops Hibernate: insert into worktops (name, description, length, height, depth, id) values (?, ?, ?, ?, ?, ?)... import org.hibernate.*; import org.hibernate.cfg.Configuration;... public void createWorktop(Worktop worktop) { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); session.save(worktop); session.flush(); session.close(); System.out.println("Created Worktop with" +...

Checking the database contents Now amend createWorktop.jsp: and WorktopManager: It worked :- <% java.util.List worktops = worktopManager.listWorktops(); for (int i = 0; i<worktops.size(); i++) { Worktop theWorktop = (Worktop) worktops.get(i); %> Worktop, Description: <% } } else {%> private List listWorktops() { List result = null; SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); result = session.createQuery("from Worktop").list(); session.flush(); session.close(); return result; }

Tutorial exercises During the tutorial, follow the above example first, then: 1. Add (if you haven’t already) a form to enter new worktop details. N.B. The database is emptied EVERY time tomcat restarts (change to access if you wish to keep data). 2. Add a separate page (e.g. listWorktops.jsp) to display a list of worktops names only. 3. Add the ability to read a worktop - so when a user clicks on an entry in the list, the detail is shown. Hint - use (Worktop) session.get(Worktop.class, id); 4. Add a form to update a worktop’s details by reading into a form, then updating the details. hint - use session.merge(worktop) 5. Add the ability to delete a worktop entry - preferably with confirmation (use javascript); try session.delete(worktop);

Where’s the benefit? Consider: ● How much Sql did you need to write? ● Where do we need to change if (say) we only ‘mark’ worktops for deletion? (i.e. have a deleted flag) ● What if we change the html? ● What if we change the database contents? ● What if we change database implementation (e.g. to Access)?