using an object-oriented database to support a web application built with java technologies charles...

28
Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006 CCSC 2006 CCSC 2006

Upload: braiden-ingerson

Post on 01-Apr-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

Using an Object-Oriented Databaseto Support a Web ApplicationBuilt with Java Technologies

Using an Object-Oriented Databaseto Support a Web ApplicationBuilt with Java Technologies

Charles R. Moen, M.S.Morris M. Liaw, Ph.D.

April 21, 2006

CCSC 2006CCSC 2006

Page 2: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

2

Our MotivationOur Motivation

Why use an object-oriented database (OODB) to support a Java web application?

An OODB is the natural way to store OO data

• Because data objects can be saved without having to translate them to records in a table

Speed and efficiency

• Because stored data objects can be loaded without translation—no joins are required

Page 3: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

3

OverviewOverview

1. The web application from the user’s point of view

• The Online Grade Book pages• A quick demo

2. The data

3. The structure of the Online Grade Book

4. The functionality of the OO database management software, ObjectStore

Page 4: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

4

The Online Grade BookThe Online Grade Book

http://oodb-8.cl.uh.edu:8080/OSJIGradeBook/CheckGrades

Sample Student ID: p001111

Page 5: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

5

The Online Grade BookThe Online Grade Book

The teacher’s interface

Page 6: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

6

The DataThe Data

Person

- userID : int- password : String- fName : String- mName : String- lName : String- midtermExam : double- finalExam : double- presentation : double- groupProject : double- individualProject : double- courseScore : double- courseGrade : String- courseID : String- admin : boolean

Weight

- midtermWt : double- finalWt : double- presentationWt : double- groupProjectWt : double- individualProjectWt : double- courseID : String

Page 7: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

7

Structure ofthe Online Grade Book

Structure ofthe Online Grade Book

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 8: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

8

Object-orienteddatabase

Object-orienteddatabase

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 9: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

9

Objects are stored and retrieved by Data Access Objects

Objects are stored and retrieved by Data Access Objects

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 10: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

10

Person and Weight objectsare returned by the DAOs

Person and Weight objectsare returned by the DAOs

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 11: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

11

Services provided by the business tier

Services provided by the business tier

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 12: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

12

Model-View-Controllerweb tier architecture

Model-View-Controllerweb tier architecture

Controller

<<JSP>>Login

ViewObjectStoreDatabase

The Data Access Objects contain most of the ObjectStore code.

Model

<<Servlet>>GradeBookController

<<JSP>>StudentGradeReport

GradeBookDAOFactory- properties : Properties

+ getPersonDAO() : PersonDAO+ getWeightDAO() : WeightDAO

PersonDAO

+ PersonDAO( URL : String )+ findPerson( pw : String ) : Person+ insertPerson( p : Person, w : Weight )+ deletePerson( pw : String )+ updatePerson( delta : Person,

p : Person, w : Weight )+ selectAllPersonsNotAdmin() : TreeSet+ shutdown()

WeightDAO

+ WeightDAO( URL : String )+ findWeight( cid : String ) : Weight+ insertWeight( w : Weight )+ deleteWeight( cid : String )+ updateWeight( delta : Weight, w : Weight )+ selectAllWeights() : TreeSet+ shutdown()

Creates DAO objects

Accesses the database

Accesses the database

The remote implementation of the business services that are available in the Grade Book application

The client-side representation of the business services that are available in the Grade Book application

Business tierWeb tier

HTTP Request

HTTP Response

Adds the Transfer Object to the Session

Gets data fromthe Transfer Object

DAOs return transient

Transfer Objects

TCP/IPForwards

the Request

Person

Gets DAOobjects

<<interface>>GradeBook

+ validateStudent( pw : String ) : Person+ validateAdmin( id : Vector ) : TreeSet+ addStudent( p : Person ) : TreeSet+ removeStudent( pw : String ) : TreeSet+ editStudent( p : Person ) : TreeSet+ getAllWeights() : HashMap+ editWeights( w : Weight ) : TreeSet

GradeBookDelegate GradeBookService

- personDAO : PersonDAO- weightDAO : WeightDAO

Uses a WeightDAO object to calculate a student’s course score

Calls the business services of the Grade Book and gets the Transfer Object

The GradeBookService object defines the ObjectStore transactions.

