#region Apache Notice /***************************************************************************** * $Revision: 469233 $ * $LastChangedDate$ * $LastChangedBy$ * * iBATIS.NET Data Mapper * Copyright (C) 2008/2005 - The Apache Software Foundation * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ********************************************************************************/ #endregion #region Using using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using Apache.Ibatis.Common.Contracts; using Apache.Ibatis.Common.Utilities.Objects; using Apache.Ibatis.DataMapper.Model.Sql; using Apache.Ibatis.DataMapper.Exceptions; using Apache.Ibatis.DataMapper.Model.Cache; using Apache.Ibatis.DataMapper.Model.ParameterMapping; using Apache.Ibatis.DataMapper.Model.ResultMapping; using Apache.Ibatis.DataMapper.Model.Sql.External; #endregion namespace Apache.Ibatis.DataMapper.Model.Statements { /// /// Summary description for Statement. /// [Serializable] [DebuggerDisplay("Statement: {Id}")] public class Statement : IStatement { #region Fields [NonSerialized] private readonly string id = string.Empty; [NonSerialized] private ParameterMap parameterMap = null; [NonSerialized] private readonly Type parameterClass = null; [NonSerialized] private readonly ResultMapCollection resultMaps = new ResultMapCollection(); [NonSerialized] private readonly Type resultClass = null; [NonSerialized] private readonly Type listClass = null; [NonSerialized] private readonly IFactory listClassFactory = null; [NonSerialized] private readonly CacheModel cacheModel = null; [NonSerialized] private readonly bool allowRemapping = false; [NonSerialized] private readonly string extends = string.Empty; [NonSerialized] private ISql sql = null; [NonSerialized] private ISqlSource sqlSource = null; [NonSerialized] private readonly bool preserveWhitespace; #endregion #region Properties /// /// Gets the result class type. /// /// The result class. public Type ResultClass { get { return resultClass; } } /// /// Gets the list class type. /// /// The list class. public Type ListClass { get { return listClass; } } /// /// Gets a value indicating whether [allow remapping]. /// /// true if [allow remapping]; otherwise, false. public bool AllowRemapping { get { return allowRemapping; } } /// /// Gets the extend statement name. /// /// The extend statement. public virtual string ExtendStatement { get { return extends; } } /// /// Tell us if a cacheModel is attached to this statement. /// public bool HasCacheModel { get { return cacheModel != null; } } /// /// Gets the cache model used by this statement. /// /// The cache model. public CacheModel CacheModel { get { return cacheModel; } } /// /// Gets the parameter class type. /// /// The parameter class. public Type ParameterClass { get { return parameterClass; } } /// /// Gets the name used to identify the statement amongst the others. /// public string Id { get { return id; } } /// /// The sql statement /// public ISql Sql { get { return sql; } set { if (value == null) throw new DataMapperException("The sql statement query text is required in the statement tag " + id); sql = value; } } /// /// The ResultMap used by the statement. /// public ResultMapCollection ResultsMap { get { return resultMaps; } } /// /// The parameterMap used by the statement. /// public ParameterMap ParameterMap { get { return parameterMap; } set { parameterMap = value; } } /// /// The type of the statement (text or procedure) /// Default Text. /// /// Text or StoredProcedure public virtual CommandType CommandType { get { return CommandType.Text; } } /// /// Gets the SQL source. /// /// The SQL source. public ISqlSource SqlSource { get { return sqlSource; } set { sqlSource = value;} } /// /// Gets or sets a value indicating whether whitespace within <statement> nodes should be preserved. /// /// /// Using the default value of false may cause single line SQL comments '--' to comment out more than expected. A /// safer commenting syntax is to always use the multi-line comments supported by most vendors: '/* ... */' /// public bool PreserveWhitespace { get { return preserveWhitespace; } } #endregion /// /// Initializes a new instance of the class. /// /// The id. /// The parameter class. /// The parameter map. /// The result class. /// The result maps. /// The list class. /// The list class factory. /// The cache model. /// if set to true [remap results]. /// The extends. /// The SQL source. /// Preserve whitespace. public Statement( string id, Type parameterClass, ParameterMap parameterMap, Type resultClass, ResultMapCollection resultMaps, Type listClass, IFactory listClassFactory, CacheModel cacheModel, bool remapResults, string extends, ISqlSource sqlSource, bool preserveWhitespace) { Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving argument id"); this.id = id; this.parameterClass = parameterClass; this.parameterMap = parameterMap; this.resultClass = resultClass; this.resultMaps = resultMaps; this.listClass = listClass; this.listClassFactory = listClassFactory; this.cacheModel = cacheModel; allowRemapping = remapResults; this.extends = extends; this.sqlSource = sqlSource; this.preserveWhitespace = preserveWhitespace; } #region Methods /// /// Create an instance of 'IList' class. /// /// An object which implment IList. public IList CreateInstanceOfListClass() { return (IList)listClassFactory.CreateInstance(null); } /// /// Create an instance of a generic 'IList' class. /// /// An object which implment IList. public IList CreateInstanceOfGenericListClass() { return (IList)listClassFactory.CreateInstance(null); } #endregion } }