Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 174

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

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unique identity concept</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Unique identity concept</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 uses the concept of uniqueness of each object in reference cache. If an object is accessed by multiple queries or through 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. You can simply use '==' to check the identity of two database objects.</p>



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

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.cs: <span class="fscMemberName">CheckUniqueness</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63"><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;"> CheckUniqueness()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_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_CheckUniqueness_472_63_40_470_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_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_CheckUniqueness_472_63_40_470_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_40_470_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_CheckUniqueness_472_63_131_427_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_CheckUniqueness_472_63_131_427_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_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_CheckUniqueness_472_63_131_427_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_131_427_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"/>        IObjectSet cars </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;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Car car </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Car)cars[</span><span style="color: #800080;">0</span><span style="color: #000000;">];
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        String pilotName </span><span style="color: #000000;">=</span><span style="color: #000000;"> car.Pilot.Name;
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(pilotName));
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)pilots[</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"/>        System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieved objects are identical: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> (pilot </span><span style="color: #000000;">==</span><span style="color: #000000;"> car.Pilot));
</span><span style="color: #008080;">13</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;">14</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;">15</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_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_CheckUniqueness_472_63_444_466_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_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_CheckUniqueness_472_63_444_466_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckUniqueness_472_63_444_466_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Close();
</span><span style="color: #008080;">17</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;">18</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">CheckUniqueness</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63"><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_CheckUniqueness_599_63_15_653_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_CheckUniqueness_599_63_15_653_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_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_CheckUniqueness_599_63_15_653_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_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_CheckUniqueness_599_63_15_653_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub CheckUniqueness()</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckUniqueness_599_63_15_653_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> CheckUniqueness()
</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;"> cars </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </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;">06</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;"> car </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;">(cars(</span><span style="color: #800080;">0</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"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> pilotName </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">String</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> car.Pilot.Name
</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;"> pilots </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(pilotName))
</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;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(pilots(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Pilot)
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieved objects are identical: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> (pilot </span><span style="color: #0000FF;">Is</span><span style="color: #000000;"> car.Pilot).ToString())
</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;">Finally</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.Close()
</span><span style="color: #008080;">13</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;">14</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>How does db4o realize such behavior? Each object is loaded into reference cache only once in the session: db4o will return a new object only if it is not present in the cache yet, otherwise it will give you a reference to the object already in cache. This helps db4o to distinguish between objects that are to be updated and those ones that are to be created. All "known" objects are the subjects of update whereas "unknown" should be created. (Note that the reference system will only be in place as long as an ObjectContainer is open. Closing and reopening an ObjectContainer will clean the references system of the ObjectContainer and all objects in RAM will be treated as "new" afterwards.). </p>



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

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.cs: <span class="fscMemberName">CheckReferenceCache</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67"><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;"> CheckReferenceCache()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_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_CheckReferenceCache_1437_67_44_483_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_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_CheckReferenceCache_1437_67_44_483_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_44_483_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_CheckReferenceCache_1437_67_135_440_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_CheckReferenceCache_1437_67_135_440_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_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_CheckReferenceCache_1437_67_135_440_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_135_440_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"/>        IObjectSet pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)pilots[</span><span style="color: #800080;">0</span><span style="color: #000000;">];
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        String pilotName </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot.Name;
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        pilot.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">new name</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieving pilot by name: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotName);
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet pilots1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(pilotName));
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ListResult(pilots1);
</span><span style="color: #008080;">14</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;">15</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;">16</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_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_CheckReferenceCache_1437_67_457_479_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_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_CheckReferenceCache_1437_67_457_479_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCache_1437_67_457_479_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Close();
</span><span style="color: #008080;">18</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;">19</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">CheckReferenceCache</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67"><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_CheckReferenceCache_1568_67_15_652_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_CheckReferenceCache_1568_67_15_652_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_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_CheckReferenceCache_1568_67_15_652_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_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_CheckReferenceCache_1568_67_15_652_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub CheckReferenceCache()</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCache_1568_67_15_652_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> CheckReferenceCache()
</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;"> pilots </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">06</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;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(pilots(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Pilot)
</span><span style="color: #008080;">07</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;"> pilotName </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">String</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot.Name
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                pilot.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">new name</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieving pilot by name: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotName)
</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;"> pilots1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(pilotName))
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(pilots1)
</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;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</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: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">15</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>In the example <i>pilot</i> object is retrieved from the database (placed into cache) and changed, but not saved. The following retrieval uses pilot's name to retrieve the object from the database, but that object was already instantiated, so its cached (and modified) instance is actually returned.</p>

<p>Such behavior can be sometimes undesirable - you may expect to get object as it saved in the database instead of its modified instance in cache. One of the ways to do that is to use <a href="../../tuning/utility_methods/peekpersisted.html" class="wikiLink">ExtObjectContainer#peekPersisted(object)</a>&nbsp;method, which will give you a disconnected copy of a database object.</p>

<p>Another way is to purge objects from the cache before re-retrieving them.</p>

<p>You can use the following methods:</p>

<ul>
<li>ExtObjectContainer#isCached(object) shows if the object is present in reference cache</li>

<li>ExtObjectContainer#purge(object) removes the object from the cache.</li>
</ul>

<p>Let's look at our previous example extended with these methods:</p>



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

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.cs: <span class="fscMemberName">CheckReferenceCacheWithPurge</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76"><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;"> CheckReferenceCacheWithPurge()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_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_CheckReferenceCacheWithPurge_2765_76_53_610_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_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_CheckReferenceCacheWithPurge_2765_76_53_610_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_53_610_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_CheckReferenceCacheWithPurge_2765_76_144_567_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_CheckReferenceCacheWithPurge_2765_76_144_567_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_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_CheckReferenceCacheWithPurge_2765_76_144_567_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_144_567_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"/>        IObjectSet pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)pilots[</span><span style="color: #800080;">0</span><span style="color: #000000;">];
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        String pilotName </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot.Name;
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        pilot.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">new name</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieving pilot by name: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotName);
</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;"> pilotID </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Ext().GetID(pilot);
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (db.Ext().IsCached(pilotID))
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_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_CheckReferenceCacheWithPurge_2765_76_447_482_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_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_CheckReferenceCacheWithPurge_2765_76_447_482_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_447_482_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          db.Ext().Purge(pilot);
</span><span style="color: #008080;">16</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;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet pilots1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(pilotName));
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ListResult(pilots1);
</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_CheckReferenceCacheWithPurge_2765_76_584_606_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_CheckReferenceCacheWithPurge_2765_76_584_606_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_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_CheckReferenceCacheWithPurge_2765_76_584_606_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_CheckReferenceCacheWithPurge_2765_76_584_606_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">CheckReferenceCacheWithPurge</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76"><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_CheckReferenceCacheWithPurge_2905_76_15_837_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_CheckReferenceCacheWithPurge_2905_76_15_837_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_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_CheckReferenceCacheWithPurge_2905_76_15_837_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_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_CheckReferenceCacheWithPurge_2905_76_15_837_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub CheckReferenceCacheWithPurge()</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_CheckReferenceCacheWithPurge_2905_76_15_837_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> CheckReferenceCacheWithPurge()
</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;"> pilots </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">06</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;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(pilots(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Pilot)
</span><span style="color: #008080;">07</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;"> pilotName </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">String</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot.Name
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                pilot.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">new name</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                System.Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Retrieving pilot by name: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotName)
</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;"> pilotID </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(pilot)
</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;">If</span><span style="color: #000000;"> db.Ext().IsCached(pilotID) </span><span style="color: #0000FF;">Then</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().Purge(pilot)
</span><span style="color: #008080;">13</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;">If</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"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> pilots1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(pilotName))
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(pilots1)
</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: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</span><span style="color: #008080;">18</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;">19</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>Now the second retrieval re-instantiates Pilot object from the database.</p>

<p>An object removed with ExtObjectContainer#purge(object) becomes "unknown" to the ObjectContainer, so this method may also be used to create multiple copies of objects:</p>



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

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">IdentityExample.cs: <span class="fscMemberName">TestCopyingWithPurge</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68"><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;"> TestCopyingWithPurge()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_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_TestCopyingWithPurge_3310_68_45_374_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_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_TestCopyingWithPurge_3310_68_45_374_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_45_374_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_TestCopyingWithPurge_3310_68_136_331_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_TestCopyingWithPurge_3310_68_136_331_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_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_TestCopyingWithPurge_3310_68_136_331_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_136_331_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"/>        IObjectSet pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)pilots[</span><span style="color: #800080;">0</span><span style="color: #000000;">];
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Ext().Purge(pilot);
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Set(pilot);
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ListResult(pilots);
</span><span style="color: #008080;">13</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;">14</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;">15</span><span style="color: #000000;"><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_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_TestCopyingWithPurge_3310_68_348_370_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_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_TestCopyingWithPurge_3310_68_348_370_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityCS.ZipsIdentityExample.Cs_IdentityExample.Cs_TestCopyingWithPurge_3310_68_348_370_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Close();
</span><span style="color: #008080;">17</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;">18</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">TestCopyingWithPurge</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68"><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_TestCopyingWithPurge_3442_68_15_519_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_TestCopyingWithPurge_3442_68_15_519_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_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_TestCopyingWithPurge_3442_68_15_519_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_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_TestCopyingWithPurge_3442_68_15_519_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub TestCopyingWithPurge()</span><span id="ResourcesReferenceBasic_ConceptsObject_IdentityidentityVB.ZipsIdentityExample.Vb_IdentityExample.Vb_TestCopyingWithPurge_3442_68_15_519_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> TestCopyingWithPurge()
</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;"> pilots </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">06</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;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(pilots(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Pilot)
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Ext().Purge(pilot)
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Set(pilot)
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                pilots </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(pilots)
</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;">Finally</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.Close()
</span><span style="color: #008080;">13</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;">14</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>Each reference in db4o works directly with the object. As only one instance of the object exists in cache there is no problem with object locks.</p>

<p>You can see an example of another concept used in JDO system <a href="http://access1.sun.com/jdo/">http://access1.sun.com/jdo/</a> </p>

<p>Actually db4o reference is a pointer to the object in the database file. It means that the size of the database does not affect query time: the object is retrieved from the known position without any necessity to traverse values.</p></div>
    </div>
    <div id="footer">
					This revision (13) was last Modified 2008-03-02T16:39:20 by Tetyana.
				</div>
  </body>
</html>