rhodes 1.5.5 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (529) hide show
  1. data/CHANGELOG +5 -0
  2. data/Manifest.txt +214 -32
  3. data/Rakefile +33 -10
  4. data/bin/upgrade-rhodes-app +0 -1
  5. data/lib/build/compileERB/bb.rb +2 -2
  6. data/lib/build/compileERB/default.rb +7 -5
  7. data/lib/build/jake.rb +1 -1
  8. data/lib/extensions/digest-md5/ext.yml +1 -1
  9. data/lib/extensions/digest-md5/ext/Rakefile +35 -36
  10. data/lib/extensions/digest-md5/ext/build.bat +1 -0
  11. data/lib/extensions/digest-md5/ext/digest-md5.vcproj +203 -0
  12. data/lib/extensions/digest-sha1/ext.yml +1 -1
  13. data/lib/extensions/digest/ext.yml +1 -1
  14. data/lib/extensions/digest/ext/Rakefile +35 -39
  15. data/lib/extensions/digest/ext/build.bat +1 -2
  16. data/lib/extensions/digest/ext/digest.vcproj +203 -0
  17. data/lib/framework/rho/render.rb +79 -22
  18. data/lib/framework/rho/rho.rb +294 -56
  19. data/lib/framework/rho/rhoapplication.rb +10 -0
  20. data/lib/framework/rho/rhofsconnector.rb +2 -6
  21. data/lib/framework/rho/rhoutils.rb +56 -14
  22. data/lib/framework/rho/rhoviewhelpers.rb +2 -0
  23. data/lib/framework/rhodes.rb +2 -2
  24. data/lib/framework/rhom/rhom.rb +42 -15
  25. data/lib/framework/rhom/rhom_db_adapter.rb +165 -159
  26. data/lib/framework/rhom/rhom_object.rb +0 -1
  27. data/lib/framework/rhom/rhom_object_factory.rb +343 -166
  28. data/lib/framework/rhom/rhom_source.rb +28 -15
  29. data/lib/framework/version.rb +2 -2
  30. data/lib/rhodes.rb +2 -2
  31. data/platform/android/Rhodes/AndroidManifest.xml +2 -2
  32. data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +39 -44
  33. data/platform/android/Rhodes/jni/include/JNIRhodes.h +1 -1
  34. data/platform/android/Rhodes/jni/include/details/rhojava.inc +23 -20
  35. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_RhoMenu.h +61 -0
  36. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_Rhodes.h +16 -0
  37. data/platform/android/Rhodes/jni/include/jni/com_rhomobile_rhodes_alert_Alert.h +21 -0
  38. data/platform/android/Rhodes/jni/include/sslimpl.h +1 -1
  39. data/platform/android/Rhodes/jni/src/alert.cpp +32 -5
  40. data/platform/android/Rhodes/jni/src/callbacks.cpp +51 -21
  41. data/platform/android/Rhodes/jni/src/mapview.cpp +3 -8
  42. data/platform/android/Rhodes/jni/src/menu.cpp +70 -0
  43. data/platform/android/Rhodes/jni/src/navbar.cpp +16 -0
  44. data/platform/android/Rhodes/jni/src/rhodes.cpp +37 -0
  45. data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -3
  46. data/platform/android/Rhodes/jni/src/webview.cpp +21 -7
  47. data/platform/android/Rhodes/res/drawable/alert_alert.png +0 -0
  48. data/platform/android/Rhodes/res/drawable/alert_info.png +0 -0
  49. data/platform/android/Rhodes/res/drawable/alert_question.png +0 -0
  50. data/platform/android/Rhodes/res/drawable/camera.png +0 -0
  51. data/platform/android/Rhodes/res/layout/camera.xml +18 -3
  52. data/platform/android/Rhodes/res/menu/options.xml +0 -10
  53. data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +5 -10
  54. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +12 -0
  55. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java +105 -0
  56. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +157 -122
  57. data/platform/android/Rhodes/src/com/rhomobile/rhodes/SplashScreen.java +7 -58
  58. data/platform/android/Rhodes/src/com/rhomobile/rhodes/WebView.java +16 -0
  59. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +220 -17
  60. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java +22 -4
  61. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +44 -25
  62. data/platform/android/Rhodes/src/com/rhomobile/rhodes/geolocation/GeoLocation.java +10 -0
  63. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/MainView.java +3 -0
  64. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +10 -21
  65. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +15 -12
  66. data/platform/android/Rhodes/src/com/rhomobile/rhodes/phonebook/Phonebook.java +44 -0
  67. data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +47 -3
  68. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +13 -6
  69. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/TelUriHandler.java +11 -5
  70. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/UriHandler.java +1 -4
  71. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/VideoUriHandler.java +61 -0
  72. data/platform/android/build/RhodesSRC_build.files +3 -0
  73. data/platform/android/build/android.rake +173 -60
  74. data/platform/android/build/androidcommon.rb +1 -2
  75. data/platform/android/build/librhocommon_build.files +5 -0
  76. data/platform/android/build/librhodes_build.files +2 -0
  77. data/platform/android/build/libruby_build.files +2 -1
  78. data/platform/bb/Hsqldb/Hsqldb.jdp +0 -3
  79. data/platform/bb/Hsqldb/src/com/rho/db/FileUtilBB.java +1 -1
  80. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +16 -1
  81. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +5 -0
  82. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +25 -4
  83. data/platform/bb/Hsqldb/src/com/rho/db/Journal.java +1 -1
  84. data/platform/bb/Hsqldb/src/com/rho/file/FileAccessBB.java +0 -1
  85. data/platform/bb/Hsqldb/src/j2me/math/Number.java +6 -3
  86. data/platform/bb/Hsqldb/src/org/hsqldb/CompiledStatementExecutor.java +2 -1
  87. data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +1 -0
  88. data/platform/bb/Hsqldb/src/org/hsqldb/Parser.java +1 -0
  89. data/platform/bb/Hsqldb/src/org/hsqldb/Result.java +2 -0
  90. data/platform/bb/Hsqldb/src/org/hsqldb/Select.java +12 -6
  91. data/platform/bb/Hsqldb/src/org/hsqldb/Session.java +19 -12
  92. data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +10 -4
  93. data/platform/bb/Hsqldb/src/org/hsqldb/Token.java +10 -2
  94. data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +3 -3
  95. data/platform/bb/Hsqldb/src/org/hsqldb/lib/java/JavaSystem.java +1 -1
  96. data/platform/bb/Hsqldb/src/org/hsqldb/persist/HsqlProperties.java +2 -1
  97. data/platform/bb/Hsqldb/src/org/hsqldb/persist/ScaledRAFile.java +1 -1
  98. data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptReaderText.java +1 -1
  99. data/platform/bb/Hsqldb/src/org/hsqldb/scriptio/ScriptWriterBase.java +1 -1
  100. data/platform/bb/RubyVM/RubyVM.jdp +9 -10
  101. data/platform/bb/build/RubyVM_build.files +9 -7
  102. data/platform/bb/build/bb.rake +13 -3
  103. data/platform/bb/build/hsqldb_build.files +0 -2
  104. data/platform/bb/build/rhodes_build.files +5 -2
  105. data/platform/bb/rhodes/platform/4.7/com/rho/RhoMainScreen.java +8 -0
  106. data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +154 -0
  107. data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +8 -0
  108. data/platform/bb/rhodes/platform/common/com/rho/BrowserAdapter5.java +28 -0
  109. data/platform/bb/rhodes/rhodes.jdp +12 -7
  110. data/platform/bb/rhodes/src/com/rho/BrowserAdapter.java +331 -0
  111. data/platform/bb/rhodes/src/com/rho/BrowserAdapter5.java +28 -0
  112. data/platform/bb/rhodes/src/com/rho/IBrowserAdapter.java +10 -0
  113. data/platform/bb/rhodes/src/com/rho/RhoMainScreen.java +4 -0
  114. data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +2 -4
  115. data/platform/bb/rhodes/src/com/rho/{Jsr75File.java → file/Jsr75File.java} +83 -36
  116. data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/Jsr75RAFileImpl.java +0 -1
  117. data/platform/bb/{Hsqldb → rhodes}/src/com/rho/file/PersistRAFileImpl.java +0 -2
  118. data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +8 -10
  119. data/platform/bb/rhodes/src/com/rho/rubyext/Alert.java +1 -1
  120. data/platform/bb/rhodes/src/com/rho/rubyext/GeoLocation.java +39 -0
  121. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +63 -2
  122. data/platform/bb/rhodes/src/com/rho/rubyext/WebView.java +100 -0
  123. data/platform/bb/rhodes/src/rhomobile/LogScreen.java +1 -1
  124. data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +13 -1
  125. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +138 -492
  126. data/platform/bb/rhodes/src/rhomobile/SecondaryResourceFetchThread.java +11 -2
  127. data/platform/bb/rhodes/src/rhomobile/Utilities.java +14 -10
  128. data/platform/bb/rhodes/src/rhomobile/camera/CameraScreen.java +5 -14
  129. data/platform/bb/rhodes/src/rhomobile/camera/ImageBrowserScreen.java +1 -1
  130. data/platform/bb/rhodes/src/rhomobile/mapview/GoogleMapField.java +2 -2
  131. data/platform/iphone/Classes/AppManager/AppManager.m +37 -14
  132. data/platform/iphone/Classes/Camera/PickImageDelegate.h +15 -4
  133. data/platform/iphone/Classes/Camera/PickImageDelegate.m +53 -50
  134. data/platform/iphone/Classes/DateTimePicker.h +17 -0
  135. data/platform/iphone/Classes/DateTimePicker.m +35 -0
  136. data/platform/iphone/Classes/GeoLocation/LocationController.m +2 -3
  137. data/platform/iphone/Classes/LogOptionsController.m +3 -2
  138. data/platform/iphone/Classes/LogViewController.m +4 -2
  139. data/platform/iphone/Classes/MapView/GoogleGeocoder.m +12 -20
  140. data/platform/iphone/Classes/MapView/MapAnnotation.h +9 -13
  141. data/platform/iphone/Classes/MapView/MapAnnotation.m +17 -65
  142. data/platform/iphone/Classes/MapView/MapViewController.h +1 -7
  143. data/platform/iphone/Classes/MapView/MapViewController.m +51 -25
  144. data/platform/iphone/Classes/NativeBar.h +0 -12
  145. data/platform/iphone/Classes/NativeBar.m +121 -2
  146. data/platform/iphone/Classes/NavBar.h +16 -0
  147. data/platform/iphone/Classes/NavBar.m +115 -0
  148. data/platform/iphone/Classes/RhoAlert.h +19 -0
  149. data/platform/iphone/Classes/RhoAlert.m +258 -0
  150. data/platform/iphone/Classes/RhoDelegate.m +1 -0
  151. data/platform/iphone/Classes/RhoMainView.h +33 -0
  152. data/platform/iphone/Classes/Rhodes.h +56 -0
  153. data/platform/iphone/Classes/Rhodes.m +533 -0
  154. data/platform/iphone/Classes/RingtoneManager.h +17 -0
  155. data/platform/iphone/Classes/RingtoneManager.m +73 -0
  156. data/platform/iphone/Classes/SimpleMainView.h +30 -0
  157. data/platform/iphone/Classes/SimpleMainView.m +380 -0
  158. data/platform/iphone/Classes/TabbedMainView.h +24 -0
  159. data/platform/iphone/Classes/TabbedMainView.m +202 -0
  160. data/platform/iphone/Classes/WebView.m +123 -0
  161. data/platform/iphone/Classes/rho/net/NetRequestImpl.m +2 -2
  162. data/platform/iphone/Classes/rho/net/sslimpl.cpp +13 -1
  163. data/platform/iphone/Classes/rho/net/sslimpl.h +1 -1
  164. data/platform/iphone/Info.plist +1 -1
  165. data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +44 -0
  166. data/platform/iphone/main.m +1 -2
  167. data/platform/iphone/rbuild/iphone.rake +8 -16
  168. data/platform/iphone/rhoextlib/dosyscall.c +1 -1
  169. data/platform/iphone/rhoextlib/rhoextlib.xcodeproj/project.pbxproj +6 -4
  170. data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +12 -0
  171. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +97 -62
  172. data/platform/iphone/rhosynclib/rhosynclib.xcodeproj/project.pbxproj +12 -0
  173. data/platform/osx/Rhodes Launcher/launch.rb +14 -21
  174. data/platform/shared/common/AppMenu.cpp +122 -0
  175. data/platform/shared/common/AppMenu.h +46 -0
  176. data/platform/shared/common/PosixThreadImpl.cpp +1 -1
  177. data/platform/shared/common/RhoConf.cpp +27 -2
  178. data/platform/shared/common/RhoConf.h +5 -0
  179. data/platform/shared/common/RhoFilePath.h +21 -0
  180. data/platform/shared/common/RhoStd.h +44 -5
  181. data/platform/shared/common/RhoTime.h +20 -7
  182. data/platform/shared/common/RhodesApp.cpp +236 -177
  183. data/platform/shared/common/RhodesApp.h +36 -13
  184. data/platform/shared/common/SplashScreen.cpp +2 -2
  185. data/platform/shared/common/StringConverter.h +10 -11
  186. data/platform/shared/common/rhoparams.c +0 -6
  187. data/platform/shared/curl/lib/rhossl.c +3 -2
  188. data/platform/shared/curl/lib/url.c +0 -5
  189. data/platform/shared/db/DBAdapter.cpp +304 -81
  190. data/platform/shared/db/DBAdapter.h +24 -7
  191. data/platform/shared/db/DBAttrManager.cpp +83 -30
  192. data/platform/shared/db/DBAttrManager.h +6 -0
  193. data/platform/shared/db/DBResult.h +15 -4
  194. data/platform/shared/json/JSONIterator.cpp +100 -3
  195. data/platform/shared/json/JSONIterator.h +28 -3
  196. data/platform/shared/net/AsyncHttp.cpp +25 -22
  197. data/platform/shared/net/AsyncHttp.h +10 -6
  198. data/platform/shared/net/CURLNetRequest.cpp +115 -36
  199. data/platform/shared/net/CURLNetRequest.h +6 -0
  200. data/platform/shared/net/HttpServer.cpp +6 -4
  201. data/platform/shared/net/HttpServer.h +0 -1
  202. data/platform/shared/net/INetRequest.h +19 -3
  203. data/platform/shared/net/URI.cpp +2 -2
  204. data/platform/shared/net/ssl.cpp +2 -2
  205. data/platform/shared/net/ssl.h +2 -2
  206. data/platform/shared/ruby/ext/alert/alert.i +14 -2
  207. data/platform/shared/ruby/ext/alert/alert_wrap.c +40 -20
  208. data/platform/shared/ruby/ext/asynchttp/asynchttp.i +8 -8
  209. data/platform/shared/ruby/ext/asynchttp/asynchttp_wrap.c +112 -16
  210. data/platform/shared/ruby/ext/geolocation/geolocation.i +16 -12
  211. data/platform/shared/ruby/ext/geolocation/geolocation_wrap.c +481 -125
  212. data/platform/shared/ruby/ext/navbar/navbar.i +20 -0
  213. data/platform/shared/ruby/ext/navbar/navbar_wrap.c +1859 -0
  214. data/platform/shared/ruby/ext/rho/extensions.c +1 -1
  215. data/platform/shared/ruby/ext/rho/rhoruby.c +32 -2
  216. data/platform/shared/ruby/ext/rho/rhoruby.h +7 -2
  217. data/platform/shared/ruby/ext/rhoconf/rhoconf.i +4 -0
  218. data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +31 -0
  219. data/platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c +188 -3226
  220. data/platform/shared/ruby/ext/syncengine/syncengine.i +14 -25
  221. data/platform/shared/ruby/ext/syncengine/syncengine_wrap.c +96 -104
  222. data/platform/shared/ruby/ext/system/system.i +12 -0
  223. data/platform/shared/ruby/ext/system/system_wrap.c +101 -7
  224. data/platform/shared/ruby/ext/webview/webview.i +20 -15
  225. data/platform/shared/ruby/ext/webview/webview_wrap.c +42 -16
  226. data/platform/shared/ruby/thread_pthread.c +4 -4
  227. data/platform/shared/ruby/thread_win32.c +4 -4
  228. data/platform/shared/ruby/wince/io_wce.c +0 -1
  229. data/platform/shared/rubyJVM/src/com/rho/FilePath.java +18 -2
  230. data/platform/shared/rubyJVM/src/com/rho/IRhoRubyHelper.java +1 -0
  231. data/platform/shared/rubyJVM/src/com/rho/Properties.java +9 -0
  232. data/platform/shared/rubyJVM/src/com/rho/RhoClassFactory.java +2 -3
  233. data/platform/shared/rubyJVM/src/com/rho/RhoConf.java +47 -8
  234. data/platform/shared/rubyJVM/src/com/rho/RhoLogConf.java +1 -0
  235. data/platform/shared/rubyJVM/src/com/rho/RhoLogFileSink.java +1 -0
  236. data/platform/shared/rubyJVM/src/com/rho/RhoRuby.java +43 -5
  237. data/platform/shared/rubyJVM/src/com/rho/RhodesApp.java +98 -3
  238. data/platform/shared/rubyJVM/src/com/rho/db/DBAdapter.java +460 -175
  239. data/platform/shared/rubyJVM/src/com/rho/db/DBAttrManager.java +81 -33
  240. data/platform/shared/rubyJVM/src/com/rho/db/IDBCallback.java +3 -5
  241. data/platform/shared/rubyJVM/src/com/rho/db/IDBResult.java +2 -0
  242. data/platform/shared/rubyJVM/src/com/rho/db/IDBStorage.java +2 -0
  243. data/platform/shared/rubyJVM/src/com/rho/{IFile.java → file/IFile.java} +1 -1
  244. data/platform/shared/rubyJVM/src/com/rho/{IFileAccess.java → file/IFileAccess.java} +1 -1
  245. data/platform/shared/rubyJVM/src/com/rho/{IRAFile.java → file/IRAFile.java} +1 -1
  246. data/platform/{bb/Hsqldb/src/com/rho/db → shared/rubyJVM/src/com/rho/file}/RandomAccessFile.java +1 -2
  247. data/platform/shared/rubyJVM/src/com/rho/{SimpleFile.java → file/SimpleFile.java} +5 -1
  248. data/platform/shared/rubyJVM/src/com/rho/net/AsyncHttp.java +23 -18
  249. data/platform/shared/rubyJVM/src/com/rho/net/NetRequest.java +167 -250
  250. data/platform/shared/rubyJVM/src/com/rho/net/RhoConnection.java +100 -30
  251. data/platform/shared/rubyJVM/src/com/rho/net/URI.java +0 -1
  252. data/platform/shared/rubyJVM/src/com/rho/sync/ClientRegister.java +30 -33
  253. data/platform/shared/rubyJVM/src/com/rho/sync/ISyncProtocol.java +20 -0
  254. data/platform/shared/rubyJVM/src/com/rho/sync/JSONEntry.java +5 -0
  255. data/platform/shared/rubyJVM/src/com/rho/sync/JSONStructIterator.java +74 -0
  256. data/platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java +486 -257
  257. data/platform/shared/rubyJVM/src/com/rho/sync/SyncNotify.java +89 -58
  258. data/platform/shared/rubyJVM/src/com/rho/sync/SyncProtocol_3.java +79 -0
  259. data/platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java +634 -495
  260. data/platform/shared/rubyJVM/src/com/rho/sync/SyncThread.java +74 -90
  261. data/platform/shared/rubyJVM/src/com/xruby/GeneratedMethods/RubySymbol_Methods.java +1 -0
  262. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyThread.java +6 -0
  263. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyRuntime.java +6 -2
  264. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubySymbol.java +17 -1
  265. data/platform/shared/rubyJVM/src/com/xruby/runtime/lang/RubyValue.java +1 -0
  266. data/platform/shared/rubyJVM/src/org/json/me/JSONObject.java +3 -0
  267. data/platform/shared/rubyext/GeoLocation.cpp +23 -0
  268. data/platform/shared/rubyext/GeoLocation.h +2 -0
  269. data/platform/shared/rubyext/RhoRuby.cpp +31 -0
  270. data/platform/shared/rubyext/RhoRuby.h +32 -0
  271. data/platform/shared/rubyext/System.cpp +14 -3
  272. data/platform/shared/rubyext/WebView.h +21 -0
  273. data/platform/shared/sync/ClientRegister.cpp +23 -28
  274. data/platform/shared/sync/ClientRegister.h +6 -2
  275. data/platform/shared/sync/ISyncProtocol.h +29 -0
  276. data/platform/shared/sync/SyncEngine.cpp +450 -190
  277. data/platform/shared/sync/SyncEngine.h +28 -38
  278. data/platform/shared/sync/SyncNotify.cpp +43 -41
  279. data/platform/shared/sync/SyncNotify.h +7 -7
  280. data/platform/shared/sync/SyncProtocol_3.h +86 -0
  281. data/platform/shared/sync/SyncSource.cpp +535 -371
  282. data/platform/shared/sync/SyncSource.h +48 -55
  283. data/platform/shared/sync/SyncThread.cpp +59 -103
  284. data/platform/shared/sync/SyncThread.h +10 -23
  285. data/platform/shared/unzip/unzip.cpp +3 -2
  286. data/platform/shared/unzip/unzip.h +5 -1
  287. data/platform/shared/wtl80/include/atlapp.h +10 -10
  288. data/platform/wm/RhoLib/RhoLib.vcproj +32 -0
  289. data/platform/wm/build/build_inf.js +40 -3
  290. data/platform/wm/build/wm.rake +95 -9
  291. data/platform/wm/rhodes/Alert.cpp +4 -0
  292. data/platform/wm/rhodes/DateTimePicker.cpp +183 -0
  293. data/platform/wm/rhodes/DateTimePicker.h +100 -0
  294. data/platform/wm/rhodes/MainWindow.cpp +222 -209
  295. data/platform/wm/rhodes/MainWindow.h +28 -35
  296. data/platform/wm/rhodes/Rhodes.cpp +20 -60
  297. data/platform/wm/rhodes/Rhodes.rc +41 -7
  298. data/platform/wm/rhodes/Utils.cpp +65 -0
  299. data/platform/wm/rhodes/Utils.h +9 -0
  300. data/platform/wm/rhodes/camera/Camera.cpp +2 -2
  301. data/platform/wm/rhodes/menubar.cpp +2 -33
  302. data/platform/wm/rhodes/menubar.h +0 -14
  303. data/platform/wm/rhodes/resource.h +13 -11
  304. data/platform/wm/rhodes/rho/net/NetRequest.cpp +16 -35
  305. data/platform/wm/rhodes/rho/net/NetRequest.h +8 -2
  306. data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +264 -46
  307. data/platform/wm/rhodes/rho/net/NetRequestImpl.h +14 -4
  308. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.cpp +1 -1
  309. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.h +1 -1
  310. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +77 -4
  311. data/platform/wm/rhodes/rho/rubyext/WebView.cpp +63 -0
  312. data/platform/wm/rhodes/rhodes.vcproj +20 -66
  313. data/platform/wm/rhodes/stdafx.h +22 -0
  314. data/platform/wm/rubylib/rubylib.vcproj +4 -0
  315. data/platform/wm/syncengine/syncengine.vcproj +8 -0
  316. data/platform/wm/tools/detool.sln +66 -0
  317. data/platform/wm/tools/detool/DEMComInterface.tlb +0 -0
  318. data/platform/wm/tools/detool/ReadMe.txt +33 -0
  319. data/platform/wm/tools/detool/detool.cpp +559 -0
  320. data/platform/wm/tools/detool/detool.h +5 -0
  321. data/platform/wm/tools/detool/detool.vcproj +233 -0
  322. data/platform/wm/tools/detool/stdafx.cpp +8 -0
  323. data/platform/wm/tools/detool/stdafx.h +15 -0
  324. data/platform/wm/tools/detool/targetver.h +24 -0
  325. data/platform/wm/tools/rhosetup/ReadMe.txt +41 -0
  326. data/platform/wm/tools/rhosetup/rhosetup.cpp +52 -0
  327. data/platform/wm/tools/rhosetup/rhosetup.vcproj +641 -0
  328. data/platform/wm/tools/rhosetup/stdafx.cpp +8 -0
  329. data/platform/wm/tools/rhosetup/stdafx.h +59 -0
  330. data/rakefile.rb +33 -10
  331. data/res/build-tools/db/syncdb.schema +25 -23
  332. data/res/build-tools/db/syncdb.triggers +1 -1
  333. data/res/build-tools/detool.exe +0 -0
  334. data/res/build-tools/rhosetup.dll +0 -0
  335. data/res/generators/rhogen.rb +27 -22
  336. data/res/generators/templates/application/app/Settings/controller.rb +3 -1
  337. data/res/generators/templates/application/app/Settings/home.bb.erb +17 -0
  338. data/res/generators/templates/application/app/Settings/home.erb +21 -12
  339. data/res/generators/templates/application/app/Settings/index.bb.erb +32 -0
  340. data/res/generators/templates/application/app/Settings/index.erb +44 -15
  341. data/res/generators/templates/application/app/Settings/login.bb.erb +35 -0
  342. data/res/generators/templates/application/app/Settings/login.erb +29 -30
  343. data/res/generators/templates/application/app/Settings/reset.bb.erb +15 -0
  344. data/res/generators/templates/application/app/Settings/reset.erb +16 -13
  345. data/res/generators/templates/application/app/Settings/wait.bb.erb +3 -0
  346. data/res/generators/templates/application/app/Settings/wait.erb +4 -4
  347. data/res/generators/templates/application/app/application.rb +8 -0
  348. data/res/generators/templates/application/app/helpers/browser_helper.rb +13 -0
  349. data/res/generators/templates/application/app/index.bb.erb +26 -0
  350. data/res/generators/templates/application/app/index.erb +21 -12
  351. data/res/generators/templates/application/app/layout.erb +9 -11
  352. data/res/generators/templates/application/public/css/android.css +285 -0
  353. data/res/generators/templates/application/public/css/blackberry.css +85 -78
  354. data/res/generators/templates/application/public/css/iphone.css +286 -296
  355. data/res/generators/templates/application/public/css/webkit.css +34 -0
  356. data/res/generators/templates/application/public/css/windows_mobile.css +208 -0
  357. data/res/generators/templates/application/public/icons/Read me first - license.txt +14 -0
  358. data/res/generators/templates/application/public/icons/about.png +0 -0
  359. data/res/generators/templates/application/public/icons/airplane.png +0 -0
  360. data/res/generators/templates/application/public/icons/baby.png +0 -0
  361. data/res/generators/templates/application/public/icons/badge.png +0 -0
  362. data/res/generators/templates/application/public/icons/bandaid.png +0 -0
  363. data/res/generators/templates/application/public/icons/bar-chart.png +0 -0
  364. data/res/generators/templates/application/public/icons/battery.png +0 -0
  365. data/res/generators/templates/application/public/icons/beaker.png +0 -0
  366. data/res/generators/templates/application/public/icons/beaker2.png +0 -0
  367. data/res/generators/templates/application/public/icons/beermug.png +0 -0
  368. data/res/generators/templates/application/public/icons/bird.png +0 -0
  369. data/res/generators/templates/application/public/icons/book.png +0 -0
  370. data/res/generators/templates/application/public/icons/bookmark.png +0 -0
  371. data/res/generators/templates/application/public/icons/brightness.png +0 -0
  372. data/res/generators/templates/application/public/icons/bug.png +0 -0
  373. data/res/generators/templates/application/public/icons/cabinet.png +0 -0
  374. data/res/generators/templates/application/public/icons/calendar.png +0 -0
  375. data/res/generators/templates/application/public/icons/camera.png +0 -0
  376. data/res/generators/templates/application/public/icons/changeName.rb +22 -0
  377. data/res/generators/templates/application/public/icons/chat2.png +0 -0
  378. data/res/generators/templates/application/public/icons/chicken.png +0 -0
  379. data/res/generators/templates/application/public/icons/clock.png +0 -0
  380. data/res/generators/templates/application/public/icons/cloud.png +0 -0
  381. data/res/generators/templates/application/public/icons/coffee.png +0 -0
  382. data/res/generators/templates/application/public/icons/compass.png +0 -0
  383. data/res/generators/templates/application/public/icons/contrast.png +0 -0
  384. data/res/generators/templates/application/public/icons/dashboard.png +0 -0
  385. data/res/generators/templates/application/public/icons/display.png +0 -0
  386. data/res/generators/templates/application/public/icons/dogpaw.png +0 -0
  387. data/res/generators/templates/application/public/icons/download.png +0 -0
  388. data/res/generators/templates/application/public/icons/dumbbell.png +0 -0
  389. data/res/generators/templates/application/public/icons/ekg.png +0 -0
  390. data/res/generators/templates/application/public/icons/envelope.png +0 -0
  391. data/res/generators/templates/application/public/icons/equalizer.png +0 -0
  392. data/res/generators/templates/application/public/icons/eye.png +0 -0
  393. data/res/generators/templates/application/public/icons/film-roll.png +0 -0
  394. data/res/generators/templates/application/public/icons/flag.png +0 -0
  395. data/res/generators/templates/application/public/icons/fork-and-knife.png +0 -0
  396. data/res/generators/templates/application/public/icons/fuel.png +0 -0
  397. data/res/generators/templates/application/public/icons/gameplan.png +0 -0
  398. data/res/generators/templates/application/public/icons/gear.png +0 -0
  399. data/res/generators/templates/application/public/icons/gear2.png +0 -0
  400. data/res/generators/templates/application/public/icons/gift.png +0 -0
  401. data/res/generators/templates/application/public/icons/heart.png +0 -0
  402. data/res/generators/templates/application/public/icons/house.png +0 -0
  403. data/res/generators/templates/application/public/icons/inbox.png +0 -0
  404. data/res/generators/templates/application/public/icons/index-cards.png +0 -0
  405. data/res/generators/templates/application/public/icons/iphone.png +0 -0
  406. data/res/generators/templates/application/public/icons/ipod.png +0 -0
  407. data/res/generators/templates/application/public/icons/key.png +0 -0
  408. data/res/generators/templates/application/public/icons/lifebuoy.png +0 -0
  409. data/res/generators/templates/application/public/icons/lightbulb.png +0 -0
  410. data/res/generators/templates/application/public/icons/line-chart.png +0 -0
  411. data/res/generators/templates/application/public/icons/location.png +0 -0
  412. data/res/generators/templates/application/public/icons/lock.png +0 -0
  413. data/res/generators/templates/application/public/icons/loopback.png +0 -0
  414. data/res/generators/templates/application/public/icons/magnifying-glass.png +0 -0
  415. data/res/generators/templates/application/public/icons/map-marker.png +0 -0
  416. data/res/generators/templates/application/public/icons/map.png +0 -0
  417. data/res/generators/templates/application/public/icons/medical-bag.png +0 -0
  418. data/res/generators/templates/application/public/icons/medical.png +0 -0
  419. data/res/generators/templates/application/public/icons/microphone.png +0 -0
  420. data/res/generators/templates/application/public/icons/movie1.png +0 -0
  421. data/res/generators/templates/application/public/icons/movie2.png +0 -0
  422. data/res/generators/templates/application/public/icons/network.png +0 -0
  423. data/res/generators/templates/application/public/icons/note.png +0 -0
  424. data/res/generators/templates/application/public/icons/outlet.png +0 -0
  425. data/res/generators/templates/application/public/icons/palette.png +0 -0
  426. data/res/generators/templates/application/public/icons/paperclip.png +0 -0
  427. data/res/generators/templates/application/public/icons/phone.png +0 -0
  428. data/res/generators/templates/application/public/icons/photos.png +0 -0
  429. data/res/generators/templates/application/public/icons/piano.png +0 -0
  430. data/res/generators/templates/application/public/icons/picture-frame.png +0 -0
  431. data/res/generators/templates/application/public/icons/pill.png +0 -0
  432. data/res/generators/templates/application/public/icons/pin.png +0 -0
  433. data/res/generators/templates/application/public/icons/pinetree.png +0 -0
  434. data/res/generators/templates/application/public/icons/planet.png +0 -0
  435. data/res/generators/templates/application/public/icons/puzzle.png +0 -0
  436. data/res/generators/templates/application/public/icons/radar.png +0 -0
  437. data/res/generators/templates/application/public/icons/redo.png +0 -0
  438. data/res/generators/templates/application/public/icons/refresh.png +0 -0
  439. data/res/generators/templates/application/public/icons/runner.png +0 -0
  440. data/res/generators/templates/application/public/icons/shoebox.png +0 -0
  441. data/res/generators/templates/application/public/icons/shopping-bag.png +0 -0
  442. data/res/generators/templates/application/public/icons/shopping-cart.png +0 -0
  443. data/res/generators/templates/application/public/icons/shuffle.png +0 -0
  444. data/res/generators/templates/application/public/icons/signpost.png +0 -0
  445. data/res/generators/templates/application/public/icons/skull-n-crossbones.png +0 -0
  446. data/res/generators/templates/application/public/icons/skull.png +0 -0
  447. data/res/generators/templates/application/public/icons/sliders.png +0 -0
  448. data/res/generators/templates/application/public/icons/spraycan.png +0 -0
  449. data/res/generators/templates/application/public/icons/squiggle.png +0 -0
  450. data/res/generators/templates/application/public/icons/star.png +0 -0
  451. data/res/generators/templates/application/public/icons/stopwatch.png +0 -0
  452. data/res/generators/templates/application/public/icons/suitcase.png +0 -0
  453. data/res/generators/templates/application/public/icons/tag.png +0 -0
  454. data/res/generators/templates/application/public/icons/tags.png +0 -0
  455. data/res/generators/templates/application/public/icons/target.png +0 -0
  456. data/res/generators/templates/application/public/icons/testtube.png +0 -0
  457. data/res/generators/templates/application/public/icons/thermometer.png +0 -0
  458. data/res/generators/templates/application/public/icons/toolbox.png +0 -0
  459. data/res/generators/templates/application/public/icons/trophy.png +0 -0
  460. data/res/generators/templates/application/public/icons/tshirt.png +0 -0
  461. data/res/generators/templates/application/public/icons/tv.png +0 -0
  462. data/res/generators/templates/application/public/icons/umbrella.png +0 -0
  463. data/res/generators/templates/application/public/icons/walk.png +0 -0
  464. data/res/generators/templates/application/public/icons/weather.png +0 -0
  465. data/res/generators/templates/application/public/icons/widescreen.png +0 -0
  466. data/res/generators/templates/application/public/icons/wineglass.png +0 -0
  467. data/res/generators/templates/application/public/icons/zap.png +0 -0
  468. data/res/generators/templates/application/public/images/android/btn_check_off.png +0 -0
  469. data/res/generators/templates/application/public/images/android/btn_check_on.png +0 -0
  470. data/res/generators/templates/application/public/images/android/btn_radio_off.png +0 -0
  471. data/res/generators/templates/application/public/images/android/btn_radio_on.png +0 -0
  472. data/res/generators/templates/application/public/images/android/ic_menu_more.png +0 -0
  473. data/res/generators/templates/application/public/images/iphone/disclosure.png +0 -0
  474. data/res/generators/templates/application/public/images/iphone/disclosure_detail.png +0 -0
  475. data/res/generators/templates/application/public/images/iphone/radiobutton.png +0 -0
  476. data/res/generators/templates/application/public/images/iphone/select.png +0 -0
  477. data/res/generators/templates/application/public/images/iphone/switch.png +0 -0
  478. data/res/generators/templates/application/public/images/listArrow.png +0 -0
  479. data/res/generators/templates/application/public/images/listArrowDown.png +0 -0
  480. data/res/generators/templates/model/controller.rb +2 -0
  481. data/res/generators/templates/model/edit.bb.erb +24 -0
  482. data/res/generators/templates/model/edit.erb +21 -25
  483. data/res/generators/templates/model/index.bb.erb +21 -0
  484. data/res/generators/templates/model/index.erb +28 -14
  485. data/res/generators/templates/model/new.bb.erb +24 -0
  486. data/res/generators/templates/model/new.erb +20 -20
  487. data/res/generators/templates/model/show.bb.erb +21 -0
  488. data/res/generators/templates/model/show.erb +15 -15
  489. data/rhobuild.yml +37 -0
  490. data/rhodes.gemspec +1 -1
  491. data/spec/framework_spec/app/Account/config.rb +57 -1
  492. data/spec/framework_spec/app/Case/config.rb +1 -1
  493. data/spec/framework_spec/app/Customer/config.rb +1 -1
  494. data/spec/framework_spec/app/Product/config.rb +15 -1
  495. data/spec/framework_spec/app/spec/fixtures/object_values.txt +90 -90
  496. data/spec/framework_spec/app/spec/pagination/fixtures/object_values.txt +91 -91
  497. data/spec/framework_spec/app/spec/rho_spec.rb +1 -1
  498. data/spec/framework_spec/app/spec/rhom_object_spec.rb +47 -28
  499. data/spec/framework_spec/app/spec/rhom_spec.rb +8 -8
  500. data/spec/framework_spec/app/spec/spec_helper.rb +13 -5
  501. data/spec/framework_spec/app/spec_runner.rb +5 -4
  502. data/spec/framework_spec/public/css/base.css +0 -1
  503. data/spec/framework_spec/public/css/iphone.css +0 -1
  504. data/spec/framework_spec/rhoconfig.txt +3 -1
  505. metadata +220 -37
  506. data/platform/bb/rhodes/src/rhomobile/WebView.java +0 -90
  507. data/platform/iphone/Classes/BarItem.h +0 -27
  508. data/platform/iphone/Classes/BarItem.m +0 -32
  509. data/platform/iphone/Classes/JSString.h +0 -12
  510. data/platform/iphone/Classes/JSString.m +0 -7
  511. data/platform/iphone/Classes/RhoRunnerAppDelegate.h +0 -48
  512. data/platform/iphone/Classes/RhoRunnerAppDelegate.m +0 -617
  513. data/platform/iphone/Classes/Server/ServerHost.h +0 -81
  514. data/platform/iphone/Classes/Server/ServerHost.m +0 -597
  515. data/platform/iphone/Classes/Server/WebViewUrl.h +0 -13
  516. data/platform/iphone/Classes/Server/WebViewUrl.m +0 -8
  517. data/platform/iphone/Classes/TabBarDelegate.h +0 -39
  518. data/platform/iphone/Classes/TabBarDelegate.m +0 -151
  519. data/platform/iphone/Classes/Utils/unzip.cpp +0 -4328
  520. data/platform/iphone/Classes/Utils/unzip.h +0 -234
  521. data/platform/iphone/Classes/WebViewController.h +0 -59
  522. data/platform/iphone/Classes/WebViewController.m +0 -472
  523. data/platform/wm/rhodes/GetURLDialog.cpp +0 -64
  524. data/platform/wm/rhodes/GetURLDialog.h +0 -39
  525. data/res/generators/templates/application/public/css/base.css +0 -39
  526. data/res/generators/templates/application/public/css/rho.css +0 -3
  527. data/res/generators/templates/application/public/css/xhtml.css +0 -114
  528. data/spec/framework_spec/app/Question/config.rb +0 -3
  529. data/spec/generator_spec/source_generator_spec.rb +0 -27