WeightPerson

Page 13: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

13

ObjectStoreObjectStore

The OO database management system• Progress Software Corporation

http://www.progress.com/ http://www.objectstore.com/datasheet/index.ssp

• Educational license available

Functionality• Persistence-capable classes• Class file postprocessor• ObjectStore Session• Root objects• Transactions and retrieving objects• Object queries

Page 14: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

14

Persistence Capable ClassesPersistence Capable Classes

Classes that can instantiate objects to be stored in ObjectStore

Ordinary Java classes with an extra import statement

import com.odi.*;

Before objects of these classes can be stored, the classes must be made persistence-capable by the class file postprocessor

Page 15: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

15

Class File PostprocessorClass File Postprocessor

Ordinary Java classes must be made persistence-capable before their objects can be stored with ObjectStore

1. Compile the classes with javac

2. Run the class file postprocessor on the command lineosjcfp –dest ..\classes Person.class

– Also runs on a batch of Java class files

– Makes annotations in the class files

3. Instantiate persistent objects with these annotated class files

Page 16: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

16

Opening the OODBOpening the OODB

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons; private void initialize( String dbName ){ session = Session.getCurrent(); if( session == null ){ session = Session.create(null, null); } session.join(); try{ db = Database.open( dbName, ObjectStore.UPDATE ); }catch( DatabaseNotFoundException e ){ db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); }

To use an ObjectStore database:

• Get or create an ObjectStore session

• Join the session

PersonDAO.java

All ObjectStore operations must be in a session

Page 17: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

17

Opening the OODBOpening the OODB

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons; private void initialize( String dbName ){ session = Session.getCurrent(); if( session == null ){ session = Session.create(null, null); } session.join(); try{ db = Database.open( dbName, ObjectStore.UPDATE ); }catch( DatabaseNotFoundException e ){ db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); }

After the session is joined, the database can be opened

PersonDAO.java

All ObjectStore operations must be in a session

Page 18: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

18

Closing the OODBClosing the OODB

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons;

//...

public void shutdown(){ db.close(); objectStoreSession.terminate(); }

The shutdown method canbe called to close the database and terminatethe session

PersonDAO.java

All ObjectStore operations must be in a session

Page 19: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

19

Root ObjectsRoot Objects

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons; private void initialize( String dbName ){ session = Session.getCurrent(); if( session == null ){ session = Session.create(null, null); } session.join(); try{ db = Database.open( dbName, ObjectStore.UPDATE ); }catch( DatabaseNotFoundException e ){ db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); }

Root

• A persistent object stored in the database

• Has a unique name

• Handle that’s used to store or retrieve any persistent object

• Usually it’s a collection object that can be used to store many similar persistent objects – analogous to how a table stores records

PersonDAO.java

All stored objects must have a root

Page 20: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

20

TransactionsTransactions

A root must be created or retrieved inside a transaction

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons; private void initialize( String dbName ){

//join the session and open the database

Transaction tr = Transaction.begin( ObjectStore.UPDATE ); try{ allPersons = (OSHashMap)db.getRoot("allPersons"); }catch( DatabaseRootNotFoundException e ){ db.createRoot("allPersons", allPersons = new OSHashMap()); } tr.commit(ObjectStore.RETAIN_READONLY); }

Get the root from the database

PersonDAO.java

First, the session is joined, and the database is opened(previous slide)

Begin a transaction

Commit the transaction

Page 21: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

21

Retrieving an ObjectRetrieving an Object

Objects can be retrieved, inserted, deleted or updated inside a transaction

