private DataTable GetDataTable(IPersistenceObjectCollection persistenceObjectCollection, IObjectKey parentObjectKey, HybridDictionary parameterCollection) { var pf = PersistenceFacade.GetInstance(); var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName); var dt = new DataTable(); var connection = pf.GetDbConnection(_rdbObjectMapperInfo.RdbConnectionKey); using (connection) { var command = connection.CreateCommand(); command.CommandText = _rdbObjectMapperInfo.MethodNameSelect ?? string.Format("{0}_sel", _rdbObjectMapperInfo.RdbEntityName); command.CommandType = CommandType.StoredProcedure; pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", parentObjectKey); foreach (DictionaryEntry param in parameterCollection) { if (fieldMapperCollection.Contains(param.Key.ToString())) { pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldMapperCollection[param.Key.ToString()].ToString(), param.Value); } else // implied name from param.Key.ToString() { pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, param.Key.ToString(), param.Value); } } var adapter = pf.GetDbDataAdapter(_rdbObjectMapperInfo.RdbConnectionKey); adapter.SelectCommand = command; adapter.Fill(dt); return(dt); } }
public void Get(IPersistenceObjectCollection persistenceObjectCollection, HybridDictionary parameterCollection) { var persistenceObjectType = persistenceObjectCollection.GetType(); var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObjectType.FullName) as IRecordSetMapper; if (mapper == null) { throw new ApplicationException("Mapper is not defined for " + persistenceObjectType.FullName); } mapper.Get(persistenceObjectCollection, parameterCollection); }
public void Get(IPersistenceObjectCollection persistenceObjectCollection, IObjectKey parentObjectKey, HybridDictionary parameterCollection) { if (_proxyTypeSelect == null) { throw new ApplicationException(string.Format("Proxy Get Method is not defined for object {0}.", persistenceObjectCollection.GetType().Name)); } using (var proxy = (IDisposable)Activator.CreateInstance(_proxyTypeSelect)) { try { var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName); var methodInfo = _proxyTypeSelect.GetMethod(_mapperInfo.MethodNameSelect); // copy objectKey collection and parameterCollection into a combined collection var objectKeyFieldCollection = parentObjectKey.ToDictionary(); var combinedParameterCollection = new HybridDictionary(objectKeyFieldCollection.Count + parameterCollection.Count); foreach (DictionaryEntry item in objectKeyFieldCollection) { combinedParameterCollection.Add(item.Key, item.Value); } foreach (DictionaryEntry item in parameterCollection) { combinedParameterCollection.Add(item.Key, item.Value); } var parameterValueCollection = WsRecordMapper.PopulateMethodParameters(methodInfo, fieldMapperCollection, combinedParameterCollection); WsRecordMapper.ProcessProxyCallBack(proxy, _callbackTypeSelect, _mapperInfo.ProxyCallbackPropertyNameSelect); var result = methodInfo.Invoke(proxy, parameterValueCollection); Populate(persistenceObjectCollection, result); WsRecordMapper.Populate(persistenceObjectCollection, methodInfo, parameterValueCollection, result); } catch (TargetInvocationException ex) { if (ex.InnerException != null) { throw ex.InnerException; } throw; } } }
public void Get(IPersistenceObjectCollection persistenceObjectCollection, HybridDictionary parameterCollection) { if (_proxyTypeSelect == null) { throw new ApplicationException(string.Format("Proxy Get Method is not defined for object {0}.", persistenceObjectCollection.GetType().Name)); } using (var proxy = (IDisposable)Activator.CreateInstance(_proxyTypeSelect)) { try { var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName); var methodInfo = _proxyTypeSelect.GetMethod(_mapperInfo.MethodNameSelect); var parameterValueCollection = WsRecordMapper.PopulateMethodParameters(methodInfo, fieldMapperCollection, parameterCollection); WsRecordMapper.ProcessProxyCallBack(proxy, _callbackTypeSelect, _mapperInfo.ProxyCallbackPropertyNameSelect); var result = methodInfo.Invoke(proxy, parameterValueCollection); Populate(persistenceObjectCollection, result); WsRecordMapper.Populate(persistenceObjectCollection, methodInfo, parameterValueCollection, result); } catch (TargetInvocationException ex) { if (ex.InnerException != null) { throw ex.InnerException; } throw; } } }