@@ -38,16 +38,14 @@ public class SyncNotify {
38
38
  static Mutex m_mxObjectNotify = new Mutex();
39
39
 
40
40
  Hashtable/*<int,SyncNotification>*/ m_mapSyncNotifications = new Hashtable();
41
- Hashtable/*<int,SyncNotification>*/ m_mapSearchNotifications = new Hashtable();
42
-
43
- SyncNotification m_initialSyncNotify;
41
+ SyncNotification m_pSearchNotification;
42
+ SyncNotification m_bulkSyncNotify;
44
43
 
45
44
  Mutex m_mxSyncNotifications = new Mutex();
46
45
  ISyncStatusListener m_syncStatusListener = null;
47
46
  boolean m_bEnableReporting = false;
48
47
 
49
48
  SyncEngine getSync(){ return m_syncEngine; }
50
- DBAdapter getDB(){ return getSync().getDB(); }
51
49
  NetRequest getNet(){ return getSync().getNet(); }
52
50
 
53
51
  SyncNotify( SyncEngine syncEngine )
@@ -142,13 +140,15 @@ public class SyncNotify {
142
140
  if (nNotifyType == enNone.intValue())
143
141
  continue;
144
142
 
143
+ //This is slow operation
144
+ /*
145
145
  if ( nNotifyType == enDelete.intValue() )
146
146
  {
147
147
  IDBResult res = getDB().executeSQL("SELECT object FROM object_values where object=? LIMIT 1 OFFSET 0", strObject );
148
148
  if ( !res.isEnd() )
149
149
  nNotifyType = enUpdate.intValue();
150
150
  }
151
-
151
+ */
152
152
  if ( strBody.length() > 0 )
153
153
  strBody += "&rho_callback=1&";
154
154
 
@@ -174,10 +174,7 @@ public class SyncNotify {
174
174
  return;
175
175
  }
176
176
 
177
- NetResponse resp = getNet().pushData( strUrl, strBody, null );
178
- if ( !resp.isOK() )
179
- LOG.ERROR( "Fire object notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData() );
180
-
177
+ callNotify(strUrl, strBody);
181
178
  }
182
179
 
183
180
  void onObjectChanged(Integer nSrcID, String strObject, Integer nType)
@@ -275,7 +272,7 @@ public class SyncNotify {
275
272
 
276
273
  if ( strFullUrl.length() > 0 )
277
274
  {
278
- IDBResult res = getDB().executeSQL("SELECT source_id from sources order by source_id");
275
+ IDBResult res = DBAdapter.getUserDB().executeSQL("SELECT source_id from sources order by source_id");
279
276
  for ( ; !res.isEnd(); res.next() )
280
277
  m_mapSyncNotifications.put( new Integer(res.getIntByIdx(0)), new SyncNotification( strFullUrl, strParams, false ) );
281
278
  }
@@ -294,25 +291,25 @@ public class SyncNotify {
294
291
  }
295
292
  }
296
293
 
297
- void setSearchNotification(int source_id, String strUrl, String strParams )throws Exception
294
+ void setSearchNotification(String strUrl, String strParams )throws Exception
298
295
  {
299
- LOG.INFO( "Set search notification. Source ID: " + source_id + "; Url :" + strUrl + "; Params: " + strParams );
296
+ LOG.INFO( "Set search notification. Url :" + strUrl + "; Params: " + strParams );
300
297
  String strFullUrl = getNet().resolveUrl(strUrl);
301
298
 
302
299
  if ( strFullUrl.length() > 0 )
303
300
  {
304
301
  synchronized(m_mxSyncNotifications){
305
- m_mapSearchNotifications.put(new Integer(source_id),new SyncNotification( strFullUrl, strParams, true ) );
302
+ m_pSearchNotification = new SyncNotification( strFullUrl, strParams, true );
306
303
  }
307
- LOG.INFO( " Done Set search notification. Source ID: " + source_id + "; Url :" + strFullUrl + "; Params: " + strParams );
304
+ LOG.INFO( " Done Set search notification. Url :" + strFullUrl + "; Params: " + strParams );
308
305
  }
309
306
  }
310
307
 
311
- void setInitialSyncNotification(String strUrl, String strParams )throws Exception
308
+ void setBulkSyncNotification(String strUrl, String strParams )throws Exception
312
309
  {
313
310
  String strFullUrl = getNet().resolveUrl(strUrl);
314
311
 
315
- m_initialSyncNotify = new SyncNotification( strFullUrl, strParams, true );
312
+ m_bulkSyncNotify = new SyncNotification( strFullUrl, strParams, false );
316
313
  }
317
314
 
318
315
  public void setSyncStatusListener(ISyncStatusListener listener)
@@ -357,7 +354,7 @@ public class SyncNotify {
357
354
  }
358
355
  }
359
356
 
360
- void fireInitialSyncNotification( boolean bFinish, int nErrCode )
357
+ void fireBulkSyncNotification( boolean bFinish, String status, String partition, int nErrCode )
361
358
  {
362
359
  if ( getSync().getState() == SyncEngine.esExit )
363
360
  return;
@@ -365,7 +362,7 @@ public class SyncNotify {
365
362
  //TODO: show report
366
363
  if( nErrCode != RhoRuby.ERR_NONE)
367
364
  {
368
- String strMessage = RhoRuby.getMessageText("sync_failed_for") + "initial.";
365
+ String strMessage = RhoRuby.getMessageText("sync_failed_for") + "bulk.";
369
366
  reportSyncStatus(strMessage,nErrCode,"");
370
367
  }
371
368
 
@@ -374,11 +371,13 @@ public class SyncNotify {
374
371
  String strBody = "", strUrl;
375
372
  synchronized(m_mxSyncNotifications)
376
373
  {
377
- if ( m_initialSyncNotify == null )
374
+ if ( m_bulkSyncNotify == null )
378
375
  return;
379
376
 
380
- strUrl = m_initialSyncNotify.m_strUrl;
377
+ strUrl = m_bulkSyncNotify.m_strUrl;
381
378
  strBody = "rho_callback=1";
379
+ strBody += "&partition=" + partition;
380
+ strBody += "&bulk_status="+status;
382
381
  strBody += "&status=";
383
382
  if ( bFinish )
384
383
  {
@@ -396,32 +395,22 @@ public class SyncNotify {
396
395
  else
397
396
  strBody += "in_progress";
398
397
 
399
- if ( m_initialSyncNotify.m_strParams.length() > 0 )
400
- strBody += "&" + m_initialSyncNotify.m_strParams;
398
+ if ( m_bulkSyncNotify.m_strParams.length() > 0 )
399
+ strBody += "&" + m_bulkSyncNotify.m_strParams;
401
400
 
402
- bRemoveAfterFire = bRemoveAfterFire && m_initialSyncNotify.m_bRemoveAfterFire;
401
+ bRemoveAfterFire = bRemoveAfterFire && m_bulkSyncNotify.m_bRemoveAfterFire;
403
402
  }
404
403
 
405
404
  if ( bRemoveAfterFire )
406
- clearInitialSyncNotification();
405
+ clearBulkSyncNotification();
407
406
 
408
- LOG.INFO( "Fire initial notification.Url :" + strUrl + "; Body: " + strBody );
409
-
410
- NetResponse resp = getNet().pushData( strUrl, strBody, null );
411
- if ( !resp.isOK() )
412
- LOG.ERROR( "Fire intial notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData() );
413
- else
414
- {
415
- String szData = resp.getCharData();
416
- if ( szData != null && szData.equals("stop") )
417
- {
418
- clearInitialSyncNotification();
419
- }
420
- }
421
-
407
+ LOG.INFO( "Fire bulk notification.Url :" + strUrl + "; Body: " + strBody );
408
+
409
+ if ( callNotify(strUrl, strBody) )
410
+ clearBulkSyncNotification();
422
411
  }catch(Exception exc)
423
412
  {
424
- LOG.ERROR("Fire initial notification failed.", exc);
413
+ LOG.ERROR("Fire bulk notification failed.", exc);
425
414
  }
426
415
 
427
416
  }
@@ -433,7 +422,7 @@ public class SyncNotify {
433
422
 
434
423
  if( strMessage.length() > 0 || nErrCode != RhoRuby.ERR_NONE)
435
424
  {
436
- if ( !( src != null && src.m_strParams.length()>0) )
425
+ if ( !( src != null && src.isSearch()) )
437
426
  {
438
427
  if ( src != null && (strMessage==null || strMessage.length() == 0) )
439
428
  strMessage = RhoRuby.getMessageText("sync_failed_for") + src.getName() + ".";
@@ -455,7 +444,12 @@ public class SyncNotify {
455
444
  boolean bRemoveAfterFire = bFinish;
456
445
  {
457
446
  synchronized(m_mxSyncNotifications){
458
- SyncNotification sn = (SyncNotification)(src.isSearch() ? m_mapSearchNotifications.get(src.getID()) : m_mapSyncNotifications.get(src.getID()));
447
+ SyncNotification sn = null;
448
+ if ( src.isSearch() )
449
+ sn = m_pSearchNotification;
450
+ else
451
+ sn = (SyncNotification)m_mapSyncNotifications.get(src.getID());
452
+
459
453
  if ( sn == null )
460
454
  return;
461
455
 
@@ -496,25 +490,43 @@ public class SyncNotify {
496
490
  clearNotification(src);
497
491
 
498
492
  LOG.INFO( "Fire notification. Source ID: " + src.getID() + "; Url :" + strUrl + "; Body: " + strBody );
499
-
500
- NetResponse resp = getNet().pushData( strUrl, strBody, null );
501
- if ( !resp.isOK() )
502
- LOG.ERROR( "Fire notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData() );
503
- else
504
- {
505
- String szData = resp.getCharData();
506
- if ( szData != null && szData.equals("stop") )
507
- {
508
- clearNotification(src);
509
- }
510
- }
511
-
493
+
494
+ if ( callNotify(strUrl, strBody) )
495
+ clearNotification(src);
512
496
  }catch(Exception exc)
513
497
  {
514
498
  LOG.ERROR("Fire notification failed.", exc);
515
499
  }
516
500
  }
517
501
 
502
+ boolean callNotify(String strUrl, String strBody )throws Exception
503
+ {
504
+ /* if ( getSync().isNoThreadedMode() )
505
+ {
506
+ const char* szName = strrchr(strUrl.c_str(), '/');
507
+ if (!szName)
508
+ szName = strUrl.c_str();
509
+ else
510
+ szName++;
511
+
512
+ String strName = "C_";
513
+ strName += szName;
514
+ rho_ruby_set_const( strName.c_str(), strBody.c_str());
515
+ return false;
516
+ }*/
517
+
518
+ NetResponse resp = getNet().pushData( strUrl, strBody, null );
519
+ if ( !resp.isOK() )
520
+ LOG.ERROR( "Fire object notification failed. Code: " + resp.getRespCode() + "; Error body: " + resp.getCharData() );
521
+ else
522
+ {
523
+ String szData = resp.getCharData();
524
+ return szData != null && szData.equals("stop");
525
+ }
526
+
527
+ return false;
528
+ }
529
+
518
530
  void clearNotification(SyncSource src)
519
531
  {
520
532
  LOG.INFO( "Clear notification. Source : " + src.getName());
@@ -522,7 +534,7 @@ public class SyncNotify {
522
534
  synchronized(m_mxSyncNotifications)
523
535
  {
524
536
  if ( src.isSearch() )
525
- m_mapSearchNotifications.remove(src.getID());
537
+ m_pSearchNotification = null;
526
538
  else
527
539
  m_mapSyncNotifications.remove(src.getID());
528
540
  }
@@ -540,12 +552,12 @@ public class SyncNotify {
540
552
  }
541
553
  }
542
554
 
543
- void clearInitialSyncNotification()
555
+ void clearBulkSyncNotification()
544
556
  {
545
- LOG.INFO( "Clear initial notification." );
557
+ LOG.INFO( "Clear bulk notification." );
546
558
 
547
559
  synchronized(m_mxSyncNotifications){
548
- m_initialSyncNotify = null;
560
+ m_bulkSyncNotify = null;
549
561
  }
550
562
  }
551
563
 
@@ -586,5 +598,24 @@ public class SyncNotify {
586
598
 
587
599
  return nCount;
588
600
  }
601
+
602
+ void callLoginCallback(String callback, int nErrCode, String strMessage)
603
+ {
604
+ try{
605
+ String strBody = "error_code=" + nErrCode;
606
+ strBody += "&error_message=" + URI.urlEncode(strMessage != null? strMessage : "");
607
+ strBody += "&rho_callback=1";
608
+
609
+ String strUrl = getNet().resolveUrl(callback);
610
+
611
+ LOG.INFO( "Login callback: " + callback + ". Body: "+ strBody );
612
+
613
+ callNotify(strUrl, strBody);
614
+ }catch(Exception exc)
615
+ {
616
+ LOG.ERROR("Call Login callback failed.", exc);
617
+ }
618
+ }
619
+
589
620
 
590
621
  }
@@ -0,0 +1,79 @@
1
+ package com.rho.sync;
2
+
3
+ import com.rho.RhoConf;
4
+ import com.rho.FilePath;
5
+
6
+ public class SyncProtocol_3 implements ISyncProtocol
7
+ {
8
+ String m_strContentType;
9
+
10
+ public SyncProtocol_3()
11
+ {
12
+ m_strContentType = "application/json";
13
+ }
14
+
15
+ public String getContentType(){ return m_strContentType; }
16
+ public int getVersion(){ return 3; }
17
+
18
+ public String getLoginUrl()
19
+ {
20
+ return RhoConf.getInstance().getPath("syncserver") + "clientlogin";
21
+ }
22
+
23
+ public String getLoginBody( String name, String password)
24
+ {
25
+ return "{\"login\":\"" + name + "\",\"password\":\"" + password + "\",\"remember_me\":1}";
26
+ }
27
+
28
+ public String getClientCreateUrl()
29
+ {
30
+ return RhoConf.getInstance().getPath("syncserver") + "clientcreate";
31
+ }
32
+
33
+ public String getClientRegisterUrl()
34
+ {
35
+ return RhoConf.getInstance().getPath("syncserver") + "clientregister";
36
+ }
37
+
38
+ public String getClientRegisterBody( String strClientID, String strPin, int nPort, String strType )
39
+ {
40
+ return "{\"client_id\":\"" + strClientID +
41
+ "\",\"device_pin\":\"" + strPin +
42
+ "\",\"device_port\":\"" + nPort +
43
+ "\",\"device_type\":\"" + strType + "\"}";
44
+ }
45
+
46
+ public String getClientResetUrl(String strClientID)
47
+ {
48
+ return RhoConf.getInstance().getPath("syncserver") + "clientreset?client_id=" + strClientID;
49
+ }
50
+
51
+ public String getClientChangesUrl()
52
+ {
53
+ String strUrl = RhoConf.getInstance().getPath("syncserver");
54
+ return strUrl.substring(0,strUrl.length()-1);
55
+ }
56
+
57
+ public String getServerQueryUrl(String strAction )
58
+ {
59
+ String strUrl = RhoConf.getInstance().getPath("syncserver");
60
+ if ( strAction.length() > 0 )
61
+ strUrl = FilePath.join(strUrl, strAction);
62
+ else
63
+ strUrl = strUrl.substring(0,strUrl.length()-1);
64
+
65
+ return strUrl;
66
+ }
67
+
68
+ public String getServerQueryBody(String strSrcName, String strClientID, int nPageSize )
69
+ {
70
+ String strQuery = "?client_id=" + strClientID +
71
+ "&p_size=" + nPageSize + "&version=3";
72
+
73
+ if ( strSrcName.length() > 0 )
74
+ strQuery += "&source_name=" + strSrcName;
75
+
76
+ return strQuery;
77
+ }
78
+
79
+ }
@@ -23,15 +23,19 @@ import com.rho.RhoEmptyLogger;
23
23
  import com.rho.RhoEmptyProfiler;
24
24
  import com.rho.RhoLogger;
25
25
  import com.rho.RhoProfiler;
26
+ import com.rho.RhodesApp;
27
+ import com.rho.Tokenizer;
26
28
  import com.rho.net.*;
27
29
  import com.rho.db.*;
28
- import java.util.Vector;
29
30
 
30
- import org.json.me.JSONException;
31
+ import java.util.Enumeration;
32
+ import java.util.Vector;
33
+ import java.util.Hashtable;
31
34
 
32
35
  import com.rho.FilePath;
33
36
  import com.rho.TimeInterval;
34
37
  import com.rho.RhoRuby;
38
+ import com.rho.net.NetRequest.MultipartItem;
35
39
 
36
40
  class SyncSource
37
41
  {
@@ -41,104 +45,157 @@ class SyncSource
41
45
  private static final RhoProfiler PROF = RhoProfiler.RHO_STRIP_PROFILER ? new RhoEmptyProfiler() :
42
46
  new RhoProfiler();
43
47
 
44
- public static final int edpNone = 0, edpDeleteObjects = 2;
45
-
46
- static class SyncBlob
48
+ static class CAttrValue
47
49
  {
48
- String m_strBody;
49
- String m_strFilePath;
50
+ String m_strAttrib = "";
51
+ String m_strValue = "";
52
+ String m_strBlobSuffix = "";
50
53
 
51
- SyncBlob(String body, String filePath ){
52
- m_strBody = body; m_strFilePath = filePath;
53
- }
54
+ CAttrValue(String strAttrib, String strValue)
55
+ {
56
+ m_strAttrib = strAttrib;
57
+ m_strValue = strValue;
54
58
 
55
- String getBody(){ return m_strBody; }
56
- String getFilePath(){ return m_strFilePath; }
59
+ if ( m_strAttrib.endsWith("-rhoblob") )
60
+ {
61
+ m_strBlobSuffix = "-rhoblob";
62
+ m_strAttrib = m_strAttrib.substring(0,m_strAttrib.length()-m_strBlobSuffix.length());
63
+ }
64
+ }
57
65
  };
58
66
 
59
67
  SyncEngine m_syncEngine;
60
-
68
+ DBAdapter m_dbAdapter;
69
+
61
70
  Integer m_nID;
62
- String m_strName;
63
- String m_strUrl;
71
+ String m_strName = "";
64
72
  long m_token = 0;
73
+ String m_strSyncType = "";
65
74
  boolean m_bTokenFromDB;
66
75
 
67
76
  int m_nCurPageCount, m_nInserted, m_nDeleted, m_nTotalCount, m_nAttribCounter=0;
68
77
  boolean m_bGetAtLeastOnePage = false;
69
- int m_eSyncServerDataPass = edpNone;
70
78
  int m_nErrCode = RhoRuby.ERR_NONE;
71
79
  String m_strError = "";
72
- String m_strParams = "";
73
- String m_strAction = "";
74
- boolean m_bSearchSyncChanges = false;
75
- int m_nProgressStep = -1;
76
- String m_strUrlParams = "";
80
+ public boolean m_bIsSearch = false;
77
81
 
78
- String m_strPushBody = "";
82
+ //String m_strPushBody = "";
79
83
  Vector/*Ptr<CSyncBlob*>*/ m_arSyncBlobs = new Vector();
80
84
 
81
- String m_strAskParams = "";
82
85
  int m_nRefreshTime = 0;
86
+ int m_nProgressStep = -1;
87
+ boolean m_bSchemaSource;
88
+ Hashtable/*<String,String>*/ m_hashLinks = new Hashtable();
89
+ Vector/*Ptr<net::CMultipartItem*>*/ m_arMultipartItems = new Vector();
90
+ Vector/*<String>*/ m_arBlobAttrs = new Vector();
83
91
 
84
- String getUrl() { return m_strUrl; }
85
92
  Integer getID() { return m_nID; }
86
93
  String getName() { return m_strName; }
94
+ String getSyncType(){ return m_strSyncType; }
87
95
  int getServerObjectsCount(){ return m_nInserted+m_nDeleted; }
88
- boolean isSearch(){ return m_strParams.length() > 0;}
96
+ boolean isSearch(){ return m_bIsSearch;}
89
97
 
90
98
  long getToken(){ return m_token; }
99
+ boolean isTokenFromDB(){ return m_bTokenFromDB; }
91
100
  void setToken(long token){ m_token = token; m_bTokenFromDB = false; }
92
101
  boolean isEmptyToken()
93
102
  {
94
103
  return m_token == 0;
95
104
  }
96
- void setAskParams(String ask){ m_strAskParams = ask;}
97
- String getAskParams(){ return m_strAskParams;}
105
+
106
+ int getProgressStep(){ return m_nProgressStep; }
107
+ void setProgressStep(int nProgressStep){ m_nProgressStep = nProgressStep; }
108
+
109
+ boolean getGetAtLeastOnePage(){ return m_bGetAtLeastOnePage; }
110
+ int getRefreshTime(){ return m_nRefreshTime; }
111
+
98
112
  int getInsertedCount() { return m_nInserted; }
99
113
  int getDeletedCount() { return m_nDeleted; }
100
114
  void setCurPageCount(int nCurPageCount){m_nCurPageCount = nCurPageCount;}
101
115
  void setTotalCount(int nTotalCount){m_nTotalCount = nTotalCount;}
102
116
  int getCurPageCount(){return m_nCurPageCount;}
103
117
  int getTotalCount(){return m_nTotalCount;}
104
- int getProgressStep(){ return m_nProgressStep; }
105
118
 
106
- void setSyncServerDataPass(int ePass){m_eSyncServerDataPass = ePass;}
107
- boolean isDeleteObjectsPass(){ return m_eSyncServerDataPass == edpDeleteObjects; }
108
-
109
119
  SyncEngine getSync(){ return m_syncEngine; }
110
120
  SyncNotify getNotify(){ return getSync().getNotify(); }
111
- DBAdapter getDB(){ return getSync().getDB(); }
112
121
  NetRequest getNet(){ return getSync().getNet(); }
122
+ ISyncProtocol getProtocol(){ return getSync().getProtocol(); }
113
123
  void setRefreshTime( int nRefreshTime ){ m_nRefreshTime = nRefreshTime;}
114
- void setUrlParams(String strParams){m_strUrlParams=strParams!=null?strParams:"";}
115
- void setUrl(String strUrl){m_strUrl=strUrl;}
116
-
117
- SyncSource(int id, String strUrl, String name, long token, SyncEngine syncEngine )
124
+ DBAdapter getDB(){ return m_dbAdapter; }
125
+
126
+ SyncSource(SyncEngine syncEngine, DBAdapter db)throws DBException
118
127
  {
119
128
  m_syncEngine = syncEngine;
120
- m_nID = new Integer(id);
121
- m_strUrl = strUrl;
122
- m_strName = name;
123
- m_token = token;
124
- m_bTokenFromDB = true;
129
+ m_dbAdapter = db;
130
+
131
+ m_nID = new Integer(0);
125
132
 
133
+ m_bTokenFromDB = true;
134
+
126
135
  m_nCurPageCount = 0;
127
136
  m_nInserted = 0;
128
137
  m_nDeleted = 0;
138
+ m_nTotalCount = 0;
139
+ m_bGetAtLeastOnePage = false;
140
+
141
+ m_nErrCode = RhoRuby.ERR_NONE;
142
+ m_bIsSearch = false;
143
+ m_bSchemaSource = db.isTableExist(m_strName);
129
144
  }
130
145
 
131
- SyncSource(SyncEngine syncEngine)
146
+ SyncSource(int id, String name, String strSyncType, DBAdapter db, SyncEngine syncEngine )throws DBException
132
147
  {
133
148
  m_syncEngine = syncEngine;
134
- m_nID = new Integer(0);
135
- m_strUrl = "";
136
- m_strName = "";
137
- m_bTokenFromDB = true;
149
+ m_dbAdapter = db;
150
+ m_nID = new Integer(id);
151
+ m_strName = name;
152
+ m_strSyncType = strSyncType;
138
153
 
139
154
  m_nCurPageCount = 0;
140
155
  m_nInserted = 0;
141
156
  m_nDeleted = 0;
157
+ m_nTotalCount = 0;
158
+ m_bGetAtLeastOnePage = false;
159
+
160
+ m_nErrCode = RhoRuby.ERR_NONE;
161
+ m_bIsSearch = false;
162
+
163
+ IDBResult res = db.executeSQL("SELECT token,links from sources WHERE source_id=?", m_nID);
164
+ if ( !res.isEnd() )
165
+ {
166
+ m_token = res.getLongByIdx(0);
167
+ m_bTokenFromDB = true;
168
+ }else
169
+ {
170
+ m_token = 0;
171
+ m_bTokenFromDB = true;
172
+ }
173
+
174
+ m_bSchemaSource = db.isTableExist(m_strName);
175
+ parseLinks(res.getStringByIdx(1));
176
+ }
177
+
178
+ void parseLinks(String strLinks)
179
+ {
180
+ if (strLinks.length() == 0 )
181
+ return;
182
+
183
+ Tokenizer oTokenizer = new Tokenizer( strLinks, "," );
184
+
185
+ String strSrcName = "";
186
+ while (oTokenizer.hasMoreTokens())
187
+ {
188
+ String tok = oTokenizer.nextToken();
189
+ if (tok.length() == 0)
190
+ continue;
191
+
192
+ if ( strSrcName.length() > 0 )
193
+ {
194
+ m_hashLinks.put(strSrcName, tok);
195
+ strSrcName = "";
196
+ }else
197
+ strSrcName = tok;
198
+ }
142
199
  }
143
200
 
144
201
  void sync() throws Exception
@@ -146,44 +203,13 @@ class SyncSource
146
203
  getNotify().fireSyncNotification(null, false, RhoRuby.ERR_NONE, RhoRuby.getMessageText("syncronizing") + getName() + "...");
147
204
 
148
205
  TimeInterval startTime = TimeInterval.getCurrentTime();
206
+ m_bIsSearch = false;
149
207
 
150
208
  try{
151
- PROF.START("Pull");
152
209
  if ( isEmptyToken() )
153
210
  processToken(1);
154
211
 
155
- boolean bSyncedServer = false;
156
- if ( m_strParams.length() == 0 || m_bSearchSyncChanges )
157
- {
158
- if ( isPendingClientChanges() )
159
- {
160
- LOG.INFO("Client has unconfirmed items in database. Sync server first.");
161
- syncServerChanges();
162
- bSyncedServer = true;
163
- }
164
-
165
- if ( bSyncedServer && isPendingClientChanges() )
166
- {
167
- LOG.ERROR("Client still has unconfirmed items in database. Sync is stopped.");
168
- getSync().setState(SyncEngine.esStop);
169
- }
170
- else
171
- {
172
- boolean bSyncClient = false;
173
- {
174
- IDBResult res = getDB().executeSQL("SELECT object FROM changed_values WHERE source_id=? and sent<=1 LIMIT 1 OFFSET 0", getID());
175
- bSyncClient = !res.isEnd();
176
- }
177
- if ( bSyncClient )
178
- {
179
- syncClientChanges();
180
- getAndremoveAsk();
181
- bSyncedServer = false;
182
- }
183
- }
184
- }
185
- PROF.STOP("Pull");
186
-
212
+ boolean bSyncedServer = syncClientChanges();
187
213
  if ( !bSyncedServer )
188
214
  syncServerChanges();
189
215
 
@@ -193,193 +219,215 @@ class SyncSource
193
219
  throw exc;
194
220
  }finally{
195
221
  TimeInterval endTime = TimeInterval.getCurrentTime();
196
- getDB().executeSQL("UPDATE sources set last_updated=?,last_inserted_size=?,last_deleted_size=?, "+
222
+ getDB().executeSQL("UPDATE sources set last_updated=?,last_inserted_size=?,last_deleted_size=?, "+
197
223
  "last_sync_duration=?,last_sync_success=?, backend_refresh_time=? WHERE source_id=?",
198
224
  new Long(endTime.toULong()/1000), new Integer(getInsertedCount()), new Integer(getDeletedCount()), new Long((endTime.minus(startTime)).toULong()),
199
225
  new Integer(m_bGetAtLeastOnePage?1:0), new Integer(m_nRefreshTime), getID() );
200
226
  }
201
227
  }
202
228
 
229
+ boolean syncClientChanges()throws Exception
230
+ {
231
+ boolean bSyncedServer = false;
232
+ if ( isPendingClientChanges() )
233
+ {
234
+ syncServerChanges();
235
+ bSyncedServer = true;
236
+ }
237
+
238
+ if ( bSyncedServer && isPendingClientChanges() )
239
+ getSync().setState(SyncEngine.esStop);
240
+ else
241
+ {
242
+ PROF.START("Pull");
243
+
244
+ boolean bSyncClient = false;
245
+ {
246
+ IDBResult res = getDB().executeSQL("SELECT object FROM changed_values WHERE source_id=? LIMIT 1 OFFSET 0", getID());
247
+ bSyncClient = !res.isEnd();
248
+ }
249
+ if ( bSyncClient )
250
+ {
251
+ doSyncClientChanges();
252
+ bSyncedServer = false;
253
+ }
254
+
255
+ PROF.STOP("Pull");
256
+ }
257
+
258
+ return bSyncedServer;
259
+ }
260
+
203
261
  boolean isPendingClientChanges()throws DBException
204
262
  {
205
263
  IDBResult res = getDB().executeSQL("SELECT object FROM changed_values WHERE source_id=? and update_type='create' and sent>1 LIMIT 1 OFFSET 0", getID());
206
264
  return !res.isEnd();
207
265
  }
208
-
209
- void syncClientBlobs(String strBaseQuery)throws Exception
266
+
267
+ void doSyncClientChanges()throws Exception
210
268
  {
211
- String strQuery;
212
- for( int i = 0; i < m_arSyncBlobs.size(); i ++)
269
+ String arUpdateTypes[] = {"create", "update", "delete"};
270
+ boolean arUpdateSent[] = {false, false, false};
271
+
272
+ m_arMultipartItems.removeAllElements();
273
+ m_arBlobAttrs.removeAllElements();
274
+ String strBody = "{\"source_name\":\"" + getName() + "\",\"client_id\":\"" + getSync().getClientID() + "\"";
275
+ boolean bSend = false;
276
+ int i = 0;
277
+ for( i = 0; i < 3 && getSync().isContinueSync(); i++ )
213
278
  {
214
- SyncBlob blob = (SyncBlob)m_arSyncBlobs.elementAt(i);
215
-
216
- String strFilePath = RhoClassFactory.createFile().getDirPath("");
217
- String strBlobPath = blob.getFilePath();
218
- if ( strBlobPath.startsWith("/") )
219
- strBlobPath = strBlobPath.substring(1);
220
-
221
- strFilePath += strBlobPath;
222
-
223
- strQuery = strBaseQuery + "&" + blob.getBody();
224
- try{
225
- NetResponse resp = getNet().pushFile(strQuery, strFilePath, getSync(), null );
226
- if ( !resp.isOK() )
227
- {
228
- getSync().setState(SyncEngine.esStop);
229
- m_nErrCode = RhoRuby.ERR_REMOTESERVER;
230
- //m_strError = resp.getCharData();
231
- return;
232
- }
233
- }catch(Exception exc)
234
- {
235
- m_nErrCode = RhoRuby.getNetErrorCode(exc);
236
- throw exc;
237
- }
279
+ String strBody1;
280
+ strBody1 = makePushBody_Ver3(arUpdateTypes[i]);
281
+ if (strBody1.length() > 0)
282
+ {
283
+ strBody += "," + strBody1;
238
284
 
239
- getDB().startTransaction();
240
- getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and attrib_type=? and value=?", getID(), "blob.file", blob.getFilePath() );
241
- getDB().executeSQL("DELETE FROM object_values WHERE source_id=? and attrib_type=? and value=?", getID(), "blob.file", blob.getFilePath() );
242
- getDB().endTransaction();
285
+ String strBlobAttrs = "";
286
+ for ( int j = 0; j < (int)m_arBlobAttrs.size(); j++)
287
+ {
288
+ if ( strBlobAttrs.length() > 0 )
289
+ strBlobAttrs += ",";
290
+
291
+ strBlobAttrs += "\"" + m_arBlobAttrs.elementAt(j) + "\"";
292
+ }
293
+
294
+ if ( strBlobAttrs.length() > 0 )
295
+ strBody += ",\"blob_fields\":[" + strBlobAttrs + "]";
296
+
297
+ arUpdateSent[i] = true;
298
+ bSend = true;
299
+ }
243
300
  }
244
-
245
- m_arSyncBlobs.removeAllElements();
246
- }
301
+ strBody += "}";
247
302
 
248
- void syncClientChanges()throws Exception
249
- {
250
- String[] arUpdateTypes = {"create", "update", "delete"};
251
- for( int i = 0; i < 3 && getSync().isContinueSync(); i++ )
303
+ if ( bSend )
252
304
  {
253
- String strUrl = getUrl() + "/" + arUpdateTypes[i];
254
- strUrl += "objects";
255
- String strQuery = SyncEngine.SYNC_SOURCE_FORMAT() + "&client_id=" + getSync().getClientID();
305
+ LOG.INFO( "Push client changes to server. Source: " + getName() + "Size :" + strBody.length() );
306
+ LOG.TRACE("Push body: " + strBody);
256
307
 
257
- m_arSyncBlobs.removeAllElements();
258
- String strBody = makePushBody(arUpdateTypes[i]);
259
- if ( strBody.length() > 0 )
308
+ if ( m_arMultipartItems.size() > 0 )
260
309
  {
261
- LOG.INFO( "Push client changes to server. Source: " + getName() + "Size :" + strBody.length() );
262
- LOG.TRACE("Push body: " + strBody);
263
-
264
- NetResponse resp = getNet().pushData(strUrl+strQuery,strBody, getSync());
310
+ MultipartItem oItem = new MultipartItem();
311
+ oItem.m_strBody = strBody;
312
+ //oItem.m_strContentType = getProtocol().getContentType();
313
+ oItem.m_strName = "cud";
314
+ m_arMultipartItems.addElement(oItem);
315
+
316
+ NetResponse resp = getNet().pushMultipartData( getProtocol().getClientChangesUrl(), m_arMultipartItems, getSync(), null );
265
317
  if ( !resp.isOK() )
266
318
  {
267
319
  getSync().setState(SyncEngine.esStop);
268
320
  m_nErrCode = RhoRuby.ERR_REMOTESERVER;
269
- continue;
270
321
  }
271
- }
272
-
273
- if ( m_arSyncBlobs.size()>0 )
322
+ }else
274
323
  {
275
- LOG.INFO( "Push blobs to server. Source: " + getName() + "Count :" + m_arSyncBlobs.size() );
276
- //oo conflicts
277
- if ( i < 1 ) //create
278
- getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and (attrib_type IS NULL or attrib_type!=?) and sent=1",
279
- getID(), arUpdateTypes[i], "blob.file" );
280
- else
281
- //
282
- getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and (attrib_type IS NULL or attrib_type!=?) and sent=1",
283
- getID(), arUpdateTypes[i], "blob.file" );
284
-
285
- syncClientBlobs(strUrl+strQuery);
286
- }else if ( strBody.length() > 0 )
324
+ NetResponse resp = getNet().pushData( getProtocol().getClientChangesUrl(), strBody, getSync());
325
+ if ( !resp.isOK() )
326
+ {
327
+ getSync().setState(SyncEngine.esStop);
328
+ m_nErrCode = RhoRuby.ERR_REMOTESERVER;
329
+ }
330
+ }
331
+ }
332
+
333
+ for( i = 0; i < 3 && getSync().isContinueSync(); i++ )
334
+ {
335
+ if ( arUpdateSent[i] )
287
336
  {
288
337
  //oo conflicts
289
338
  if ( i < 1 ) //create
290
339
  getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] );
291
340
  else
292
341
  //
293
- getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] );
342
+ getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] );
294
343
  }
295
344
  }
345
+
346
+ m_arMultipartItems.removeAllElements();
347
+ m_arBlobAttrs.removeAllElements();
296
348
  }
297
349
 
298
- /*
299
- * Construct the body of the request by filtering
300
- * the attr_filter string. The body format should
301
- * look like the following:
302
- * create: attrvals[][attrib]=<name|industry>&attrvals[][object]=<locallygeneratedid>&attrvals[][value]=<some value>
303
- * update: attrvals[][attrib]=<name|industry>&attrvals[][object]=<remoteid>&attrvals[][value]=<some new value>
304
- * delete: attrvals[][attrib]=<name|industry>&attrvals[][object]=<remoteid>
305
- */
306
-
307
- String makePushBody( String szUpdateType)throws DBException
350
+ //{"source_name":"SampleAdapter","client_id":1,"create":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}}
351
+ //{"source_name":"SampleAdapter","client_id":1,"update":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}}
352
+ //{"source_name":"SampleAdapter","client_id":1,"delete":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}}
353
+ //{"source_name":"SampleAdapter","client_id":1,"delete":{"3":{"brand":"HTC","name":"Fuze","price":"299.99"}},"create":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}},"update":{"2":{"brand":"Android","name":"G2","price":"99.99"}}}
354
+ String makePushBody_Ver3( String strUpdateType)throws DBException
308
355
  {
309
356
  String strBody = "";
310
- getDB().Lock();
311
-
312
- IDBResult res = getDB().executeSQL("SELECT attrib, object, value, attrib_type, main_id "+
313
- "FROM changed_values where source_id=? and update_type =? and sent<=1 ORDER BY sent DESC", getID(), szUpdateType );
357
+ getDB().Lock();
358
+ IDBResult res = getDB().executeSQL("SELECT attrib, object, value, attrib_type "+
359
+ "FROM changed_values where source_id=? and update_type =? and sent<=1 ORDER BY object", getID(), strUpdateType );
360
+
314
361
  if ( res.isEnd() )
315
362
  {
316
- getDB().Unlock();
317
- return strBody;
363
+ getDB().Unlock();
364
+ return strBody;
318
365
  }
319
-
366
+
367
+ String strCurObject = "";
368
+ boolean bFirst = true;
320
369
  for( ; !res.isEnd(); res.next() )
321
370
  {
322
- String strSrcBody = "attrvals[][attrib]=" + res.getStringByIdx(0);
323
-
324
- if ( res.getStringByIdx(1).length() > 0 )
325
- strSrcBody += "&attrvals[][object]=" + res.getStringByIdx(1);
326
-
327
- long main_id = res.getLongByIdx(4);
328
- if ( main_id != 0 )
329
- strSrcBody += "&attrvals[][id]=" + main_id;
330
-
371
+ String strAttrib = res.getStringByIdx(0);
372
+ String strObject = res.getStringByIdx(1);
331
373
  String value = res.getStringByIdx(2);
332
374
  String attribType = res.getStringByIdx(3);
333
-
334
-
335
- //if ( value.length() > 0 )
375
+
376
+ if ( attribType.compareTo("blob.file") == 0 )
336
377
  {
337
- if ( attribType.equals("blob.file") )
378
+ MultipartItem oItem = new MultipartItem();
379
+ oItem.m_strFilePath = RhodesApp.getInstance().resolveDBFilesPath(value);
380
+ oItem.m_strContentType = "application/octet-stream";
381
+ oItem.m_strName = strAttrib + "-" + strObject;
382
+
383
+ m_arBlobAttrs.addElement(strAttrib);
384
+ m_arMultipartItems.addElement(oItem);
385
+ }
386
+
387
+ if ( strBody.length() == 0 )
388
+ strBody += "\"" + strUpdateType + "\":{";
389
+
390
+ if ( strObject.compareTo(strCurObject) != 0 )
391
+ {
392
+ if ( strCurObject.length() > 0 )
338
393
  {
339
- FilePath oBlobPath = new FilePath(value);
340
- strSrcBody += "&attrvals[][value]=";
341
- strSrcBody += oBlobPath.getBaseName();
342
- strSrcBody += "&attrvals[][attrib_type]=blob";
343
-
344
- if ( value.length() > 0 )
345
- m_arSyncBlobs.addElement(new SyncBlob(strSrcBody,value));
346
- continue;
347
- }else
348
- strSrcBody += "&attrvals[][value]=" + value;
394
+ if ( !bFirst )
395
+ strBody += "}";
396
+ strBody += ",";
397
+ }
398
+
399
+ bFirst = true;
400
+ strBody += "\"" + strObject + "\"";
401
+ strCurObject = strObject;
349
402
  }
350
-
351
- if ( strBody.length() > 0 )
352
- strBody += "&";
353
-
354
- strBody += strSrcBody;
355
- }
356
-
357
- getDB().executeSQL("UPDATE changed_values SET sent=1 WHERE source_id=? and update_type=? and sent=0", getID(), szUpdateType );
358
- getDB().Unlock();
359
-
360
- return strBody;
361
- }
403
+
404
+ if (!bFirst)
405
+ strBody += ",";
362
406
 
363
- void getAndremoveAsk()throws DBException
364
- {
365
- String askParams = "";
366
- {
367
- IDBResult res = getDB().executeSQL("SELECT object, attrib, value "+
368
- "FROM changed_values WHERE source_id=? and update_type =?", getID(), "ask" );
369
- if ( !res.isEnd() )
407
+ if ( strAttrib.length() > 0 )
370
408
  {
371
- askParams = res.getStringByIdx(2);
409
+ if ( bFirst )
410
+ strBody += ":{";
372
411
 
373
- getDB().executeSQL("DELETE FROM object_values WHERE object=? and attrib=? and source_id=?",
374
- res.getStringByIdx(0), res.getStringByIdx(1), getID() );
412
+ strBody += "\"" + strAttrib + "\":\"" + value + "\"";
413
+ bFirst = false;
375
414
  }
376
-
377
- getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=?", getID(), "ask" );
378
415
  }
379
416
 
380
- setAskParams(askParams);
417
+ if ( strBody.length() > 0 )
418
+ {
419
+ if ( !bFirst )
420
+ strBody += "}";
421
+
422
+ strBody += "}";
423
+ }
424
+
425
+ getDB().executeSQL("UPDATE changed_values SET sent=1 WHERE source_id=? and update_type=? and sent=0", getID(), strUpdateType );
426
+ getDB().Unlock();
427
+
428
+ return strBody;
381
429
  }
382
-
430
+
383
431
  void syncServerChanges()throws Exception
384
432
  {
385
433
  LOG.INFO("Sync server changes source ID :" + getID() );
@@ -387,42 +435,24 @@ class SyncSource
387
435
  while( getSync().isContinueSync() )
388
436
  {
389
437
  setCurPageCount(0);
390
- String strUrl = getUrl();
391
- if ( m_strAction.length() > 0 )
392
- strUrl = FilePath.join(strUrl, m_strAction);
393
-
394
- String strQuery = SyncEngine.SYNC_SOURCE_FORMAT() + "&client_id=" + getSync().getClientID() +
395
- "&p_size=" + getSync().SYNC_PAGE_SIZE() + "&version=" + getSync().SYNC_VERSION();
396
- if ( m_strParams.length() > 0 )
397
- strQuery += m_strParams;
398
-
399
- if( m_strUrlParams.length() > 0 )
400
- strQuery += "&" + m_strUrlParams;
401
-
402
- if ( getAskParams().length() > 0 )
403
- {
404
- getSync();
405
- strUrl += SyncEngine.SYNC_ASK_ACTION();
406
- strQuery += "&question=" + getAskParams();
407
- }
408
-
438
+ String strUrl = getProtocol().getServerQueryUrl("");
439
+ String strQuery = getProtocol().getServerQueryBody(getName(), getSync().getClientID(), getSync().getSyncPageSize());
440
+
409
441
  if ( !m_bTokenFromDB && getToken() > 1 )
410
- strQuery += "&ack_token=" + getToken();
411
-
442
+ strQuery += "&token=" + getToken();
443
+
412
444
  LOG.INFO( "Pull changes from server. Url: " + (strUrl+strQuery) );
413
445
 
414
446
  NetResponse resp = null;
415
447
  try{
416
- PROF.START("Net");
417
- resp = getNet().pullData(strUrl+strQuery, getSync());
448
+ PROF.START("Net");
449
+ resp = getNet().pullData(strUrl+strQuery, getSync());
418
450
  PROF.STOP("Net");
419
-
451
+
420
452
  if ( !resp.isOK() )
421
453
  {
422
454
  getSync().stopSync();
423
- m_nErrCode = RhoRuby.ERR_REMOTESERVER;
424
- //m_strError = resp.getCharData();
425
-
455
+ m_nErrCode = RhoRuby.getErrorFromResponse(resp);
426
456
  continue;
427
457
  }
428
458
  }catch(Exception exc)
@@ -430,312 +460,429 @@ class SyncSource
430
460
  m_nErrCode = RhoRuby.getNetErrorCode(exc);
431
461
  throw exc;
432
462
  }
433
-
434
- processServerData(resp.getCharData());
435
-
436
- //String strData =
437
- // "[{count:16},{version:2},{rt:0},{total_count:16},{token:\"31272969717999\"},{s:\"Years\",ol:[{o:\"7\",av:[{a:\"year\",i:847548358725629473,v:\"2000\"}]},{o:\"11\",av:[{a:\"year\",i:412366391662703410,v:\"1996\"}]},{o:\"20\",av:[{a:\"year\",i:137205700852855225,v:\"2010\"}]},{o:\"8\",av:[{a:\"year\",i:679868441309756807,v:\"1999\"}]},{o:\"12\",av:[{a:\"year\",i:456800387229102986,v:\"1995\"}]},{o:\"3\",av:[{a:\"year\",i:734226969968776876,v:\"2004\"}]},{o:\"9\",av:[{a:\"year\",i:56010014622863357,v:\"1998\"}]},{o:\"17\",av:[{a:\"year\",i:822839088903421583,v:\"2007\"}]},{o:\"4\",av:[{a:\"year\",i:694980267678628747,v:\"2003\"}]},{o:\"18\",av:[{a:\"year\",i:454618145604696729,v:\"2008\"}]},{o:\"5\",av:[{a:\"year\",i:161829862235046918,v:\"2002\"}]},{o:\"1\",av:[{a:\"year\",i:429713603438265228,v:\"2006\"}]},{o:\"19\",av:[{a:\"year\",i:53905967515604512,v:\"2009\"}]},{o:\"6\",av:[{a:\"year\",i:623979215240715853,v:\"2001\"}]},{o:\"10\",av:[{a:\"year\",i:906257189782972492,v:\"1997\"}]},{o:\"2\",av:[{a:\"year\",i:659684360823905556,v:\"2005\"}]}]}]";
438
- //"[{count:10},{version:1},{total_count: 5425},{token: 123},{s:\"RhoDeleteSource\",ol:[{o:\"rho_del_obj\",av:[{i:55550425},{i:75665819},{i:338165272},{i:402396629},{i:521753981},{i:664143530},{i:678116186},{i:831092394},{i:956041217},{i:970452458}]}]}]";
439
- /*"[{count: 124},{version: 1},{total_count: 5425},{token: 123},"
440
- "{s:\"Product\",ol:["
441
- "{oo:\"123\",o:\"2ed2e0c7-8c4c-99c6-1b37-498d250bb8e7\",av:["
442
- "{a:\"first_name\",i:47354289,v:\"Lars. \n\n Burgess\", t:\"blob\"},"
443
- "{a:\"second_name\",i:55555,v:\"Burgess\"}]},"
444
- "{oo:\"456\", e:\"Something went wrong creating this record on the backend: code 7\"}"
445
- "]}]"; */
446
- /*"[{count: 1},{version: 1},{total_count: 1},{token: 123},"
447
- "{s:\"Product\",ol:["
448
- "{oo:\"94\", e:\"Something went wrong creating this record on the backend: code 7\"}"
449
- "]}]";*/
450
- /*"[{count: 1},{version: 1},{total_count: 1},{token: 123},"
451
- "{s:\"Product\",ol:["
452
- "{o:\"94\", av:["
453
- "{a:\"TEST\",i:55555,v:\"Geny\"}]},"
454
- "]}]";
455
-
456
- //u:\"query\",
457
- */
458
- //processServerData(strData);
459
-
460
- if ( getAskParams().length() > 0 || getCurPageCount() == 0 )
463
+
464
+ String szData = resp.getCharData();
465
+
466
+ PROF.START("Parse");
467
+ JSONArrayIterator oJsonArr = new JSONArrayIterator(szData);
468
+ PROF.STOP("Parse");
469
+
470
+ processServerResponse_ver3(oJsonArr);
471
+
472
+ if ( getToken() == 0 )
461
473
  break;
462
474
  }
463
475
  }
