#region Apache Notice
/*****************************************************************************
* $Revision: 450157 $
* $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.Generic;
using System.Data;
using Apache.Ibatis.Common.Contracts;
using Apache.Ibatis.Common.Utilities;
using Apache.Ibatis.Common.Utilities.Objects;
using Apache.Ibatis.DataMapper.DataExchange;
using Apache.Ibatis.DataMapper.Model.Events;
#endregion
namespace Apache.Ibatis.DataMapper.Model.ResultMapping
{
///
/// Implementation of interface for auto mapping
///
public class AutoResultMap : IResultMap
{
[NonSerialized]
private bool isInitalized = false;
[NonSerialized]
private readonly Type resultClass = null;
[NonSerialized]
private readonly IFactory resultClassFactory = null;
[NonSerialized]
private readonly ResultPropertyCollection properties = new ResultPropertyCollection();
[NonSerialized]
private IDataExchange dataExchange = null;
[NonSerialized]
private readonly bool isSimpleType = false;
[NonSerialized]
private readonly List keyProperties= new List();
///
/// Initializes a new instance of the class.
///
/// The result class.
/// The result class factory.
/// The data exchange.
/// if set to true [is simple type].
public AutoResultMap(Type resultClass, IFactory resultClassFactory, IDataExchange dataExchange, bool isSimpleType)
{
Contract.Require.That(resultClass, Is.Not.Null).When("retrieving argument resultClass in AutoResultMap constructor");
Contract.Require.That(dataExchange, Is.Not.Null).When("retrieving argument dataExchange in AutoResultMap constructor");
Contract.Require.That(dataExchange, Is.Not.Null).When("retrieving argument typeHandlerFactory in AutoResultMap constructor");
this.resultClass = resultClass;
this.resultClassFactory = resultClassFactory;
this.dataExchange = dataExchange;
this.isSimpleType = isSimpleType;
}
#region IResultMap Members
///
/// The GroupBy Properties.
///
public List GroupByPropertyNames
{
get { throw new NotImplementedException("The property 'GroupByPropertyNames' is not implemented."); }
}
///
/// The collection of ResultProperty.
///
public ResultPropertyCollection Properties
{
get { return properties; }
}
///
/// The GroupBy Properties.
///
///
public ResultPropertyCollection GroupByProperties
{
get { throw new NotImplementedException("The property 'GroupByProperties' is not implemented."); }
}
///
/// The collection of constructor parameters.
///
public ArgumentPropertyCollection Parameters
{
get { throw new NotImplementedException("The property 'Parameters' is not implemented."); }
}
///
/// Gets or sets a value indicating whether this instance is initalized.
///
///
/// true if this instance is initalized; otherwise, false.
///
public bool IsInitalized
{
get { return isInitalized; }
set { isInitalized = value; }
}
///
/// Identifier used to identify the resultMap amongst the others.
///
///
/// GetProduct
public string Id
{
get { return resultClass.Name; }
}
///
/// The output type class of the resultMap.
///
///
public Type Class
{
get { return resultClass; }
}
///
/// Sets the IDataExchange
///
///
public IDataExchange DataExchange
{
set { dataExchange = value; }
}
///
/// Create an instance Of result.
///
/// An array of values that matches the number, order and type
/// of the parameters for this constructor.
/// An object.
public object CreateInstanceOfResult(object[] parameters)
{
if (!isSimpleType)
{
return resultClassFactory.CreateInstance(null);
}
return TypeUtils.InstantiatePrimitiveType(resultClass);
}
///
/// Set the value of an object property.
///
/// The object to set the property.
/// The result property to use.
/// The database value to set.
public void SetValueOfProperty(ref object target, ResultProperty property, object dataBaseValue)
{
dataExchange.SetData(ref target, property, dataBaseValue);
}
///
///
///
///
public IResultMap ResolveSubMap(IDataReader dataReader)
{
return this;
}
///
/// The Key (used for resolved circular reference).
///
///
public List KeyPropertyNames
{
get { return keyProperties; }
}
///
/// The Keys Properties.
///
///
public ResultPropertyCollection KeysProperties
{
get { throw new NotImplementedException("The method or operation is not implemented."); }
}
#endregion
#region IResultMapEvents Members
///
/// Handles event generated before creating an instance of the object.
///
public event EventHandler PreCreate
{
add { throw new NotImplementedException("PreCreate EventHandler"); }
remove { throw new NotImplementedException("PreCreate EventHandler"); }
}
///
/// Handles event generated after creating an instance of the object.
///
public event EventHandler PostCreate
{
add { throw new NotImplementedException("PostCreate EventHandler"); }
remove { throw new NotImplementedException("PostCreate EventHandler"); }
}
#endregion
///
/// Clones this instance.
///
///
public AutoResultMap Clone()
{
return new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType);
}
}
}