<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="docs.css"> <!--[if gte IE 5]> <link href="docs_ie.css" rel="stylesheet" type="text/css"> <![endif]--> </head> <body><div id="pagecontainer"><table><tr><td width="5"> </td><td><a name="IDs"></a><br> <a name="outline229"></a><br><h1>16. IDs</h1><br> The db4o team recommends, not to use object IDs where this is not necessary. db4o keeps track of object identities in a transparent way, by identifying "known" objects on updates. The reference system also makes sure that every persistent object is instantiated only once, when a graph of objects is retrieved from the database, no matter which access path is chosen. If an object is accessed by multiple queries or by multiple navigation access paths, db4o will always return the one single object, helping you to put your object graph together exactly the same way as it was when it was stored, without having to use IDs.<br> <br> The use of IDs does make sense when object and database are disconnected, for instance in stateless applications.<br> <br> db4o provides two types of ID systems.<br> <br> <ul> <a name="outline230"></a><br><h2>16.1. Internal IDs</h2>The internal db4o ID is a physical pointer into the database with only one indirection in the file to the actual object so it is the fastest external access to an object db4o provides. The internal ID of an object is available with<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>objectContainer.Ext().GetID(object);</code></td></tr></table> <br> To get an object for an internal ID use<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>objectContainer.Ext().GetByID(id);</code></td></tr></table> <br> Note that #GetByID() does not activate objects. If you want to work with objects that you get with #GetByID(), your code would have to make sure the object is <a href="Deep.html#Activation">activated</a> by calling<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>objectContainer.Activate(object, depth);</code></td></tr></table> <br> db4o assigns internal IDs to any stored first class object. These internal IDs are guaranteed to be unique within one IObjectContainer/IObjectServer and they will stay the same for every object when an IObjectContainer/IObjectServer is closed and reopened. Internal IDs <b>will change</b> when an object is moved from one IObjectContainer to another, as it happens during Defragment.<br> <br> <a name="outline231"></a><br><h2>16.2. Unique Universal IDs (UUIDs)</h2>For long term external references and to identify an object even after it has been copied or moved to another IObjectContainer, db4o supplies UUIDs. These UUIDs are not generated by default, since they occupy some space and consume some performance for maintaining their index. UUIDs can be turned on globally or for individual classes:<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>IFileConfiguration#GenerateUUIDs(Int32.MaxValue); <br> Db4oFactory.Configure().ObjectClass(typeof(Foo)).GenerateUUIDs(true);</code></td></tr></table> <br> The respective methods for working with UUIDs are:<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>IExtObjectContainer#GetObjectInfo(object) <br> IObjectInfo#GetUUID();<br> IExtObjectContainer#GetByUUID(Db4oUUID);</code></td></tr></table> <br> <br><br><div id="footer"><p align="center">Do you have any questions, suggestions or feedback? Ask your questions in the <a href="http://developer.db4o.com/Forums.aspx" target=_top>db4o forums</a>. Join the <a href="http://developer.db4o.com" target=_top>db4o community</a> for addional resources and news.<br><br><a href="http://www.db4o.com/" target=_top><small>www.db4o.com</small></a></p>.</div><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></td></tr></table></div></body></html>