464
476
 
465
- void processServerData(String szData)throws Exception
477
+ void processServerResponse_ver3(JSONArrayIterator oJsonArr)throws Exception
466
478
  {
467
- LOG.TRACE("Server data: " + szData);
468
- PROF.START("Parse");
469
- JSONArrayIterator oJsonArr = new JSONArrayIterator(szData);
470
- PROF.STOP("Parse");
471
-
472
479
  PROF.START("Data1");
473
- if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("error") )
480
+
481
+ int nVersion = 0;
482
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
474
483
  {
475
- m_strError = oJsonArr.getCurItem().getString("error");
476
- m_nErrCode = RhoRuby.ERR_CUSTOMSYNCSERVER;
484
+ nVersion = oJsonArr.getCurItem().getInt("version");
485
+ oJsonArr.next();
486
+ }
487
+
488
+ if ( nVersion != getProtocol().getVersion() )
489
+ {
490
+ LOG.ERROR("Sync server send data with incompatible version. Client version: " + getProtocol().getVersion() +
491
+ "; Server response version: " + nVersion + ". Source name: " + getName() );
477
492
  getSync().stopSync();
493
+ m_nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
478
494
  return;
479
495
  }
480
-
481
- if ( !oJsonArr.isEnd() )
496
+
497
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source") )
482
498
  {
483
- setCurPageCount(oJsonArr.getCurItem().getInt("count"));
499
+ //skip it. it uses in search only
484
500
  oJsonArr.next();
485
501
  }
