
Advanced Issues in Object-Oriented Database Development
Explore advanced topics in object-oriented database development such as unique internal object IDs, weak references, ID scenarios, common problems with IDs, and the use of unique universal IDs (UUIDs) for better object management.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CSCI 5433- Object Oriented Database Development Chapter 12: Advanced Issues Manasa Katuru Presentation id# 16 [Pages (309 to 319)]
Topics IDs UUIDs INDEXING CALL BACKS
IDs Any object stored , gets an unique internal object ID, which looks like a key that is within the entire db40 database. Object ID s that have been written to DB are cached by the Object Container and are known as weak references. Weak references mechanism also ensures that every object is instantiated only once when an entire object graph is retrieved from the database.
ID Scenario Client 1 retrieves an object o1 from the db4o server, and has to send this object to client 2 via Java Remote Method Invocation (RMI) or some similar mechanism. Client 2 receives this object, but now this object is not connected to any ObjectContainer. Therefore it has no weakreferences in any container cache. Now client 2 somehow needs the ID of the object if the user wants to change.
Client 1 can obtain the ID of the object by calling long anID= db1.Ext( ).GetID(object); // C# long anID= db1.ext( ).getID(object); // JAVA Here, db1 is client 1 s Object Container reference. Client 1 passes the ID to client 2. Client 2 can then bind its copy of the object to the stored object. db2.Ext( ).Bind(o1,anID); // C# db2.ext( ).bind(o1,anID); // JAVA For example, client 1 might do better by just sending the ID of the object and letting client 2 retrieve the correct object from the server by ID: Object o1= db2. Ext( ).GetByID(anID); // C# Object o1= db2.ext( ).getByID(anID); // JAVA
Common Problems With IDs The method GetByID() does not activate the object.To work with the object retrieved in that way, activate the object by calling objectContainer. Eg: Activate(object, depth) A problem that arises with GetID() and Bind() when object is actually a deep graph as the graph is traversed to get the ID of every object in the graph and then individually bind each one. It s always a good idea to avoid relying on IDs because they can change over time, and so are not in fact like fixed primary keys.
Unique Universal IDs ( UUIDs ) These UUIDs are guaranteed to stay unique even if the objects are moved from one Object Container to another. The example shows that we can turn UUID generation for a specific class .
Now we need the respective methods to retrieve the UUID s and to retrieve the object by a UUID. Db here is the Object Container reference, so db.Ext( ) is an ExtObjectContainer.
INDEXES Indexing is a common way to improve performance of databases. In an RDBMS, it allows fast access to rows in tables. The information of several rows is taken, aggregated in some way, and put into a new row. Index is much smaller than the original row and can be optimized for fast search algorithms using balanced B-trees. In an object database, you can similarly use a balanced tree index to avoid doing a full object scan.
Usage of INDEXES In db4o, field on which an index should be created is selected. Once the index is stored, database becomes larger, therefore, storage and update performance will be reduced. As a result, test application with a typical load of data to determine if the performance increase outweighs the penalties of size growth and Set/Delete performance decrease. To turn indexing on, have to configure this on the ObjectContainer before it is opened. Configuring will simply set the internal flag i_indexed to true on the object field selected.
Take care to use the correct name of the field. db4o will not throw an illegal argument exception if the field does not exist. It simply create no index. // C# Db4o.Configure().ObjectClass(typeOf(Person)).ObjectField("_name").Indexed(true); // JAVA Db4o.configure().objectClass(Person.class).objectField("_name").indexed(true); Remove the index with the following code : // C# Db4o.Configure().ObjectClass(typeOf(Person)).ObjectField("_name").Indexed(false); // JAVA Db4o.configure().objectClass(Person.class).objectField("_name").indexed(false);
07/11/12 To create an index on a large number of objects Store all objects using an ObjectContainer , where indexing is turned on. set and commit your objects. This will keep memory consumption low. On the other hand, store all objects with indexing off. Then configure the index and reopen the ObjectContainer again. If a class is attached, an index will be created. This is much faster than the first case.
Performance levels File Size for Database Objects When Using Index
Callbacks Callbacks are methods that are called by db4o in response to database events. db4o defines a set of callback methods in the ObjectCallBacks interface. The ObjectCallbacks Interface in Java // JAVA package com.db4o.ext; public interface ObjectCallbacks { public boolean objectCanActivate(ObjectContainer container); public boolean objectCanDeactivate(ObjectContainer container); public boolean objectCanDelete(ObjectContainer container); public boolean objectCanNew(ObjectContainer container); public boolean objectCanUpdate(ObjectContainer container); public void objectOnActivate(ObjectContainer container); public void objectOnDeactivate(ObjectContainer container); public void objectOnDelete(ObjectContainer container); public void objectOnNew(ObjectContainer container); public void objectOnUpdate(ObjectContainer container);
The Fruit Class with Callback Method in Java // JAVA package com.db4o.dg2db4o.chapter12; import com.db4o.ext.ObjectCallbacks; import com.db4o.ObjectContainer; import java.util.List; import java.util.ArrayList; public class Fruit { private String _name; private int _amount; private List<String> amountHistory; public Fruit(String name, int amount){ _name = name; _amount = amount; amountHistory = new ArrayList<String>(); } public boolean objectCanUpdate(ObjectContainer container){ amountHistory.add( new Long(System.currentTimeMillis()).toString() + ", " + _amount); System.out.println("I was updated!"); return true; // Can be updated! } public String toString(){ String ret="Name=" + _name + "\nAmount=" + _amount; for (String s : amountHistory) { ret += "\nModified at:" + s; } return ret; } 07/11/12
// JAVA Db4o.configure().objectClass(Fruit.class).cascadeOnUpdate(true); ObjectContainer db = Db4o.openFile("C:/ch12.yap"); Fruit mac = new Fruit("Macintosh Red", 200); db.set(mac); mac.setAmount(250); mac.setAmount(300); db.set(mac); Thread.sleep(2000); // need to throw or catch InterruptedException mac.setAmount(400); db.set(mac); db.commit(); db.ext().refresh(mac,3); System.out.println(mac); db.close(); Output : I was updated! I was updated! Name=Macintosh Red Amount=400 Modified at:1139415800301, 300 Modified at:1139415802309, 400
Other Possible Use Cases for Callbacks Setting default values after refactoring. Checking object integrity before storing objects. Setting transient fields. Restoring the connected state when objects are activated. Creating special indexes.