Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs Mon Oct 30 11:09:11 2006 @@ -61,16 +61,17 @@ /// <param name="resultObject">The result object.</param> public object Process(RequestScope request, ref IDataReader reader, object resultObject) { - // Check if the ResultClass is a 'primitive' Type - if (request.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(request.Statement.ResultClass)) + + // Check if the ResultClass is a 'primitive' Type + if (request.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(request.CurrentResultMap.Class)) { return _simpleTypeStrategy.Process(request, ref reader, resultObject); } - else if (typeof(IDictionary).IsAssignableFrom(request.Statement.ResultClass)) + else if (typeof(IDictionary).IsAssignableFrom(request.CurrentResultMap.Class)) { return _dictionaryStrategy.Process(request, ref reader, resultObject); } - else if (typeof(IList).IsAssignableFrom(request.Statement.ResultClass)) + else if (typeof(IList).IsAssignableFrom(request.CurrentResultMap.Class)) { return _listStrategy.Process(request, ref reader, resultObject); }
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultMapStrategy.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultMapStrategy.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultMapStrategy.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultMapStrategy.cs Mon Oct 30 11:09:11 2006 @@ -29,11 +29,11 @@ namespace IBatisNet.DataMapper.MappedStatements.ResultStrategy { - /// <summary> - /// <see cref="IResultStrategy"/> implementation when - /// a 'resultMap' attribute is specified. - /// </summary> - public sealed class ResultMapStrategy : BaseStrategy, IResultStrategy + /// <summary> + /// <see cref="IResultStrategy"/> implementation when + /// a 'resultMap' attribute is specified. + /// </summary> + public sealed class ResultMapStrategy : BaseStrategy, IResultStrategy { #region IResultStrategy Members @@ -48,7 +48,7 @@ { object outObject = resultObject; - ResultMap resultMap = request.Statement.ResultMap.ResolveSubMap(reader); + IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader); if (outObject == null) { @@ -74,7 +74,7 @@ property.PropertyStrategy.Set(request, resultMap, property, ref outObject, reader, null); } - return outObject; + return outObject; } #endregion Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs Mon Oct 30 11:09:11 2006 @@ -23,52 +23,53 @@ ********************************************************************************/ #endregion +using IBatisNet.DataMapper.Configuration.ResultMapping; using IBatisNet.DataMapper.Configuration.Statements; namespace IBatisNet.DataMapper.MappedStatements.ResultStrategy { - /// <summary> - /// Factory to get <see cref="IResultStrategy"/> implementation. - /// </summary> + /// <summary> + /// Factory to get <see cref="IResultStrategy"/> implementation. + /// </summary> public sealed class ResultStrategyFactory { - private static IResultStrategy _resultClassStrategy = null; - private static IResultStrategy _resultMapStrategy = null; - private static IResultStrategy _objectStrategy = null; + private static IResultStrategy _resultClassStrategy = null; + private static IResultStrategy _resultMapStrategy = null; + private static IResultStrategy _objectStrategy = null; - /// <summary> - /// Initializes the <see cref="ResultStrategyFactory"/> class. - /// </summary> - static ResultStrategyFactory() - { - _resultMapStrategy = new ResultMapStrategy(); - _resultClassStrategy = new ResultClassStrategy(); - _objectStrategy = new ObjectStrategy(); - } + /// <summary> + /// Initializes the <see cref="ResultStrategyFactory"/> class. + /// </summary> + static ResultStrategyFactory() + { + _resultMapStrategy = new ResultMapStrategy(); + _resultClassStrategy = new ResultClassStrategy(); + _objectStrategy = new ObjectStrategy(); + } - /// <summary> - /// Finds the <see cref="IResultStrategy"/>. - /// </summary> - /// <param name="statement">The statement.</param> - /// <returns>The <see cref="IResultStrategy"/></returns> - public static IResultStrategy Get(IStatement statement) - { - // If there's an ResultMap, use it - if (statement.ResultMap != null) - { - return _resultMapStrategy; - } - else // else try to use a ResultClass - { - if (statement.ResultClass != null) - { - return _resultClassStrategy; - } - else - { - return _objectStrategy; - } - } - } + /// <summary> + /// Finds the <see cref="IResultStrategy"/>. + /// </summary> + /// <param name="statement">The statement.</param> + /// <returns>The <see cref="IResultStrategy"/></returns> + public static IResultStrategy Get(IStatement statement) + { + // If there's an ResultMap, use it + if (statement.ResultsMap.Count > 0) + { + if (statement.ResultsMap[0] is ResultMap) + { + return _resultMapStrategy; + } + else // it is an AutoResultMap + { + return _resultClassStrategy; + } + } + else + { + return _objectStrategy; + } + } } } Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/SimpleTypeStrategy.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/SimpleTypeStrategy.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/SimpleTypeStrategy.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/SimpleTypeStrategy.cs Mon Oct 30 11:09:11 2006 @@ -49,27 +49,35 @@ /// <param name="resultObject">The result object.</param> public object Process(RequestScope request, ref IDataReader reader, object resultObject) { - object outObject = resultObject; + object outObject = resultObject; + AutoResultMap resultMap = request.CurrentResultMap as AutoResultMap; + + if (outObject == null) + { + outObject = resultMap.CreateInstanceOfResultClass(); + } - if (outObject == null) - { - outObject = request.Statement.CreateInstanceOfResultClass(); - } + if (!resultMap.IsInitalized) + { + lock(resultMap) + { + if (!resultMap.IsInitalized) + { + // Create a ResultProperty + ResultProperty property = new ResultProperty(); + property.PropertyName = "value"; + property.ColumnIndex = 0; + property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(outObject.GetType()); + property.PropertyStrategy = PropertyStrategyFactory.Get(property); - // Create a ResultMap - ResultMap resultMap = new ResultMap(request.DataExchangeFactory); + resultMap.Properties.Add(property); + resultMap.DataExchange = request.DataExchangeFactory.GetDataExchangeForClass(typeof(int));// set the PrimitiveDataExchange + resultMap.IsInitalized = true; + } + } + } - // Create a ResultProperty - ResultProperty property = new ResultProperty(); - property.PropertyName = "value"; - property.ColumnIndex = 0; - property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(outObject.GetType()); - property.PropertyStrategy = PropertyStrategyFactory.Get(property); - - resultMap.AddResultPropery(property); - resultMap.DataExchange = request.DataExchangeFactory.GetDataExchangeForClass( typeof(int) );// set the PrimitiveDataExchange - - property.PropertyStrategy.Set(request, resultMap, property, ref outObject, reader, null); + resultMap.Properties[0].PropertyStrategy.Set(request, resultMap, resultMap.Properties[0], ref outObject, reader, null); return outObject; } Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs Mon Oct 30 11:09:11 2006 @@ -51,7 +51,11 @@ /// Empty parameter map /// </summary> public const string EMPTY_PARAMETER_MAP = "iBATIS.Empty.ParameterMap"; - + /// <summary> + /// Dot representation. + /// </summary> + public const string DOT = "."; + #region Fields private ErrorContext _errorContext = null; @@ -127,7 +131,7 @@ public string SqlMapNamespace { set { _sqlMapNamespace = value; } - get { return _sqlMapNamespace; } + get { return _sqlMapNamespace; } } /// <summary> @@ -264,6 +268,22 @@ #endregion + /// <summary> + /// Register under Statement Name or Fully Qualified Statement Name + /// </summary> + /// <param name="id">An Identity</param> + /// <returns>The new Identity</returns> + public string ApplyNamespace(string id) + { + string newId = id; + + if (_sqlMapNamespace != null && _sqlMapNamespace.Length > 0 + && id != null && id.Length > 0 && id.IndexOf(".") < 0) + { + newId = _sqlMapNamespace + DOT + id; + } + return newId; + } /// <summary> /// Resolves the type handler. Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Mon Oct 30 11:09:11 2006 @@ -40,113 +40,128 @@ namespace IBatisNet.DataMapper.Scope { - /// <summary> - /// Hold data during the process of a mapped statement. - /// </summary> - public class RequestScope : IScope - { - #region Fields - - private IStatement _statement = null ; - private ErrorContext _errorContext = null; - private ParameterMap _parameterMap = null; - private PreparedStatement _preparedStatement = null; - private IDbCommand _command = null; - private Queue _selects = new Queue(); - bool _rowDataFound= false; - private static long _nextId = 0; - private long _id = 0; - private DataExchangeFactory _dataExchangeFactory = null; - private IDalSession _session = null; - private IMappedStatement _mappedStatement = null; - - #endregion - - #region Properties - - /// <summary> - /// The current <see cref="IMappedStatement"/>. - /// </summary> - public IMappedStatement MappedStatement - { - set { _mappedStatement = value; } - get { return _mappedStatement; } - } - - /// <summary> - /// Gets the current <see cref="IStatement"/>. - /// </summary> - /// <value>The statement.</value> - public IStatement Statement - { - get{ return _statement; } - } - - /// <summary> - /// The current <see cref="IDalSession"/>. - /// </summary> - public IDalSession Session - { + /// <summary> + /// Hold data during the process of a mapped statement. + /// </summary> + public class RequestScope : IScope + { + #region Fields + + private IStatement _statement = null; + private ErrorContext _errorContext = null; + private ParameterMap _parameterMap = null; + private PreparedStatement _preparedStatement = null; + private IDbCommand _command = null; + private Queue _selects = new Queue(); + bool _rowDataFound = false; + private static long _nextId = 0; + private long _id = 0; + private DataExchangeFactory _dataExchangeFactory = null; + private IDalSession _session = null; + private IMappedStatement _mappedStatement = null; + private int _currentResultMapIndex = -1; + + #endregion + + #region Properties + + /// <summary> + /// The current <see cref="IMappedStatement"/>. + /// </summary> + public IMappedStatement MappedStatement + { + set { _mappedStatement = value; } + get { return _mappedStatement; } + } + + /// <summary> + /// Gets the current <see cref="IStatement"/>. + /// </summary> + /// <value>The statement.</value> + public IStatement Statement + { + get { return _statement; } + } + + /// <summary> + /// The current <see cref="IDalSession"/>. + /// </summary> + public IDalSession Session + { get { return _session; } - } + } + + /// <summary> + /// The <see cref="IDbCommand"/> to execute + /// </summary> + public IDbCommand IDbCommand + { + set { _command = value; } + get { return _command; } + } - /// <summary> - /// The <see cref="IDbCommand"/> to execute - /// </summary> - public IDbCommand IDbCommand - { - set { _command = value; } - get { return _command; } - } - - /// <summary> - /// Indicate if the statement have find data - /// </summary> - public bool IsRowDataFound - { - set { _rowDataFound = value; } - get { return _rowDataFound; } - } - - /// <summary> - /// The 'select' result property to process after having process the main properties. - /// </summary> - public Queue QueueSelect - { - get { return _selects; } - set { _selects = value; } - } - - /// <summary> - /// The <see cref="ResultMap"/> used by this request. - /// </summary> - public ResultMap ResultMap - { - get { return _statement.ResultMap; } - } - - /// <summary> - /// The <see cref="ParameterMap"/> used by this request. - /// </summary> - public ParameterMap ParameterMap - { - set { _parameterMap = value; } - get { return _parameterMap; } - } - - /// <summary> - /// The <see cref="PreparedStatement"/> used by this request. - /// </summary> - public PreparedStatement PreparedStatement - { - get { return _preparedStatement; } - set { _preparedStatement = value; } - } + /// <summary> + /// Indicate if the statement have find data + /// </summary> + public bool IsRowDataFound + { + set { _rowDataFound = value; } + get { return _rowDataFound; } + } + /// <summary> + /// The 'select' result property to process after having process the main properties. + /// </summary> + public Queue QueueSelect + { + get { return _selects; } + set { _selects = value; } + } - #endregion + /// <summary> + /// The current <see cref="IResultMap"/> used by this request. + /// </summary> + public IResultMap CurrentResultMap + { + get { return _statement.ResultsMap[_currentResultMapIndex]; } + } - #region Constructors + /// <summary> + /// Moves to the next result map. + /// </summary> + /// <returns></returns> + public bool MoveNextResultMap() + { + if (_currentResultMapIndex < _statement.ResultsMap.Count - 1) + { + _currentResultMapIndex++; + return true; + } + return false; + } + + /// <summary> + /// The <see cref="ParameterMap"/> used by this request. + /// </summary> + public ParameterMap ParameterMap + { + set { _parameterMap = value; } + get { return _parameterMap; } + } + + /// <summary> + /// The <see cref="PreparedStatement"/> used by this request. + /// </summary> + public PreparedStatement PreparedStatement + { + get { return _preparedStatement; } + set { _preparedStatement = value; } + } + + + #endregion + + #region Constructors /// <summary> @@ -155,78 +170,78 @@ /// <param name="dataExchangeFactory">The data exchange factory.</param> /// <param name="session">The session.</param> /// <param name="statement">The statement</param> - public RequestScope( - DataExchangeFactory dataExchangeFactory, + public RequestScope( + DataExchangeFactory dataExchangeFactory, IDalSession session, - IStatement statement + IStatement statement ) - { - _errorContext = new ErrorContext(); + { + _errorContext = new ErrorContext(); - _statement = statement; - _parameterMap = statement.ParameterMap; + _statement = statement; + _parameterMap = statement.ParameterMap; _session = session; - _dataExchangeFactory = dataExchangeFactory; - _id = GetNextId(); - } - #endregion - - #region Method - - /// <summary> - /// Check if the specify object is equal to the current object. - /// </summary> - /// <param name="obj"></param> - /// <returns></returns> - public override bool Equals(object obj) - { - if (this == obj) {return true;} - if (!(obj is RequestScope)) {return false;} - - RequestScope scope = (RequestScope) obj; - - if (_id != scope._id) return false; - - return true; - } - - /// <summary> - /// Get the HashCode for this RequestScope - /// </summary> - /// <returns></returns> - public override int GetHashCode() - { - return (int) (_id ^ (_id >> 32)); - } - - /// <summary> - /// Method to get a unique ID - /// </summary> - /// <returns>The new ID</returns> - [MethodImpl(MethodImplOptions.Synchronized)] - public static long GetNextId() - { - return _nextId++; - } - #endregion - - #region IScope Members - - /// <summary> - /// A factory for DataExchange objects - /// </summary> - public DataExchangeFactory DataExchangeFactory - { - get { return _dataExchangeFactory; } - } - - /// <summary> - /// Get the request's error context - /// </summary> - public ErrorContext ErrorContext - { - get { return _errorContext; } - } - #endregion - } + _dataExchangeFactory = dataExchangeFactory; + _id = GetNextId(); + } + #endregion + + #region Method + + /// <summary> + /// Check if the specify object is equal to the current object. + /// </summary> + /// <param name="obj"></param> + /// <returns></returns> + public override bool Equals(object obj) + { + if (this == obj) { return true; } + if (!(obj is RequestScope)) { return false; } + + RequestScope scope = (RequestScope)obj; + + if (_id != scope._id) return false; + + return true; + } + + /// <summary> + /// Get the HashCode for this RequestScope + /// </summary> + /// <returns></returns> + public override int GetHashCode() + { + return (int)(_id ^ (_id >> 32)); + } + + /// <summary> + /// Method to get a unique ID + /// </summary> + /// <returns>The new ID</returns> + [MethodImpl(MethodImplOptions.Synchronized)] + public static long GetNextId() + { + return _nextId++; + } + #endregion + + #region IScope Members + + /// <summary> + /// A factory for DataExchange objects + /// </summary> + public DataExchangeFactory DataExchangeFactory + { + get { return _dataExchangeFactory; } + } + + /// <summary> + /// Get the request's error context + /// </summary> + public ErrorContext ErrorContext + { + get { return _errorContext; } + } + #endregion + } } Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?view=diff&rev=469233&r1=469232&r2=469233 ============================================================================== --- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original) +++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Mon Oct 30 11:09:11 2006 @@ -194,109 +194,6 @@ #region Methods - #region Configure - - /// <summary> - /// Configure an SqlMap. - /// </summary> - /// <param name="document">An xml sql map configuration document.</param> - /// <returns>the SqlMap</returns> - [Obsolete("This method will be remove in next version, use DomSqlMapBuilder.Configure.", false)] - static public ISqlMapper Configure(XmlDocument document) - { - return new DomSqlMapBuilder().Build( document, false ); - } - - /// <summary> - /// Configure an SqlMap from default resource file named SqlMap.config. - /// </summary> - /// <returns>An SqlMap</returns> - /// <remarks>The file path is relative to the application root.</remarks> - [Obsolete("This method will be remove in future version, use DomSqlMapBuilder.Configure.", false)] - static public ISqlMapper Configure() - { - return Configure( Resources.GetConfigAsXmlDocument(DomSqlMapBuilder.DEFAULT_FILE_CONFIG_NAME) ); - } - - - /// <summary> - /// Configure an SqlMap from via a relative ressource path. - /// </summary> - /// <param name="resource"> - /// A relative ressource path from your Application root - /// or an absolue file path file:\\c:\dir\a.config - /// </param> - /// <returns>An SqlMap</returns> - [Obsolete("This method will be remove in future version, use DomSqlMapBuilder.Configure.", false)] - public static ISqlMapper Configure(string resource) - { - XmlDocument document = null; - if (resource.StartsWith("file://")) - { - document = Resources.GetUrlAsXmlDocument( resource.Remove(0, 7) ); - } - else - { - document = Resources.GetResourceAsXmlDocument( resource ); - } - return new DomSqlMapBuilder().Build( document, false); - } - - - /// <summary> - /// Configure and monitor the default configuration file for modifications - /// and automatically reconfigure SqlMap. - /// </summary> - /// <returns>An SqlMap</returns> - [Obsolete("This method will be remove in future version, use DomSqlMapBuilder.Configure.", false)] - public static ISqlMapper ConfigureAndWatch(ConfigureHandler configureDelegate) - { - return ConfigureAndWatch( DomSqlMapBuilder.DEFAULT_FILE_CONFIG_NAME, configureDelegate ) ; - } - - - /// <summary> - /// Configure and monitor the configuration file for modifications - /// and automatically reconfigure SqlMap. - /// </summary> - /// <param name="resource"> - /// A relative ressource path from your Application root - /// or a absolue file path file:\\c:\dir\a.config - /// </param> - ///<param name="configureDelegate"> - /// Delegate called when the file has changed, to rebuild the dal. - /// </param> - /// <returns>An SqlMap</returns> - [Obsolete("This method will be remove in future version, use DomSqlMapBuilder.Configure.", false)] - public static ISqlMapper ConfigureAndWatch(string resource, ConfigureHandler configureDelegate) - { - XmlDocument document = null; - if (resource.StartsWith("file://")) - { - document = Resources.GetUrlAsXmlDocument( resource.Remove(0, 7) ); - } - else - { - document = Resources.GetResourceAsXmlDocument( resource ); - } - - ConfigWatcherHandler.ClearFilesMonitored(); - ConfigWatcherHandler.AddFileToWatch( Resources.GetFileInfo( resource ) ); - - TimerCallback callBakDelegate = new TimerCallback( DomSqlMapBuilder.OnConfigFileChange ); - - StateConfig state = new StateConfig(); - state.FileName = resource; - state.ConfigureHandler = configureDelegate; - - new ConfigWatcherHandler( callBakDelegate, state ); - - return new DomSqlMapBuilder().Build( document, true ); - } - - - #endregion - #region Manage Connection, Transaction /// <summary> @@ -1147,6 +1044,7 @@ /// <param name="parameterObject">The object used to set the parameters in the SQL</param> /// <param name="pageSize">The maximum number of objects to store in each page</param> /// <returns>A PaginatedList of beans containing the rows</returns> + [Obsolete("This method will be remove in future version.", false)] public PaginatedList QueryForPaginatedList(String statementName, object parameterObject, int pageSize) { IMappedStatement statement = GetMappedStatement(statementName); @@ -1503,7 +1401,7 @@ /// </summary> /// <param name="name">The name of the result map</param> /// <returns>The ResultMap</returns> - public ResultMap GetResultMap(string name) + public IResultMap GetResultMap(string name) { if (_resultMaps.Contains(name) == false) { @@ -1516,7 +1414,7 @@ /// Adds a (named) ResultMap /// </summary> /// <param name="resultMap">The ResultMap to add</param> - public void AddResultMap(ResultMap resultMap) + public void AddResultMap(IResultMap resultMap) { if (_resultMaps.Contains(resultMap.Id) == true) {