486
- int nVersion = 0;
487
- if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version") )
502
+
503
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("token"))
488
504
  {
489
- nVersion = oJsonArr.getCurItem().getInt("version");
505
+ processToken(oJsonArr.getCurItem().getUInt64("token"));
490
506
  oJsonArr.next();
491
507
  }
492
-
493
- if ( nVersion != getSync().SYNC_VERSION() )
508
+
509
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("count") )
494
510
  {
495
- LOG.ERROR("Sync server send data with incompatible version. Client version: " + getSync().SYNC_VERSION() +
496
- "; Server response version: " + nVersion + ". Source name: " + getName() );
497
- getSync().stopSync();
498
- m_nErrCode = RhoRuby.ERR_SYNCVERSION;
499
- return;
511
+ setCurPageCount(oJsonArr.getCurItem().getInt("count"));
512
+ oJsonArr.next();
500
513
  }
501
-
502
- if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("rt") )
514
+
515
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("refresh_time") )
503
516
  {
504
- setRefreshTime(oJsonArr.getCurItem().getInt("rt"));
517
+ setRefreshTime(oJsonArr.getCurItem().getInt("refresh_time"));
505
518
  oJsonArr.next();
506
519
  }
507
-
520
+
521
+ if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("progress_count") )
522
+ {
523
+ //TODO: progress_count
524
+ //setTotalCount(oJsonArr.getCurItem().getInt("progress_count"));
525
+ oJsonArr.next();
526
+ }
527
+
508
528
  if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
