motion-yapper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.travis.yml +2 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/motion-yapper.rb +1 -0
  8. data/lib/yapper.rb +3 -5
  9. data/lib/yapper/config.rb +2 -0
  10. data/lib/yapper/db.rb +105 -40
  11. data/lib/yapper/document.rb +7 -4
  12. data/lib/yapper/document/callbacks.rb +0 -7
  13. data/lib/yapper/document/{persistance.rb → persistence.rb} +27 -21
  14. data/lib/yapper/document/relation.rb +29 -22
  15. data/lib/yapper/document/selection.rb +122 -54
  16. data/lib/yapper/extensions.rb +12 -24
  17. data/lib/yapper/settings.rb +43 -0
  18. data/lib/yapper/timestamps.rb +2 -0
  19. data/lib/yapper/version.rb +1 -1
  20. data/{yapper.gemspec → motion-yapper.gemspec} +0 -0
  21. data/spec/integration/{where_spec.rb → criteria_spec.rb} +78 -10
  22. data/spec/integration/db_spec.rb +70 -0
  23. data/spec/integration/defaults_spec.rb +37 -0
  24. data/spec/integration/extensions_spec.rb +14 -0
  25. data/spec/integration/{persistance_spec.rb → persistence_spec.rb} +0 -0
  26. data/spec/integration/relation_spec.rb +4 -4
  27. data/vendor/Podfile.lock +9 -11
  28. data/vendor/Pods/.build/libPods-CocoaLumberjack.a +0 -0
  29. data/vendor/Pods/.build/libPods-NSData+MD5Digest.a +0 -0
  30. data/vendor/Pods/.build/libPods-YapDatabase.a +0 -0
  31. data/vendor/Pods/.build/libPods.a +0 -0
  32. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +4 -4
  33. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  34. data/vendor/Pods/{CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h → BuildHeaders/CocoaLumberjack/DDContextFilterLogFormatter.h} +6 -8
  35. data/vendor/Pods/BuildHeaders/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  36. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +67 -32
  37. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog+LOGV.h +99 -0
  38. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +98 -65
  39. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDMultiFormatter.h +30 -0
  40. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +39 -25
  41. data/vendor/Pods/BuildHeaders/YapDatabase/NSDictionary+YapDatabase.h +8 -0
  42. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +1 -0
  43. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +3 -0
  44. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +4 -4
  45. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +21 -19
  46. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +1 -1
  47. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +35 -31
  48. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +8 -35
  49. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -2
  50. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  51. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  52. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +8 -0
  53. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +43 -21
  54. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationship.h +35 -0
  55. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  56. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  57. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdgePrivate.h +79 -0
  58. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  59. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  60. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipPrivate.h +125 -0
  61. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  62. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  63. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +10 -0
  64. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  65. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +131 -21
  66. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +48 -107
  67. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +2 -2
  68. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +1 -0
  69. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +17 -0
  70. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +10 -3
  71. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +18 -1
  72. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  73. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTypes.h +99 -0
  74. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +4 -4
  75. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +51 -50
  76. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +14 -14
  77. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +546 -546
  78. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +67 -32
  79. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1093 -907
  80. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog+LOGV.h +99 -0
  81. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +98 -65
  82. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +873 -748
  83. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +39 -25
  84. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1284 -1243
  85. data/vendor/Pods/{BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h → CocoaLumberjack/Lumberjack/Extensions/DDContextFilterLogFormatter.h} +6 -8
  86. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{ContextFilterLogFormatter.m → DDContextFilterLogFormatter.m} +70 -70
  87. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  88. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDDispatchQueueLogFormatter.m +253 -0
  89. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.h +30 -0
  90. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.m +127 -0
  91. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +1 -1
  92. data/vendor/Pods/CocoaLumberjack/README.markdown +52 -15
  93. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +4 -4
  94. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  95. data/vendor/Pods/Headers/CocoaLumberjack/{ContextFilterLogFormatter.h → DDContextFilterLogFormatter.h} +6 -8
  96. data/vendor/Pods/Headers/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  97. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +67 -32
  98. data/vendor/Pods/Headers/CocoaLumberjack/DDLog+LOGV.h +99 -0
  99. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +98 -65
  100. data/vendor/Pods/Headers/CocoaLumberjack/DDMultiFormatter.h +30 -0
  101. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +39 -25
  102. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +3 -0
  103. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +4 -4
  104. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +21 -19
  105. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +8 -35
  106. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  107. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  108. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationship.h +35 -0
  109. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  110. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  111. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  112. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  113. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  114. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  115. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +131 -21
  116. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +48 -107
  117. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +2 -2
  118. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +1 -0
  119. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +17 -0
  120. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +10 -3
  121. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  122. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTypes.h +99 -0
  123. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +2 -0
  124. data/vendor/Pods/Headers/____Pods-environment.h +15 -15
  125. data/vendor/Pods/Manifest.lock +9 -11
  126. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +1 -1
  127. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +2 -0
  128. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +1 -1
  129. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +1 -1
  130. data/vendor/Pods/{Pods-Acknowledgements.markdown → Pods-acknowledgements.markdown} +0 -37
  131. data/vendor/Pods/{Pods-Acknowledgements.plist → Pods-acknowledgements.plist} +0 -45
  132. data/vendor/Pods/Pods-environment.h +15 -15
  133. data/vendor/Pods/Pods.xcconfig +3 -3
  134. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +2426 -3155
  135. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-CocoaLumberjack.xcscheme +59 -0
  136. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-NSData+MD5Digest.xcscheme +59 -0
  137. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-YapDatabase.xcscheme +59 -0
  138. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods.xcscheme +59 -0
  139. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/xcschememanagement.plist +31 -0
  140. data/vendor/Pods/YapDatabase/README.md +3 -1
  141. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +0 -2
  142. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +8 -35
  143. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +25 -41
  144. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +17 -17
  145. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +403 -134
  146. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTypes.h +32 -0
  147. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +8 -0
  148. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +8 -8
  149. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +113 -62
  150. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +35 -31
  151. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +25 -0
  152. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +1 -1
  153. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +25 -1
  154. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipEdgePrivate.h +79 -0
  155. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipPrivate.h +125 -0
  156. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.h +35 -0
  157. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.m +129 -0
  158. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.h +29 -0
  159. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.m +802 -0
  160. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.h +163 -0
  161. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.m +408 -0
  162. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipNode.h +99 -0
  163. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.h +59 -0
  164. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.m +29 -0
  165. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.h +384 -0
  166. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.m +5254 -0
  167. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +10 -0
  168. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  169. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +49 -0
  170. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +12 -0
  171. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +9 -8
  172. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +62 -1
  173. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +148 -45
  174. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +18 -1
  175. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +2 -2
  176. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +15 -9
  177. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +17 -0
  178. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +211 -64
  179. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +48 -107
  180. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +10 -7
  181. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +1 -0
  182. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +13 -22
  183. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +10 -3
  184. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +75 -24
  185. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +725 -244
  186. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTypes.h +99 -0
  187. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.h +8 -0
  188. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.m +19 -0
  189. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +1 -0
  190. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +12 -0
  191. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +1 -1
  192. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +3 -3
  193. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +43 -21
  194. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +4 -0
  195. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +3 -0
  196. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +5 -0
  197. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +4 -4
  198. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +84 -93
  199. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +21 -19
  200. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +381 -209
  201. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +131 -21
  202. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +587 -267
  203. data/vendor/Pods/{Pods.bridgesupport → build-iPhoneSimulator/Pods.bridgesupport} +633 -2557
  204. data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
  205. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +2 -1
  206. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +2 -1
  207. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +4 -2
  208. metadata +80 -108
  209. data/Gemfile.lock +0 -63
  210. data/lib/yapper/attachment.rb +0 -48
  211. data/lib/yapper/document/attachment.rb +0 -26
  212. data/lib/yapper/sync.rb +0 -134
  213. data/lib/yapper/sync/data.rb +0 -12
  214. data/lib/yapper/sync/event.rb +0 -194
  215. data/lib/yapper/sync/queue.rb +0 -164
  216. data/spec/integration/all_spec.rb +0 -40
  217. data/spec/integration/sync_spec.rb +0 -42
  218. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -641
  219. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1396
  220. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
  221. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -327
  222. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -113
  223. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -321
  224. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
  225. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -150
  226. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  227. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -157
  228. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -43
  229. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  230. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -143
  231. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -370
  232. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -848
  233. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
  234. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -167
  235. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
  236. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -191
  237. data/vendor/Pods/AFNetworking/LICENSE +0 -19
  238. data/vendor/Pods/AFNetworking/README.md +0 -208
  239. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -641
  240. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
  241. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -113
  242. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
  243. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  244. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -43
  245. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  246. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -370
  247. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
  248. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
  249. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +0 -109
  250. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +0 -251
  251. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -641
  252. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
  253. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -113
  254. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
  255. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  256. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -43
  257. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  258. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -370
  259. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
  260. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
  261. data/vendor/Pods/Headers/Reachability/Reachability.h +0 -109
  262. data/vendor/Pods/Headers/YapDatabase/YapCache.h +0 -90
  263. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +0 -29
  264. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +0 -37
  265. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +0 -440
  266. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -19
  267. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +0 -69
  268. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +0 -158
  269. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +0 -17
  270. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +0 -424
  271. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +0 -73
  272. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +0 -13
  273. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +0 -121
  274. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +0 -94
  275. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +0 -72
  276. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +0 -36
  277. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +0 -27
  278. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +0 -153
  279. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +0 -17
  280. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +0 -74
  281. data/vendor/Pods/Headers/YapDatabase/YapNull.h +0 -17
  282. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +0 -15
  283. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +0 -17
  284. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +0 -5
  285. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +0 -5
  286. data/vendor/Pods/Pods-AFNetworking-dummy.m +0 -5
  287. data/vendor/Pods/Pods-AFNetworking-prefix.pch +0 -17
  288. data/vendor/Pods/Pods-AFNetworking.xcconfig +0 -1
  289. data/vendor/Pods/Pods-Reachability-Private.xcconfig +0 -5
  290. data/vendor/Pods/Pods-Reachability-dummy.m +0 -5
  291. data/vendor/Pods/Pods-Reachability-prefix.pch +0 -5
  292. data/vendor/Pods/Pods-Reachability.xcconfig +0 -1
  293. data/vendor/Pods/Reachability/LICENCE.txt +0 -24
  294. data/vendor/Pods/Reachability/README.md +0 -65
  295. data/vendor/Pods/Reachability/Reachability.h +0 -109
  296. data/vendor/Pods/Reachability/Reachability.m +0 -527
