Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 166

db4o-doc-7.4-2.fc13.i686.rpm

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Binding objects</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Binding objects</h1><script>
//We attach this function to a browser object as a variable so that if multiple of these blocks are
//present on the same page, then they will simply over-write eachother with the same function instead
//of generating a naming collision.
window.WikiCodeFormattingCopyToClipboard = function copyToClipboard(sID){
	var sContent = document.getElementById(sID).innerText;
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", sContent);
	}
	else
	{
		alert("You must enable javascript access to your clipboard for this feature to work. Please referr to your browser documentation or Google search for instructions.");
	}
}
</script>


<p>Db4o adds additional flexibility to its reference system allowing the user to re-associate an object with its stored instance or to replace an object in database:</p>



<span name="cs_wiki_filter" csw_filters="cs">

<p>c#:  </p>
<p><code>IExtObjectContainer#Bind(object,id)</code></p>

</span>

<span name="cs_wiki_filter" csw_filters="vb">

<p>VB:</p>
<p><code>IExtObjectContainer#Bind(object,id)</code></p>

</span>

<p>Typical usecases could be:</p>

<ul>
<li><a href="../../implementation_strategies/type_handling/static_fields_and_enums.html" class="wikiLink">enums and static fields</a></li>

<li>working on objects disconnected from the database</li>

<li>refactoring</li>
</ul>

<p>
The following requirements should be met:</p>

<ul>
<li>The ID needs to be a valid internal object ID, previously retrieved with ExtObjectContainer#getID(object)</li>

<li>The object parameter needs to be of the same class as the stored object.</li>
</ul>

<p>
Calling ExtObjectContainer#bind(object,id) does not have any impact on persisted objects. It only attaches the new object to the database identity. ObjectContainer#set(object) should be used to persist the change.</p>

<p>Let's look how it works in practice. </p>



<span name="cs_wiki_filter" csw_filters="cs">

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.cs: <span class="fscMemberName">TestBind</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> TestBind()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_33_557_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      SetObjects();
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      IObjectContainer db </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName);
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> 
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_124_514_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IQuery q </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query();
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        q.Constrain(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Car));
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        q.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_model</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> q.Execute();
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Car car1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Car)result[</span><span style="color: #800080;">0</span><span style="color: #000000;">];
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> IdCar1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Ext().GetID(car1);
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Car car2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">BMW</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Rubens Barrichello</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">));
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Ext().Bind(car2,IdCar1);
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Set(car2);
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Car));
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ListResult(result);
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>      }</span></span><span style="color: #000000;"> 
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> 
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestBind_1293_56_531_553_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Close();
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>      }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>    }</span></span></div></pre></div></div>

</span>

<span name="cs_wiki_filter" csw_filters="vb">

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.vb: <span class="fscMemberName">TestBind</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub TestBind()</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestBind_1413_56_15_779_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> TestBind()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            SetObjects()
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName)
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> q </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query()
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Constrain(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Car))
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_model</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> q.Execute()
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> car1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(result(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Car)
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> IdCar1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Ext().GetID(car1)
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> car2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">BMW</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Rubens Barrichello</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">))
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Ext().Bind(car2, IdCar1)
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Set(car2)
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Car))
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(result)
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div>

</span>

<p>So this method gives you control over internal object storage. But its usage is potentially dangerous and normally should be avoided. Let's look at an example how <code>bind</code> can damage your object consistency:</p><p>Imagine three objects referencing eachother:</p>
<p>a1 =&gt; b1 =&gt; c1</p>
<p>Now if you call #bind() to replace b1 with b2 in memory you will get the 
following:</p>
<p>a1 =&gt; b1 =&gt; c1<br>b2 =&gt; c1</p>
<p>b2 will be the new in-memory copy of the persistent object formerly known as 
b1.<br>a1 will still point to b1 which is now a transient object.<br>If you now 
store a1, you will get a duplicate copy of b1 stored.</p><p>Please, remember this scenario and use ExtObjectContainer#bind(object,id) only for short-lived objects and in controlled situations where no other references exist.</p><p>For the scenarios, which merging disconnected transient object, please refer to <a href="http://developer.db4o.com/ProjectSpaces/view.aspx/Incubator">Merge Module</a> project suggested design.<br></p></div>
    </div>
    <div id="footer">
					This revision (13) was last Modified 2008-03-02T17:59:04 by Tetyana.
				</div>
  </body>
</html>