Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 CCSC 2006

2 2 Our 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

3 3 Overview 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

4 4 The Online Grade Book Sample Student ID: p001111

5 5 The Online Grade Book The teacher’s interface

6 6 The 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

7 7 Structure of the Online Grade Book Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

8 8 Object-oriented database Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

9 9 Objects are stored and retrieved by Data Access Objects Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

10 10 Person and Weight objects are returned by the DAOs Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

11 11 Services provided by the business tier Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

12 12 Model-View-Controller web tier architecture Controller > Login View ObjectStore Database The Data Access Objects contain most of the ObjectStore code. Model > GradeBookController > 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 from the Transfer Object DAOs return transient Transfer Objects TCP/IP Forwards the Request Person Gets DAO objects > 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. Weight Person

13 13 ObjectStore  The OO database management system Progress Software Corporation Educational license available  Functionality Persistence-capable classes Class file postprocessor ObjectStore Session Root objects Transactions and retrieving objects Object queries

14 14 Persistence 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

15 15 Class 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 line osjcfp –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

16 16 Opening 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

17 17 Opening 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

18 18 Closing 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 can be called to close the database and terminate the session PersonDAO.java All ObjectStore operations must be in a session

19 19 Root 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

20 20 Transactions 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

21 21 Retrieving 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

22 22 Retrieving 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()

23 23 Hollow 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

24 24 Transient 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

25 25 ObjectStore 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

26 26 Conclusion  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

27 27 Thank You Any questions?

28 28 References Alur, D., Crupi, J., Malks, D., Core J2EE Patterns: Best Practices and Design Strategies, 2nd edition. Upper Saddle River, NJ: Prentice Hall PTR, Bloor Research, ObjectStore from Progress Software, Hall, M., Core Servlets and JavaServer Pages. Upper Saddle River, NJ: Prentice Hall PTR, Lamb, C., Landis, G., Orenstein, J., Weinreb, D., The ObjectStore Database System, Communications of the ACM, 34(10), 50–63, 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, Progress Software Corporation, ObjectStore Java Interface Release 6.1 Bookshelf,


Download ppt "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."

Similar presentations


Ads by Google