@@ -443,40 +443,148 @@
443
443
 
444
444
  /**
445
445
  * Primitive access.
446
+ * This method is available in case you need to store irregular data that
447
+ * shouldn't go through the configured serializer/deserializer.
446
448
  *
447
- * These are available in-case you store irregular data
448
- * that shouldn't go through configured serializer/deserializer.
449
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
450
+ *
451
+ * Remember that if you place primitive data into the database via this method,
452
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
453
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
454
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
455
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
456
+ *
457
+ * This method is the primitive version of setObject:forKey:inCollection:.
458
+ * For more information see the documentation for setObject:forKey:inCollection:.
459
+ *
460
+ * @see setObject:forKey:inCollection:
461
+ * @see primitiveDataForKey:inCollection:
462
+ **/
463
+ - (void)setPrimitiveData:(NSData *)primitiveData forKey:(NSString *)key inCollection:(NSString *)collection;
464
+
465
+ /**
466
+ * Primitive access.
467
+ * This method is available in case you need to store irregular data that
468
+ * shouldn't go through the configured serializer/deserializer.
469
+ *
470
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
449
471
  *
450
- * @see objectForKey:collection:
472
+ * Remember that if you place primitive data into the database via this method,
473
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
474
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
475
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
476
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
477
+ *
478
+ * This method is the primitive version of setObject:forKey:inCollection:withMetadata:.
479
+ * For more information see the documentation for setObject:forKey:inCollection:withMetadata:.
480
+ *
481
+ * @see setObject:forKey:inCollection:withMetadata:
482
+ * @see primitiveDataForKey:inCollection:
483
+ * @see primitiveMetadataForKey:inCollection:
451
484
  **/
452
- - (void)setPrimitiveData:(NSData *)data forKey:(NSString *)key inCollection:(NSString *)collection;
453
- - (void)setPrimitiveData:(NSData *)data
485
+ - (void)setPrimitiveData:(NSData *)primitiveData
454
486
  forKey:(NSString *)key
455
487
  inCollection:(NSString *)collection
456
488
  withPrimitiveMetadata:(NSData *)primitiveMetadata;
457
- - (void)setPrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection;
489
+
490
+ /**
491
+ * Primitive access.
492
+ * This method is available in case you need to store irregular data that
493
+ * shouldn't go through the configured serializer/deserializer.
494
+ *
495
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
496
+ *
497
+ * Remember that if you place primitive data into the database via this method,
498
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
499
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
500
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
501
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
502
+ *
503
+ * This method is the primitive version of replaceObject:forKey:inCollection:.
504
+ * For more information see the documentation for replaceObject:forKey:inCollection:.
505
+ *
506
+ * @see replaceObject:forKey:inCollection:
507
+ * @see primitiveDataForKey:inCollection:
508
+ **/
509
+ - (void)replacePrimitiveData:(NSData *)primitiveData forKey:(NSString *)key inCollection:(NSString *)collection;
510
+
511
+ /**
512
+ * Primitive access.
513
+ * This method is available in case you need to store irregular data that
514
+ * shouldn't go through the configured serializer/deserializer.
515
+ *
516
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
517
+ *
518
+ * Remember that if you place primitive data into the database via this method,
519
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
520
+ * primitiveMetadataForKey:inCollection:). If you attempt to access it via the object accessor
521
+ * (metadataForKey:inCollection), then the system will attempt to deserialize the primitive data via the
522
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
523
+ *
524
+ * This method is the primitive version of replaceMetadata:forKey:inCollection:.
525
+ * For more information see the documentation for replaceMetadata:forKey:inCollection:.
526
+ *
527
+ * @see replaceMetadata:forKey:inCollection:
528
+ * @see primitiveMetadataForKey:inCollection:
529
+ **/
530
+ - (void)replacePrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection;
531
+
532
+ /**
533
+ * DEPRECATED: Use replacePrimitiveMetadata:forKey:inCollection: instead.
534
+ **/
535
+ - (void)setPrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection
536
+ __attribute((deprecated("Use method replacePrimitiveMetadata:forKey:inCollection: instead")));
458
537
 
459
538
  #pragma mark Object & Metadata
460
539
 
461
540
  /**
462
541
  * Sets the object for the given key/collection.
463
- * Objects are automatically serialized using the database's configured serializer.
542
+ * The object is automatically serialized using the database's configured objectSerializer.
464
543
  *
465
- * You may optionally pass metadata about the object.
466
- * The metadata is also written to the database for persistent storage, and thus persists between sessions.
467
- * Metadata is serialized/deserialized to/from disk just like the object.
544
+ * If you pass nil for the object, then this method will remove the row from the database (if it exists).
545
+ *
546
+ * This method implicitly sets the associated metadata to nil.
468
547
  **/
469
548
  - (void)setObject:(id)object forKey:(NSString *)key inCollection:(NSString *)collection;
549
+
550
+ /**
551
+ * Sets the object & metadata for the given key/collection.
552
+ *
553
+ * The object is automatically serialized using the database's configured objectSerializer.
554
+ * The metadata is automatically serialized using the database's configured metadataSerializer.
555
+ *
556
+ * The metadata is optional. You can pass nil for the metadata is unneeded.
557
+ * If non-nil then the metadata is also written to the database (metadata is also persistent).
558
+ *
559
+ * If you pass nil for the object, then this method will remove the row from the database (if it exists).
560
+ **/
470
561
  - (void)setObject:(id)object forKey:(NSString *)key inCollection:(NSString *)collection withMetadata:(id)metadata;
471
562
 
472
563
  /**
473
- * Updates the metadata, and only the metadata, for the given key/collection.
474
- * The object for the key doesn't change.
564
+ * If a row with the given key/collection exists, then replaces the object for that row with the new value.
565
+ * It only replaces the object. The metadata for the row doesn't change.
566
+ *
567
+ * If there is no row in the database for the given key/collection then this method does nothing.
568
+ *
569
+ * If you pass nil for the object, then this method will remove
570
+ **/
571
+ - (void)replaceObject:(id)object forKey:(NSString *)key inCollection:(NSString *)collection;
572
+
573
+ /**
574
+ * If a row with the given key/collection exists, then replaces the metadata for that row with the new value.
575
+ * It only replaces the metadata. The object for the row doesn't change.
475
576
  *
476
- * Note: If there is no stored object for the given key/collection, this method does nothing.
477
- * If you pass nil for the metadata, any given metadata associated with the key/colleciton is removed.
577
+ * If there is no row in the database for the given key/collection then this method does nothing.
578
+ *
579
+ * If you pass nil for the metadata, any metadata previously associated with the key/collection is removed.
580
+ **/
581
+ - (void)replaceMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection;
582
+
583
+ /**
584
+ * DEPRECATED: Use replaceMetadata:forKey:inCollection: instead.
478
585
  **/