509
529
  {
510
530
  setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
511
531
  oJsonArr.next();
512
532
  }
513
-
514
- // if ( getServerObjectsCount() == 0 )
515
- // getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
516
-
517
- if ( !oJsonArr.isEnd() )
533
+ /* if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source-error") )
518
534
  {
519
- processToken(oJsonArr.getCurItem().getUInt64("token"));
520
- oJsonArr.next();
521
- }else if ( getCurPageCount() == 0 )
535
+ CJSONEntry oJsonErr = oJsonArr.getCurItem().getEntry("source-error");
536
+ m_strError = oJsonErr.getString("message");
537
+ m_nErrCode = RhoRuby.ERR_CUSTOMSYNCSERVER;
538
+ getSync().stopSync();
539
+ return;
540
+ }*/
541
+
542
+ //if ( getServerObjectsCount() == 0 )
543
+ // getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
544
+
545
+ if ( getToken() == 0 )
522
546
  {
523
- //oo conflicts
524
- getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
525
- //
526
- processToken(0);
547
+ //oo conflicts
548
+ getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID() );
549
+ //
550
+
527
551
  }
528
-
529
- LOG.INFO( "Got " + getCurPageCount() + "(Processed: " + getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
530
- + ". Version: " + nVersion );
531
-
532
- PROF.STOP("Data1");
533
- if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
534
- {
535
- PROF.START("Data");
536
- getDB().startTransaction();
537
-
538
- try{
539
- int nSavedPos = oJsonArr.getCurPos();
540
- setSyncServerDataPass(edpNone);
541
- processServerData_Ver1(oJsonArr);
542
-
543
- setSyncServerDataPass(edpDeleteObjects);
544
- oJsonArr.reset(nSavedPos);
545
- processServerData_Ver1(oJsonArr);
546
-
547
- PROF.STOP("Data");
548
-
549
- PROF.START("DB");
550
- getDB().endTransaction();
551
- PROF.STOP("DB");
552
-
553
- getNotify().fireObjectsNotification();
554
-
555
- }catch(Exception exc){
556
- getDB().rollback();
557
- throw exc;
558
- }
559
-
560
- }
561
-
552
+
553
+ LOG.INFO("Got " + getCurPageCount() + "(Processed: " + getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
554
+ + ". Version: " + nVersion );
555
+
556
+ PROF.STOP("Data1");
557
+ if ( !oJsonArr.isEnd() && getSync().isContinueSync() )
558
+ {
559
+ JSONEntry oCmds = oJsonArr.getCurItem();
560
+ PROF.START("Data");
561
+
562
+ getDB().startTransaction();
563
+ if ( oCmds.hasName("metadata") && getSync().isContinueSync() )
564
+ {
565
+ String strMetadata = oCmds.getString("metadata");
566
+ getDB().executeSQL("UPDATE sources SET metadata=? WHERE source_id=?", strMetadata, getID() );
567
+ }
568
+ if ( oCmds.hasName("links") && getSync().isContinueSync() )
569
+ processSyncCommand("links", oCmds.getEntry("links") );
570
+ if ( oCmds.hasName("delete") && getSync().isContinueSync() )
571
+ processSyncCommand("delete", oCmds.getEntry("delete") );
572
+ if ( oCmds.hasName("insert") && getSync().isContinueSync() )
573
+ processSyncCommand("insert", oCmds.getEntry("insert") );
574
+
575
+ PROF.STOP("Data");
576
+
577
+ PROF.START("DB");
578
+ getDB().endTransaction();
579
+ PROF.STOP("DB");
580
+
581
+ getNotify().fireObjectsNotification();
582
+ }
583
+
562
584
  PROF.START("Data1");
