Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 415

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Advanced Features" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>IDs and UUIDs</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../Resources/Code/prettify.js">
        </script>
        <script src="../Resources/Code/lang-vb.js">
        </script>
        <script src="../Resources/Code/jquery.min.js">
        </script>
        <script src="../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../index_CSH.html#advanced_topics/ids_and_uuids.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../advanced_topics.htm">Advanced Features</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">IDs And UUIDs</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1><a name="kanchor72"></a>IDs and UUIDs</h1>
        <P>The db4o team recommends not to use object IDs where it is not necessary. db4o keeps track of object identities in a transparent way, by identifying "known" objects on updates.  <a href="../basics/identity_concept.htm" target="" title="" alt="" class="MCXref">See "Identity Concept"</a></P>
        <P>If you really need to have ids for you're object, take a look at this comparison. <a href="../platform_specific_issues/disconnected_objects/comparison_of_ids.htm" target="" title="" alt="" class="MCXref">See "Comparison Of Different IDs"</a></P>
        <h2>Internal IDs</h2>
        <p>Each object, except value objects like ints, floats or string, do have an internal id. This id is unique within on db4o database and db4o uses it internally for managing the objects. However you also can access this id or retrieve objects by the internal id.</p>
        <p>You can get the internal id of an object from the extended object container.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">long interalId = container.Ext().GetID(obj);</pre>
            <div class="codesnippet-meta">Db4oInternalIdExample.cs: get the db4o internal ids
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim interalId As Long = container.Ext().GetID(obj)</pre>
            <div class="codesnippet-meta">Db4oInternalIdExample.vb: get the db4o internal ids
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>And you can retrieve an object by the internal id. Note that when you get an object by its internal id that it won't be activated. Therefore you have to explicitly activate the object.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">long internalId = idForObject;
object objectForID = container.Ext().GetByID(internalId);
// getting by id doesn't activate the object
// so you need to do it manually
container.Ext().Activate(objectForID);</pre>
            <div class="codesnippet-meta">Db4oInternalIdExample.cs: get an object by db4o internal id
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim internalId As Long = idForObject
Dim objForID As Object = container.Ext().GetByID(internalId)
' getting by id doesn't activate the object
' so you need to do it manually
container.Ext().Activate(objForID)</pre>
            <div class="codesnippet-meta">Db4oInternalIdExample.vb: get an object by db4o internal id
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <h2>db4o UUIDs</h2>
        <p>db4o can also generate a UUIDs for each object. The UUIDs main purpose is to enable <a href="../drs_stub.htm">replication</a>. By default db4o doesn't assign a UUID to each object. You have to enable this <a href="../configuration/file/generate_uuids.htm">globally</a> or for <a href="../configuration/objectclass/generate_uuid.htm">certain types</a>.&#160;For example:</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.File.GenerateUUIDs = ConfigScope.Globally;</pre>
            <div class="codesnippet-meta">FileConfiguration.cs: Enable db4o uuids globally
			<div class="codedownload"><a href="../CodeExamples/configuration/file/Example-configuration-file-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.File.GenerateUUIDs = ConfigScope.Globally</pre>
            <div class="codesnippet-meta">FileConfiguration.vb: Enable db4o uuids globally
			<div class="codedownload"><a href="../CodeExamples/configuration/file/Example-configuration-file-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>A db4o UUID consists of two parts. The first part is the database signature which is unique to the database.</p>
        <p>The second part a unique id within the object-container for the object. Both parts together represent a unique id. </p>
        <p>You can get the db4o uuid from the extended object container.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Db4oUUID uuid = container.Ext().GetObjectInfo(obj).GetUUID();</pre>
            <div class="codesnippet-meta">Db4oUuidExample.cs: get the db4o-uuid
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim uuid As Db4oUUID = container.Ext().GetObjectInfo(obj).GetUUID()</pre>
            <div class="codesnippet-meta">Db4oUuidExample.vb: get the db4o-uuid
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>And you can get an object by its UUID.  Note that when you get an object by its UUIDthat it won't be activated. Therefore you have to explicitly activate the object.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">object objectForId = container.Ext().GetByUUID(idForObject);
// getting by uuid doesn't activate the object
// so you need to do it manually
container.Ext().Activate(objectForId);</pre>
            <div class="codesnippet-meta">Db4oUuidExample.cs: get an object by a db4o-uuid
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim objForId As Object = container.Ext().GetByUUID(idForObject)
' getting by uuid doesn't activate the object
' so you need to do it manually
container.Ext().Activate(objForId)</pre>
            <div class="codesnippet-meta">Db4oUuidExample.vb: get an object by a db4o-uuid
			<div class="codedownload"><a href="../CodeExamples/disconnectedobj/idexamples/Example-disconnectedobj-idexamples-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <script type="text/javascript" src="../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>