No Slide Title

Download Report

Transcript No Slide Title

Tallinna Tehnikaülikool
Informaatikainstituut
Javal baseeruv objektide püsivuse kiht Jakamar
Bakalaureusetöö
Üliõpilane:
Matrikli nr:
Juhendaja:
Erki Suurjaak
970772
Tarmo Veskioja
Defence Overview
•
•
•
•
What is object persistence
What solution did I propose
What is Jakamar
Benefits and tradeoffs
What is object persistence
• objects existing beyond application’s
lifetime
Objects
Objects
Objects
Application
Data Store
Concerns using OOP and RDBMS
• handling changes in the data structure
• possible to reuse persistence logic
What solution did I propose
Persistence Broker design pattern
• enables full separation of business and
persistence logic
• easily customizable for different
applications
• offers useful functionality, like object
caching
Architecture
Simple architecture
User
Interface
Classes
Business
classes
Using a Persistence Broker
User
Interface
Classes
Business
classes
Persistence
Broker
Cache
Database
Database
What is Jakamar
• a reusable component
• provides automated persistence
Jakamar in the thesis
•
•
•
•
architecture
program flow
functionality
error handling
•
•
•
•
security
concurrent use
logging
configuration
Benefits
• Easier maintenance
• Less program code to write: access to
persistence via simple operations like
– store(object)
– delete(object)
– retrieve(query criteria)
Benefits (2)
Accessing the database directly
Using Jakamar
Connection connection =
DriverManager.getConnection("jdbc:odbc:emt");
Statement stmt = connection.createStatement();
ResultSet rs =
stmt.executeQuery("SELECT * FROM PERSON WHERE location =
'Jõhvi'");
Collection results = new ArrayList();
while (rs.next()) {
Person person = new Person();
person.id
= rs.getInt("id");
person.firstName = rs.getString("firstName");
person.lastName = rs.getString("lastName");
person.location = rs.getString("location");
results.add(person);
Statement stmtSub = connection.createStatement();
ResultSet rsSub = stmtSub.executeQuery(
"SELECT * FROM PHONE WHERE personId = " + person.id);
while (rsSub.next()) {
Phone phone = new Phone();
phone.id
= rsSub.getInt("id");
phone.personId = rsSub.getInt("personId");
phone.phone
= rsSub.getString("phone");
person.phones.add(phone);
}
stmtSub.close();
}
stmt.close();
connection.close();
PersistenceBroker broker =
PersistenceBrokerFactory.create("conf.xml");
Person param = new Person();
param.location = "Jõhvi";
Query query = broker.createQuery(param,
new String[]{"location"}, null);
Collection results =
broker.retrieveCollection(query);
Tradeoffs
• decrease in functionality
– with embedded SQL,extremely complex
queries accessible as easily as simple
retrieval
– with Jakamar, restrictions on query
complexity
Benchmarks
• better performance on object retrieval
• worse performance on storing objects
Simple retrieval
Repeated?
No
Yes
Simple update
Repeated?
No
Yes
Factor to
Jakamar
1,20
0,81
Factor to
Jakamar
1,03
2,00
Retrieval with related objects
Repeated?
Factor to
Jakamar
No
1,04
Yes
0,17
Insert with related objects
Repeated?
Factor to
Jakamar
No
2,20
Repeated? - whether the same operation was repeated multiple times
Conclusion
• the Persistence Broker pattern is a good
approach
• Jakamar is a viable component
– faster development
– better modularized application structure
– possibly better performance on retrieval
Further development
•
•
•
•
•
•
cursors
transactions
Object Query Language
distributed use
extent classes
graphical configuration interface
Persistent
Persistent
Queries
Objects
Objects
Application
Application
Applications
Persistent
Persistent
Identities
Objects
Objects
Persistent
Persistent
Persistent
Objects
Objects
Objects
Cache
Persistent
Persistent
Persistent
Objects
Objects
Objects
Persistence
Broker
Persistent
Persistent
Persistent
Persistent
Persistent
Persistent
Objects
Objects
Objects
Objects
Objects
Objects
Persistent
Persistent
Persistent
Objects
Objects
Objects
Persistent
Persistent
Persistent
Objects
Objects
Objects
Caches persistent
objects
Looking up cached
instances
Retrieving
Storing and deleting
Persistent
Persistent
Queries
Objects
Objects
Persistent
Persistent
Persistent
Objects
Objects
Objects
Delegating queries
from the application
to lower level
Persistence Mapping
Persistent
Persistent
Field
Objects
Objects
Values
Specifying the field
values of objects to
store or delete
Persistent
Persistent
Field
Objects
Objects
Values
Persistent
Persistent
Field
Objects
Objects
Values
Specifying the
criteria field values
Database-specific
SQL queries
Reflection
Persistent
Persistent
Field
Objects
Objects
Values
Returning the field
values for retrieved
objects
Handles executing
SQL statements
Accesses object
fields dynamically
Persistent
Persistent
Persistent
Objects
Objects
Objects
Deleting storage and
deletion
Contains
mappings between
classes and tables
Persistent
Persistent
Persistent
Objects
Objects
Objects
Persistent
Persistent
Field
Objects
Objects
Values
Query Mechanism
Persistent
Persistent
SELECT
Objects
Objects
Queries
Persistent
Persistent
ACTION
Objects
Objects
Queries
Persistent
Persistent
SELECT
Objects
Objects
Results
Database
Conversion
Persistent
Persistent
Column
Objects
Objects
Values
Converts object
field values to
table column
values and vice
versa
Object relations
Person
id : int
firstName : String
lastName : String
1
location : String
phones : Collection
PERSON
id: int
firstName: varchar
lastName: varchar
location: varchar
n
Phone
id : int
phone : String
PHONE
id: int
personId: int
phone: varchar