Click here to Skip to main content
15,881,803 members
Articles / Programming Languages / C#

Using a Database Over a Webservice

Rate me:
Please Sign up or sign in to vote.
4.43/5 (5 votes)
29 May 20073 min read 48.5K   539   44  
This article shows an example implementation of a database used over a Web-Service
/* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com */

using System.Collections;
using Db4objects.Db4o.Internal.Fieldindex;
using Db4objects.Db4o.Internal.Query.Processor;

namespace Db4objects.Db4o.Internal.Fieldindex
{
	public class FieldIndexProcessor
	{
		private readonly QCandidates _candidates;

		public FieldIndexProcessor(QCandidates candidates)
		{
			_candidates = candidates;
		}

		public virtual FieldIndexProcessorResult Run()
		{
			IIndexedNode bestIndex = SelectBestIndex();
			if (null == bestIndex)
			{
				return FieldIndexProcessorResult.NO_INDEX_FOUND;
			}
			if (bestIndex.ResultSize() > 0)
			{
				IIndexedNode resolved = ResolveFully(bestIndex);
				if (null == resolved)
				{
					return FieldIndexProcessorResult.NO_INDEX_FOUND;
				}
				return new FieldIndexProcessorResult(resolved);
			}
			return FieldIndexProcessorResult.FOUND_INDEX_BUT_NO_MATCH;
		}

		private IIndexedNode ResolveFully(IIndexedNode bestIndex)
		{
			if (null == bestIndex)
			{
				return null;
			}
			if (bestIndex.IsResolved())
			{
				return bestIndex;
			}
			return ResolveFully(bestIndex.Resolve());
		}

		public virtual IIndexedNode SelectBestIndex()
		{
			IEnumerator i = CollectIndexedNodes();
			if (!i.MoveNext())
			{
				return null;
			}
			IIndexedNode best = (IIndexedNode)i.Current;
			while (i.MoveNext())
			{
				IIndexedNode leaf = (IIndexedNode)i.Current;
				if (leaf.ResultSize() < best.ResultSize())
				{
					best = leaf;
				}
			}
			return best;
		}

		public virtual IEnumerator CollectIndexedNodes()
		{
			return new IndexedNodeCollector(_candidates).GetNodes();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions