rhodes 2.3.0 → 2.3.1.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/CHANGELOG +6 -0
  2. data/Manifest.txt +5819 -0
  3. data/README.md +2 -2
  4. data/Rakefile +9 -5
  5. data/doc/build.txt +7 -13
  6. data/doc/configuration.txt +4 -0
  7. data/doc/connect-to-web-services.txt +0 -1
  8. data/doc/device-caps.txt +2 -2
  9. data/doc/extensions.txt +2 -0
  10. data/doc/linea.txt +699 -0
  11. data/doc/rhom.txt +2 -1
  12. data/doc/synchronization.txt +39 -2
  13. data/doc/ui.txt +1 -0
  14. data/installer/README.html +1 -1
  15. data/lib/build/jake.rb +3 -0
  16. data/lib/framework/res/esri.wm.png +0 -0
  17. data/lib/framework/rho/render.rb +2 -0
  18. data/lib/framework/rho/rho.rb +17 -10
  19. data/lib/framework/rho/rhoapplication.rb +13 -3
  20. data/lib/framework/rho/rhoevent_bb.rb +3 -1
  21. data/lib/framework/rho/rhoevent_c.rb +4 -1
  22. data/lib/framework/rhodes.rb +1 -1
  23. data/lib/framework/rhom/rhom.rb +10 -0
  24. data/lib/framework/rhom/rhom_object_factory.rb +45 -0
  25. data/lib/framework/rhom/rhom_source.rb +1 -1
  26. data/lib/framework/version.rb +1 -1
  27. data/lib/rhodes.rb +1 -1
  28. data/platform/android/Rhodes/AndroidManifest.xml +2 -2
  29. data/platform/android/Rhodes/jni/include/rhodes/RhoClassFactory.h +1 -1
  30. data/platform/android/Rhodes/jni/src/RhoClassFactory.cpp +1 -1
  31. data/platform/android/Rhodes/jni/src/callbacks.cpp +9 -11
  32. data/platform/android/Rhodes/jni/src/event.cpp +17 -9
  33. data/platform/android/Rhodes/jni/src/mapview.cpp +34 -4
  34. data/platform/android/Rhodes/jni/src/rhodes.cpp +1 -1
  35. data/platform/android/Rhodes/res/drawable/esri.png +0 -0
  36. data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +1 -0
  37. data/platform/android/Rhodes/src/com/rhomobile/rhodes/BaseActivity.java +3 -0
  38. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivity.java +8 -5
  39. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +80 -9
  40. data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +29 -8
  41. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +4 -1
  42. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +50 -10
  43. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/MapView.java +3 -0
  44. data/platform/android/build/android.rake +45 -23
  45. data/platform/android/build/librhocommon_build.files +1 -0
  46. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +6 -1
  47. data/platform/bb/Hsqldb/src/org/hsqldb/CachedDataRow.java +1 -1
  48. data/platform/bb/Hsqldb/src/org/hsqldb/CachedRow.java +3 -2
  49. data/platform/bb/Hsqldb/src/org/hsqldb/Row.java +1 -1
  50. data/platform/bb/Hsqldb/src/org/hsqldb/persist/CachedObject.java +1 -1
  51. data/platform/bb/Hsqldb/src/org/hsqldb/persist/DataFileCache.java +66 -16
  52. data/platform/bb/Hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java +1 -1
  53. data/platform/bb/RubyVM/src/com/rho/RhoCrypto.java +116 -0
  54. data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +39 -2
  55. data/platform/bb/RubyVM/src/com/rho/Tokenizer.java +11 -6
  56. data/platform/bb/RubyVM/src/com/rho/db/DBAdapter.java +157 -150
  57. data/platform/bb/RubyVM/src/com/rho/db/IDBStorage.java +1 -1
  58. data/platform/bb/RubyVM/src/com/rho/file/RhoFile.java +15 -0
  59. data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +35 -23
  60. data/platform/bb/RubyVM/src/com/rho/net/NetRequest.java +6 -9
  61. data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +54 -16
  62. data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +18 -9
  63. data/platform/bb/RubyVM/src/com/rho/sync/SyncSource.java +37 -59
  64. data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +3 -0
  65. data/platform/bb/build/RubyVM_build.files +1 -0
  66. data/platform/bb/build/bb.rake +4 -5
  67. data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +4 -1
  68. data/platform/bb/rhodes/platform/5.0/com/rho/db/SqliteStorage.java +8 -3
  69. data/platform/bb/rhodes/resources/esri.png +0 -0
  70. data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +2 -0
  71. data/platform/bb/rhodes/src/com/rho/db/SqliteStorage.java +8 -3
  72. data/platform/bb/rhodes/src/com/rho/rubyext/RhoCalendar.java +4 -1
  73. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +2 -0
  74. data/platform/bb/rhodes/src/rhomobile/mapview/ESRIMapField.java +9 -0
  75. data/platform/iphone/Classes/Event/Event.m +12 -2
  76. data/platform/iphone/Classes/NativeBar.h +12 -11
  77. data/platform/iphone/Classes/NativeBar.m +13 -3
  78. data/platform/iphone/Classes/Rhodes.m +48 -10
  79. data/platform/iphone/Classes/SimpleMainView.h +1 -0
  80. data/platform/iphone/Classes/SimpleMainView.m +7 -1
  81. data/platform/iphone/Classes/SplitView/LeftViewController.m +3 -0
  82. data/platform/iphone/Classes/SplitView/RightViewController.m +11 -6
  83. data/platform/iphone/Classes/SplitView/SplittedMainView.m +8 -0
  84. data/platform/iphone/Classes/TabbedMainView.m +39 -3
  85. data/platform/iphone/Info.plist +1 -1
  86. data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +4 -0
  87. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +3 -3
  88. data/platform/shared/SyncClient/SyncClient.cpp +23 -23
  89. data/platform/shared/common/IRhoClassFactory.h +6 -4
  90. data/platform/shared/common/RhoAppAdapter.h +1 -1
  91. data/platform/shared/common/RhoFile.cpp +10 -0
  92. data/platform/shared/common/RhoFile.h +1 -0
  93. data/platform/shared/common/RhoMutexLock.h +1 -1
  94. data/platform/shared/common/RhoStd.h +5 -0
  95. data/platform/shared/common/RhoThread.cpp +2 -2
  96. data/platform/shared/common/RhoThread.h +1 -2
  97. data/platform/shared/common/RhodesApp.cpp +33 -55
  98. data/platform/shared/common/RhodesApp.h +0 -5
  99. data/platform/shared/common/RhodesAppBase.cpp +1 -1
  100. data/platform/shared/common/SplashScreen.cpp +1 -2
  101. data/platform/shared/common/ThreadQueue.cpp +31 -4
  102. data/platform/shared/common/ThreadQueue.h +10 -3
  103. data/platform/shared/common/Tokenizer.cpp +12 -8
  104. data/platform/shared/common/iphone/RhoClassFactory.cpp +5 -8
  105. data/platform/shared/common/iphone/RhoClassfactory.h +1 -1
  106. data/platform/shared/common/map/ESRIMapEngine.cpp +17 -7
  107. data/platform/shared/common/map/ESRIMapEngine.h +11 -1
  108. data/platform/shared/common/map/GoogleMapEngine.cpp +3 -3
  109. data/platform/shared/common/map/GoogleMapEngine.h +2 -2
  110. data/platform/shared/common/map/MapEngine.cpp +37 -0
  111. data/platform/shared/common/map/MapEngine.h +5 -0
  112. data/platform/shared/db/DBAdapter.cpp +113 -81
  113. data/platform/shared/db/DBAdapter.h +21 -5
  114. data/platform/shared/db/DBAttrManager.cpp +2 -2
  115. data/platform/shared/db/DBResult.h +28 -0
  116. data/platform/shared/net/AsyncHttp.cpp +48 -48
  117. data/platform/shared/net/AsyncHttp.h +15 -12
  118. data/platform/shared/net/CURLNetRequest.cpp +27 -105
  119. data/platform/shared/net/CURLNetRequest.h +8 -15
  120. data/platform/shared/net/INetRequest.cpp +122 -0
  121. data/platform/shared/net/INetRequest.h +96 -23
  122. data/platform/shared/net/ssl.cpp +1 -1
  123. data/platform/shared/ruby/ext/calendar/calendar.i +2 -2
  124. data/platform/shared/ruby/ext/calendar/calendar_wrap.c +30 -3
  125. data/platform/shared/rubyext/GeoLocation.cpp +4 -5
  126. data/platform/shared/rubyext/GeoLocation.h +4 -4
  127. data/platform/shared/rubyext/RhoAppAdapter.cpp +1 -1
  128. data/platform/shared/rubyext/System.cpp +3 -0
  129. data/platform/shared/sync/ClientRegister.cpp +6 -9
  130. data/platform/shared/sync/ClientRegister.h +8 -6
  131. data/platform/shared/sync/SyncEngine.cpp +54 -30
  132. data/platform/shared/sync/SyncEngine.h +9 -11
  133. data/platform/shared/sync/SyncNotify.cpp +19 -14
  134. data/platform/shared/sync/SyncNotify.h +5 -12
  135. data/platform/shared/sync/SyncSource.cpp +53 -76
  136. data/platform/shared/sync/SyncSource.h +5 -4
  137. data/platform/shared/sync/SyncThread.cpp +5 -7
  138. data/platform/shared/sync/SyncThread.h +2 -2
  139. data/platform/wm/RhoLib/RhoLib.vcproj +43 -39
  140. data/platform/wm/build/wm.rake +19 -17
  141. data/platform/wm/rhodes/AppManager.cpp +4 -4
  142. data/platform/wm/rhodes/MainWindow.cpp +0 -1
  143. data/platform/wm/rhodes/MapView/MapViewManager.cpp +4 -0
  144. data/platform/wm/rhodes/Vibrate.cpp +2 -2
  145. data/platform/wm/rhodes/Vibrate.h +1 -1
  146. data/platform/wm/rhodes/rho/common/RhoClassFactory.cpp +7 -5
  147. data/platform/wm/rhodes/rho/common/RhoClassFactory.h +3 -3
  148. data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +24 -10
  149. data/platform/wm/rhodes/rho/net/NetRequestImpl.h +49 -25
  150. data/platform/wm/rhodes/rho/rubyext/calendar.cpp +16 -2
  151. data/platform/wm/rhodes/rhodes.vcproj +77 -85
  152. data/platform/wm/tools/detool/detool.cpp +16 -6
  153. data/rakefile.rb +9 -5
  154. data/res/build-tools/detool.exe +0 -0
  155. data/rhodes.gemspec +2 -2
  156. data/spec/phone_spec/app/spec/blobsync_spec.rb +1 -0
  157. data/spec/phone_spec/app/spec/events_spec.rb +13 -2
  158. data/spec/phone_spec/app/spec/mapview_spec.rb +2 -2
  159. data/spec/phone_spec/app/spec/nativebar_spec.rb +3 -3
  160. data/spec/phone_spec/app/spec/navbar_spec.rb +3 -3
  161. data/spec/phone_spec/app/spec/rho_spec.rb +1 -1
  162. data/spec/phone_spec/app/spec/rhom_object_spec.rb +1 -1
  163. data/spec/phone_spec/app/spec/syncengine_spec.rb +219 -0
  164. data/spec/phone_spec/build.yml +1 -0
  165. metadata +15 -8
  166. data/platform/wm/rhodes/rho/net/NetRequest.cpp +0 -89
  167. data/platform/wm/rhodes/rho/net/NetRequest.h +0 -45
