CS636 Class 13 Intro to tomcat, JPA
Last time: HTTP, Chap. 18 in Murach
HTTP request has verb: GET or POST (some others too)
Syntax of request first line: GET path HTTP/1.1
or POST path HTTP/1.1
After this: request headers, then a blank line to tie them off
After this, for POST only: the POST "body", the data being sent to the server
The data is typed by the Content-type request header
Response first line: status code and string
After this: response headers, then a blank line to tie them off
After this: response body, the data being sent from the server to answer the request (may be trivial for POST)
The data is typed by the Content-type response header
HTTP is stateless
Servlets are key to handling user input and dynamic HTML in a web app.
URL accessing my tomcat installation: http://topcat.cs.umb.edu:11600/cs636/index.html
local path = /cs636/index.html on this tomcat installation
This file in the filesystem: /home/eoneil/cs636/tomcat-6.0/webapps/cs636/index.html
Root of my tomcat’s website files: /home/eoneil/cs636/tomcat-6.0/webapps
Here GET command is GET /cs636/index.html HTTP/1.1, done after TCP connection to topcat.cs.umb.edu on port 11600.
Tomcat interprets the local path: web app name "cs636", file index.html within it.
Since it's HTML, tomcat just reads it and sends it back on the same TCP connection. (static web server behavior)
Object/Relational Mapping idea: take advantage of the similarities in data model and object model and automate the conversion of database data to/from objects.
Hibernate project evolved into JPA1, then JPA2 standards, part of JEE, close to EJBs but separable. Your JPA2 knowledge can be used for Hibernate projects, and EJBs.
Although JPA2 is considered part of JEE, not JSE, it does not depend on anything else in JEE, so can be used as an extension of JSE, as we will do for pizza2 and music2, the JPA versions of the projects.
JPA2, released in late ’09, is widely used already and supported by Hibernate ORM and Eclipselink, among other “providers”, i.e., implementations.
Mappings specified by annotations in domain classes or XML files—we’ll use annotations, the programmer’s favorite method.« persistent object » - standard terminology, but possibly misleading
The domain objects are tied to persistent row(s) in DB
Java object identity: its ref’s value, the address of object in memory
but this changes from one scratch copy to another
Persistent identity: PK val of row of entity table in DB: Typically a field in the object.
Example: id column value of pizza_orders table row, becomes the value in id field of the corresponding PizzaOrder object
Worry: We could end up with 2 Java objects with the same persistent id, apply change to one of them, get mixed up.
One thing the JPA runtime does is make sure there’s only one, by tracking each one it knows about.
Changes in a Java object can happen anytime via method calls by program
vs. Change in the persistence(row) via transactions
These changes are not perfectly synchronized, so we end up with Java objects being “quasi-transactional”, not usually a problem in our case of short transactions related to individual service methods.
We have to tell JPA about a domain object before it can help us with persistence
Look at Chap. 13 slides.