Sophie

Sophie

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

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="Basics Operations &amp; Concepts|Update Concept" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Update Depth In Action</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#basics/update_concept/update_depth_in_action.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../basics.htm">Basics Operations &amp; Concepts</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../update_concept.htm">Update Concept</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Update Depth In Action</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>Update Depth In Action</h1>
        <p>Let's see db4o's update depth in action. We store a few cars with their pilots in the database. Then we update a car and its driver and store the car. The we reopen the database and check if everything was updated. To our surprise the car-name was updated, but the driver isn't. This is the direct result of db4o's update depth policy. It only updates object to a certain update-depth. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">using (IObjectContainer container = Db4oEmbedded.OpenFile(DatabaseFile))
{
    Car car = QueryForCar(container);
    car.CarName = "New Mercedes";
    car.Driver.Name = "New Driver Name";

    // With the default-update depth of one, only the changes
    // on the car-object are stored, but not the changes on
    // the person
    container.Store(car);
}
using (IObjectContainer container = Db4oEmbedded.OpenFile(DatabaseFile))
{
    Car car = QueryForCar(container);
    Console.WriteLine("Car-Name:" + car.CarName);
    Console.WriteLine("Driver-Name:" + car.Driver.Name);
}</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.cs: Update depth limits what is store when updating objects
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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">Using container As IObjectContainer = Db4oEmbedded.OpenFile(DatabaseFile)
    Dim car As Car = QueryForCar(container)
    car.CarName = "New Mercedes"
    car.Driver.Name = "New Driver Name"

    ' With the default-update depth of one, only the changes
    ' on the car-object are stored, but not the changes on
    ' the person
    container.Store(car)
End Using
Using container As IObjectContainer = Db4oEmbedded.OpenFile(DatabaseFile)
    Dim car As Car = QueryForCar(container)
    Console.WriteLine("Car-Name:" &amp; car.CarName)
    Console.WriteLine("Driver-Name:" &amp; car.Driver.Name)
End Using</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.vb: Update depth limits what is store when updating objects
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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>Explicitly Store The Driver</h2>
        <p>One solution to this issue is to store updated object explicitly, except value objects. So in our case we would store the car and the pilot. This works fine for simple models. However as the model gets more complex this is probably not a feasible solution.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Car car = QueryForCar(container);
car.CarName = "New Mercedes";
car.Driver.Name = "New Driver Name";

// Explicitly store the driver to ensure that those changes are also in the database
container.Store(car);
container.Store(car.Driver);</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.cs: Explicitly store changes on the driver
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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 car As Car = QueryForCar(container)
car.CarName = "New Mercedes"
car.Driver.Name = "New Driver Name"

' Explicitly store the driver to ensure that those changes are also in the database
container.Store(car)</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.vb: Explicitly store changes on the driver
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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>There also a variation of this. You can use the store method of the extended container and explicitly state the update depth for the store operation.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Car car = QueryForCar(container);
car.CarName = "New Mercedes";
car.Driver.Name = "New Driver Name";

// Explicitly state the update depth
container.Ext().Store(car, 2);</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.cs: Explicitly use the update depth
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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 car As Car = QueryForCar(container)
car.CarName = "New Mercedes"
car.Driver.Name = "New Driver Name"

' Explicitly state the update depth</pre>
            <div class="codesnippet-meta">UpdateDepthPitfall.vb: Explicitly use the update depth
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/updatedepth/Example-pitfalls-updatedepth-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>Configure Update Depth</h2>
        <p>As alternative you can configure the update depth. You can increase it <a href="../../configuration/common/update_depth.htm">globally</a> or for <a href="../../configuration/objectclass/update_depth.htm">certain classes</a>. It's also possible to enable cascading updates for certain <a href="../../configuration/objectclass/cascade_on_update.htm">classes</a> or <a href="../../configuration/objectfield_configuration.htm">fields</a>.</p>
        <h2>Transparent Persistence</h2>
        <p>You can get rid of all the update depth troubles by using transparent persistence. In this mode db4o tracks all changes and stores them. <a href="transparent_persistence.htm" target="" title="" alt="" class="MCXref" xrefformat="See &quot;{paratext}&quot;">See "Transparent Persistence"</a></p>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>