563
- if ( getCurPageCount() > 0 )
564
- getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
585
+ if ( getCurPageCount() > 0 )
586
+ getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
565
587
  PROF.STOP("Data1");
566
588
  }
589
+
590
+ void processSyncCommand(String strCmd, JSONEntry oCmdEntry)throws Exception
591
+ {
592
+ JSONStructIterator objIter = new JSONStructIterator(oCmdEntry);
593
+
594
+ for( ; !objIter.isEnd() && getSync().isContinueSync(); objIter.next() )
595
+ {
596
+ String strObject = objIter.getCurKey();
597
+ JSONStructIterator attrIter = new JSONStructIterator( objIter.getCurValue() );
598
+ if ( m_bSchemaSource )
599
+ processServerCmd_Ver3_Schema(strCmd,strObject,attrIter);
600
+ else
601
+ {
602
+ for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
603
+ {
604
+ String strAttrib = attrIter.getCurKey();
605
+ String strValue = attrIter.getCurString();
606
+
607
+ processServerCmd_Ver3(strCmd,strObject,strAttrib,strValue);
608
+ }
609
+ }
567
610
 
568
- boolean processSyncObject_ver1(JSONEntry oJsonObject, Integer nSrcID)throws Exception
611
+ int nSyncObjectCount = getNotify().incLastSyncObjectCount(getID());
612
+ if ( getProgressStep() > 0 && (nSyncObjectCount%getProgressStep() == 0) )
613
+ getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
614
+
615
+ if ( getDB().isUIWaitDB() )
616
+ {
617
+ LOG.INFO("Commit transaction because of UI request.");
618
+ getDB().endTransaction();
619
+ SyncThread.getInstance().sleep(1000);
620
+ getDB().startTransaction();
621
+ }
622
+ }
623
+ }
624
+
625
+ void processLinks(String strOldObject, String strNewObject)throws Exception
569
626
  {
570
- String strOldObject = oJsonObject.getString("oo");
571
- if ( isDeleteObjectsPass() != (nSrcID.intValue() < 0) )
572
- return true;
573
-
574
- if ( oJsonObject.hasName("e") )
627
+ Enumeration vals = m_hashLinks.elements();
628
+ Enumeration keys = m_hashLinks.keys();
629
+ while (vals.hasMoreElements())
630
+ {
631
+ SyncSource pSrc = getSync().findSourceByName((String)keys.nextElement());
632
+ if ( pSrc != null )
633
+ pSrc.updateLink(strOldObject, strNewObject, (String)vals.nextElement());
634
+ }
635
+ }
636
+
637
+ void updateLink(String strOldObject, String strNewObject, String strAttrib)throws Exception
638
+ {
639
+ if ( m_bSchemaSource )
575
640
  {
576
- String strError = oJsonObject.getString("e");
577
- getNotify().addCreateObjectError(nSrcID,strOldObject,strError);
578
- return true;
641
+ String strSqlUpdate = "UPDATE ";
642
+ strSqlUpdate += getName() + " SET " + strAttrib + "=? where " + strAttrib + "=?";
643
+
644
+ getDB().executeSQL(strSqlUpdate, strNewObject, strOldObject );
579
645
  }
646
+ else
647
+ getDB().executeSQL("UPDATE object_values SET value=? where attrib=? and source_id=? and value=?",
648
+ strNewObject, strAttrib, getID(), strOldObject );
580
649
 
581
- String strObject = oJsonObject.getString("o");
582
- JSONArrayIterator oJsonArr = new JSONArrayIterator(oJsonObject, "av");
583
- //oo conflicts
584
- boolean bUpdatedOO = false;
585
- //
586
- for( ; !oJsonArr.isEnd() && getSync().isContinueSync(); m_nAttribCounter++, oJsonArr.next() )
587
- {
588
- JSONEntry oJsonEntry = oJsonArr.getCurItem();
589
- if ( oJsonEntry.isEmpty() )
590
- continue;
650
+ getDB().executeSQL("UPDATE changed_values SET value=? where attrib=? and source_id=? and value=?",
651
+ strNewObject, strAttrib, getID(), strOldObject );
652
+ }
653
+
654
+ void processServerCmd_Ver3_Schema(String strCmd, String strObject, JSONStructIterator attrIter)throws Exception
655
+ {
656
+ if ( strCmd.compareTo("insert") == 0 )
657
+ {
658
+ Vector/*<String>*/ vecValues = new Vector(), vecAttrs = new Vector();
659
+ String strCols = "", strQuest = "", strSet = "";
660
+ for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
661
+ {
662
+ CAttrValue oAttrValue = new CAttrValue(attrIter.getCurKey(),attrIter.getCurString());
663
+ if ( !processBlob(strCmd,strObject,oAttrValue) )
664
+ continue;
665
+
666
+ if ( strCols.length() > 0 )
667
+ strCols += ",";
668
+ if ( strQuest.length() > 0)
669
+ strQuest += ",";
670
+ if ( strSet.length() > 0)
671
+ strSet += ",";
672
+
673
+ strCols += oAttrValue.m_strAttrib;
674
+ strQuest += "?";
675
+ strSet += oAttrValue.m_strAttrib + "=?";
676
+ vecAttrs.addElement(oAttrValue.m_strAttrib);
677
+ vecValues.addElement(oAttrValue.m_strValue);
678
+ }
679
+ vecValues.addElement(strObject);
680
+ if ( strCols.length() > 0 )
681
+ strCols += ",";
682
+ if ( strQuest.length() > 0)
683
+ strQuest += ",";
591
684
 
592
- if ( nSrcID.intValue() >= 0 ) //insert
593
- {
594
- CValue value = new CValue(oJsonEntry,1);
595
- if ( !downloadBlob(value) )
596
- return false;
597
-
598
- String strAttrib = oJsonEntry.getString("a");
599
- //oo conflicts
600
- if ( strOldObject != null && !bUpdatedOO )
685
+ strCols += "object";
686
+ strQuest += "?";
687
+
688
+ String strSqlInsert = "INSERT INTO ";
689
+ strSqlInsert += getName() + " (";
690
+ strSqlInsert += strCols + ") VALUES(" + strQuest + ")";
691
+
692
+ if ( !getSync().isContinueSync() )
693
+ return;
694
+
695
+ IDBResult resInsert = getDB().executeSQLReportNonUniqueEx(strSqlInsert, vecValues );
696
+ if ( resInsert.isNonUnique() )
697
+ {
698
+ String strSqlUpdate = "UPDATE ";
699
+ strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";
700
+ getDB().executeSQLEx(strSqlUpdate, vecValues);
701
+
702
+ // oo conflicts
703
+ for( int i = 0; i < (int)vecAttrs.size(); i++ )
601
704
  {
602
- getDB().executeSQL("UPDATE object_values SET object=? where object=? and source_id=?", strObject, strOldObject, nSrcID );
603
- getDB().executeSQL("UPDATE changed_values SET object=? where object=? and source_id=?", strObject, strOldObject, nSrcID );
705
+ getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1",
706
+ strObject, vecAttrs.elementAt(i), getID() );
707
+ }
708
+ //
709
+ }
710
+
711
+ getNotify().onObjectChanged(getID(),strObject, SyncNotify.enUpdate);
712
+ m_nInserted++;
713
+ }else if (strCmd.compareTo("delete") == 0)
714
+ {
715
+ Vector/*<String>*/ vecAttrs = new Vector();
716
+ String strSet = "";
717
+ for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
718
+ {
719
+ CAttrValue oAttrValue = new CAttrValue(attrIter.getCurKey(),attrIter.getCurString());
720
+
721
+ if ( strSet.length() > 0 )
722
+ strSet += ",";
604
723
 
605
- getNotify().onObjectChanged(nSrcID,strOldObject, SyncNotify.enCreate);
724
+ vecAttrs.addElement(oAttrValue.m_strAttrib);
725
+ strSet += oAttrValue.m_strAttrib + "=NULL";
726
+ }
606
727
 
607
- bUpdatedOO = true;
728
+ String strSqlUpdate = "UPDATE ";
729
+ strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";
730
+
731
+ if ( strSet.length() == 0 || !getSync().isContinueSync() )
732
+ return;
733
+
734
+ getDB().executeSQL(strSqlUpdate, strObject);
735
+ //Remove item if all nulls
736
+ String strSelect = "SELECT * FROM " + getName() + " WHERE object=?";
737
+ IDBResult res = getDB().executeSQL( strSelect, strObject );
738
+ if ( !res.isEnd() )
739
+ {
740
+ boolean bAllNulls = true;
741
+ for( int i = 0; i < res.getColCount(); i ++)
742
+ {
743
+ if ( !res.isNullByIdx(i) && res.getColName(i).compareTo("object")!=0 )
744
+ {
745
+ bAllNulls = false;
746
+ break;
747
+ }
608
748
  }
609
-
610
- IDBResult resInsert = getDB().executeSQLReportNonUnique("INSERT INTO object_values "+
611
- "(id, attrib, source_id, object, value, attrib_type) VALUES(?,?,?,?,?,?)",
612
- value.m_nID, strAttrib, nSrcID, strObject,
613
- value.m_strValue, value.m_strAttrType );
614
- if ( resInsert.isNonUnique() )
615
- {
616
- getDB().executeSQL("UPDATE object_values "+
617
- "SET id=?, value=?, attrib_type=? WHERE object=? and attrib=? and source_id=?",
618
- value.m_nID, value.m_strValue, value.m_strAttrType,
619
- strObject, strAttrib, nSrcID );
620
-
621
- // oo conflicts
622
- getDB().executeSQL("UPDATE changed_values SET main_id=? where object=? and attrib=? and source_id=? and sent<=1", value.m_nID, strObject, strAttrib, nSrcID );
623
- getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1", strObject, strAttrib, nSrcID );
624
- //
625
- }
626
-
627
- getNotify().onObjectChanged(nSrcID,strObject, SyncNotify.enUpdate);
628
-
629
- m_nInserted++;
630
- }else
631
- {
632
- long id = oJsonEntry.getLong("i");
633
-
634
- IDBResult res = getDB().executeSQL("SELECT source_id, object FROM object_values where id=?", id );
635
- if ( !res.isEnd() )
749
+
750
+ if (bAllNulls)
636
751
  {
637
- LOG.TRACE("Delete: " + id);
638
- Integer nDelSrcID = new Integer(res.getIntByIdx(0));
639
- String strDelObject = res.getStringByIdx(1);
640
- getDB().executeSQL("DELETE FROM object_values where id=?", id );
641
- getNotify().onObjectChanged(nDelSrcID, strDelObject, SyncNotify.enDelete);
752
+ String strDelete = "DELETE FROM " + getName() + " WHERE object=?";
753
+ getDB().executeSQL( strDelete, strObject);
642
754
  }
643
- // oo conflicts
644
- getDB().executeSQL("UPDATE changed_values SET sent=3 where main_id=?", id );
645
- //
646
-
647
- m_nDeleted++;
648
- }
649
- }
650
-
651
- return true;
755
+ }
756
+
757
+ getNotify().onObjectChanged(getID(), strObject, SyncNotify.enDelete);
758
+ // oo conflicts
759
+ for( int i = 0; i < (int)vecAttrs.size(); i++ )
760
+ {
761
+ getDB().executeSQL("UPDATE changed_values SET sent=3 where object=? and attrib=? and source_id=?",
762
+ strObject, vecAttrs.elementAt(i), getID() );
763
+ }
764
+ //
765
+
766
+ m_nDeleted++;
767
+ }else if ( strCmd.compareTo("links") == 0 )
768
+ {
769
+ String strValue = attrIter.getCurString();
770
+ processLinks(strObject, strValue);
771
+
772
+ String strSqlUpdate = "UPDATE ";
773
+ strSqlUpdate += getName() + " SET object=? WHERE object=?";
774
+ getDB().executeSQL(strSqlUpdate, strValue, strObject);
775
+
776
+ getDB().executeSQL("UPDATE changed_values SET object=?,sent=3 where object=? and source_id=?", strValue, strObject, getID() );
777
+ getNotify().onObjectChanged(getID(), strObject, SyncNotify.enCreate);
778
+ }
779
+
652
780
  }
