Sophie

Sophie

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

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

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>PeekPersisted</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>PeekPersisted</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 loads each object into reference cache only once in the session, thus ensuring that independently of the way of retrieving, you will always get a reference to the same object. This concept certainly makes things clearer, but in some cases you will want to operate on the copy of an object.
</p>
<p>Typical usecases can be:</p>
<ul>
<li>
comparing object's changes in a running transaction with the original object in a database;</li>
<li>safely changing an object without making changes to the database;</li>
<li>
modifying an object in several threads independently, writing the changes to the database after conflict resolution.</li>
</ul>
<p>Db4o helps you with these tasks providing the following method:</p>


<span name="cs_wiki_filter" csw_filters="cs">
<p>c#:   <code>IExtObjectContainer.PeekPersisted(object, depth, committed)</code></p>
</span>
<span name="cs_wiki_filter" csw_filters="vb">
<p>VB:   <code>IExtObjectContainer.PeekPersisted(object, depth, committed)</code></p>
</span>

<p>This method creates a copy of a database object in memory instantiating its members up to depth parameter value. The object has no connection to the database.</p>
<p>Committed parameter defines whether committed or set values are to be returned.<br>
Let's see how you can use it.</p>
<p>We will use 2 threads measuring temperature independently in different parts of the car: somewhere in the cabin (getCabinTemperature) and on the conditioner unit (getConditionerTemperature).After some period of time the average measured value will be written to the database.</p>


<span name="cs_wiki_filter" csw_filters="cs">
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">PeekPersistedExample.cs: <span class="fscMemberName">MeasureCarTemperature</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73"><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;"> MeasureCarTemperature()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Open_Text').style.display='inline';"/>    </span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_46_1017_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="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_137_959_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 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;">08</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;"> (result.Size() </span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">)
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_215_954_Open_Text"><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"/>          Car car </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;">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)db.Ext().PeekPersisted(car, </span><span style="color: #800080;">5</span><span style="color: #000000;">, </span><span style="color: #0000FF;">true</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"/>          Change1 ch1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Change1();
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          ch1.Init(car1);
</span><span style="color: #008080;">14</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;"> (Car)db.Ext().PeekPersisted(car, </span><span style="color: #800080;">5</span><span style="color: #000000;">, </span><span style="color: #0000FF;">true</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"/>          Change2 ch2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Change2();
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          ch2.Init(car2);
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          Thread.Sleep(</span><span style="color: #800080;">300</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"/>          </span><span style="color: #008000;">//</span><span style="color: #008000;"> We can work on the database object at the same time</span><span style="color: #008000;">
</span><span style="color: #008080;">19</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">          car.Model </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">BMW M3Coupe</span><span style="color: #800000;">&quot;</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"/>          db.Set(car);
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          ch1.Stop();
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          ch2.Stop();
</span><span style="color: #008080;">23</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;">car1 saved to the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> db.Ext().IsStored(car1));
</span><span style="color: #008080;">24</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;">car2 saved to the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> db.Ext().IsStored(car1));
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> temperature </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000FF;">int</span><span style="color: #000000;">)((car1.Temperature </span><span style="color: #000000;">+</span><span style="color: #000000;"> car2.Temperature)</span><span style="color: #000000;">/</span><span style="color: #800080;">2</span><span style="color: #000000;">);
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          car.Temperature </span><span style="color: #000000;">=</span><span style="color: #000000;"> temperature;
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          db.Set(car);
</span><span style="color: #008080;">28</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;">29</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;">30</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;">31</span><span style="color: #000000;"><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Open_Text').style.display='inline';"/>      </span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceTuningUtility_MethodspersistCS.ZipsPeekPersistedExample.Cs_PeekPersistedExample.Cs_MeasureCarTemperature_1655_73_976_998_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">32</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        db.Close();
</span><span style="color: #008080;">33</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;">34</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      �heckCar();
</span><span style="color: #008080;">35</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">PeekPersistedExample.vb: <span class="fscMemberName">MeasureCarTemperature</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73"><div><!--

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

--><span style="color: #008080;">01</span><img id="ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_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="ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub MeasureCarTemperature()</span><span id="ResourcesReferenceTuningUtility_MethodspersistVB.ZipsPeekPersistedExample.Vb_PeekPersistedExample.Vb_MeasureCarTemperature_1786_73_15_1478_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> MeasureCarTemperature()
</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;"> result </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;">If</span><span style="color: #000000;"> result.Size() </span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Then</span><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"/>                    </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;">(result(</span><span style="color: #800080;">0</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"/>                    </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;">(db.Ext().PeekPersisted(car, </span><span style="color: #800080;">5</span><span style="color: #000000;">, </span><span style="color: #0000FF;">True</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"/>                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> ch1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Change1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Change1()
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    ch1.Init(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;">CType</span><span style="color: #000000;">(db.Ext().PeekPersisted(car, </span><span style="color: #800080;">5</span><span style="color: #000000;">, </span><span style="color: #0000FF;">True</span><span style="color: #000000;">), Car)
</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;">Dim</span><span style="color: #000000;"> ch2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Change2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Change2()
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    ch2.Init(car2)
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Thread.Sleep(</span><span style="color: #800080;">300</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: #008000;">'</span><span style="color: #008000;"> We can work on the database object at the same time</span><span style="color: #008000;">
</span><span style="color: #008080;">16</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    car.Model </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">BMW M3Coupe</span><span style="color: #800000;">&quot;</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.Set(car)
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    ch1.Kill()
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    ch2.Kill()
</span><span style="color: #008080;">20</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;">car1 saved to the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> db.Ext().IsStored(car1).ToString())
</span><span style="color: #008080;">21</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;">car2 saved to the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> db.Ext().IsStored(car1).ToString())
</span><span style="color: #008080;">22</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;"> temperature </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Integer</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(((car1.Temperature </span><span style="color: #000000;">+</span><span style="color: #000000;"> car2.Temperature) </span><span style="color: #000000;">/</span><span style="color: #000000;"> </span><span style="color: #800080;">2</span><span style="color: #000000;">), </span><span style="color: #0000FF;">Integer</span><span style="color: #000000;">)
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    car.Temperature </span><span style="color: #000000;">=</span><span style="color: #000000;"> temperature
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    db.Set(car)
</span><span style="color: #008080;">25</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;">26</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;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</span><span style="color: #008080;">28</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;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            �heckCar()
</span><span style="color: #008080;">30</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>peekPersisted method gives you an easy way to work with database objects' clones. Remember that these clones are totally disconnected from the database. If you will try to save such object:</p>

<span name="cs_wiki_filter" csw_filters="cs">
<p>c#:   <code>IObjectContainer.Set(peekPersistedObject)</code></p>
</span>
<span name="cs_wiki_filter" csw_filters="vb">
<p>VB:   <code>IObjectContainer#Set(peekPersistedObject)</code></p>
</span>
<p>you will get a new object in the database.</p></div>
    </div>
    <div id="footer">
					This revision (8) was last Modified 2006-11-13T16:24:04 by Tetyana.
				</div>
  </body>
</html>