rhodes 2.0.0.beta9 → 2.0.0.beta10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/lib/extensions/fileutils/fileutils.rb +1591 -0
  2. data/lib/extensions/rhoxml/rexml/document.rb +6 -3
  3. data/lib/extensions/rhoxml/rexml/element.rb +21 -4
  4. data/lib/extensions/rhoxml/rexml/parsers/xpathparser.rb +1 -0
  5. data/lib/framework/rho/rho.rb +72 -46
  6. data/lib/framework/rho/rhoapplication.rb +2 -13
  7. data/lib/framework/rhodes.rb +1 -1
  8. data/lib/framework/rhom/rhom_model.rb +14 -16
  9. data/lib/framework/rhom/rhom_object_factory.rb +2 -2
  10. data/lib/rhodes.rb +1 -1
  11. data/platform/android/Rhodes/res/layout/directory_list.xml +1 -1
  12. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +33 -5
  13. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Utils.java +12 -0
  14. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java +9 -12
  15. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/FileList.java +52 -72
  16. data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +1 -5
  17. data/platform/android/build/androidcommon.rb +10 -11
  18. data/platform/iphone/Classes/GeoLocation/LocationController.m +13 -1
  19. data/platform/iphone/Classes/SimpleMainView.m +14 -2
  20. data/platform/shared/ruby/thread.c +2 -0
  21. data/platform/shared/rubyJVM/src/com/rho/net/AsyncHttp.java +1 -1
  22. data/platform/shared/rubyJVM/src/com/rho/sync/SyncEngine.java +2 -2
  23. data/platform/shared/rubyJVM/src/com/rho/sync/SyncSource.java +1 -0
  24. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/ObjectFactory.java +6 -2
  25. data/platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyMatchData.java +1 -1
  26. data/platform/shared/sync/SyncEngine.cpp +3 -2
  27. data/platform/shared/sync/SyncSource.cpp +1 -0
  28. data/res/build-tools/db/syncdb.schema +0 -1
  29. data/rhodes.gemspec +1 -1
  30. metadata +4 -3
@@ -492,13 +492,16 @@ module REXML
492
492
 
493
493
  def value
494
494
  #TODO:
495
- #return @unnormalized if @unnormalized
496
- #@unnormalized = Text::unnormalize( @string, doctype )
495
+ return @unnormalized if @unnormalized
496
+ @unnormalized = Text::unnormalize( @string, doctype )
497
497
 
498
- @string
498
+ @unnormalized
499
499
  end
500
500
 
501
501
  #TODO optimize it - regular expressions is slow on BB
502
+ def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil )
503
+ string.to_s.gsub(/\&amp;/, "&").gsub(/\&quot;/, "\"").gsub(/\&gt;/, ">").gsub(/\&lt;/, "<")
504
+ end
502
505
  =begin
503
506
  def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil )
504
507
  string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) {
@@ -77,8 +77,8 @@ module REXML
77
77
  rv = "<#@expanded_name"
78
78
 
79
79
  @attributes.each_attribute do |attr|
80
- rv << " "
81
- attr.write( rv, 0 )
80
+ rv << " " << attr
81
+ #attr.write( rv, 0 )
82
82
  end
83
83
 
84
84
  if children.size > 0
@@ -913,8 +913,7 @@ module REXML
913
913
  # XPath.each(doc.root, 'child::node()', &block)
914
914
  # #-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/>
915
915
  def each( xpath=nil, &block)
916
- puts "each : #{xpath}"
917
- XPath::each( @element, xpath ) {|e| yield e if e.kind_of? Element }
916
+ XPath::each( @element, xpath ) {|e| yield e if e.kind_of?( Element) }
918
917
  end
919
918
 
920
919
  def collect( xpath=nil, &block )
@@ -983,5 +982,23 @@ module REXML
983
982
  def initialize element
984
983
  @element = element
985
984
  end
985
+
986
+ # Iterates over the attributes of an Element. Yields actual Attribute
987
+ # nodes, not String values.
988
+ #
989
+ # doc = Document.new '<a x="1" y="2"/>'
990
+ # doc.root.attributes.each_attribute {|attr|
991
+ # p attr.expanded_name+" => "+attr.value
992
+ # }
993
+ def each_attribute # :yields: attribute
994
+ each_value do |val|
995
+ #if val.kind_of? Attribute
996
+ yield val
997
+ #else
998
+ # val.each_value { |atr| yield atr }
999
+ #end
1000
+ end
1001
+ end
1002
+
986
1003
  end
987
1004
  end
@@ -17,6 +17,7 @@ module REXML
17
17
  end
18
18
 
19
19
  def parse path
20
+ return [:child, :any] if path == '*'
20
21
  path.gsub!(/([\(\[])\s+/, '\1') # Strip ignorable spaces
21
22
  path.gsub!( /\s+([\]\)])/, '\1' )
22
23
  parsed = []
@@ -39,6 +39,7 @@ module Rho
39
39
 
40
40
  # Initialize application and sources
41
41
  @@rho_framework = self
42
+ @db_partitions = {}
42
43
  init_sources()
43
44
  end
44
45
 
@@ -154,6 +155,21 @@ module Rho
154
155
  end
155
156
  end
156
157
 
158
+ def check_source_migration(app)
159
+ uniq_sources = Rho::RhoConfig::sources.values
160
+ uniq_sources.each do |source|
161
+ next unless source['migrate_version']
162
+
163
+ db = ::Rho::RHO.get_src_db(source['name'])
164
+
165
+ if !app.on_migrate_source(source['migrate_version'], source)
166
+ db.execute_batch_sql(source['schema']['sql'])
167
+ end
168
+
169
+ db.update_into_table('sources', {"schema_version"=>source['schema_version']},{"name"=>source['name']})
170
+ end
171
+ end
172
+
157
173
  def load_server_sources(data)
158
174
  puts "load_server_sources : #{data}"
159
175
 
@@ -183,23 +199,32 @@ module Rho
183
199
 
184
200
  hashSrcs = Rhom::RhomSource::find_all_ashash
185
201
  puts "hashSrcs : #{hashSrcs}"
202
+ Rho::RhoConfig::reset_max_config_srcid()
186
203
  arSrc.each do |name, src|
187
204
  oldSrc = hashSrcs[name]
188
205
  puts "oldSrc: #{oldSrc}"
189
206
  #update schema_version
190
207
  src['schema_version'] = src['schema']['version'] if src['schema'] && src['schema']['version']
191
- if oldSrc
192
- oldVer = oldSrc.schema_version
193
- newVer = src['schema_version']
194
- if ( oldVer != newVer )
195
- get_app(APPNAME).on_migrate_source(oldSrc.schema_version, src)
196
- end
208
+ src['sync_type'] ||= 'incremental'
209
+ #if oldSrc
210
+ # oldVer = oldSrc.schema_version
211
+ # newVer = src['schema_version']
212
+ # if ( oldVer != newVer )
213
+ # get_app(APPNAME).on_migrate_source(oldSrc.schema_version, src)
214
+ # end
215
+ #end
216
+
217
+ Rho::RhoConfig::sources[name] = nil
218
+ @db_partitions.each_value do |db_part|
219
+ db_part.delete_from_table('sources', {"name"=>name})
197
220
  end
198
221
 
199
222
  Rho::RhoConfig::add_source(name, src)
200
223
  end
201
224
 
202
225
  init_sources()
226
+
227
+ check_source_migration(get_app(APPNAME))
203
228
  rescue Exception => e
204
229
  puts "Error load_server_sources: #{e}"
205
230
  puts "Trace: #{e.backtrace}"
@@ -219,7 +244,6 @@ module Rho
219
244
  def init_sources()
220
245
  return unless defined? Rho::RhoConfig::sources
221
246
 
222
- @db_partitions = {}
223
247
  uniq_sources = Rho::RhoConfig::sources.values
224
248
  puts 'init_sources: ' + uniq_sources.inspect
225
249
 
@@ -229,7 +253,7 @@ module Rho
229
253
 
230
254
  uniq_sources.each do |source|
231
255
  partition = source['partition']
232
- @db_partitions[partition] = nil
256
+ @db_partitions[partition] = nil unless @db_partitions[partition]
233
257
 
234
258
  if source['belongs_to']
235
259
  source['belongs_to'].each do |attrib, src_name|
@@ -250,10 +274,11 @@ module Rho
250
274
  end
251
275
 
252
276
  #user partition should alwayse exist
253
- @db_partitions['user'] = nil
277
+ @db_partitions['user'] = nil unless @db_partitions['user']
254
278
  hash_migrate = {}
255
- @db_partitions.each_key do |partition|
256
- db = Rhom::RhomDbAdapter.new(Rho::RhoFSConnector::get_db_fullpathname(partition), partition)
279
+ puts "@db_partitions : #{@db_partitions}"
280
+ @db_partitions.each do |partition, db|
281
+ db = Rhom::RhomDbAdapter.new(Rho::RhoFSConnector::get_db_fullpathname(partition), partition) unless db
257
282
  db.start_transaction
258
283
  begin
259
284
  init_db_sources(db, uniq_sources, partition,hash_migrate)
@@ -269,35 +294,32 @@ module Rho
269
294
  ::Rho::RHO.init_schema_sources(hash_migrate)
270
295
  end
271
296
 
272
- def self.processIndexes(index_ar, src_name, is_unique)
297
+ def self.processIndexes(index_param, src_name, is_unique)
273
298
 
274
- return "" unless index_ar
299
+ return "" unless index_param
275
300
 
276
301
  strUnique = 'UNIQUE' if is_unique
277
302
  strRes = ""
278
- index_ar.each do |index_param|
279
-
280
- if index_param.is_a?( String )
281
- strRes = index_param
282
- else
283
- nInd = 0
303
+ if index_param.is_a?( String )
304
+ strRes = index_param
305
+ else
306
+ nInd = 0
307
+
308
+ index_param.each do |index_name, index_cols|
309
+ strCols = ""
310
+ if index_cols.is_a?(String)
311
+ index_cols = index_cols.split(',')
312
+ end
284
313
 
285
- index_param.each do |index_name, index_cols|
286
- strCols = ""
287
- if index_cols.is_a?(String)
288
- index_cols = index_cols.split(',')
289
- end
290
-
291
- index_cols.each do |col|
292
- strCols += ',' if strCols.length() > 0
293
- strCols += "\"#{col}\""
294
- end
295
-
296
- #strIndName = "rhoIndex" + (is_unique ? "U" : "" ) + "_#{nInd}"
297
- strIndex = "CREATE #{strUnique} INDEX \"#{index_name}\" on #{src_name} (#{strCols});\r\n"
298
- strRes += strIndex
299
- nInd += 1
314
+ index_cols.each do |col|
315
+ strCols += ',' if strCols.length() > 0
316
+ strCols += "\"#{col}\""
300
317
  end
318
+
319
+ #strIndName = "rhoIndex" + (is_unique ? "U" : "" ) + "_#{nInd}"
320
+ strIndex = "CREATE #{strUnique} INDEX \"#{index_name}\" on #{src_name} (#{strCols});\r\n"
321
+ strRes += strIndex
322
+ nInd += 1
301
323
  end
302
324
  end
303
325
  strRes
@@ -310,7 +332,7 @@ module Rho
310
332
  uniq_sources.each do |source|
311
333
  db = get_src_db(source['name'])
312
334
 
313
- next unless source['schema'] && source['model_type'] == 'fixed_schema'
335
+ next unless source['schema']
314
336
 
315
337
  call_migrate = false
316
338
  if db.table_exist?(source['name'])
@@ -354,9 +376,15 @@ module Rho
354
376
  return source['str_blob_attribs'] if source['str_blob_attribs']
355
377
  source['str_blob_attribs'] = ""
356
378
 
357
- if source['schema'] && source['schema']['property']
379
+ if source['schema']
380
+ props = source['schema']['property']
381
+ else
382
+ props = source['property']
383
+ end
384
+
385
+ if props
358
386
  str = ""
359
- source['schema']['property'].each do |name, ar_type|
387
+ props.each do |name, ar_type|
360
388
  if ar_type && ar_type.is_a?(String)
361
389
  ar_type = ar_type.split(',')
362
390
  end
@@ -389,11 +417,10 @@ module Rho
389
417
  partition = source['partition']
390
418
  sync_type = source['sync_type']
391
419
  schema_version = source['schema_version']
392
- model_type = source['model_type']
393
420
  associations = source['str_associations']
394
421
  blob_attribs = process_blob_attribs(source, db)
395
422
 
396
- attribs = db.select_from_table('sources','sync_priority,source_id,partition, sync_type, schema_version, associations, blob_attribs, model_type', {'name'=>name})
423
+ attribs = db.select_from_table('sources','sync_priority,source_id,partition, sync_type, schema_version, associations, blob_attribs', {'name'=>name})
397
424
 
398
425
  if attribs && attribs.size > 0
399
426
  if attribs[0]['sync_priority'].to_i != sync_priority.to_i
@@ -418,11 +445,7 @@ module Rho
418
445
  if attribs[0]['blob_attribs'] != blob_attribs
419
446
  db.update_into_table('sources', {"blob_attribs"=>blob_attribs},{"name"=>name})
420
447
  end
421
-
422
- if attribs[0]['model_type'] != model_type
423
- db.update_into_table('sources', {"model_type"=>model_type},{"name"=>name})
424
- end
425
-
448
+
426
449
  if !source['source_id']
427
450
  source['source_id'] = attribs[0]['source_id'].to_i
428
451
  Rho::RhoConfig::sources[name]['source_id'] = attribs[0]['source_id'].to_i
@@ -438,8 +461,7 @@ module Rho
438
461
 
439
462
  db.insert_into_table('sources',
440
463
  {"source_id"=>source['source_id'],"name"=>name, "sync_priority"=>sync_priority, "sync_type"=>sync_type, "partition"=>partition,
441
- "schema_version"=>source['schema_version'], 'associations'=>associations, 'blob_attribs'=>blob_attribs,
442
- "model_type"=>model_type })
464
+ "schema_version"=>source['schema_version'], 'associations'=>associations, 'blob_attribs'=>blob_attribs })
443
465
 
444
466
  end
445
467
 
@@ -653,6 +675,10 @@ module Rho
653
675
  def max_config_srcid
654
676
  @@max_config_srcid
655
677
  end
678
+
679
+ def reset_max_config_srcid
680
+ @@max_config_srcid = 1
681
+ end
656
682
 
657
683
  def show_log
658
684
  RhoConf.show_log
@@ -36,18 +36,7 @@ module Rho
36
36
  NativeBar.create(NOBAR_TYPE, [])
37
37
  end
38
38
 
39
- uniq_sources = Rho::RhoConfig::sources.values
40
- uniq_sources.each do |source|
41
- next unless source['migrate_version']
42
-
43
- db = ::Rho::RHO.get_src_db(source['name'])
44
-
45
- if !on_migrate_source(source['migrate_version'], source)
46
- db.execute_batch_sql(source['schema']['sql'])
47
- end
48
-
49
- db.update_into_table('sources', {"schema_version"=>source['schema_version']},{"name"=>source['name']})
50
- end
39
+ ::Rho::RHO.get_instance().check_source_migration(self)
51
40
 
52
41
  end
53
42
 
@@ -58,7 +47,7 @@ module Rho
58
47
  #return true to run script creating table
59
48
  def on_migrate_source(old_version, new_src)
60
49
  puts "on_migrate_source; old_version :#{old_version}; new_src : #{new_src}"