479
- - (void)setMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection;
586
+ - (void)setMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection
587
+ __attribute((deprecated("Use method replaceMetadata:forKey:inCollection: instead")));
480
588
 
481
589
  #pragma mark Touch
482
590
 
@@ -487,11 +595,13 @@
487
595
  *
488
596
  * You have a BNBook object in your database.
489
597
  * One of the properties of the book object is a URL pointing to an image for the front cover of the book.
490
- * This image gets changed. Thus the UI representation of the book needs to be updated to reflect the updated image.
491
- * You realize that all your views are already listening for YapDatabaseModified notifications,
492
- * so if you update the object in the database, all your views are already wired to update the UI appropriately.
493
- * However, the actual object itself didn't change. So while there technically isn't any reason to
494
- * update the object on disk, doing so would be the most efficient way to keep the UI up-to-date.
598
+ * This image gets changed on the server. Thus the UI representation of the book needs to be updated
599
+ * to reflect the updated image on the server. You realize that all your views are already listening for
600
+ * YapDatabaseModified notifications, so if you update the object in the database then all your views are
601
+ * already wired to update the UI appropriately. However, the actual object itself didn't change. So while
602
+ * there technically isn't any reason to update the object on disk, doing so would be the easiest way to
603
+ * keep the UI up-to-date. So what you really want is a way to "mark" the object as updated, without actually
604
+ * incurring the overhead of rewriting it to disk.
495
605
  *
496
606
  * And this is exactly what the touch methods were designed for.
497
607
  * It won't actually cause the object to get rewritten to disk.
@@ -502,7 +612,7 @@
502
612
  * and passing the object & metadata that already exists for the key. But without the overhead of fetching the items,
503
613
  * or re-writing the items to disk.
504
614
  *
505
- * The touchMetadataForKey: method is similar to calling setMetadata:forKey:,
615
+ * The touchMetadataForKey: method is similar to calling replaceMetadata:forKey:,
506
616
  * and passing the metadata that already exists for the key. But without the overhead of fetching the metadata,
507
617
  * or re-writing the metadata to disk.
508
618
  *
@@ -78,12 +78,57 @@
78
78
 
79
79
  - (void)preCommitReadWriteTransaction
80
80
  {
81
+ // Step 1:
82
+ //
83
+ // Allow extensions to flush changes to the main database table.
84
+ // This is different from flushing changes to their own private tables.
85
+ // We're referring here to the main collection/key/value table that's public.
86
+
87
+ __block BOOL restart;
88
+ __block BOOL prevExtModifiesMainDatabaseTable;
89
+ do
90
+ {
91
+ isMutated = NO;
92
+
93
+ restart = NO;
94
+ prevExtModifiesMainDatabaseTable = NO;
95
+
96
+ [extensions enumerateKeysAndObjectsUsingBlock:^(id extNameObj, id extTransactionObj, BOOL *stop) {
97
+
98
+ BOOL extModifiesMainDatabaseTable =
99
+ [(YapDatabaseExtensionTransaction *)extTransactionObj flushPendingChangesToMainDatabaseTable];
100
+
101
+ if (extModifiesMainDatabaseTable)
102
+ {
103
+ if (!isMutated)
104
+ {
105
+ prevExtModifiesMainDatabaseTable = YES;
106
+ }
107
+ else
108
+ {
109
+ if (prevExtModifiesMainDatabaseTable)
110
+ {
111
+ restart = YES;
112
+ *stop = YES;
113
+ }
114
+ else
115
+ {
116
+ prevExtModifiesMainDatabaseTable = YES;
117
+ }
118
+ }
119
+ }
120
+ }];
121
+
122
+ } while (restart);
123
+
124
+ // Step 2:
125
+ //
81
126
  // Allow extensions to perform any "cleanup" code needed before the changesets are requested,
82
127
  // and before the commit is executed.
83
128
 
84
129
  [extensions enumerateKeysAndObjectsUsingBlock:^(id extNameObj, id extTransactionObj, BOOL *stop) {
85
130
 
86
- [(YapDatabaseExtensionTransaction *)extTransactionObj preCommitReadWriteTransaction];
131
+ [(YapDatabaseExtensionTransaction *)extTransactionObj prepareChangeset];
87
132
  }];
88
133
  }
89
134
 
@@ -328,23 +373,25 @@
328
373
  return result;
329
374
  }
330
375
 
331
- - (BOOL)getKey:(NSString **)keyPtr collection:(NSString **)collectionPtr forRowid:(int64_t)rowid
376
+ - (YapCollectionKey *)collectionKeyForRowid:(int64_t)rowid
332
377
  {
378
+ NSNumber *rowidNumber = @(rowid);
379
+
380
+ YapCollectionKey *collectionKey = [connection->keyCache objectForKey:rowidNumber];
381
+ if (collectionKey)
382
+ {
383
+ return collectionKey;
384
+ }
385
+
333
386
  sqlite3_stmt *statement = [connection getKeyForRowidStatement];
334
387
  if (statement == NULL) {
335
- if (keyPtr) *keyPtr = nil;
336
- if (collectionPtr) *collectionPtr = nil;
337
- return NO;
388
+ return nil;
338
389
  }
339
390
 
340
391
  // SELECT "collection", "key" FROM "database2" WHERE "rowid" = ?;
341
392
 
342
393
  sqlite3_bind_int64(statement, 1, rowid);
343
394
 
344
- NSString *collection = nil;
345
- NSString *key = nil;
346
- BOOL result = NO;
347
-
348
395
  int status = sqlite3_step(statement);
349
396
  if (status == SQLITE_ROW)
350
397
  {
@@ -357,10 +404,12 @@
357
404
  const unsigned char *text1 = sqlite3_column_text(statement, 1);
358
405
  int textSize1 = sqlite3_column_bytes(statement, 1);
359
406
 
360
- collection = [[NSString alloc] initWithBytes:text0 length:textSize0 encoding:NSUTF8StringEncoding];
361
- key = [[NSString alloc] initWithBytes:text1 length:textSize1 encoding:NSUTF8StringEncoding];
407
+ NSString *collection = [[NSString alloc] initWithBytes:text0 length:textSize0 encoding:NSUTF8StringEncoding];
408
+ NSString *key = [[NSString alloc] initWithBytes:text1 length:textSize1 encoding:NSUTF8StringEncoding];
362
409
 
363
- result = YES;
410
+ collectionKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
411
+
412
+ [connection->keyCache setObject:collectionKey forKey:rowidNumber];
364
413
  }
365
414
  else if (status == SQLITE_ERROR)
366
415
  {
@@ -370,249 +419,127 @@
370
419
  sqlite3_clear_bindings(statement);
371
420
  sqlite3_reset(statement);
372
421
 
373
- if (keyPtr) *keyPtr = key;
374
- if (collectionPtr) *collectionPtr = collection;
375
- return result;
422
+ return collectionKey;
376
423
  }
377
424
 
378
- - (BOOL)getKey:(NSString **)keyPtr
379
- collection:(NSString **)collectionPtr
380
- object:(id *)objectPtr
381
- forRowid:(int64_t)rowid
425
+ - (BOOL)getCollectionKey:(YapCollectionKey **)collectionKeyPtr object:(id *)objectPtr forRowid:(int64_t)rowid
382
426
  {
383
- sqlite3_stmt *statement = [connection getKeyDataForRowidStatement];
384
- if (statement == NULL) {
385
- if (keyPtr) *keyPtr = nil;
386
- if (collectionPtr) *collectionPtr = nil;
427
+ YapCollectionKey *collectionKey = [self collectionKeyForRowid:rowid];
428
+ if (collectionKey)
429
+ {
430
+ id object = [self objectForCollectionKey:collectionKey withRowid:rowid];
431
+
432
+ if (collectionKeyPtr) *collectionKeyPtr = collectionKey;
433
+ if (objectPtr) *objectPtr = object;
434
+ return YES;
435
+ }
436
+ else
437
+ {
438
+ if (collectionKeyPtr) *collectionKeyPtr = nil;
387
439
  if (objectPtr) *objectPtr = nil;
388
440
  return NO;
389
441
  }
390
-
391
- // SELECT "collection", "key", "data" FROM "database2" WHERE "rowid" = ?;
392
-
393
- sqlite3_bind_int64(statement, 1, rowid);
394
-
395
- NSString *collection = nil;
396
- NSString *key = nil;
397
- id object = nil;
398
- BOOL result = NO;
399
-
400
- int status = sqlite3_step(statement);
401
- if (status == SQLITE_ROW)
442
+ }
443
+
444
+ - (BOOL)getCollectionKey:(YapCollectionKey **)collectionKeyPtr metadata:(id *)metadataPtr forRowid:(int64_t)rowid
445
+ {
446
+ YapCollectionKey *collectionKey = [self collectionKeyForRowid:rowid];
447
+ if (collectionKey)
402
448
  {
403
- if (connection->needsMarkSqlLevelSharedReadLock)
404
- [connection markSqlLevelSharedReadLockAcquired];
405
-
406
- const unsigned char *text0 = sqlite3_column_text(statement, 0);
407
- int textSize0 = sqlite3_column_bytes(statement, 0);
408
-
409
- const unsigned char *text1 = sqlite3_column_text(statement, 1);
410
- int textSize1 = sqlite3_column_bytes(statement, 1);
411
-
412
- collection = [[NSString alloc] initWithBytes:text0 length:textSize0 encoding:NSUTF8StringEncoding];
413
- key = [[NSString alloc] initWithBytes:text1 length:textSize1 encoding:NSUTF8StringEncoding];
414
-
415
- YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
416
-
417
- object = [connection->objectCache objectForKey:cacheKey];
418
- if (object == nil)
419
- {
420
- const void *blob = sqlite3_column_blob(statement, 2);
421
- int blobSize = sqlite3_column_bytes(statement, 2);
422
-
423
- // Performance tuning:
424
- // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
425
-
426
- NSData *data = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
427
- object = connection->database->objectDeserializer(collection, key, data);
428
-
429
- if (object)
430
- [connection->objectCache setObject:object forKey:cacheKey];
431
- }
449
+ id metadata = [self metadataForCollectionKey:collectionKey withRowid:rowid];
432
450
 
433
- result = YES;
451
+ if (collectionKeyPtr) *collectionKeyPtr = collectionKey;
452
+ if (metadataPtr) *metadataPtr = metadata;
453
+ return YES;
434
454
  }
435
- else if (status == SQLITE_ERROR)
455
+ else
436
456
  {
437
- YDBLogError(@"Error executing 'getKeyDataForRowidStatement': %d %s", status, sqlite3_errmsg(connection->db));
457
+ if (collectionKeyPtr) *collectionKeyPtr = nil;
458
+ if (metadataPtr) *metadataPtr = nil;
459
+ return NO;
438
460
  }
439
-
440
- sqlite3_clear_bindings(statement);
441
- sqlite3_reset(statement);
442
-
443
- if (keyPtr) *keyPtr = key;
444
- if (collectionPtr) *collectionPtr = collection;
445
- if (objectPtr) *objectPtr = object;
446
- return result;
447
461
  }
448
462
 
449
- - (BOOL)getKey:(NSString **)keyPtr
450
- collection:(NSString **)collectionPtr
451
- metadata:(id *)metadataPtr
452
- forRowid:(int64_t)rowid
463
+ - (BOOL)getCollectionKey:(YapCollectionKey **)collectionKeyPtr
464
+ object:(id *)objectPtr
465
+ metadata:(id *)metadataPtr
466
+ forRowid:(int64_t)rowid
453
467
  {
454
- sqlite3_stmt *statement = [connection getKeyMetadataForRowidStatement];
455
- if (statement == NULL) {
456
- if (keyPtr) *keyPtr = nil;
457
- if (collectionPtr) *collectionPtr = nil;
468
+ YapCollectionKey *collectionKey = [self collectionKeyForRowid:rowid];
469
+ if (collectionKey == nil)
470
+ {
471
+ if (collectionKeyPtr) *collectionKeyPtr = nil;
472
+ if (objectPtr) *objectPtr = nil;
458
473
  if (metadataPtr) *metadataPtr = nil;
459
474
  return NO;
460
475
  }
461
476
 
462
- // SELECT "collection", "key", "metadata" FROM "database2" WHERE "rowid" = ?;
477
+ id object = [connection->objectCache objectForKey:collectionKey];
478
+ id metadata = [connection->metadataCache objectForKey:collectionKey];
463
479
 
464
- sqlite3_bind_int64(statement, 1, rowid);
465
-
466
- NSString *collection = nil;
467
- NSString *key = nil;
468
- id metadata = nil;
469
- BOOL result = NO;
470
-
471
- int status = sqlite3_step(statement);
472
- if (status == SQLITE_ROW)
480
+ if (object || metadata)
473
481
  {
474
- if (connection->needsMarkSqlLevelSharedReadLock)
475
- [connection markSqlLevelSharedReadLockAcquired];
476
-
477
- const unsigned char *text0 = sqlite3_column_text(statement, 0);
478
- int textSize0 = sqlite3_column_bytes(statement, 0);
479
-
480
- const unsigned char *text1 = sqlite3_column_text(statement, 1);
481
- int textSize1 = sqlite3_column_bytes(statement, 1);
482
-
483
- collection = [[NSString alloc] initWithBytes:text0 length:textSize0 encoding:NSUTF8StringEncoding];
484
- key = [[NSString alloc] initWithBytes:text1 length:textSize1 encoding:NSUTF8StringEncoding];
485
-
486
- YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
487
-
488
- metadata = [connection->metadataCache objectForKey:cacheKey];
489
- if (metadata)
482
+ if (object == nil)
490
483
  {
491
- if (metadata == [YapNull null])
492
- metadata = nil;
484
+ object = [self objectForCollectionKey:collectionKey withRowid:rowid];
493
485
  }
494
- else
486
+ else if (metadata == nil)
495
487
  {
496
- const void *blob = sqlite3_column_blob(statement, 2);
497
- int blobSize = sqlite3_column_bytes(statement, 2);
498
-
499
- if (blobSize > 0)
500
- {
501
- // Performance tuning:
502
- // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
503
-
504
- NSData *mData = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
505
- metadata = connection->database->metadataDeserializer(collection, key, mData);
506
- }
507
-
508
- if (metadata)
509
- [connection->metadataCache setObject:metadata forKey:cacheKey];
510
- else
511
- [connection->metadataCache setObject:[YapNull null] forKey:cacheKey];
488
+ metadata = [self metadataForCollectionKey:collectionKey withRowid:rowid];
512
489
  }
513
490
 
514
- result = YES;
515
- }
516
- else if (status == SQLITE_ERROR)
517
- {
518
- YDBLogError(@"Error executing 'getKeyMetadataForRowidStatement': %d %s",
519
- status, sqlite3_errmsg(connection->db));
491
+ if (collectionKeyPtr) *collectionKeyPtr = collectionKey;
492
+ if (objectPtr) *objectPtr = object;
493
+ if (metadataPtr) *metadataPtr = metadata;
494
+ return YES;
520
495
  }
521
496
 
522
- sqlite3_clear_bindings(statement);
523
- sqlite3_reset(statement);
524
-
525
- if (keyPtr) *keyPtr = key;
526
- if (collectionPtr) *collectionPtr = collection;
527
- if (metadataPtr) *metadataPtr = metadata;
528
- return result;
529
- }
530
-
531
- - (BOOL)getKey:(NSString **)keyPtr
532
- collection:(NSString **)collectionPtr
533
- object:(id *)objectPtr
534
- metadata:(id *)metadataPtr
535
- forRowid:(int64_t)rowid
536
- {
537
497
  sqlite3_stmt *statement = [connection getAllForRowidStatement];
538
498
  if (statement == NULL) {
539
- if (keyPtr) *keyPtr = nil;
540
- if (collectionPtr) *collectionPtr = nil;
499
+ if (collectionKeyPtr) *collectionKeyPtr = nil;
541
500
  if (objectPtr) *objectPtr = nil;
542
501
  if (metadataPtr) *metadataPtr = nil;
543
502
  return NO;
544
503
  }
545
504
 
546
- // SELECT "collection", "key", "data", "metadata" FROM "database2" WHERE "rowid" = ?;
505
+ // SELECT "data", "metadata" FROM "database2" WHERE "rowid" = ?;
547
506
 
548
507
  sqlite3_bind_int64(statement, 1, rowid);
549
508
 
550
- NSString *collection = nil;
551
- NSString *key = nil;
552
- id object = nil;
553
- id metadata = nil;
554
- BOOL result = NO;
555
-
556
509
  int status = sqlite3_step(statement);
557
510
  if (status == SQLITE_ROW)
558
511
  {
559
512
  if (connection->needsMarkSqlLevelSharedReadLock)
560
513
  [connection markSqlLevelSharedReadLockAcquired];
561
514
 
562
- const unsigned char *text0 = sqlite3_column_text(statement, 0);
563
- int textSize0 = sqlite3_column_bytes(statement, 0);
515
+ const void *blob = sqlite3_column_blob(statement, 0);
516
+ int blobSize = sqlite3_column_bytes(statement, 0);
564
517
 
565
- const unsigned char *text1 = sqlite3_column_text(statement, 1);
566
- int textSize1 = sqlite3_column_bytes(statement, 1);
518
+ // Performance tuning:
519
+ // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
567
520
 
568
- collection = [[NSString alloc] initWithBytes:text0 length:textSize0 encoding:NSUTF8StringEncoding];
569
- key = [[NSString alloc] initWithBytes:text1 length:textSize1 encoding:NSUTF8StringEncoding];
521
+ NSData *data = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
522
+ object = connection->database->objectDeserializer(collectionKey.collection, collectionKey.key, data);
570
523
 
571
- YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
524
+ if (object)
525
+ [connection->objectCache setObject:object forKey:collectionKey];
572
526
 
573
- object = [connection->objectCache objectForKey:cacheKey];
574
- if (object == nil)
527
+ const void *mBlob = sqlite3_column_blob(statement, 1);
528
+ int mBlobSize = sqlite3_column_bytes(statement, 1);
529
+
530
+ if (mBlobSize > 0)
575
531
  {
576
- const void *blob = sqlite3_column_blob(statement, 2);
577
- int blobSize = sqlite3_column_bytes(statement, 2);
578
-
579
532
  // Performance tuning:
580
533
  // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
581
534
 
582
- NSData *data = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
583
- object = connection->database->objectDeserializer(collection, key, data);
584
-
585
- if (object)
586
- [connection->objectCache setObject:object forKey:cacheKey];
535
+ NSData *mData = [NSData dataWithBytesNoCopy:(void *)mBlob length:mBlobSize freeWhenDone:NO];
536
+ metadata = connection->database->metadataDeserializer(collectionKey.collection, collectionKey.key, mData);
587
537
  }
588
538
 
589
- metadata = [connection->metadataCache objectForKey:cacheKey];
590
539
  if (metadata)
591
- {
592
- if (metadata == [YapNull null])
593
- metadata = nil;
594
- }
540
+ [connection->metadataCache setObject:metadata forKey:collectionKey];
595
541
  else
596
- {
597
- const void *blob = sqlite3_column_blob(statement, 3);
598
- int blobSize = sqlite3_column_bytes(statement, 3);
599
-
600
- if (blobSize > 0)
601
- {
602
- // Performance tuning:
603
- // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
604
-
605
- NSData *mData = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
606
- metadata = connection->database->metadataDeserializer(collection, key, mData);
607
- }
608
-
609
- if (metadata)
610
- [connection->metadataCache setObject:metadata forKey:cacheKey];
611
- else
612
- [connection->metadataCache setObject:[YapNull null] forKey:cacheKey];
613
- }
614
-
615
- result = YES;
542
+ [connection->metadataCache setObject:[YapNull null] forKey:collectionKey];
616
543
  }
617
544
  else if (status == SQLITE_ERROR)
618
545
  {
@@ -622,14 +549,13 @@
622
549
  sqlite3_clear_bindings(statement);
623
550
  sqlite3_reset(statement);
624
551
 
625
- if (keyPtr) *keyPtr = key;
626
- if (collectionPtr) *collectionPtr = collection;
552
+ if (collectionKeyPtr) *collectionKeyPtr = collectionKey;
627
553
  if (objectPtr) *objectPtr = object;
628
554
  if (metadataPtr) *metadataPtr = metadata;
629
- return result;
555
+ return YES;
630
556
  }
631
557
 
632
- - (BOOL)hasRowForRowid:(int64_t)rowid
558
+ - (BOOL)hasRowid:(int64_t)rowid
633
559
  {
634
560
  sqlite3_stmt *statement = [connection getCountForRowidStatement];
635
561
  if (statement == NULL) return NO;
@@ -661,11 +587,15 @@
661
587
 
662
588
  - (id)objectForKey:(NSString *)key inCollection:(NSString *)collection withRowid:(int64_t)rowid
663
589
  {
664
- if (key == nil) return nil;
665
- if (collection == nil) collection = @"";
666
-
667
590
  YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
668
591
 
592
+ return [self objectForCollectionKey:cacheKey withRowid:rowid];
593
+ }
594
+
595
+ - (id)objectForCollectionKey:(YapCollectionKey *)cacheKey withRowid:(int64_t)rowid
596
+ {
597
+ if (cacheKey == nil) return nil;
598
+
669
599
  id object = [connection->objectCache objectForKey:cacheKey];
670
600
  if (object)
671
601
  return object;
@@ -690,7 +620,7 @@
690
620
  // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
691
621
 
692
622
  NSData *data = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
693
- object = connection->database->objectDeserializer(collection, key, data);
623
+ object = connection->database->objectDeserializer(cacheKey.collection, cacheKey.key, data);
694
624
 
695
625
  if (object)
696
626
  [connection->objectCache setObject:object forKey:cacheKey];
@@ -706,6 +636,57 @@
706
636
  return object;
707
637
  }
708
638
 
639
+ - (id)metadataForKey:(NSString *)key inCollection:(NSString *)collection withRowid:(int64_t)rowid
640
+ {
641
+ YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
642
+
643
+ return [self metadataForCollectionKey:cacheKey withRowid:rowid];
644
+ }
645
+
646
+ - (id)metadataForCollectionKey:(YapCollectionKey *)cacheKey withRowid:(int64_t)rowid
647
+ {
648
+ if (cacheKey == nil) return nil;
649
+
650
+ id metadata = [connection->metadataCache objectForKey:cacheKey];
651
+ if (metadata)
652
+ return metadata;
653
+
654
+ sqlite3_stmt *statement = [connection getMetadataForRowidStatement];
655
+ if (statement == NULL) return nil;
656
+
657
+ // SELECT "metadata" FROM "database2" WHERE "rowid" = ?;
658
+
659
+ sqlite3_bind_int64(statement, 1, rowid);
660
+
661
+ int status = sqlite3_step(statement);
662
+ if (status == SQLITE_ROW)
663
+ {
664
+ if (connection->needsMarkSqlLevelSharedReadLock)
665
+ [connection markSqlLevelSharedReadLockAcquired];
666
+
667
+ const void *blob = sqlite3_column_blob(statement, 0);
668
+ int blobSize = sqlite3_column_bytes(statement, 0);
669
+
670
+ // Performance tuning:
671
+ // Use dataWithBytesNoCopy to avoid an extra allocation and memcpy.
672
+
673
+ NSData *data = [NSData dataWithBytesNoCopy:(void *)blob length:blobSize freeWhenDone:NO];
674
+ metadata = connection->database->metadataDeserializer(cacheKey.collection, cacheKey.key, data);
675
+
676
+ if (metadata)
677
+ [connection->metadataCache setObject:metadata forKey:cacheKey];
678
+ }
679
+ else if (status == SQLITE_ERROR)
680
+ {
681
+ YDBLogError(@"Error executing 'getMetadataForRowidStatement': %d %s", status, sqlite3_errmsg(connection->db));
682
+ }
683
+
684
+ sqlite3_clear_bindings(statement);
685
+ sqlite3_reset(statement);
686
+
687
+ return metadata;
688
+ }
689
+
709
690
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
710
691
  #pragma mark Primitive
711
692
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4140,6 +4121,45 @@
4140
4121
  FreeYapDatabaseString(&_key);
4141
4122
  }
4142
4123
 
4124
+ - (void)removeValueForKey:(NSString *)key extension:(NSString *)extensionName
4125
+ {
4126
+ // Be careful with this statement.
4127
+ //
4128
+ // The snapshot value is in the yap table, and uses an empty string for the extensionName.
4129
+ // The snapshot value is critical to the underlying architecture of the system.
4130
+ // Removing it could cripple the system.
4131
+
4132
+ NSAssert(key != nil, @"Invalid key!");
4133
+ NSAssert(extensionName != nil, @"Invalid extensionName!");
4134
+
4135
+ sqlite3_stmt *statement = [connection yapRemoveForKeyStatement];
4136
+ if (statement == NULL) return;
4137
+
4138
+ // DELETE FROM "yap2" WHERE "extension" = ? AND "key" = ?;
4139
+
4140
+ YapDatabaseString _extension; MakeYapDatabaseString(&_extension, extensionName);
4141
+ sqlite3_bind_text(statement, 1, _extension.str, _extension.length, SQLITE_STATIC);
4142
+
4143
+ YapDatabaseString _key; MakeYapDatabaseString(&_key, key);
4144
+ sqlite3_bind_text(statement, 2, _key.str, _key.length, SQLITE_STATIC);
4145
+
4146
+ int status = sqlite3_step(statement);
4147
+ if (status == SQLITE_DONE)
4148
+ {
4149
+ connection->hasDiskChanges = YES;
4150
+ }
4151
+ else
4152
+ {
4153
+ YDBLogError(@"Error executing 'yapRemoveForKeyStatement': %d %s, extension(%@)",
4154
+ status, sqlite3_errmsg(connection->db), extensionName);
4155
+ }
4156
+
4157
+ sqlite3_clear_bindings(statement);
4158
+ sqlite3_reset(statement);
4159
+ FreeYapDatabaseString(&_extension);
4160
+ FreeYapDatabaseString(&_key);
4161
+ }
4162
+
4143
4163
  - (void)removeAllValuesForExtension:(NSString *)extensionName
4144
4164
  {
4145
4165
  // Be careful with this statement.
@@ -4148,7 +4168,7 @@
4148
4168
  // The snapshot value is critical to the underlying architecture of the system.
4149
4169
  // Removing it could cripple the system.
4150
4170
 
4151
- NSAssert(extensionName != nil, @"Invalid extensionName. Would result in removing snapshot from yap table!");
4171
+ NSAssert(extensionName != nil, @"Invalid extensionName!");
4152
4172
 
4153
4173
  sqlite3_stmt *statement = [connection yapRemoveExtensionStatement];
4154
4174
  if (statement == NULL) return;
@@ -4239,11 +4259,50 @@
4239
4259
  #pragma mark Primitive
4240
4260
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4241
4261
 
4262
+ /**
4263
+ * Primitive access.
4264
+ * This method is available in case you need to store irregular data that
4265
+ * shouldn't go through the configured serializer/deserializer.
4266
+ *
4267
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
4268
+ *
4269
+ * Remember that if you place primitive data into the database via this method,
4270
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
4271
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
4272
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
4273
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
4274
+ *
4275
+ * This method is the primitive version of setObject:forKey:inCollection:.
4276
+ * For more information see the documentation for setObject:forKey:inCollection:.
4277
+ *
4278
+ * @see setObject:forKey:inCollection:
4279
+ * @see primitiveDataForKey:inCollection:
4280
+ **/
4242
4281
  - (void)setPrimitiveData:(NSData *)primitiveData forKey:(NSString *)key inCollection:(NSString *)collection
4243
4282
  {
4244
4283
  [self setPrimitiveData:primitiveData forKey:key inCollection:collection withPrimitiveMetadata:nil];
4245
4284
  }
4246
4285
 
4286
+ /**
4287
+ * Primitive access.
4288
+ * This method is available in case you need to store irregular data that
4289
+ * shouldn't go through the configured serializer/deserializer.
4290
+ *
4291
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
4292
+ *
4293
+ * Remember that if you place primitive data into the database via this method,
4294
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
4295
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
4296
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
4297
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
4298
+ *
4299
+ * This method is the primitive version of setObject:forKey:inCollection:withMetadata:.
4300
+ * For more information see the documentation for setObject:forKey:inCollection:withMetadata:.
4301
+ *
4302
+ * @see setObject:forKey:inCollection:withMetadata:
4303
+ * @see primitiveDataForKey:inCollection:
4304
+ * @see primitiveMetadataForKey:inCollection:
4305
+ **/
4247
4306
  - (void)setPrimitiveData:(NSData *)primitiveData
4248
4307
  forKey:(NSString *)key
4249
4308
  inCollection:(NSString *)collection
@@ -4374,14 +4433,99 @@
4374
4433
 
4375
4434
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4376
4435
  {
4377
- [extTransaction handleRemoveObjectForKey:cacheKey.key // mutable string protection
4378
- inCollection:cacheKey.collection // mutable string protection
4379
- withRowid:rowid];
4436
+ [extTransaction handleRemoveObjectForCollectionKey:cacheKey withRowid:rowid];
4380
4437
  }
4381
4438
  }
4382
4439
  }
4383
4440
 
4384
- - (void)setPrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection
4441
+ /**
4442
+ * Primitive access.
4443
+ * This method is available in case you need to store irregular data that
4444
+ * shouldn't go through the configured serializer/deserializer.
4445
+ *
4446
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
4447
+ *
4448
+ * Remember that if you place primitive data into the database via this method,
4449
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
4450
+ * primitiveDataForKey:inCollection:). If you attempt to access it via the object accessor
4451
+ * (objectForKey:inCollection), then the system will attempt to deserialize the primitive data via the
4452
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
4453
+ *
4454
+ * This method is the primitive version of replaceObject:forKey:inCollection:.
4455
+ * For more information see the documentation for replaceObject:forKey:inCollection:.
4456
+ *
4457
+ * @see replaceObject:forKey:inCollection:
4458
+ * @see primitiveDataForKey:inCollection:
4459
+ **/
4460
+ - (void)replacePrimitiveData:(NSData *)primitiveData forKey:(NSString *)key inCollection:(NSString *)collection
4461
+ {
4462
+ if (primitiveData == nil)
4463
+ {
4464
+ [self removeObjectForKey:key inCollection:collection];
4465
+ return;
4466
+ }
4467
+
4468
+ if (collection == nil) collection = @"";
4469
+
4470
+ int64_t rowid = 0;
4471
+ if (![self getRowid:&rowid forKey:key inCollection:collection]) return;
4472
+
4473
+ sqlite3_stmt *statement = [connection updateObjectForRowidStatement];
4474
+ if (statement == NULL) return;
4475
+
4476
+ // UPDATE "database2" SET "data" = ? WHERE "rowid" = ?;
4477
+
4478
+ sqlite3_bind_blob(statement, 1, primitiveData.bytes, (int)primitiveData.length, SQLITE_STATIC);
4479
+ sqlite3_bind_int64(statement, 2, rowid);
4480
+
4481
+ BOOL updated = YES;
4482
+
4483
+ int status = sqlite3_step(statement);
4484
+ if (status != SQLITE_DONE)
4485
+ {
4486
+ YDBLogError(@"Error executing 'updateObjectForRowidStatement': %d %s",
4487
+ status, sqlite3_errmsg(connection->db));
4488
+ updated = NO;
4489
+ }
4490
+
4491
+ sqlite3_clear_bindings(statement);
4492
+ sqlite3_reset(statement);
4493
+
4494
+ if (!updated) return;
4495
+
4496
+ connection->hasDiskChanges = YES;
4497
+ isMutated = YES; // mutation during enumeration protection
4498
+ YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
4499
+
4500
+ [connection->objectCache removeObjectForKey:cacheKey];
4501
+ [connection->objectChanges setObject:[YapNull null] forKey:cacheKey];
4502
+
4503
+ for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4504
+ {
4505
+ [extTransaction handleRemoveObjectForCollectionKey:cacheKey withRowid:rowid];
4506
+ }
4507
+ }
4508
+
4509
+ /**
4510
+ * Primitive access.
4511
+ * This method is available in case you need to store irregular data that
4512
+ * shouldn't go through the configured serializer/deserializer.
4513
+ *
4514
+ * Primitive data is stored into the database, but doesn't get routed through any of the extensions.
4515
+ *
4516
+ * Remember that if you place primitive data into the database via this method,
4517
+ * you are responsible for accessing it via the appropriate primitive accessor (such as
4518
+ * primitiveMetadataForKey:inCollection:). If you attempt to access it via the object accessor
4519
+ * (metadataForKey:inCollection), then the system will attempt to deserialize the primitive data via the
4520
+ * configured deserializer, which may or may not work depending on the primitive data you're storing.
4521
+ *
4522
+ * This method is the primitive version of replaceMetadata:forKey:inCollection:.
4523
+ * For more information see the documentation for replaceMetadata:forKey:inCollection:.
4524
+ *
4525
+ * @see replaceMetadata:forKey:inCollection:
4526
+ * @see primitiveMetadataForKey:inCollection:
4527
+ **/
4528
+ - (void)replacePrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection
4385
4529
  {
4386
4530
  if (collection == nil) collection = @"";
4387
4531
 
@@ -4392,9 +4536,6 @@
4392
4536
  if (statement == NULL) return;
4393
4537
 
4394
4538
  // UPDATE "database2" SET "metadata" = ? WHERE "rowid" = ?;
4395
- //
4396
- // To use SQLITE_STATIC on our data blob, we use the objc_precise_lifetime attribute.
4397
- // This ensures the data isn't released until it goes out of scope.
4398
4539
 
4399
4540
  sqlite3_bind_blob(statement, 1, primitiveMetadata.bytes, (int)primitiveMetadata.length, SQLITE_STATIC);
4400
4541
  sqlite3_bind_int64(statement, 2, rowid);
@@ -4423,13 +4564,18 @@
4423
4564
 
4424
4565
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4425
4566
  {
4426
- [extTransaction handleUpdateMetadata:nil
4427
- forKey:cacheKey.key // mutable string protection
4428
- inCollection:cacheKey.collection // mutable string protection
4429
- withRowid:rowid];
4567
+ [extTransaction handleReplaceMetadata:nil forCollectionKey:cacheKey withRowid:rowid];
4430
4568
  }
4431
4569
  }
4432
4570
 
4571
+ /**
4572
+ * DEPRECATED: Use replacePrimitiveMetadata:forKey:inCollection: instead.
4573
+ **/
4574
+ - (void)setPrimitiveMetadata:(NSData *)primitiveMetadata forKey:(NSString *)key inCollection:(NSString *)collection
4575
+ {
4576
+ [self replacePrimitiveMetadata:primitiveMetadata forKey:key inCollection:collection];
4577
+ }
4578
+
4433
4579
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4434
4580
  #pragma mark Object & Metadata
4435
4581
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4591,6 +4737,8 @@
4591
4737
  isMutated = YES; // mutation during enumeration protection
4592
4738
  YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
4593
4739
 
4740
+ [connection->keyCache setObject:cacheKey forKey:@(rowid)];
4741
+
4594
4742
  id _object = nil;
4595
4743
  if (connection->objectPolicy == YapDatabasePolicyContainment) {
4596
4744
  _object = [YapNull null];
@@ -4639,25 +4787,138 @@
4639
4787
  {
4640
4788
  if (found)
4641
4789
  [extTransaction handleUpdateObject:object
4642
- forKey:cacheKey.key // mutable string protection
4643
- inCollection:cacheKey.collection // mutable string protection
4790
+ forCollectionKey:cacheKey
4644
4791
  withMetadata:metadata
4645
4792
  rowid:rowid];
4646
4793
  else
4647
4794
  [extTransaction handleInsertObject:object
4648
- forKey:cacheKey.key // mutable string protection
4649
- inCollection:cacheKey.collection // mutable string protection
4795
+ forCollectionKey:cacheKey
4650
4796
  withMetadata:metadata
4651
4797
  rowid:rowid];
4652
4798
  }
4653
4799
  }
4654
4800
 
4655
- - (void)setMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection
4801
+ /**
4802
+ * If a row with the given key/collection exists, then replaces the object for that row with the new value.
4803
+ * It only replaces the object. The metadata for the row doesn't change.
4804
+ *
4805
+ * If there is no row in the database for the given key/collection then this method does nothing.
4806
+ *
4807
+ * If you pass nil for the object, then this method will remove
4808
+ **/
4809
+ - (void)replaceObject:(id)object forKey:(NSString *)key inCollection:(NSString *)collection
4656
4810
  {
4811
+ int64_t rowid = 0;
4812
+ if ([self getRowid:&rowid forKey:key inCollection:collection])
4813
+ {
4814
+ [self replaceObject:object forKey:key inCollection:collection withRowid:rowid];
4815
+ }
4816
+ }
4817
+
4818
+ - (void)replaceObject:(id)object forKey:(NSString *)key inCollection:(NSString *)collection withRowid:(int64_t)rowid
4819
+ {
4820
+ if (object == nil)
4821
+ {
4822
+ [self removeObjectForKey:key inCollection:collection];
4823
+ return;
4824
+ }
4825
+
4826
+ NSAssert(key != nil, @"Internal error");
4657
4827
  if (collection == nil) collection = @"";
4658
4828
 
4829
+ if (connection->database->objectSanitizer)
4830
+ {
4831
+ object = connection->database->objectSanitizer(collection, key, object);
4832
+ if (object == nil)
4833
+ {
4834
+ YDBLogWarn(@"Object sanitizer returned nil for key(%@) object: %@", key, object);
4835
+
4836
+ [self removeObjectForKey:key inCollection:collection withRowid:rowid];
4837
+ return;
4838
+ }
4839
+ }
4840
+
4841
+ sqlite3_stmt *statement = [connection updateObjectForRowidStatement];
4842
+ if (statement == NULL) return;
4843
+
4844
+ // UPDATE "database2" SET "data" = ? WHERE "rowid" = ?;
4845
+ //
4846
+ // To use SQLITE_STATIC on our data blob, we use the objc_precise_lifetime attribute.
4847
+ // This ensures the data isn't released until it goes out of scope.
4848
+
4849
+ __attribute__((objc_precise_lifetime)) NSData *rawData =
4850
+ connection->database->objectSerializer(collection, key, object);
4851
+ sqlite3_bind_blob(statement, 1, rawData.bytes, (int)rawData.length, SQLITE_STATIC);
4852
+
4853
+ sqlite3_bind_int64(statement, 2, rowid);
4854
+
4855
+ BOOL updated = YES;
4856
+
4857
+ int status = sqlite3_step(statement);
4858
+ if (status != SQLITE_DONE)
4859
+ {
4860
+ YDBLogError(@"Error executing 'updateDataForRowidStatement': %d %s",
4861
+ status, sqlite3_errmsg(connection->db));
4862
+ updated = NO;
4863
+ }
4864
+
4865
+ sqlite3_clear_bindings(statement);
4866
+ sqlite3_reset(statement);
4867
+
4868
+ if (!updated) return;
4869
+
4870
+ connection->hasDiskChanges = YES;
4871
+ isMutated = YES; // mutation during enumeration protection
4872
+ YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
4873
+
4874
+ id _object = nil;
4875
+ if (connection->objectPolicy == YapDatabasePolicyContainment) {
4876
+ _object = [YapNull null];
4877
+ }
4878
+ else if (connection->objectPolicy == YapDatabasePolicyShare) {
4879
+ _object = object;
4880
+ }
4881
+ else // if (connection->objectPolicy = YapDatabasePolicyCopy)
4882
+ {
4883
+ if ([object conformsToProtocol:@protocol(NSCopying)])
4884
+ _object = [object copy];
4885
+ else
4886
+ _object = [YapNull null];
4887
+ }
4888
+
4889
+ [connection->objectCache setObject:object forKey:cacheKey];
4890
+ [connection->objectChanges setObject:_object forKey:cacheKey];
4891
+
4892
+ for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4893
+ {
4894
+ [extTransaction handleReplaceObject:object forCollectionKey:cacheKey withRowid:rowid];
4895
+ }
4896
+ }
4897
+
4898
+ /**
4899
+ * If a row with the given key/collection exists, then replaces the metadata for that row with the new value.
4900
+ * It only replaces the metadata. The object for the row doesn't change.
4901
+ *
4902
+ * If there is no row in the database for the given key/collection then this method does nothing.
4903
+ *
4904
+ * If you pass nil for the metadata, any metadata previously associated with the key/collection is removed.
4905
+ **/
4906
+ - (void)replaceMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection
4907
+ {
4659
4908
  int64_t rowid = 0;
4660
- if (![self getRowid:&rowid forKey:key inCollection:collection]) return;
4909
+ if ([self getRowid:&rowid forKey:key inCollection:collection])
4910
+ {
4911
+ [self replaceMetadata:metadata forKey:key inCollection:collection withRowid:rowid];
4912
+ }
4913
+ }
4914
+
4915
+ - (void)replaceMetadata:(id)metadata
4916
+ forKey:(NSString *)key
4917
+ inCollection:(NSString *)collection
4918
+ withRowid:(int64_t)rowid
4919
+ {
4920
+ NSAssert(key != nil, @"Internal error");
4921
+ if (collection == nil) collection = @"";
4661
4922
 
4662
4923
  if (metadata && connection->database->metadataSanitizer)
4663
4924
  {
@@ -4729,13 +4990,18 @@
4729
4990
 
4730
4991
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4731
4992
  {
4732
- [extTransaction handleUpdateMetadata:metadata
4733
- forKey:cacheKey.key // mutable string protection
4734
- inCollection:cacheKey.collection // mutable string protection
4735
- withRowid:rowid];
4993
+ [extTransaction handleReplaceMetadata:metadata forCollectionKey:cacheKey withRowid:rowid];
4736
4994
  }
4737
4995
  }
4738
4996
 
4997
+ /**
4998
+ * DEPRECATED: Use replaceMetadata:forKey:inCollection: instead.
4999
+ **/
5000
+ - (void)setMetadata:(id)metadata forKey:(NSString *)key inCollection:(NSString *)collection
5001
+ {
5002
+ [self replaceMetadata:metadata forKey:key inCollection:collection];
5003
+ }
5004
+
4739
5005
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4740
5006
  #pragma mark Touch
4741
5007
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4757,9 +5023,7 @@
4757
5023
 
4758
5024
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4759
5025
  {
4760
- [extTransaction handleTouchObjectForKey:cacheKey.key // mutable string protection
4761
- inCollection:cacheKey.collection // mutable string protection
4762
- withRowid:rowid];
5026
+ [extTransaction handleTouchObjectForCollectionKey:cacheKey withRowid:rowid];
4763
5027
  }
4764
5028
  }
4765
5029
 
@@ -4777,9 +5041,7 @@
4777
5041
 
4778
5042
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4779
5043
  {
4780
- [extTransaction handleTouchMetadataForKey:cacheKey.key // mutable string protection
4781
- inCollection:cacheKey.collection // mutable string protection
4782
- withRowid:rowid];
5044
+ [extTransaction handleTouchMetadataForCollectionKey:cacheKey withRowid:rowid];
4783
5045
  }
4784
5046
  }
4785
5047
 
@@ -4787,13 +5049,11 @@
4787
5049
  #pragma mark Remove
4788
5050
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4789
5051
 
4790
- - (void)removeObjectForKey:(NSString *)key inCollection:(NSString *)collection
5052
+ - (void)removeObjectForKey:(NSString *)key inCollection:(NSString *)collection withRowid:(int64_t)rowid
4791
5053
  {
5054
+ if (key == nil) return;
4792
5055
  if (collection == nil) collection = @"";
4793
5056
 
4794
- int64_t rowid = 0;
4795
- if (![self getRowid:&rowid forKey:key inCollection:collection]) return;
4796
-
4797
5057
  sqlite3_stmt *statement = [connection removeForRowidStatement];
4798
5058
  if (statement == NULL) return;
4799
5059
 
@@ -4819,19 +5079,29 @@
4819
5079
  connection->hasDiskChanges = YES;
4820
5080
  isMutated = YES; // mutation during enumeration protection
4821
5081
  YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
5082
+ NSNumber *rowidNumber = @(rowid);
4822
5083
 
5084
+ [connection->keyCache removeObjectForKey:rowidNumber];
4823
5085
  [connection->objectCache removeObjectForKey:cacheKey];
4824
5086
  [connection->metadataCache removeObjectForKey:cacheKey];
4825
5087
 
4826
5088
  [connection->objectChanges removeObjectForKey:cacheKey];
4827
5089
  [connection->metadataChanges removeObjectForKey:cacheKey];
4828
5090
  [connection->removedKeys addObject:cacheKey];
5091
+ [connection->removedRowids addObject:rowidNumber];
4829
5092
 
4830
5093
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
4831
5094
  {
4832
- [extTransaction handleRemoveObjectForKey:cacheKey.key // mutable string protection
4833
- inCollection:cacheKey.collection // mutable string protection
4834
- withRowid:rowid];
5095
+ [extTransaction handleRemoveObjectForCollectionKey:cacheKey withRowid:rowid];
5096
+ }
5097
+ }
5098
+
5099
+ - (void)removeObjectForKey:(NSString *)key inCollection:(NSString *)collection
5100
+ {
5101
+ int64_t rowid = 0;
5102
+ if ([self getRowid:&rowid forKey:key inCollection:collection])
5103
+ {
5104
+ [self removeObjectForKey:key inCollection:collection withRowid:rowid];
4835
5105
  }
4836
5106
  }
4837
5107
 
@@ -4998,6 +5268,9 @@
4998
5268
  connection->hasDiskChanges = YES;
4999
5269
  isMutated = YES; // mutation during enumeration protection
5000
5270
 
5271
+ [connection->keyCache removeObjectsForKeys:foundRowids];
5272
+ [connection->removedRowids addObjectsFromArray:foundRowids];
5273
+
5001
5274
  for (NSString *key in foundKeys)
5002
5275
  {
5003
5276
  YapCollectionKey *cacheKey = [[YapCollectionKey alloc] initWithCollection:collection key:key];
@@ -5038,38 +5311,82 @@
5038
5311
 
5039
5312
  // Purge the caches and changesets
5040
5313
 
5041
- NSMutableArray *keysToRemove = [NSMutableArray array];
5314
+ NSMutableArray *toRemove = [NSMutableArray array];
5042
5315
 
5043
- void(^block)(id, BOOL*) = ^void (id key, BOOL *stop) {
5316
+ { // keyCache
5044
5317
 
5045
- __unsafe_unretained YapCollectionKey *cacheKey = (YapCollectionKey *)key;
5046
- if ([cacheKey.collection isEqualToString:collection])
5047
- {
5048
- [keysToRemove addObject:cacheKey];
5049
- }
5050
- };
5051
-
5052
- [connection->objectCache enumerateKeysWithBlock:block];
5053
- [connection->objectCache removeObjectsForKeys:keysToRemove];
5054
-
5055
- [keysToRemove removeAllObjects];
5056
-
5057
- for (id key in [connection->objectChanges keyEnumerator]) {
5058
- block(key, NULL);
5318
+ [connection->keyCache enumerateKeysAndObjectsWithBlock:^(id key, id obj, BOOL *stop) {
5319
+
5320
+ __unsafe_unretained NSNumber *rowidNumber = (NSNumber *)key;
5321
+ __unsafe_unretained YapCollectionKey *collectionKey = (YapCollectionKey *)obj;
5322
+ if ([collectionKey.collection isEqualToString:collection])
5323
+ {
5324
+ [toRemove addObject:rowidNumber];
5325
+ }
5326
+ }];
5327
+
5328
+ [connection->keyCache removeObjectsForKeys:toRemove];
5329
+ [toRemove removeAllObjects];
5059
5330
  }
5060
- [connection->objectChanges removeObjectsForKeys:keysToRemove];
5061
5331
 
5062
- [keysToRemove removeAllObjects];
5332
+ { // objectCache
5333
+
5334
+ [connection->objectCache enumerateKeysWithBlock:^(id key, BOOL *stop) {
5335
+
5336
+ __unsafe_unretained YapCollectionKey *cacheKey = (YapCollectionKey *)key;
5337
+ if ([cacheKey.collection isEqualToString:collection])
5338
+ {
5339
+ [toRemove addObject:cacheKey];
5340
+ }
5341
+ }];
5342
+
5343
+ [connection->objectCache removeObjectsForKeys:toRemove];
5344
+ [toRemove removeAllObjects];
5345
+ }
5063
5346
 
5064
- [connection->metadataCache enumerateKeysWithBlock:block];
5065
- [connection->metadataCache removeObjectsForKeys:keysToRemove];
5347
+ { // objectChanges
5348
+
5349
+ for (id key in [connection->objectChanges keyEnumerator])
5350
+ {
5351
+ __unsafe_unretained YapCollectionKey *cacheKey = (YapCollectionKey *)key;
5352
+ if ([cacheKey.collection isEqualToString:collection])
5353
+ {
5354
+ [toRemove addObject:cacheKey];
5355
+ }
5356
+ }
5357
+
5358
+ [connection->objectChanges removeObjectsForKeys:toRemove];
5359
+ [toRemove removeAllObjects];
5360
+ }
5066
5361
 
5067
- [keysToRemove removeAllObjects];
5362
+ { // metadataCache
5363
+
5364
+ [connection->metadataCache enumerateKeysWithBlock:^(id key, BOOL *stop) {
5365
+
5366
+ __unsafe_unretained YapCollectionKey *cacheKey = (YapCollectionKey *)key;
5367
+ if ([cacheKey.collection isEqualToString:collection])
5368
+ {
5369
+ [toRemove addObject:cacheKey];
5370
+ }
5371
+ }];
5372
+
5373
+ [connection->metadataCache removeObjectsForKeys:toRemove];
5374
+ [toRemove removeAllObjects];
5375
+ }
5068
5376
 
5069
- for (id key in [connection->metadataChanges keyEnumerator]) {
5070
- block(key, NULL);
5377
+ { // metadataChanges
5378
+
5379
+ for (id key in [connection->metadataChanges keyEnumerator])
5380
+ {
5381
+ __unsafe_unretained YapCollectionKey *cacheKey = (YapCollectionKey *)key;
5382
+ if ([cacheKey.collection isEqualToString:collection])
5383
+ {
5384
+ [toRemove addObject:cacheKey];
5385
+ }
5386
+ }
5387
+
5388
+ [connection->metadataChanges removeObjectsForKeys:toRemove];
5071
5389
  }
5072
- [connection->metadataChanges removeObjectsForKeys:keysToRemove];
5073
5390
 
5074
5391
  [connection->removedCollections addObject:collection];
5075
5392
 
@@ -5230,6 +5547,8 @@
5230
5547
  connection->hasDiskChanges = YES;
5231
5548
  isMutated = YES; // mutation during enumeration protection
5232
5549
 
5550
+ [connection->removedRowids addObjectsFromArray:foundRowids];
5551
+
5233
5552
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])
5234
5553
  {
5235
5554
  [extTransaction handleRemoveObjectsForKeys:foundKeys
@@ -5271,6 +5590,7 @@
5271
5590
  [connection->metadataChanges removeAllObjects];
5272
5591
  [connection->removedKeys removeAllObjects];
5273
5592
  [connection->removedCollections removeAllObjects];
5593
+ [connection->removedRowids removeAllObjects];
5274
5594
  connection->allKeysRemoved = YES;
5275
5595
 
5276
5596
  for (id <YapDatabaseExtensionTransaction_Hooks> extTransaction in [self orderedExtensions])