/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { IFactory factory = request.DataExchangeFactory.ObjectFactory.CreateFactory(postSelect.ResultProperty.SetAccessor.MemberType, Type.EmptyTypes); object values = factory.CreateInstance(null); postSelect.Statement.ExecuteQueryForList(request.Session, postSelect.Keys, (IList)values); postSelect.ResultProperty.Set(postSelect.Target, values); }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an <see cref="IList"/> property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { object values = mapping.LazyFactory.CreateProxy(request.MappedStatement.ModelStore.DataMapper, selectStatement, keys, target, mapping.SetAccessor); mapping.Set(target, values); } else { if (mapping.SetAccessor.MemberType.GetGenericTypeDefinition() == typeof(IList <>)) { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForGenericIList; } request.DelayedLoad.Enqueue(postSelect); } }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { // How to: Examine and Instantiate Generic Types with Reflection // http://msdn2.microsoft.com/en-us/library/b8ytshk6.aspx //Type[] typeArgs = postSelect.ResultProperty.SetAccessor.MemberType.GetGenericArguments(); //Type genericList = typeof(IList<>); //Type constructedType = genericList.MakeGenericType(typeArgs); Type elementType = postSelect.ResultProperty.SetAccessor.MemberType.GetGenericArguments()[0]; Type mappedStatementType = postSelect.Statement.GetType(); //Type[] typeArguments = { typeof(ISession), typeof(object) }; MethodInfo[] mis = mappedStatementType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance); MethodInfo mi = null; for (int i = 0; i < mis.Length; i++) { if (mis[i].IsGenericMethod && mis[i].Name == "ExecuteQueryForList" && mis[i].GetParameters().Length == 2) { mi = mis[i]; break; } } MethodInfo miConstructed = mi.MakeGenericMethod(elementType); // Invoke the method. object[] args = { request.Session, postSelect.Keys }; object values = miConstructed.Invoke(postSelect.Statement, args); postSelect.ResultProperty.Set(postSelect.Target, values); }
public void Execute(PostBindind postSelect, RequestScope request) { object obj2 = request.DataExchangeFactory.ObjectFactory.CreateFactory(postSelect.ResultProperty.SetAccessor.MemberType, Type.EmptyTypes).CreateInstance(null); postSelect.Statement.ExecuteQueryForList(request.Session, postSelect.Keys, (IList)obj2); postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, obj2); }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an <see cref="IList"/> property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { object values = mapping.LazyFactory.CreateProxy(request.MappedStatement.ModelStore.DataMapper, selectStatement, keys, target, mapping.SetAccessor); //为target类的mapping属性设置值为values mapping.Set(target, values); } else { if (mapping.SetAccessor.MemberType.GetGenericTypeDefinition() == typeof(IList<>)) { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForGenericIList; } //å°†postSelectç±»å¯¹è±¡æ·»åŠ åˆ°é˜Ÿåˆ—ä¸ request.DelayedLoad.Enqueue(postSelect); } }
public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { IMappedStatement mappedStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select); PostBindind bindind = new PostBindind { Statement = mappedStatement, Keys = keys, Target = target, ResultProperty = mapping }; if (mapping.IsLazyLoad) { object obj2 = mapping.LazyFactory.CreateProxy(mappedStatement, keys, target, mapping.SetAccessor); mapping.SetAccessor.Set(target, obj2); } else { if (mapping.SetAccessor.MemberType == typeof(IList)) { bindind.Method = PostBindind.ExecuteMethod.ExecuteQueryForIList; } else { bindind.Method = PostBindind.ExecuteMethod.ExecuteQueryForStrongTypedIList; } request.QueueSelect.Enqueue(bindind); } }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an <see cref="IList"/> property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { object values = mapping.LazyFactory.CreateProxy(selectStatement, keys, target, mapping.SetAccessor); mapping.SetAccessor.Set(target, values); } else { if (mapping.SetAccessor.MemberType == typeof(IList)) { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForIList; } else { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForStrongTypedIList; } request.QueueSelect.Enqueue(postSelect); } }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an object property. /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { object values = mapping.LazyFactory.CreateProxy( request.MappedStatement.ModelStore.DataMapper, selectStatement, keys, target, mapping.SetAccessor); //为target类的mapping属性设置值为values mapping.Set(target, values); } else { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForObject; //å°†postSelectç±»å¯¹è±¡æ·»åŠ åˆ°é˜Ÿåˆ—ä¸ request.DelayedLoad.Enqueue(postSelect); } }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an object property. /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { object values = mapping.LazyFactory.CreateProxy( request.MappedStatement.ModelStore.DataMapper, selectStatement, keys, target, mapping.SetAccessor); mapping.Set(target, values); } else { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForObject; request.DelayedLoad.Enqueue(postSelect); } }
private static void ExecutePostSelect(RequestScope request) { while (request.QueueSelect.Count > 0) { PostBindind postSelect = request.QueueSelect.Dequeue() as PostBindind; PostSelectStrategyFactory.Get(postSelect.Method).Execute(postSelect, request); } }
private static void ExecuteDelayedLoad(RequestScope request) { while (request.DelayedLoad.Count > 0) { PostBindind postSelect = request.DelayedLoad.Dequeue(); PostSelectStrategyFactory.Get(postSelect.Method).Execute(postSelect, request); } }
public void Execute(PostBindind postSelect, RequestScope request) { IList list = postSelect.Statement.ExecuteQueryForList(request.Session, postSelect.Keys); Array array = Array.CreateInstance(postSelect.ResultProperty.SetAccessor.MemberType.GetElementType(), list.Count); int count = list.Count; for (int i = 0; i < count; i++) { array.SetValue(list[i], i); } postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, array); }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { IList values = postSelect.Statement.ExecuteQueryForList(request.Session, postSelect.Keys); Type elementType = postSelect.ResultProperty.SetAccessor.MemberType.GetElementType(); Array array = Array.CreateInstance(elementType, values.Count); int count = values.Count; for(int i=0;i<count;i++) { array.SetValue(values[i],i); } postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, array); }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an Array property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForArrayList; request.QueueSelect.Enqueue(postSelect); }
public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { IMappedStatement mappedStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select); PostBindind bindind = new PostBindind { Statement = mappedStatement, Keys = keys, Target = target, ResultProperty = mapping }; if (mapping.IsLazyLoad) { throw new NotImplementedException("Lazy load no supported for System.Array property:" + mapping.SetAccessor.Name); } bindind.Method = PostBindind.ExecuteMethod.ExecuteQueryForArrayList; request.QueueSelect.Enqueue(bindind); }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an Array property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; if (mapping.IsLazyLoad) { throw new NotImplementedException("Lazy load no supported for System.Array property:" + mapping.SetAccessor.Name); } postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForArrayList; request.DelayedLoad.Enqueue(postSelect); }
///<summary> /// Sets value of the specified <see cref="ResultProperty"/> on the target object /// when a 'select' attribute exists and fills an <see cref="IList"/> property /// on the <see cref="ResultProperty"/> are empties. /// </summary> /// <param name="request">The request.</param> /// <param name="resultMap">The result map.</param> /// <param name="mapping">The ResultProperty.</param> /// <param name="target">The target.</param> /// <param name="reader">The current <see cref="IDataReader"/></param> /// <param name="keys">The keys</param> public void Set(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader, object keys) { // Get the select statement IMappedStatement selectStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select); PostBindind postSelect = new PostBindind(); postSelect.Statement = selectStatement; postSelect.Keys = keys; postSelect.Target = target; postSelect.ResultProperty = mapping; { if (mapping.SetAccessor.MemberType.GetGenericTypeDefinition() == typeof(IList <>)) { postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForGenericIList; } request.QueueSelect.Enqueue(postSelect); } }
public void Execute(PostBindind postSelect, RequestScope request) { Type[] genericArguments = postSelect.ResultProperty.SetAccessor.MemberType.GetGenericArguments(); typeof(IList <>).MakeGenericType(genericArguments); Type type2 = postSelect.ResultProperty.SetAccessor.MemberType.GetGenericArguments()[0]; MethodInfo[] methods = postSelect.Statement.GetType().GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance); MethodInfo info = null; foreach (MethodInfo info2 in methods) { if ((info2.IsGenericMethod && (info2.Name == "ExecuteQueryForList")) && (info2.GetParameters().Length == 2)) { info = info2; break; } } MethodInfo info3 = info.MakeGenericMethod(new Type[] { type2 }); object[] parameters = new object[] { request.Session, postSelect.Keys }; object obj2 = info3.Invoke(postSelect.Statement, parameters); postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, obj2); }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { object value = postSelect.Statement.ExecuteQueryForObject(request.Session, postSelect.Keys); postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, value); }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { object value = postSelect.Statement.ExecuteQueryForObject(request.Session, postSelect.Keys, null); postSelect.ResultProperty.Set(postSelect.Target, value); }
/// <summary> /// Gets the <see cref="IPostSelectStrategy"/>. /// </summary> /// <param name="method">The <see cref="PostBindind.ExecuteMethod"/>.</param> /// <returns>The <see cref="IPostSelectStrategy"/></returns> public static IPostSelectStrategy Get(PostBindind.ExecuteMethod method) { return (IPostSelectStrategy)_strategies[method]; }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, RequestScope request) { object values = postSelect.Statement.ExecuteQueryForList(request.Session, postSelect.Keys); postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, values); }
/// <summary> /// Executes the specified <see cref="PostBindind"/>. /// </summary> /// <param name="postSelect">The <see cref="PostBindind"/>.</param> /// <param name="request">The <see cref="RequestScope"/></param> public void Execute(PostBindind postSelect, IBatisNet.DataMapper.Scope.RequestScope request) { DataTable value = postSelect.Statement.ExecuteQueryForDataTable(request.Session, postSelect.Keys); postSelect.ResultProperty.SetAccessor.Set(postSelect.Target, value); }