#region Apache Notice /***************************************************************************** * $Header: $ * $Revision: 591621 $ * $Date$ * * 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 using System; using Apache.Ibatis.Common.Contracts; using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config; namespace Apache.Ibatis.DataMapper.Configuration.Module { /// /// Handles fluent configuration for ResultMapping element /// public class ResultExpression : ResultMapExpression { /// /// Initializes a new instance of the class. /// /// The module builder. public ResultExpression(ModuleBuilder builder) : base(builder) { resultExpression = this; } /// /// To the Column name. /// /// The name. /// public ResultExpression ToColumnName(string name) { Contract.Require.That(name, Is.Not.Null & Is.Not.Empty).When("retrieving name argument in ToColumnName method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_COLUMN, name); return this; } /// /// To the Column index. /// /// The index. /// public ResultExpression ToColumnIndex(int index) { Contract.Require.That(index, Is.EqualTo(0) | Is.GreaterThan(0)).When("retrieving index argument in ToColumnIndex method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_COLUMNINDEX, index.ToString()); return this; } /// /// Uses the result map. /// /// The id. /// public ResultExpression UsingResultMap(string id) { Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving id argument in UsingResultMap method"); id = builder.ApplyNamespace(id); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_RESULTMAPPING, id); return this; } /// /// With the type handler. /// /// public ResultExpression WithTypeHandler() { Type typeHandler = typeof(THandler); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPEHANDLER, typeHandler.AssemblyQualifiedName); return this; } /// /// Uses the dbtype. /// /// The name. /// public ResultExpression UsingDbType(string name) { Contract.Require.That(name, Is.Not.Null & Is.Not.Empty).When("retrieving name argument in UsingDbType method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_DBTYPE, name); return this; } /// /// Uses lazy loadind. /// /// The using lazy load. public ResultExpression UsingLazyLoad() { builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_LAZYLOAD, "true"); return this; } /// /// Uses the type. /// /// The name. /// public ResultExpression UsingType(string name) { Contract.Require.That(name, Is.Not.Null & Is.Not.Empty).When("retrieving name argument in UsingType method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPE, name); return this; } /// /// Uses the null value. /// /// The null value. /// public ResultExpression UsingNullValue(string val) { Contract.Require.That(val, Is.Not.Null & Is.Not.Empty).When("retrieving null value argument in UsingNullValue method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_NULLVALUE, val); return this; } /// /// Uses the select statment. /// /// The id statement. /// public ResultExpression UsingSelect(string id) { Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving id argument in UsingSelect method"); builder.CurrentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_SELECT, id); return this; } } }