You are on page 1of 17

Ni dung trnh by

JDBC

Hibernate

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC Simple 2 Layer


POJO: DanhMuc

maDanhMuc, tenDanhMuc
POJO: Sach maSach, tenSach, ...

maDanhMuc

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC Simple 2 Layer


DanhMucDAO, SachDAO

ArrayList<DanhMuc> layDanhSachDanhMuc()
SELECT * FROM DANHMUC rs.getString(maDanhMuc)
500 BNG?

rs.getString(tenDanhMuc)
ArrayList<Sach> layDanhSachSach() SELECT * FROM SACH
200 CT?

rs.getString(maSach), ...
rs.getString(maDanhMuc)
5

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC Simple 2 Layer


DanhMucDAO, SachDAO

themDanhMuc(DanhMuc dm)
INSERT INTO DANHMUC VALUES (?, ?) sm.setString(1, dm.getMaDanhMuc()); sm.setString(2, dm.getTenDanhMuc());
500 BNG?

themSach (Sach s)
INSERT INTO SACH VALUES (?,?,?,?) sm.setString(1, dm.getMaSach());
200 CT?

. . .
sm.setString(n, dm.getMaDanhMuc());
6

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC Simple 2 Layer


DanhMucDAO

xoaDanhMuc
capNhatDanhMuc layDanhMuc
500 BNG?

SachDAO
xoaSach capNhatSach
200 CT?

laySach
timKiemSach
7

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC Simple 2 Layer


POJO: DanhMuc

maDanhMuc, tenDanhMuc
POJO: Sach maSach, tenSach, ...

maDanhMuc
Cn hin th thng tin sch cng vi tn danh mc Xy dng phn mm hng i tng Mi quan h gia sch v danh mc?
8

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC 2 Layer
POJO: DanhMuc

maDanhMuc, tenDanhMuc
ArrayList<Sach> saches POJO: Sach

500 BNG?

maSach, tenSach, ... DanhMuc danhMuc

200 CT?

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

JDBC
Tn nhiu thi gian vit v kim th cho cc cu lnh sql select, Insert, Update, Delete cho mi bng d liu c bit nu ng dng c kh nng kt ni vi nhiu h qun tr khc nhau, cu truy vn trong mi h qun tr c th c c php khc

10

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

ORM
1000 Bng d liu

Thc hin nhanh nht c th cc thao tc thm, xa, cp nht, ly thng tin
ng dng tng tc vi nhiu h qun tr nh mysql, oracle, db2, sql server, . . . Qu trnh chuyn i nhanh thng qua cu hnh

11

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

ORM Framework
Hibernate 4

EJB 3
...

12

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

Hibernate
c pht trin bi Gavin King nm 2001

JBoss chnh thc pht trin


Hibernate t nm 2003 Cng ng pht trin ln v

c s dng rng ri.

13

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

Hibernate
Java Code
POJOs

Mappings

Hibernate

Configuaration

JDBC

DATABASE

14

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

Hibernate
Hibernate O/R Mapping

1-1, 1-n, n-1, n-n


Component, Inheritance Hibernate Transaction & Concurrency

Hibernate Query
HQL, Criteria Query, Native SQL Hibernate Cache, Filter, Interceptor, Event

Hibernate Monitor
Hibernate Toolset
15

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

Ti liu tham kho


Nguyn Hong Anh, Tp bi ging mn chuyn Java, 2011

16

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012

HI V P

17

Nguyn Hong Anh nhanh@fit.hcmus.edu.vn H KHTN - 2012