Introduction to ORM

21
1

description

Introduction to ORM

Transcript of Introduction to ORM

Page 1: Introduction to ORM

1

Page 2: Introduction to ORM

2

Page 3: Introduction to ORM

3

Page 4: Introduction to ORM

4

Page 5: Introduction to ORM

5

Page 6: Introduction to ORM

6

Page 7: Introduction to ORM

7

Page 8: Introduction to ORM

Objects present in Thread A and Thread B refer to a same row in RDBMS, but from java perspective they are not identical.

8

Page 9: Introduction to ORM

A class should be of the right granularity, it shouldn’t be too big or too tiny.

Classes should be specialists. They should do the kinds of behaviors that a thing of that type should do, and no more.

For example, suppose you have a Kitchen class that does all sorts of Kitchen things.

Like Oven things and Refrigerator things, etc. So now you’ve got Kitchen things (Kitchen being a room) and Refrigerator things and Oven things all in the same class. That’s three different things.

So rather than having the Kitchen class include all the code for Refrigerator and Oven behaviors, have the Kitchen class use a Refrigerator and Oven in a HAS-A relationship.

This keeps all three classes simple, and reusable.

9

Page 10: Introduction to ORM

User-Defined-types (UDT) is an object-relational extensions. The SQL standard supports user-defined datatypes, but poorly.

Use of UDTs or Java types inside an SQL database isn’t common practice in the industry at this time.

Oracle definition for UDT: A UDT is a serializable Java class whose instances are stored in columns. The class must implement the java.io.Serializable interface.

10

Page 11: Introduction to ORM

To make bi-directional declare a reference of Customer in class Address as shown:

public class Address {

…..

private Customer customer;

….

}

11

Page 12: Introduction to ORM

Database supports mapping the entire hierarchy to a single table or each class to its own table or each concrete class to its own table.

This concept is explained in detail in Hibernate and Inheritance.

12

Page 13: Introduction to ORM

13

Page 14: Introduction to ORM

14

Page 15: Introduction to ORM

The common metadata will be in the form of XML/annotations.

POJO: Plain Old Java Object. A simple java bean.

15

Page 16: Introduction to ORM

Dirty checking:

Lazy association:

Cache:

16

Page 17: Introduction to ORM

17

Page 18: Introduction to ORM

ASF: Apache Software Foundation.

18

Page 19: Introduction to ORM

19

Page 20: Introduction to ORM

20

Page 21: Introduction to ORM

21