Sophie

Sophie

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

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Basics Operations &amp; Concepts|Querying" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Native Queries</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../../Resources/Code/prettify.js">
        </script>
        <script src="../../Resources/Code/lang-vb.js">
        </script>
        <script src="../../Resources/Code/jquery.min.js">
        </script>
        <script src="../../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../index_CSH.html#basics/querying/native_queries.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../basics.htm">Basics Operations &amp; Concepts</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../querying.htm">Querying</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Native Queries</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1><a name="kanchor11"></a>Native Queries</h1>
        <p>Wouldn't it be nice to write queries in the programming language that you are using? Wouldn't it be nice if all your query code was 100% typesafe, 100% compile-time checked and 100% refactorable? Wouldn't it be nice if the full power of object-orientation could be used by calling methods from within queries?</p>
        <p MadCap:conditions="Primary..NET">Since <a href="linq.htm">.NET 3.5 LINQ</a> is the way to go and provides a extremely powerful query language. For older .NET versions native queries allow you do to this.</p>
        <p>Native Queries are available for all platforms supported by db4o.</p>
        <H2>Principle</H2>
        <p>Native Queries provide the ability to run one or more lines of code against all instances of a class. Native query expressions should return true to mark specific instances as part of the result set. db4o will attempt to <a href="native_queries/native_query_optimization.htm">optimize native query</a> expressions where possible and use <a href="soda_query.htm">internal query processor</a> to run them against indexes and without instantiating actual objects. </p>
        <H2>Simple Example</H2>
        <p>Let's look at how a simple native query will look like. See also a collection of example queries. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IList&lt;Pilot&gt; result = container.Query(
    delegate(Pilot pilot) { return pilot.Name == "John"; });</pre>
            <div class="codesnippet-meta">NativeQueryExamples.cs: Check for equality of the name
			<div class="codedownload"><a href="../../CodeExamples/query/nq/Example-query-nq-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim result As IList(Of Pilot) = container.Query(Of Pilot)(AddressOf QueryJohns)</pre>
            <div class="codesnippet-meta">NativeQueryExamples.vb: Check for equality of the name
			<div class="codedownload"><a href="../../CodeExamples/query/nq/Example-query-nq-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <H2>Native Query Performance</H2>
        <p>There's one drawback of native queries: Under the hood db4o tries to analyze native queries to convert them to <a href="soda_query.htm">SODA</a>. This is not possible for all queries. For some queries it is very difficult to analyze the flowgraph. In this case db4o will have to instantiate some of the persistent objects to actually run the native query code. db4o will try to analyze parts of native query expressions to keep object instantiation to the minimum.</p>
        <p>The current state of the query optimization process is detailed in the chapter on <a href="native_queries/native_query_optimization.htm">Native Query Optimization</a></p>
        <H2>Concept</H2>
        <p>The concept of native queries is taken from the following two papers:</p>
        <UL>
            <LI value="1">
                <A href="http://www.cs.utexas.edu/users/wcook/papers/NativeQueries/NativeQueries8-23-05.pdf">Cook/Rosenberger, Native Queries for Persistent Objects, A Design White Paper</A>
            </LI>
            <LI value="2">
                <A href="http://www.cs.utexas.edu/~wcook/papers/SafeQuery05/SafeQueryFinal.pdf">Cook/Rai, Safe Query Objects: Statically Typed Objects as Remotely Executable Queries</A>
            </LI>
        </UL>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>