Sophie

Sophie

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

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

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Referential Integrity</title>
    <link rel="stylesheet" type="text/css" href="../../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Referential Integrity</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 does not have a built-in referential integrity checking
mechanism. Luckily EventRegistry gives you access to all the necessary events
to implement it. You will just need to trigger validation on create, update or
delete and cancel the action if the integrity is going to be broken.</p>

<p>For example, if Car object is referencing Pilot and the
referenced object should exist, this can be ensured with the following handler
in deleting() event:</p>



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

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">CallbacksExample.cs: <span class="fscMemberName">TestIntegrityCheck</span></span></div><div class="fscCode"><pre ID="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74"><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;"> TestIntegrityCheck()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Open_Text').style.display='inline';"/>        </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_49_940_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"/>        FillContainer();
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectContainer container </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 id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Open_Text').style.display='inline';"/>        </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_155_881_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IEventRegistry registry </span><span style="color: #000000;">=</span><span style="color: #000000;"> EventRegistryFactory.ForObjectContainer(container);
</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: #008000;">//</span><span style="color: #008000;"> register an event handler, which will stop Deleting a pilot when it is referenced from a car </span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">          registry.Deleting </span><span style="color: #000000;">+=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> CancellableObjectEventHandler(OnDeleting); 
</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: #008080;">10</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;"> check the contents of the database</span><span style="color: #008000;">
</span><span style="color: #008080;">11</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">          IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Get(</span><span style="color: #0000FF;">null</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"/>          ListResult(result);
</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: #008080;">14</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;"> try to delete all the pilots</span><span style="color: #008000;">
</span><span style="color: #008080;">15</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">          result </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Open_Text').style.display='inline';"/>          </span><span style="color: #0000FF;">while</span><span style="color: #000000;">(result.HasNext()) </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_683_749_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"/>                  container.Delete(result.Next());
</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/InBlock.gif" align="top"/>          </span><span style="color: #008000;">//</span><span style="color: #008000;"> check if any of the objects were Deleted</span><span style="color: #008000;">
</span><span style="color: #008080;">20</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                result </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Get(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">);
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          ListResult(result);
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Open_Text').style.display='inline';"/>        }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_TestIntegrityCheck_521_74_890_933_Open_Text"><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"/>                CloseContainer();
</span><span style="color: #008080;">24</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;">25</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>      }</span></span></div></pre></div></div>

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">CallbacksExample.cs: <span class="fscMemberName">OnDeleting</span></span></div><div class="fscCode"><pre ID="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66"><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;"> OnDeleting(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, CancellableObjectEventArgs args)
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Open_Text').style.display='inline';"/>        </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_87_749_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"/>            Object obj </span><span style="color: #000000;">=</span><span style="color: #000000;"> args.Object;
</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;">if</span><span style="color: #000000;"> (obj </span><span style="color: #0000FF;">is</span><span style="color: #000000;"> Pilot)
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Open_Text').style.display='inline';"/>            </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_169_739_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IObjectContainer container </span><span style="color: #000000;">=</span><span style="color: #000000;"> OpenContainer();
</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: #008000;">//</span><span style="color: #008000;"> search for the cars referencing the pilot object</span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                IQuery q </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Query();
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Constrain(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Car));
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_pilot</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(obj);
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> q.Execute();
</span><span style="color: #008080;">12</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;">13</span><span style="color: #000000;"><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Open_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Closed_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Closed_Text').style.display='inline';"/><img id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Closed_Text').style.display='none'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Open_Image').style.display='inline'; document.getElementById('....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Open_Text').style.display='inline';"/>                </span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="....CallbacksCS.ZipsCallbacksExample.Cs_CallbacksExample.Cs_OnDeleting_599_66_545_725_Open_Text"><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"/>                    Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Object </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> (Pilot)obj </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> can't be Deleted as object container has references to it</span><span style="color: #800000;">&quot;</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"/>                    args.Cancel();
</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/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">CallbacksExample.vb: <span class="fscMemberName">TestIntegrityCheck</span></span></div><div class="fscCode"><pre ID="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74"><div><!--

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