public class GradeBookService implements GradeBook{ private static Session session; private PersonDAO personDAO; private WeightDAO weightDAO; public Person validateStudent(String studentID){ Transaction tr = Transaction.begin(ObjectStore.READONLY); Person student = null; try{ student = personDAO.findPerson( studentID ); }catch( DatabaseException dbe ){ tr.abort(ObjectStore.RETAIN_TRANSIENT); System.out.println( dbe.getMessage() ); return null; } tr.commit(ObjectStore.RETAIN_TRANSIENT); return student; } //...

Begin a transaction

GradeBookService.java

Almost all transactions are in the GradeBookService class

DAO objects access the OODB

Commit the transaction

Call the DAO method

Page 22: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

22

Retrieving an ObjectRetrieving an Object

DAO objects retrieve data, insert it, delete it, or update it

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons;

//...

public Person findPerson( String password ) throws DatabaseException { Person person = null; person = (Person)allPersons.get( password ); if( person == null ){ throw new DatabaseException("Can’t find"); } ObjectStore.fetch(person); return person; }

Looks for a Person object in the root that has a key value matching the studentID

PersonDAO.java

The studentID passed from validateStudent()

Page 23: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

23

Hollow ObjectsHollow Objects

Two copies of an object exist when it’s retrieved from the OODB

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons;

//...

public Person findPerson( String password ) throws DatabaseException { Person person = null; person = (Person)allPersons.get( password ); if( person == null ){ throw new DatabaseException("Can’t find"); } ObjectStore.fetch(person); return person; }

Second copy in memory:

• Initially in a “hollow” state

• All data is null

• As long as this object is used within transaction boundaries, its data will be fetched automatically

• Connected with the disk copy

PersonDAO.java

One copy is on the disk

The fetch() method can be called to explicitly fill all the data fields

Page 24: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

24

Transient ObjectsTransient Objects

A persistent object must be made transient before it can be used outside a transaction

public class GradeBookService implements GradeBook{ private static Session session; private PersonDAO personDAO; private WeightDAO weightDAO; public Person validateStudent(String studentID){ Transaction tr = Transaction.begin(ObjectStore.READONLY); Person student = null; try{ student = personDAO.findPerson( studentID ); }catch( DatabaseException dbe ){ tr.abort(ObjectStore.RETAIN_TRANSIENT); System.out.println( dbe.getMessage() ); return null; } tr.commit(ObjectStore.RETAIN_TRANSIENT); return student; }GradeBookService.java

Active persistent objects are always connected to a matching copy inside the OODB, but transient objects have no such connection.

Conversion from active state to transient state is made by committing in RETAIN_TRANSIENT mode

Page 25: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

25

ObjectStore QueriesObjectStore Queries

ObjectStore provides a means to query Java Collection objects

public class PersonDAO{ private static Session session; private static Database db; private OSHashMap allPersons; //... public TreeSet selectAllPersonsNotAdmin() { Collection allPersonsValues = allPersons.values(); Query query = new Query(Person.class, "!isAdmin()"); Iterator it = query.iterator(allPersonsValues); CompareUserIDs comp = new CompareUserIDs(); TreeSet persons = new TreeSet(comp); while( it.hasNext() ) { persons.add( (Person)it.next() ); } return persons; }PersonDAO.java

Run the query by calling its iterator method with a Collection object argument

First, get a collection of all objects stored in the root

Instantiate a Query object

• First arg is the class of objects to work with

• Second arg is an expression that returns a boolean

Page 26: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

26

ConclusionConclusion

It’s easy to use an object-oriented database to support a web application built with Java technologies

• Ordinary Java classes• Root objects are analogous to relational database tables• Session and transaction management is straightforward• Queries

There are good reasons to use an OODB to store Java objects

• Natural way to store OO data• Speed and efficiency

Page 27: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

27

Thank YouThank You

Any questions?

Page 28: Using an Object-Oriented Database to Support a Web Application Built with Java Technologies Charles R. Moen, M.S. Morris M. Liaw, Ph.D. April 21, 2006

28

ReferencesReferences

Alur, D., Crupi, J., Malks, D., Core J2EE Patterns: Best Practices and Design Strategies, 2nd edition. Upper Saddle River, NJ: Prentice Hall PTR, 2003.

Bloor Research, ObjectStore from Progress Software, http://www.objectstore.com/docs/analyst/bloor_0105_objsov.pdf, 2005.

Hall, M., Core Servlets and JavaServer Pages. Upper Saddle River, NJ: Prentice Hall PTR, 2000.

Lamb, C., Landis, G., Orenstein, J., Weinreb, D., The ObjectStore Database System, Communications of the ACM, 34(10), 50–63, 1991.

Moen, C., Liaw, M., “The Online Grade Book—A Case Study in Learning About Object-Oriented Database Technology,” ACET Journal of Computer Education and Research, Summer, 2004.

Progress Software Corporation, ObjectStore Java Interface Release 6.1 Bookshelf, http://www.objectstore.net/documentation, 2003.