61
- if new_src['model_type'] == 'fixed_schema'
50
+ if new_src['schema']
62
51
  db = ::Rho::RHO.get_src_db(new_src['name'])
63
52
  db.delete_table(new_src['name'])
64
53
 
@@ -3,7 +3,7 @@ module Rhodes
3
3
  VERSION = '2.0.0'
4
4
  end
5
5
  unless defined? Rhodes::DBVERSION
6
- DBVERSION = '2.0.3'
6
+ DBVERSION = '2.0.4'
7
7
  end
8
8
 
9
9
  end
@@ -16,21 +16,22 @@ module Rhom
16
16
  end
17
17
 
18
18
  def fixed_schema?
19
- BaseModel.model_params ||= {}
20
- BaseModel.model_params["model_type"] = "property_bag" unless BaseModel.model_params["model_type"]
21
-
22
19
  false
23
20
  end
24
21
 
25
22
  def property(name,type=:string,option=nil)
26
- fixed_schema?()
23
+ if fixed_schema?()
27
24
 
28
- BaseModel.model_params ||= {}
25
+ BaseModel.model_params ||= {}
29
26
 
30
- BaseModel.model_params['schema'] ||= {}
31
- BaseModel.model_params['schema']['property'] ||= {}
32
- BaseModel.model_params['schema']['property'][name.to_s] = [type,option]
33
-
27
+ BaseModel.model_params['schema'] ||= {}
28
+ BaseModel.model_params['schema']['property'] ||= {}
29
+ BaseModel.model_params['schema']['property'][name.to_s] = [type,option]
30
+ else
31
+ BaseModel.model_params ||= {}
32
+ BaseModel.model_params['property'] ||= {}
33
+ BaseModel.model_params['property'][name.to_s] = [type,option]
34
+ end
34
35
 