--><span style="color: #008080;">01</span><img id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Open_Text').style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Closed_Image').style.display='inline'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Closed_Text').style.display='inline';"/><img id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Closed_Text').style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Open_Image').style.display='inline'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_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="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub TestIntegrityCheck()</span><span id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_TestIntegrityCheck_731_74_15_1045_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> TestIntegrityCheck()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            FillContainer()
</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;"> container </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;"> registry </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IEventRegistry </span><span style="color: #000000;">=</span><span style="color: #000000;"> EventRegistryFactory.ForObjectContainer(container)
</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: #008000;">'</span><span style="color: #008000;"> register an event handler, which will stop Deleting a pilot when it is referenced from a car </span><span style="color: #008000;">
</span><span style="color: #008080;">07</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                </span><span style="color: #0000FF;">AddHandler</span><span style="color: #000000;"> registry.Deleting, </span><span style="color: #0000FF;">AddressOf</span><span style="color: #000000;"> OnDeleting
</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: #008000;">'</span><span style="color: #008000;"> check the contents of the database</span><span style="color: #008000;">
</span><span style="color: #008080;">09</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                </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;"> container.Get(</span><span style="color: #0000FF;">Nothing</span><span style="color: #000000;">)
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(result)
</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: #008000;">'</span><span style="color: #008000;"> try to delete all the pilots</span><span style="color: #008000;">
</span><span style="color: #008080;">12</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                result </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(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;">While</span><span style="color: #000000;"> result.HasNext
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    container.Delete(result.Next)
</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;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">While</span><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"/>                </span><span style="color: #008000;">'</span><span style="color: #008000;"> check if any of the objects were Deleted</span><span style="color: #008000;">
</span><span style="color: #008080;">17</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                result </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Get(</span><span style="color: #0000FF;">Nothing</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"/>                ListResult(result)
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</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"/>                CloseContainer()
</span><span style="color: #008080;">21</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;">22</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>

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">CallbacksExample.vb: <span class="fscMemberName">OnDeleting</span></span></div><div class="fscCode"><pre ID="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66"><div><!--

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

--><span style="color: #008080;">01</span><img id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Open_Text').style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Closed_Image').style.display='inline'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Closed_Text').style.display='inline';"/><img id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Closed_Text').style.display='none'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Open_Image').style.display='inline'; document.getElementById('....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_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="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub OnDeleting()</span><span id="....CallbacksVB.ZipsCallbacksExample.Vb_CallbacksExample.Vb_OnDeleting_809_66_15_785_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> OnDeleting(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> sender </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Object</span><span style="color: #000000;">, </span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> args </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> CancellableObjectEventArgs)
</span><span style="color: #008080;">02</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;"> obj </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Object</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> args.Object
</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;">If</span><span style="color: #000000;"> </span><span style="color: #0000FF;">TypeOf</span><span style="color: #000000;"> obj </span><span style="color: #0000FF;">Is</span><span style="color: #000000;"> Pilot </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</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: #008000;">'</span><span style="color: #008000;"> search for the cars referencing the pilot object</span><span style="color: #008000;">
</span><span style="color: #008080;">05</span><span style="color: #008000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> container </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer </span><span style="color: #000000;">=</span><span style="color: #000000;"> OpenContainer()
</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;"> q </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Query
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Constrain(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Car))
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                q.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_pilot</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(obj)
</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;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> q.Execute
</span><span style="color: #008080;">10</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;">11</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Object </span><span style="color: #800000;">&quot;</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;">(obj, Pilot).ToString() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> can't be Deleted as object container has references to it</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    args.Cancel()
</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;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</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>
You can also add handlers for creating() and updating()
events for a Car object to make sure that the pilot field is not null.&nbsp;
</div>
    </div>
    <div id="footer">
					This revision (2) was last Modified 2007-12-03T06:01:03 by Tetyana.
				</div>
  </body>
</html>