653
781
 
654
- void processServerData_Ver1(JSONArrayIterator oJsonArr)throws Exception
782
+ boolean processBlob( String strCmd, String strObject, CAttrValue oAttrValue )throws Exception
655
783
  {
656
- for( ; !oJsonArr.isEnd() && getSync().isContinueSync(); oJsonArr.next() )
657
- {
658
- JSONEntry oJsonSource = oJsonArr.getCurItem();
659
- String strSrcName = oJsonSource.getString("s");
660
- Integer nSrcID = getID();
661
- if ( strSrcName.compareTo("RhoDeleteSource") == 0 )
662
- nSrcID = new Integer(-1);
663
- else if ( strSrcName.compareTo(getName()) != 0 )
784
+ //TODO: when server return delete with rhoblob postfix - delete isBlobAttr
785
+ if ( !(oAttrValue.m_strBlobSuffix.length() > 0 || getDB().getAttrMgr().isBlobAttr(getID(), oAttrValue.m_strAttrib)) )
786
+ return true;
787
+
788
+ boolean bDownload = true;
789
+ String strDbValue = "";
790
+ if ( !getDB().getAttrMgr().isOverwriteBlobFromServer(getID(), oAttrValue.m_strAttrib) )
791
+ {
792
+ if ( m_bSchemaSource )
664
793
  {
665
- SyncSource pSrc = getSync().findSourceByName(strSrcName);
666
- if ( pSrc == null )
794
+ String strSelect = "SELECT " + oAttrValue.m_strAttrib + " FROM " + getName() + " WHERE object=?";
795
+ IDBResult res = getDB().executeSQL( strSelect, strObject);
796
+ if (!res.isEnd())
667
797
  {
668
- LOG.ERROR("Sync server send data for unknown source name:" + strSrcName);
669
- getSync().stopSync();
670
- m_nErrCode = RhoRuby.ERR_UNEXPECTEDSERVERRESPONSE;
671
- break;
798
+ strDbValue = res.getStringByIdx(0);
799
+ bDownload = strDbValue == null || strDbValue.length() == 0;
672
800
  }
673
- nSrcID = pSrc.getID();
674
- }
675
-
676
- JSONArrayIterator oJsonObjList = new JSONArrayIterator(oJsonSource, "ol");
677
- m_nAttribCounter = 0;
678
- for( ; !oJsonObjList.isEnd() && getSync().isContinueSync(); oJsonObjList.next() )
801
+ }else
679
802
  {
680
- if ( getDB().isUIWaitDB() )//|| m_nAttribCounter >= 200 )
681
- {
682
- if ( getDB().isUIWaitDB() )
683
- LOG.INFO( "Commit transaction because of UI request." );
684
-
685
- getDB().endTransaction();
686
- getDB().startTransaction();
687
-
688
- m_nAttribCounter = 0;
689
- }
690
-
691
- JSONEntry oJsonObject = oJsonObjList.getCurItem();
692
- if( !processSyncObject_ver1(oJsonObject,nSrcID))
803
+ IDBResult res = getDB().executeSQL(
804
+ "SELECT value FROM object_values WHERE object=? and attrib=? and source_id=?",
805
+ strObject, oAttrValue.m_strAttrib, getID() );
806
+ if (!res.isEnd())
693
807
  {
694
- getSync().stopSync();
695
- break;
808
+ strDbValue = res.getStringByIdx(0);
809
+ bDownload = strDbValue == null || strDbValue.length() == 0;
696
810
  }
697
-
698
- if ( !isDeleteObjectsPass() && nSrcID.intValue() >=0 )
699
- {
700
- int nSyncObjectCount = getNotify().incLastSyncObjectCount(nSrcID);
811
+ }
812
+ }
701
813
 
702
- if ( getProgressStep() > 0 && (nSyncObjectCount%getProgressStep() == 0) )
703
- getNotify().fireSyncNotification(this, false, RhoRuby.ERR_NONE, "");
704
- }
705
-
706
- m_bGetAtLeastOnePage = true;
814
+ if ( bDownload )
815
+ {
816
+ boolean bRes = false;
817
+ getDB().endTransaction();
818
+ try{
819
+ bRes = downloadBlob(oAttrValue);
820
+ }finally
821
+ {
822
+ getDB().startTransaction();
707
823
  }
824
+
825
+ return bRes;
708
826
  }
827
+
828
+ String fName = makeFileName( oAttrValue );
829
+ String fOldName = RhodesApp.getInstance().resolveDBFilesPath(strDbValue);
830
+ RhoClassFactory.createFile().renameOverwrite(fOldName, fName);
831
+
832
+ oAttrValue.m_strValue = FilePath.getRelativePath( fName, RhodesApp.getInstance().getRhoRootPath());
833
+ return true;
709
834
  }
