/* Copyright (C) 2004 - 2005  db4objects Inc.  http://www.db4o.com

This file is part of the db4o open source object database.

db4o is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation and as clarified by db4objects' GPL 
interpretation policy, available at
http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
Suite 350, San Mateo, CA 94403, USA.

db4o is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
namespace com.db4o.inside.cluster
{
	/// <exclude></exclude>
	public class ClusterQuery : com.db4o.query.Query
	{
		private readonly com.db4o.cluster.Cluster _cluster;

		private readonly com.db4o.query.Query[] _queries;

		public ClusterQuery(com.db4o.cluster.Cluster cluster, com.db4o.query.Query[] queries
			)
		{
			_cluster = cluster;
			_queries = queries;
		}

		public virtual com.db4o.query.Constraint constrain(object constraint)
		{
			lock (_cluster)
			{
				com.db4o.query.Constraint[] constraints = new com.db4o.query.Constraint[_queries.
					Length];
				for (int i = 0; i < constraints.Length; i++)
				{
					constraints[i] = _queries[i].constrain(constraint);
				}
				return new com.db4o.inside.cluster.ClusterConstraint(_cluster, constraints);
			}
		}

		public virtual com.db4o.query.Constraints constraints()
		{
			lock (_cluster)
			{
				com.db4o.query.Constraint[] constraints = new com.db4o.query.Constraint[_queries.
					Length];
				for (int i = 0; i < constraints.Length; i++)
				{
					constraints[i] = _queries[i].constraints();
				}
				return new com.db4o.inside.cluster.ClusterConstraints(_cluster, constraints);
			}
		}

		public virtual com.db4o.query.Query descend(string fieldName)
		{
			lock (_cluster)
			{
				com.db4o.query.Query[] queries = new com.db4o.query.Query[_queries.Length];
				for (int i = 0; i < queries.Length; i++)
				{
					queries[i] = _queries[i].descend(fieldName);
				}
				return new com.db4o.inside.cluster.ClusterQuery(_cluster, queries);
			}
		}

		public virtual com.db4o.ObjectSet execute()
		{
			lock (_cluster)
			{
				return new com.db4o.inside.query.ObjectSetFacade(new com.db4o.inside.cluster.ClusterQueryResult
					(_cluster, _queries));
			}
		}

		public virtual com.db4o.query.Query orderAscending()
		{
			com.db4o.inside.Exceptions4.notSupported();
			return this;
		}

		public virtual com.db4o.query.Query orderDescending()
		{
			com.db4o.inside.Exceptions4.notSupported();
			return this;
		}
	}
}
