PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/RaptorDB/Views/apimapper.cs

http://raptordb.codeplex.com
C# | 170 lines | 142 code | 24 blank | 4 comment | 10 complexity | 929a16065af823c4b3b94ededd10225e MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. namespace RaptorDB.Views
  7. {
  8. internal class apimapper : IMapAPI
  9. {
  10. public apimapper(ViewManager man)
  11. {
  12. _viewmanager = man;
  13. }
  14. ViewManager _viewmanager;
  15. private ILog _log = LogManager.GetLogger(typeof(apimapper));
  16. internal Dictionary<Guid, List<object[]>> emit = new Dictionary<Guid, List<object[]>>();
  17. internal Dictionary<Guid, List<object>> emitobj = new Dictionary<Guid, List<object>>();
  18. internal bool _RollBack = false;
  19. public void Log(string message)
  20. {
  21. _log.Debug(message);
  22. }
  23. public Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter)
  24. {
  25. return _viewmanager.Query<T>(ViewName, Filter, 0, 0);
  26. }
  27. public Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter)
  28. {
  29. return _viewmanager.Query(View, Filter, 0, 0);
  30. }
  31. public object Fetch(Guid guid)
  32. {
  33. return _viewmanager.Fetch(guid);
  34. }
  35. public void Emit(Guid docid, params object[] data)
  36. {
  37. if (data == null)
  38. return;
  39. List<object[]> d = null;
  40. if (emit.Count == 0)
  41. {
  42. d = new List<object[]>();
  43. d.Add(data);
  44. emit.Add(docid, d);
  45. }
  46. else
  47. {
  48. if (emit.TryGetValue(docid, out d))
  49. {
  50. d.Add(data);
  51. }
  52. else
  53. {
  54. d = new List<object[]>();
  55. d.Add(data);
  56. emit.Add(docid, d);
  57. }
  58. }
  59. }
  60. public void EmitObject<T>(Guid docid, T doc)
  61. {
  62. if (doc == null)
  63. return;
  64. List<object> d = null;
  65. if (emitobj.Count == 0)
  66. {
  67. d = new List<object>();
  68. d.Add(doc);
  69. emitobj.Add(docid, d);
  70. }
  71. else
  72. {
  73. if (emitobj.TryGetValue(docid, out d))
  74. {
  75. d.Add(doc);
  76. }
  77. else
  78. {
  79. d = new List<object>();
  80. d.Add(doc);
  81. emitobj.Add(docid, d);
  82. }
  83. }
  84. }
  85. public void RollBack()
  86. {
  87. _RollBack = true;
  88. }
  89. public Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter, int start, int count)
  90. {
  91. return _viewmanager.Query<T>(ViewName, Filter, start, count);
  92. }
  93. public Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter, int start, int count)
  94. {
  95. return _viewmanager.Query<T>(View, Filter, start, count);
  96. }
  97. public int Count(Type type)
  98. {
  99. return _viewmanager.Count(type, "");
  100. }
  101. public int Count(string viewname)
  102. {
  103. return _viewmanager.Count(viewname, "");
  104. }
  105. public int Count<T>(Type type, Expression<Predicate<T>> Filter)
  106. {
  107. return _viewmanager.Count(type, Filter);
  108. }
  109. public int Count<T>(string ViewName, Expression<Predicate<T>> Filter)
  110. {
  111. return _viewmanager.Count(ViewName, Filter);
  112. }
  113. public int Count(string ViewName, string Filter)
  114. {
  115. return _viewmanager.Count(ViewName, Filter);
  116. }
  117. public int Count<T>(Type type, string Filter)
  118. {
  119. return _viewmanager.Count(type, Filter);
  120. }
  121. public Result<T> Query<T>(Expression<Predicate<T>> Filter)
  122. {
  123. return _viewmanager.Query<T>(Filter,0,0);
  124. }
  125. public Result<T> Query<T>(Expression<Predicate<T>> Filter, int start, int count)
  126. {
  127. return _viewmanager.Query<T>(Filter, start, count);
  128. }
  129. public Result<T> Query<T>(string Filter)
  130. {
  131. return _viewmanager.Query<T>(Filter, 0, 0);
  132. }
  133. public Result<T> Query<T>(string Filter, int start, int count)
  134. {
  135. return _viewmanager.Query<T>(Filter, start, count);
  136. }
  137. public int Count<T>(Expression<Predicate<T>> Filter)
  138. {
  139. return _viewmanager.Count<T>(Filter);
  140. }
  141. //public int Count<T>(string Filter)
  142. //{
  143. // return _viewmanager.Count<T>(Filter);
  144. //}
  145. }
  146. }