35
36
  end
36
37
 
@@ -63,18 +64,18 @@ module Rhom
63
64
  return unless fixed_schema?
64
65
 
65
66
  BaseModel.model_params['schema'] ||= {}
66
- BaseModel.model_params['schema']['index'] ||= []
67
+ BaseModel.model_params['schema']['index'] ||= {}
67
68
 
68
- BaseModel.model_params['schema']['index'] << {name.to_s=>cols}
69
+ BaseModel.model_params['schema']['index'][name.to_s] = cols
69
70
  end
70
71
 
71
72
  def unique_index(name,cols)
72
73
  return unless fixed_schema?
73
74
 
74
75
  BaseModel.model_params['schema'] ||= {}
75
- BaseModel.model_params['schema']['unique_index'] ||= []
76
+ BaseModel.model_params['schema']['unique_index'] ||= {}
76
77
 
77
- BaseModel.model_params['schema']['unique_index'] << {name.to_s=>cols}
78
+ BaseModel.model_params['schema']['unique_index'][name.to_s] = cols
78
79
  end
79
80
 
80
81
  end
@@ -87,9 +88,6 @@ module Rhom
87
88
  end
88
89
 
89
90
  def fixed_schema?
90
- BaseModel.model_params ||= {}
91
- BaseModel.model_params["model_type"] = "fixed_schema" unless BaseModel.model_params["model_type"]
92
-
93
91
  true
94
92
  end
95
93
 
@@ -119,7 +119,7 @@ module Rhom
119
119
  end
120
120
 
121
121
  def is_schema_source
122
- Rho::RhoConfig.sources[get_source_name]['model_type'] == 'fixed_schema'
122
+ !Rho::RhoConfig.sources[get_source_name]['schema'].nil?
123
123
  end
124
124
  def get_schema_table_name
125
125
  get_source_name()
@@ -1059,7 +1059,7 @@ module Rhom
1059
1059
  end
