Sophie

Sophie

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

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|Activation" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Activation 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="../../SkinSupport/MadCapAll.js">
        </script>
        <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>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../index_CSH.html#basics/activation_concept/hitting_activation_depth_wall.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="../activation.htm">Activation</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Activation 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>Activation In Action</h1>
        <p>Let's see db4o's activation in action. To see activation you need a deep object-graph. To keep this example simple we create a person-class with a mother-field. This allows us to simply create a very deep object graph.</p>
        <p>First the Person class:</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">internal class Person
{
    private Person mother;
    private string name;

    public Person(string name)
    {
        this.name = name;
    }

    public Person(Person mother, string name)
    {
        this.mother = mother;
        this.name = name;
    }

    public Person Mother
    {
        get { return mother; }
    }

    public string Name
    {
        get { return name; }
    }
}</pre>
            <div class="codesnippet-meta">Person.cs: Person with a reference to the mother
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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">Friend Class Person
    Private m_mother As Person
    Private m_name As String

    Public Sub New(ByVal name As String)
        m_mother = m_mother
        Me.m_name = name
    End Sub

    Public Sub New(ByVal mother As Person, ByVal name As String)
        Me.m_mother = mother
        Me.m_name = name
    End Sub

    Public ReadOnly Property Mother() As Person
        Get
            Return m_mother
        End Get
    End Property

    Public ReadOnly Property Name() As String
        Get
            Return m_name
        End Get
    End Property
End Class</pre>
            <div class="codesnippet-meta">Person.vb: Person with a reference to the mother
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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>After that we store a deep hierarchy of persons. Let's say we store a hierarchy of seven people. Then we query for it and traverse this object graph. When we hit the sixth person, that object won't be activated, because it's outside the activation depth. That object will have all fields set to null.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Person jodie = QueryForJodie(container);

Person julia = jodie.Mother.Mother.Mother.Mother.Mother;

// This will print null
// Because julia is not activated
// and therefore all fields are not set
Console.WriteLine(julia.Name);
// This will throw a NullPointerException.
// Because julia is not activated
// and therefore all fields are not set
string joannaName = julia.Mother.Name;</pre>
            <div class="codesnippet-meta">ActivationDepthPitfall.cs: Run into not activated objects
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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 jodie As Person = QueryForJodie(container)

Dim julia As Person = jodie.Mother.Mother.Mother.Mother.Mother

' This will print null
' Because julia is not activated
' and therefore all fields are not set
Console.WriteLine(julia.Name)
' This will throw a NullPointerException.
' Because julia is not activated
' and therefore all fields are not set
Dim joannaName As String = julia.Mother.Name</pre>
            <div class="codesnippet-meta">ActivationDepthPitfall.vb: Run into not activated objects
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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>Use Explicit Activation</h2>
        <p>When we traverse deep object graphs, we know that we might run into not activated objects. Therefore you can activate objects explicitly.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Person julia = jodie.Mother.Mother.Mother.Mother.Mother;
container.Activate(julia,5);

Console.WriteLine(julia.Name);
string joannaName = julia.Mother.Name;
Console.WriteLine(joannaName);</pre>
            <div class="codesnippet-meta">ActivationDepthPitfall.cs: Fix with explicit activation
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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 julia As Person = jodie.Mother.Mother.Mother.Mother.Mother
container.Activate(julia, 5)

Console.WriteLine(julia.Name)
Dim joannaName As String = julia.Mother.Name</pre>
            <div class="codesnippet-meta">ActivationDepthPitfall.vb: Fix with explicit activation
			<div class="codedownload"><a href="../../CodeExamples/pitfalls/activation/Example-pitfalls-activation-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 Activation</h2>
        <p>You can configure db4o to increase the activation depth. You can increase it <a href="../../configuration/common/activation_depth.htm">globally</a> or for <a href="../../configuration/objectclass/minimum_activation_depth.htm">certain classes</a>. Or you can <a href="../../configuration/objectclass/cascade_on-activate.htm">cascade activate</a> certain objects.</p>
        <p>However remember that activation is there to improve the performance and save memory. If you set the activation depth to high it will hurt the performance.</p>
        <h2>Transparent Activation</h2>
        <p>If you have a very complex model or don't want to deal with all the activation hassle then transparent activation is the best option. Transparent activation will manage the activation for you. <a href="transparent_activation_framework.htm" target="" title="" alt="" class="MCXref">See "Transparent Activation"</a></p>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>