@@ -18,7 +18,7 @@ public class DBAdapter extends RubyBasic
18
18
 
19
19
  private IDBStorage m_dbStorage;
20
20
  private boolean m_bIsOpen = false;
21
- private String m_strDBPath, m_strDBVerPath;
21
+ private String m_strDBPath, m_strDbVerPath;
22
22
  private String m_strDbPartition;
23
23
  private DBAttrManager m_attrMgr = new DBAttrManager();
24
24
  static Hashtable/*Ptr<String,CDBAdapter*>*/ m_mapDBPartitions = new Hashtable();
@@ -259,7 +259,7 @@ public class DBAdapter extends RubyBasic
259
259
 
260
260
  String strPath = RhoClassFactory.createFile().getDirPath(strDBDir);
261
261
  m_strDBPath = strPath + strDBName.substring(nSlash+1);
262
- m_strDBVerPath = strPath + getNameNoExt(strDBName.substring(nSlash+1)) + ".version";
262
+ m_strDbVerPath = strPath + getNameNoExt(strDBName.substring(nSlash+1)) + ".version";
263
263
  }
264
264
 
265
265
  private String getSqlScript()
@@ -306,88 +306,80 @@ public class DBAdapter extends RubyBasic
306
306
  {
307
307
  String m_strRhoVer = "";
308
308
  String m_strAppVer = "";
309
+ boolean m_bEncrypted = false;
310
+ boolean m_bSqlite = false;
309
311
 
310
- DBVersion(){}
311
-
312
- DBVersion( String strRhoVer, String strAppVer )
312
+ boolean isRhoVerChanged(DBVersion dbNewVer)
313
313
  {
314
- m_strRhoVer = strRhoVer;
315
- m_strAppVer = strAppVer;
314
+ return m_strRhoVer.compareTo(dbNewVer.m_strRhoVer) != 0;
316
315
  }
317
- };
318
-
319
- /*private void testError()throws Exception
320
- {
321
- throw new net.rim.device.api.io.file.FileIOException(net.rim.device.api.io.file.FileIOException.FILESYSTEM_FULL);
322
- }*/
323
- DBVersion readDBVersion()throws Exception
324
- {
325
- String strFullVer = "";
326
- IRAFile file = null;
327
- try {
328
- file = RhoClassFactory.createRAFile();
329
- try{
330
- file.open(m_strDBVerPath);
331
- }catch(j2me.io.FileNotFoundException exc)
332
- {
333
- //file not exist
334
- return new DBVersion();
335
- }
336
-
337
- byte buf[] = new byte[20];
338
- // testError();
339
- int len = file.read(buf, 0, buf.length);
340
- if ( len > 0 )
341
- strFullVer = new String(buf,0,len);
342
-
343
- if ( strFullVer.length() == 0 )
344
- return new DBVersion();
345
-
346
- int nSep = strFullVer.indexOf(';');
347
- if ( nSep == -1 )
348
- return new DBVersion(strFullVer, "");
349
-
350
- return new DBVersion(strFullVer.substring(0,nSep), strFullVer.substring(nSep+1) );
316
+ boolean isAppVerChanged(DBVersion dbNewVer)
317
+ {
318
+ return m_strAppVer.compareTo(dbNewVer.m_strAppVer) != 0;
351
319
  }
352
- catch (Exception e) {
353
- LOG.ERROR("readDBVersion failed.", e);
354
- throw e;
355
- }finally
320
+
321
+ boolean isDbFormatChanged(DBVersion dbNewVer)
356
322
  {
357
- if (file!=null)
358
- try{ file.close(); }catch(Exception exc){}
323
+ return m_bEncrypted != dbNewVer.m_bEncrypted ||
324
+ m_bSqlite != dbNewVer.m_bSqlite;
359
325
  }
360
- }
361
-
362
- void writeDBVersion(DBVersion ver)throws Exception
363
- {
364
- IRAFile file = null;
365
- try{
366
- file = RhoClassFactory.createRAFile();
367
- file.open(m_strDBVerPath, "rw");
368
- String strFullVer = ver.m_strRhoVer + ";" + ver.m_strAppVer;
369
- byte[] buf = strFullVer.getBytes();
370
- file.write(buf, 0, buf.length);
371
- }catch (Exception e) {
372
- LOG.ERROR("writeDBVersion failed.", e);
373
- throw e;
374
- }finally
375
- {
376
- if (file!=null)
377
- try{ file.close(); }catch(Exception exc){}
378
- }
379
- }
326
+
327
+ void fromFile(String strFilePath)throws Exception
328
+ {
329
+ String strData = RhoFile.readStringFromFile(strFilePath);
330
+
331
+ Tokenizer oTokenizer = new Tokenizer( strData, ";" );
332
+ int nPos = 0;
333
+ while (oTokenizer.hasMoreTokens())
334
+ {
335
+ String tok = oTokenizer.nextToken();
336
+ tok.trim();
337
+
338
+ switch(nPos)
339
+ {
340
+ case 0:
341
+ m_strRhoVer = tok;
342
+ break;
343
+ case 1:
344
+ m_strAppVer = tok;
345
+ break;
346
+ case 2:
347
+ m_bEncrypted = tok.compareTo("encrypted") == 0;
348
+ break;
349
+ case 3:
350
+ m_bSqlite = tok.compareTo("sqlite") == 0;
351
+ break;
352
+ }
353
+ nPos++;
354
+ }
355
+ }
356
+
357
+ void toFile(String strFilePath)throws Exception
358
+ {
359
+ String strFullVer = m_strRhoVer + ";" + m_strAppVer +
360
+ ";" + (m_bEncrypted ? "encrypted":"") +
361
+ ";" + (m_bSqlite ? "sqlite" : "");
362
+
363
+ try{
364
+ RhoClassFactory.createFile().delete(strFilePath);
365
+ RhoFile.writeStringToFile(strFilePath, strFullVer);
366
+ }catch (Exception e) {
367
+ LOG.ERROR("writeDBVersion failed.", e);
368
+ throw e;
369
+ }
370
+ }
371
+ };
380
372
 