1060
1060
 
1061
1061
  def is_inst_schema_source
1062
- Rho::RhoConfig.sources[get_inst_source_name]['model_type'] == 'fixed_schema'
1062
+ !Rho::RhoConfig.sources[get_inst_source_name]['schema'].nil?
1063
1063
  end
1064
1064
  def get_inst_schema_table_name
1065
1065
  get_inst_source_name()
data/lib/rhodes.rb CHANGED
@@ -3,7 +3,7 @@ module Rhodes
3
3
  VERSION = '2.0.0'
4
4
  end
5
5
  unless defined? Rhodes::DBVERSION
6
- DBVERSION = '2.0.3'
6
+ DBVERSION = '2.0.4'
7
7
  end
8
8
 
9
9
  end
@@ -21,7 +21,7 @@ android:text="Look In:"
21
21
  <LinearLayout
22
22
  android:id="@+id/buttonLayout"
23
23
  android:layout_width="fill_parent"
24
- android:layout_height="wrap_content">
24
+ android:layout_height="wrap_content" android:layout_weight="1">
25
25
 
26
26
  <ImageView android:id="@+id/preview"
27
27
  android:layout_width="120px"
@@ -168,6 +168,10 @@ public class Rhodes extends Activity {
168
168
  return path;
169
169
  }
170
170
 
171
+ public static String getBlobPath() {
172
+ return RhodesInstance.getInstance().getRootPath() + "db/db-files";
173
+ }
174
+
171
175
  private RhoLogConf m_rhoLogConf = new RhoLogConf();
172
176
  public RhoLogConf getLogConf() {
173
177
  return m_rhoLogConf;
@@ -463,6 +467,8 @@ public class Rhodes extends Activity {
463
467
  public void onCreate(Bundle savedInstanceState) {
464
468
  super.onCreate(savedInstanceState);
465
469
 
470
+ Logger.T(TAG, "+++ onCreate");
471
+
466
472
  Thread ct = Thread.currentThread();
467
473
  ct.setPriority(Thread.MAX_PRIORITY);
468
474
  uiThreadId = ct.getId();
@@ -537,29 +543,51 @@ public class Rhodes extends Activity {
537
543
  });
538
544
  init.start();
539
545
  }
540
-
546
+
541
547
  @Override
542
- public void onConfigurationChanged(Configuration newConfig) {
543
- super.onConfigurationChanged(newConfig);
548
+ protected void onRestart() {
549
+ super.onRestart();
550
+ Logger.T(TAG, "+++ onRestart");
544
551
  }
545
552
 
546
553
  @Override
547
- protected void onPause() {
548
- super.onPause();
554
+ protected void onStart() {
555
+ super.onStart();
556
+ Logger.T(TAG, "+++ onStart");
549
557
  }
550
558
 
551
559
  @Override
552
560
  protected void onResume() {
553
561
  super.onResume();
562
+ Logger.T(TAG, "+++ onResume");
563
+ }
564
+
565
+ @Override
566
+ protected void onPause() {
567
+ Logger.T(TAG, "+++ onPause");
568
+ super.onPause();
554
569
  }
555
570
 
571
+ @Override
572
+ protected void onStop() {
573
+ Logger.T(TAG, "+++ onStop");
574
+ super.onStop();
575
+ }
576
+
556
577
  @Override
557
578
  protected void onDestroy() {
579
+ Logger.T(TAG, "+++ onDestroy");
558
580
  stopSelf();
559
581
 
560
582
  super.onDestroy();
561
583
  }
562
584
 
585
+ @Override
586
+ public void onConfigurationChanged(Configuration newConfig) {
587
+ Logger.T(TAG, "+++ onConfigurationChanged");
588
+ super.onConfigurationChanged(newConfig);
589
+ }
590
+
563
591
  @Override
564
592
  public boolean onKeyDown(int keyCode, KeyEvent event) {
565
593
  switch (keyCode) {