710
835
 
711
- class CValue
836
+ void processServerCmd_Ver3(String strCmd, String strObject, String strAttriba, String strValuea)throws Exception
712
837
  {
713
- String m_strValue;
714
- String m_strAttrType;
715
- Long m_nID;
716
-
717
- CValue(JSONEntry oJsonEntry)throws JSONException
718
- {
719
- m_strValue = oJsonEntry.getString("value");
720
- m_strAttrType = oJsonEntry.getString("attrib_type");
721
- m_nID = new Long(oJsonEntry.getLong("id"));
722
- }
723
- CValue(JSONEntry oJsonEntry, int nVer)throws JSONException
724
- {
725
- if ( nVer == 1 )
726
- {
727
- m_strValue = oJsonEntry.getString("v");
728
- m_strAttrType = oJsonEntry.getString("t");
729
- m_nID = new Long(oJsonEntry.getLong("i"));
730
- }
731
- }
838
+ CAttrValue oAttrValue = new CAttrValue(strAttriba,strValuea);
732
839
 
840
+ if ( strCmd.compareTo("insert") == 0 )
841
+ {
842
+ if ( !processBlob(strCmd,strObject,oAttrValue) )
843
+ return;
844
+
845
+ IDBResult resInsert = getDB().executeSQLReportNonUnique("INSERT INTO object_values "+
846
+ "(attrib, source_id, object, value) VALUES(?,?,?,?)",
847
+ oAttrValue.m_strAttrib, getID(), strObject, oAttrValue.m_strValue );
848
+
849
+ if ( resInsert.isNonUnique() )
850
+ {
851
+ getDB().executeSQL("UPDATE object_values " +
852
+ "SET value=? WHERE object=? and attrib=? and source_id=?",
853
+ oAttrValue.m_strValue, strObject, oAttrValue.m_strAttrib, getID() );
854
+
855
+ // oo conflicts
856
+ getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1",
857
+ strObject, oAttrValue.m_strAttrib, getID() );
858
+ //
859
+ }
860
+
861
+ getNotify().onObjectChanged(getID(),strObject, SyncNotify.enUpdate);
862
+ m_nInserted++;
863
+ }else if (strCmd.compareTo("delete") == 0)
864
+ {
865
+ getDB().executeSQL("DELETE FROM object_values where object=? and attrib=? and source_id=?", strObject, oAttrValue.m_strAttrib, getID() );
866
+ getNotify().onObjectChanged(getID(), strObject, SyncNotify.enDelete);
867
+ // oo conflicts
868
+ getDB().executeSQL("UPDATE changed_values SET sent=3 where object=? and attrib=? and source_id=?", strObject, oAttrValue.m_strAttrib, getID() );
869
+ //
870
+
871
+ m_nDeleted++;
872
+ }else if ( strCmd.compareTo("links") == 0 )
873
+ {
874
+ processLinks(strObject, oAttrValue.m_strValue);
875
+
876
+ getDB().executeSQL("UPDATE object_values SET object=? where object=? and source_id=?", oAttrValue.m_strValue, strObject, getID() );
877
+ getDB().executeSQL("UPDATE changed_values SET object=?,sent=3 where object=? and source_id=?", oAttrValue.m_strValue, strObject, getID() );
878
+
879
+ getNotify().onObjectChanged(getID(), strObject, SyncNotify.enCreate);
880
+ }
881
+
733
882
  }
734
883
 
735
- private String makeFileName(CValue value)throws Exception
884
+ private String makeFileName(CAttrValue value)throws Exception
736
885
  {
737
- String fName = DBAdapter.makeBlobFolderName();
738
-
739
886
  String strExt = ".bin";
740
887
  URI uri = new URI(value.m_strValue);
741
888
  int nDot = uri.getPath().lastIndexOf('.');
@@ -752,17 +899,13 @@ class SyncSource
752
899
  }
753
900
  }
754
901
 
755
- //TODO: add join method to Rho::FilePath
756
- fName += "id_" + value.m_nID.toString() + strExt;
902
+ String fName = RhodesApp.getInstance().getBlobsDirPath() + "/id_" + TimeInterval.getCurrentTime().toULong() + strExt;
757
903
 
758
904
  return fName;
759
905
  }
760
906
 
761
- boolean downloadBlob(CValue value)throws Exception
907
+ boolean downloadBlob(CAttrValue value)throws Exception
762
908
  {
763
- if ( value.m_strAttrType == null || !value.m_strAttrType.equals("blob.url") )
764
- return true;
765
-
766
909
  String fName = makeFileName( value );
767
910
  String url = value.m_strValue;
768
911
  int nQuest = url.lastIndexOf('?');
@@ -776,8 +919,8 @@ class SyncSource
776
919
  NetResponse resp = getNet().pullFile(url, fName, getSync(), null);
777
920
  if ( !resp.isOK() )
778
921
  {
779
- m_nErrCode = RhoRuby.ERR_REMOTESERVER;
780
- //m_strError = resp.getCharData();
922
+ getSync().stopSync();
923
+ m_nErrCode = RhoRuby.getErrorFromResponse(resp);
781
924
  return false;
782
925
  }
783
926
  }catch(Exception exc)
@@ -786,11 +929,7 @@ class SyncSource
786
929
  throw exc;
787
930
  }
788
931
 
789
- value.m_strAttrType = "blob.file";
790
-
791
- String root = RhoClassFactory.createFile().getDirPath("");
792
-
793
- value.m_strValue = "/" + fName.substring(root.length());
932
+ value.m_strValue = FilePath.getRelativePath( fName, RhodesApp.getInstance().getRhoRootPath());
794
933
 
795
934
  return true;
796
935
  }