381
- boolean migrateDB(DBVersion dbVer, String strRhoDBVer, String strAppDBVer )
373
+ boolean migrateDB(DBVersion dbVer, DBVersion dbNewVer )
382
374
  {
383
- LOG.INFO( "Try migrate database from " + (dbVer != null ? dbVer.m_strRhoVer:"") + " to " + (strRhoDBVer !=null ? strRhoDBVer:"") );
384
- if ( dbVer != null && strRhoDBVer != null &&
385
- (dbVer.m_strRhoVer.startsWith("1.4")||dbVer.m_strRhoVer.startsWith("1.4")) && (strRhoDBVer.startsWith("1.5")||strRhoDBVer.startsWith("1.4")) )
375
+ LOG.INFO( "Try migrate database from " + (dbVer != null ? dbVer.m_strRhoVer:"") + " to " + (dbNewVer.m_strRhoVer !=null ? dbNewVer.m_strRhoVer:"") );
376
+ if ( dbVer != null && dbNewVer.m_strRhoVer != null &&
377
+ (dbVer.m_strRhoVer.startsWith("1.4")||dbVer.m_strRhoVer.startsWith("1.4")) && (dbNewVer.m_strRhoVer.startsWith("1.5")||dbNewVer.m_strRhoVer.startsWith("1.4")) )
386
378
  {
387
- LOG.INFO( "No migration required from " + (dbVer != null ? dbVer.m_strRhoVer:"") + " to " + (strRhoDBVer !=null ? strRhoDBVer:"") );
379
+ LOG.INFO( "No migration required from " + (dbVer != null ? dbVer.m_strRhoVer:"") + " to " + (dbNewVer.m_strRhoVer !=null ? dbNewVer.m_strRhoVer:"") );
388
380
 
389
381
  try{
390
- writeDBVersion( new DBVersion(strRhoDBVer, strAppDBVer) );
382
+ dbNewVer.toFile(m_strDbVerPath);
391
383
  }catch(Exception e)
392
384
  {
393
385
  LOG.ERROR("migrateDB failed.", e);
@@ -398,18 +390,18 @@ public class DBAdapter extends RubyBasic
398
390
  }
399
391
 
400
392
  //1.2.x -> 1.5.x,1.4.x
401
- if ( dbVer != null && strRhoDBVer != null &&
402
- (dbVer.m_strRhoVer.startsWith("1.2")||dbVer.m_strRhoVer.startsWith("1.4")) && (strRhoDBVer.startsWith("1.5")||strRhoDBVer.startsWith("1.4")) )
393
+ if ( dbVer != null && dbNewVer.m_strRhoVer != null &&
394
+ (dbVer.m_strRhoVer.startsWith("1.2")||dbVer.m_strRhoVer.startsWith("1.4")) && (dbNewVer.m_strRhoVer.startsWith("1.5")||dbNewVer.m_strRhoVer.startsWith("1.4")) )
403
395
  {
404
396
  //sources
405
397
  //priority INTEGER, ADD
406
398
  //backend_refresh_time int default 0, ADD
407
- LOG.INFO("Migrate database from " + dbVer.m_strRhoVer + " to " + strRhoDBVer);
399
+ LOG.INFO("Migrate database from " + dbVer.m_strRhoVer + " to " + dbNewVer.m_strRhoVer);
408
400
 
409
401
  IDBStorage db = null;
410
402
  try{
411
403
  db = RhoClassFactory.createDBStorage();
412
- db.open( m_strDBPath, getSqlScript() );
404
+ db.open( m_strDBPath, getSqlScript(), getEncryptionInfo() );
413
405
 
414
406
  db.executeSQL( "ALTER TABLE sources ADD priority INTEGER", null, false);
415
407
  db.executeSQL( "ALTER TABLE sources ADD backend_refresh_time int default 0", null, false);
@@ -429,7 +421,7 @@ public class DBAdapter extends RubyBasic
429
421
  db.close();
430
422
  db = null;
431
423
 
432
- writeDBVersion( new DBVersion(strRhoDBVer, strAppDBVer) );
424
+ dbNewVer.toFile(m_strDbVerPath);
433
425
 
434
426
  return true;
435
427
  }catch(Exception e)
@@ -451,85 +443,100 @@ public class DBAdapter extends RubyBasic
451
443
  return false;
452
444
  }
453
445
 
454
- void checkDBVersion()throws Exception
446
+ String getEncryptionInfo()
455
447
  {
456
- String strRhoDBVer = RhoSupport.getRhoDBVersion();
457
- String strAppDBVer = RhoConf.getInstance().getString("app_db_version");
448
+ boolean bEncrypted = AppBuildConfig.getItem("encrypt_database") != null &&
449
+ AppBuildConfig.getItem("encrypt_database").compareTo("1") == 0;
458
450
 
459
- DBVersion dbVer = readDBVersion();
460
-
461
- boolean bRhoReset = false;
462
- boolean bAppReset = false;
451
+ String strRes = "";
463
452
 
464
- if ( strRhoDBVer != null && strRhoDBVer.length() > 0 )
453
+ if (bEncrypted)
454
+ {
455
+ String strAppName = "rhodes";
456
+ try{
457
+ strAppName = RhoClassFactory.createRhoRubyHelper().getModuleName();
458
+ }catch(Exception e){}
459
+
460
+ strRes = m_strDbPartition + "_" + strAppName;
461
+ }
462
+ return strRes;
463
+ }
464
+
465
+ void checkDBVersion()throws Exception
466
+ {
467
+ DBVersion dbNewVer = new DBVersion();
468
+ dbNewVer.m_strRhoVer = RhoSupport.getRhoDBVersion();
469
+ dbNewVer.m_strAppVer = RhoConf.getInstance().getString("app_db_version");
470
+ String strEncryptionInfo = getEncryptionInfo();
471
+ dbNewVer.m_bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
472
+ dbNewVer.m_bSqlite = Capabilities.USE_SQLITE;
473
+
474
+ DBVersion dbVer = new DBVersion();
475
+ dbVer.fromFile(m_strDbVerPath);
476
+
477
+ if (dbVer.m_strRhoVer.length() == 0 )
465
478
  {
466
- if ( dbVer == null || dbVer.m_strRhoVer == null || !dbVer.m_strRhoVer.equalsIgnoreCase(strRhoDBVer) )
467
- bRhoReset = true;
479
+ dbNewVer.toFile(m_strDbVerPath);
480
+ return;
468
481
  }
469
- if ( strAppDBVer != null && strAppDBVer.length() > 0 )
482
+
483
+ boolean bRhoReset = dbVer.isRhoVerChanged(dbNewVer);
484
+ boolean bAppReset = dbVer.isAppVerChanged(dbNewVer);
485
+
486
+ boolean bDbFormatChanged = dbVer.isDbFormatChanged(dbNewVer);
487
+ if ( !bDbFormatChanged && dbVer.m_bEncrypted )
470
488
  {
471
- if ( dbVer == null || dbVer.m_strAppVer == null || !dbVer.m_strAppVer.equalsIgnoreCase(strAppDBVer) )
472
- bAppReset = true;
489
+ if (!com.rho.RhoCrypto.isKeyExist(strEncryptionInfo) )
490
+ bDbFormatChanged = true;
473
491
  }
474
492
 
475
- if ( bRhoReset && !bAppReset )
476
- bRhoReset = !migrateDB(dbVer, strRhoDBVer, strAppDBVer);
477
- else if ( Capabilities.USE_SQLITE )
478
- {
479
- IFileAccess fs = RhoClassFactory.createFileAccess();
480
- String dbName = getNameNoExt(m_strDBPath);
481
- String dbNameScript = dbName + ".script";
482
- String dbNameData = dbName + ".data";
483
- String dbNameJournal = dbName + ".journal";
484
- String dbNameProperties = dbName + ".properties";
485
-
486
- if ( fs.exists(dbNameScript) )
487
- {
488
- LOG.INFO("Remove hsqldb and use sqlite for Blackberry>=5.");
489
-
490
- fs.delete(dbNameScript);
491
- fs.delete(dbNameData);
492
- fs.delete(dbNameJournal);
493
- fs.delete(dbNameProperties);
494
- bRhoReset = true;
495
- }
496
- }
493
+ if ( bDbFormatChanged )
494
+ LOG.INFO("Reset Database( format changed ):" + m_strDBPath);
495
+
496
+ if ( bRhoReset && !bAppReset && !bDbFormatChanged )
497
+ bRhoReset = !migrateDB(dbVer, dbNewVer);
497
498
 
498
- if ( bRhoReset || bAppReset )
499
+ if ( bRhoReset || bAppReset || bDbFormatChanged)
499
500
  {
500
- IDBStorage db = null;
501
- try
501
+ if ( !bDbFormatChanged )
502
502
  {
503
- db = RhoClassFactory.createDBStorage();
504
- if ( db.isDbFileExists(m_strDBPath) )
503
+ IDBStorage db = null;
504
+ try
505
505
  {
506
- db.open( m_strDBPath, "" );
507
- IDBResult res = db.executeSQL("SELECT * FROM client_info", null, false);
508
- if ( !res.isOneEnd() )
509
- {
510
- m_strClientInfoInsert = createInsertStatement(res, "client_info");
511
- m_dataClientInfo = res.getCurData();
512
- }
506
+ db = RhoClassFactory.createDBStorage();
507
+ if ( db.isDbFileExists(m_strDBPath) )
508
+ {
509
+ db.open( m_strDBPath, "", strEncryptionInfo );
510
+ IDBResult res = db.executeSQL("SELECT * FROM client_info", null, false);
511
+ if ( !res.isOneEnd() )
512
+ {
513
+ m_strClientInfoInsert = createInsertStatement(res, "client_info");
514
+ m_dataClientInfo = res.getCurData();
515
+ }
516
+ }
517
+ }catch(Exception exc)
518
+ {
519
+ LOG.ERROR("Copy client_info table failed.", exc);
520
+ }catch(Throwable e)
521
+ {
522
+ LOG.ERROR("Copy client_info table crashed.", e);
523
+ }finally
524
+ {
525
+ if (db != null )
526
+ try{ db.close(); }catch(Exception e){}
513
527
  }
514
- }catch(Exception exc)
515
- {
516
- LOG.ERROR("Copy client_info table failed.", exc);
517
- }catch(Throwable e)
518
- {
519
- LOG.ERROR("Copy client_info table crashed.", e);
520
- }finally
521
- {
522
- if (db != null )
523
- try{ db.close(); }catch(Exception e){}
524
528
  }
525
-
529
+
526
530
  m_dbStorage.deleteAllFiles(m_strDBPath);
527
531
 
528
- String fName = makeBlobFolderName();
529
- RhoClassFactory.createFile().delete(fName);
530
- DBAdapter.makeBlobFolderName(); //Create folder back
532
+ if ( this.m_strDbPartition.compareTo("user") == 0 ) //do it only once
533
+ {
534
+ String fName = makeBlobFolderName();
535
+ RhoClassFactory.createFile().delete(fName);
536
+ DBAdapter.makeBlobFolderName(); //Create folder back
537
+ }
531
538
 
532
- writeDBVersion(new DBVersion(strRhoDBVer, strAppDBVer) );
539
+ dbNewVer.toFile(m_strDbVerPath);
533
540
 
534
541
  if ( RhoConf.getInstance().isExist("bulksync_state") && RhoConf.getInstance().getInt("bulksync_state") != 0)
535
542
  RhoConf.getInstance().setInt("bulksync_state", 0, true);
@@ -579,7 +586,7 @@ public class DBAdapter extends RubyBasic
579
586
  if ( !bTemp )
580
587
  checkDBVersion();
581
588
 
582
- m_dbStorage.open(m_strDBPath, getSqlScript() );
589
+ m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo() );
583
590
 
584
591
  //executeSQL("CREATE INDEX by_src ON object_values (source_id)", null);
585
592
  m_bIsOpen = true;
@@ -694,7 +701,7 @@ public class DBAdapter extends RubyBasic
694
701
  LOG.TRACE("1. Size of " + dbNameData + ": " + fs.size(dbNameData));
695
702
 
696
703
  db = RhoClassFactory.createDBStorage();
697
- db.open( dbNewName, getSqlScript() );
704
+ db.open( dbNewName, getSqlScript(), getEncryptionInfo() );
698
705
 
699
706
  String[] vecTables = m_dbStorage.getAllTableNames();
700
707
  //IDBResult res;
@@ -734,7 +741,7 @@ public class DBAdapter extends RubyBasic
734
741
  LOG.TRACE("3. Size of " + dbNameData + ": " + fs.size(dbNameData));
735
742
 
736
743
  m_dbStorage = RhoClassFactory.createDBStorage();
737
- m_dbStorage.open(m_strDBPath, getSqlScript() );
744
+ m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo() );
738
745
  m_bIsOpen = true;
739
746
 
740
747
  //getAttrMgr().load(this);
@@ -749,7 +756,7 @@ public class DBAdapter extends RubyBasic
749
756
  {
750
757
  LOG.ERROR("destroy_table error.Try to open old DB.");
751
758
  try{
752
- m_dbStorage.open(m_strDBPath, getSqlScript() );
759
+ m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo() );
753
760
  m_bIsOpen = true;
754
761
  }catch(Exception exc)
755
762
  {
@@ -808,7 +815,7 @@ public class DBAdapter extends RubyBasic
808
815
  IDBResult resSrc = executeSQL("SELECT name, schema FROM sources where source_id=?", arSrcID.elementAt(i) );
809
816
  boolean bSchemaSource = false;
810
817
  String strTableName = "object_values";
811
- if ( !resSrc.isEnd() )
818
+ if ( !resSrc.isOneEnd() )
812
819
  {
813
820
  bSchemaSource = resSrc.getStringByIdx(1).length() > 0;
814
821
  if ( bSchemaSource )
@@ -889,10 +896,10 @@ public class DBAdapter extends RubyBasic
889
896
  {
890
897
  DBAdapter db = null;
891
898
  try{
892
- db = (DBAdapter)alloc(null);
899
+ db = (DBAdapter)alloc(null);
900
+ db.setDbPartition(m_strDbPartition);
893
901
  db.openDB(fDbName, true);
894
902
  db.m_dbStorage.createTriggers();
895
- db.setDbPartition(m_strDbPartition);
896
903
 
897
904
  db.startTransaction();
898
905
 
@@ -951,7 +958,7 @@ public class DBAdapter extends RubyBasic
951
958
  fs.renameOverwrite(fScriptName, dbNameScript);
952
959
 
953
960
  m_dbStorage = RhoClassFactory.createDBStorage();
954
- m_dbStorage.open(m_strDBPath, getSqlScript() );
961
+ m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo() );
955
962
  m_bIsOpen = true;
956
963
 
957
964
  //getAttrMgr().load(this);
@@ -966,7 +973,7 @@ public class DBAdapter extends RubyBasic
966
973
  {
967
974
  LOG.ERROR("destroy_table error.Try to open old DB.");
968
975
  try{
969
- m_dbStorage.open(m_strDBPath, getSqlScript() );
976
+ m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo() );
970
977
  m_bIsOpen = true;
971
978
  }catch(Exception exc)
972
979
  {
@@ -1152,8 +1159,8 @@ public class DBAdapter extends RubyBasic
1152
1159
  {
1153
1160
  String szDbName = arg1.toStr();
1154
1161
  String szDbPartition = arg2.toStr();
1162
+ ((DBAdapter)receiver).setDbPartition(szDbPartition);
1155
1163
  ((DBAdapter)receiver).openDB(szDbName, false);
1156
- ((DBAdapter)receiver).setDbPartition(szDbPartition);
1157
1164
 
1158
1165
  DBAdapter.getDBPartitions().put(szDbPartition, receiver);
1159
1166
 
@@ -2,7 +2,7 @@ package com.rho.db;
2
2
 
3
3
  public interface IDBStorage {
4
4
 
5
- public abstract void open(String strPath, String strSqlScript)throws DBException;
5
+ public abstract void open(String strPath, String strSqlScript, String strEncryptionInfo)throws DBException;
6
6
  public abstract void close()throws DBException;
7
7
 
8
8
  public abstract IDBResult executeSQL(String strStatement, Object[] values, boolean bReportNonUnique)throws DBException;
@@ -35,6 +35,21 @@ public class RhoFile
35
35
  return strRes;
36
36
  }
37
37
 
38
+ public static void writeStringToFile(String szFilePath, String strData)throws Exception
39
+ {
40
+ IRAFile file = null;
41
+ try{
42
+ file = RhoClassFactory.createRAFile();
43
+ file.open(szFilePath, "w");
44
+ byte[] buf = strData.getBytes();
45
+ file.write(buf, 0, buf.length);
46
+ }finally
47
+ {
48
+ if (file!=null)
49
+ try{ file.close(); }catch(Exception exc){}
50
+ }
51
+ }
52
+
38
53
  public static String readStringFromJarFile(String szFilePath, Object root)
39
54
  {
40
55
  java.io.InputStream fstream = null;
@@ -22,7 +22,6 @@ public class AsyncHttp extends ThreadQueue
22
22
  private static RhodesApp RHODESAPP(){ return RhodesApp.getInstance(); }
23
23
 
24
24
  static AsyncHttp m_pInstance;
25
- HttpCommand m_pCurCmd;
26
25
 
27
26
  static AsyncHttp Create()
28
27
  {
@@ -37,7 +36,7 @@ public class AsyncHttp extends ThreadQueue
37
36
  {
38
37
  if ( m_pInstance != null )
39
38
  {
40
- m_pInstance.cancelRequest("*", true);
39
+ m_pInstance.stop(-1);
41
40
  LOG.INFO("Thread shutdown");
42
41
 
43
42
  m_pInstance = null;
@@ -52,11 +51,9 @@ public class AsyncHttp extends ThreadQueue
52
51
  ThreadQueue.setLogCategory(LOG.getLogCategory());
53
52
 
54
53
  setPollInterval(QUEUE_POLL_INTERVAL_INFINITE);
55
-
56
- m_pCurCmd = null;
57
54
  }
58
55
 
59
- void cancelRequest(String szCallback, boolean bWait)
56
+ void cancelRequest(String szCallback)
60
57
  {
61
58
  if (szCallback == null || szCallback.length() == 0 )
62
59
  {
@@ -64,31 +61,48 @@ public class AsyncHttp extends ThreadQueue
64
61
  return;
65
62
  }
66
63
 
67
- if ( m_pCurCmd != null )
68
- m_pCurCmd.cancel();
69
-
70
- if ( bWait )
71
- stop(-1);
72
-
73
- //TODO: find command by callback and cancel it if current, remove if it is still in queue
64
+ synchronized(getCommandLock())
65
+ {
66
+ HttpCommand pCmd = (HttpCommand)getCurCommand();
67
+
68
+ if ( pCmd != null && ( szCallback.compareTo("*") == 0 || pCmd.m_strCallback.compareTo(szCallback) == 0) )
69
+ pCmd.cancel();
70
+
71
+ if ( szCallback.compareTo("*") == 0 )
72
+ getCommands().clear();
73
+ else
74
+ {
75
+ for (int i = getCommands().size()-1; i >= 0; i--)
76
+ {
77
+ HttpCommand pCmd1 = (HttpCommand)getCommands().get(i);
78
+
79
+ if ( pCmd1 != null && pCmd1.m_strCallback.compareTo(szCallback) == 0 )
80
+ getCommands().remove(i);
81
+ }
82
+
83
+ }
84
+ }
74
85
  }
75
86
 
76
- public void addQueueCommand(IQueueCommand pCmd)
87
+ public RubyValue addHttpCommand(IQueueCommand pCmd)
77
88
  {
78
89
  if ( ((HttpCommand)pCmd).m_strCallback.length()==0)
79
- processCommand(pCmd);
90
+ {
91
+ processCommandBase(pCmd);
92
+ return ((HttpCommand)pCmd).getRetValue();
93
+ }
80
94
  else
81
95
  {
82
96
  super.addQueueCommand(pCmd);
83
97
  start(epLow);
98
+
99
+ return ((HttpCommand)pCmd).getRetValue();
84
100
  }
85
101
  }
86
102
 
87
103
  public void processCommand(IQueueCommand pCmd)
88
104
  {
89
- m_pCurCmd = (HttpCommand)pCmd;
90
- m_pCurCmd.execute();
91
- m_pCurCmd = null;
105
+ ((HttpCommand)pCmd).execute();
92
106
  }
93
107
 
94
108
  public final static int hcNone = 0, hcGet = 1, hcPost=2, hcDownload=3, hcUpload =4;
@@ -245,9 +259,9 @@ public class AsyncHttp extends ThreadQueue
245
259
  }
246
260
  }
247
261
 
248
- void cancel()
262
+ public void cancel()
249
263
  {
250
- if (m_pNetRequest!=null && !m_pNetRequest.isCancelled() )
264
+ if (m_pNetRequest!=null )
251
265
  m_pNetRequest.cancel();
252
266
  }
253
267
 
@@ -355,9 +369,7 @@ public class AsyncHttp extends ThreadQueue
355
369
  AsyncHttp.Create();
356
370
 
357
371
  String command = arg1.toStr();
358
- AsyncHttp.HttpCommand pHttp = new AsyncHttp.HttpCommand( command, arg2 );
359
- AsyncHttp.getInstance().addQueueCommand(pHttp);
360
- return pHttp.getRetValue();
372
+ return AsyncHttp.getInstance().addHttpCommand(new AsyncHttp.HttpCommand( command, arg2 ));
361
373
  } catch(Exception e) {
362
374
  LOG.ERROR("do_request failed", e);
363
375
  throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
@@ -371,7 +383,7 @@ public class AsyncHttp extends ThreadQueue
371
383
  try {
372
384
  String cancel_callback = arg.toStr();
373
385
  if ( AsyncHttp.getInstance() != null )
374
- AsyncHttp.getInstance().cancelRequest(cancel_callback, false);
386
+ AsyncHttp.getInstance().cancelRequest(cancel_callback);
375
387
 
376
388
  } catch(Exception e) {
377
389
  LOG.ERROR("cancel failed", e);
@@ -181,13 +181,13 @@ public class NetRequest
181
181
  writeHeaders(headers);
182
182
  m_connection.setRequestMethod(strMethod);
183
183
  }
184
+
185
+ is = m_connection.openInputStream();
186
+ LOG.INFO("openInputStream done");
184
187
 
185
188
  code = m_connection.getResponseCode();
186
189
  LOG.INFO("getResponseCode : " + code);
187
190
 
188
- is = m_connection.openInputStream();
189
- LOG.INFO("openInputStream done");
190
-
191
191
  readHeaders(headers);
192
192
  copyHashtable(m_OutHeaders, headers);
193
193
 
@@ -529,6 +529,8 @@ public class NetRequest
529
529
 
530
530
  m_connection.setRequestMethod(IHttpConnection.GET);
531
531
 
532
+ is = m_connection.openInputStream();
533
+
532
534
  code = m_connection.getResponseCode();
533
535
 
534
536
  LOG.INFO("getResponseCode : " + code);
@@ -552,16 +554,11 @@ public class NetRequest
552
554
  oSession.logout();
553
555
  }
554
556
 
555
- //if ( code != IHttpConnection.HTTP_INTERNAL_ERROR )
556
- {
557
- is = m_connection.openInputStream();
558
- strRespBody = readFully(is, getResponseEncoding());
559
- }
557
+ strRespBody = readFully(is, getResponseEncoding());
560
558
  }else
561
559
  {
562
560
  int nRead = 0;
563
561
 
564
- is = m_connection.openInputStream();
565
562
  byte[] byteBuffer = new byte[1024*20];
566
563
 
567
564
  do{