Class: Rho::RHO
- Defined in:
- lib/framework/rho/rho.rb,
lib/framework/autocomplete/Rho.rb
Constant Summary collapse
- APPLICATIONS =
{}
- APPNAME =
'app'
- CR =
"\x0d"
- LF =
"\x0a"
- CRLF =
"\x0d\x0a"
- @@rho_framework =
nil
- @@native_bar_initialized =
nil
- @@use_new_orm =
false
- @@current_exception =
nil
Instance Attribute Summary collapse
-
#db_partitions ⇒ Object
readonly
Returns the value of attribute db_partitions.
Class Method Summary collapse
- .check_source_migration(source) ⇒ Object
- .check_sources_migration(uniq_sources) ⇒ Object
- .current_exception ⇒ Object
- .get_db_partitions ⇒ Object
- .get_instance ⇒ Object
- .get_src_db(src_name) ⇒ Object
- .get_user_db ⇒ Object
- .init_schema_sources(hash_migrate) ⇒ Object
- .init_schema_sources_partition(uniq_sources, hash_migrate, partition, db) ⇒ Object
- .init_sync_source_properties(uniq_sources) ⇒ Object
- .load_all_sources ⇒ Object
- .make_createsql_script(name, schema_attr) ⇒ Object
- .processIndexes(index_param, src_name, is_unique) ⇒ Object
- .use_new_orm ⇒ Object
Instance Method Summary collapse
- #_load_models_from_file(f) ⇒ Object
- #activate_app ⇒ Object
- #deactivate_app ⇒ Object
- #find_src_byname(db_sources, name) ⇒ Object
- #get_app(appname) ⇒ Object
- #get_start_id(db_sources, db_partition) ⇒ Object
- #init_app ⇒ Object
- #init_db_sources(db, uniq_sources, db_partition, hash_migrate) ⇒ Object
- #init_nativebar ⇒ Object
- #init_response(status, message, body) ⇒ Object
-
#init_sources ⇒ Object
setup the sources table and model attributes for all applications.
-
#initialize(app_manifest_filename = nil) ⇒ RHO
constructor
A new instance of RHO.
- #load_all_sync_sources ⇒ Object
- #load_model(modelName, init_db) ⇒ Object
- #load_models_from_file(app_manifest_filename) ⇒ Object
- #load_server_sources(data) ⇒ Object
- #make_httpdate(t) ⇒ Object
- #on_config_conflicts(conflicts) ⇒ Object
- #process_blob_attribs(source, db) ⇒ Object
- #process_model_dirs(app_manifest_filename) ⇒ Object
- #raise_rhoerror(errCode) ⇒ Object
- #reset_db_on_sync_user_changed ⇒ Object
- #send_error(exception, status, hash) ⇒ Object
- #send_response(res) ⇒ Object
- #send_response_hash(res) ⇒ Object
- #serve(req) ⇒ Object
- #serve_hash(req) ⇒ Object
- #serve_index(index_name, req) ⇒ Object
- #serve_index_hash(index_name, req) ⇒ Object
- #set_app(appname, app) ⇒ Object
- #ui_created ⇒ Object
- #ui_destroyed ⇒ Object
Constructor Details
#initialize(app_manifest_filename = nil) ⇒ RHO
Returns a new instance of RHO.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/framework/rho/rho.rb', line 70 def initialize(app_manifest_filename=nil) puts "Calling RHO.initialize #{app_manifest_filename}, use_new_orm: #{Rho::RhoConfig.use_new_orm.to_i}" @@use_new_orm = (Rho::RhoConfig.use_new_orm.to_i > 0 ? true : false) if(@@use_new_orm) puts "MZV_DEBUG: we are in use_new_orm true #{@@use_new_orm}" else puts "MZV_DEBUG: we are in use_new_orm false #{@@use_new_orm}" end # Initialize application and sources @@rho_framework = self @db_partitions = {} partitions = ['app','user','local'] partitions.each do |partition| @db_partitions[partition] = Rhom::RhomDbAdapter.new(Rho::RhoFSConnector::get_db_fullpathname(partition), partition) end require 'rhom' unless @@use_new_orm if app_manifest_filename load_models_from_file(app_manifest_filename) else load_models_from_file(Rho::RhoFSConnector::get_app_manifest_filename) end else Rhom::Rhom.get_instance().load_models(app_manifest_filename) end end |
Instance Attribute Details
#db_partitions ⇒ Object (readonly)
Returns the value of attribute db_partitions.
99 100 101 |
# File 'lib/framework/rho/rho.rb', line 99 def db_partitions @db_partitions end |
Class Method Details
.check_source_migration(source) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/framework/rho/rho.rb', line 249 def self.check_source_migration(source) return unless source.has_key?('migrate_version') db = ::Rho::RHO.get_src_db(source['name']) if !get_instance().get_app(APPNAME).on_migrate_source(source['migrate_version'], source) db.execute_batch_sql(source['schema']['sql']) end db.update_into_table('sources', {"schema_version"=>source['schema_version']},{"name"=>source['name']}) end |
.check_sources_migration(uniq_sources) ⇒ Object
243 244 245 246 247 |
# File 'lib/framework/rho/rho.rb', line 243 def self.check_sources_migration(uniq_sources) uniq_sources.each do |source| check_source_migration(source) end end |
.current_exception ⇒ Object
999 1000 1001 |
# File 'lib/framework/rho/rho.rb', line 999 def self.current_exception @@current_exception end |
.get_db_partitions ⇒ Object
121 122 123 |
# File 'lib/framework/rho/rho.rb', line 121 def self.get_db_partitions @@rho_framework.db_partitions end |
.get_instance ⇒ Object
62 63 64 |
# File 'lib/framework/rho/rho.rb', line 62 def self.get_instance @@rho_framework end |
.get_src_db(src_name) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/framework/rho/rho.rb', line 101 def self.get_src_db(src_name=nil) if src_name unless @@use_new_orm src_partition = Rho::RhoConfig.sources[src_name]['partition'] @@rho_framework.db_partitions[src_partition] else models = Rho::NewORMModel.enumerate model = models.detect { |m| m.model_name == src_name } src_partition = model.partition @@rho_framework.db_partitions[src_partition] end else @@rho_framework.db_partitions['user'] end end |
.get_user_db ⇒ Object
117 118 119 |
# File 'lib/framework/rho/rho.rb', line 117 def self.get_user_db @@rho_framework.db_partitions['user'] end |
.init_schema_sources(hash_migrate) ⇒ Object
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/framework/rho/rho.rb', line 578 def self.init_schema_sources(hash_migrate) uniq_sources = Rho::RhoConfig::sources.values puts 'init_schema_sources' ::Rho::RHO.get_db_partitions().each do |partition, db| db.start_transaction begin init_schema_sources_partition(uniq_sources, hash_migrate, partition, db) db.commit rescue Exception => e trace_msg = e.backtrace.join("\n") puts "exception when init_schema_sources: #{e}; Trace:" + trace_msg db.rollback end end puts 'END init_schema_sources' end |
.init_schema_sources_partition(uniq_sources, hash_migrate, partition, db) ⇒ Object
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/framework/rho/rho.rb', line 599 def self.init_schema_sources_partition(uniq_sources, hash_migrate, partition, db) uniq_sources.each do |source| next unless partition == source['partition'] next unless source['schema'] call_migrate = false if db.table_exist?(source['name']) next unless hash_migrate.has_key?(source['name']) call_migrate = true end strCreate =nil if source['schema'].is_a?(String) strCreate = source['schema'] else raise ArgumentError, "schema parameter should be Hash!" unless source['schema'].is_a?(Hash) strCreate = make_createsql_script(source['name'], source['schema']) end #puts "source['schema'] : #{source['schema']}" #hashSchema = Rho::JSON.parse(source['schema']) #puts "hashSchema : #{hashSchema}" #src['schema'] = hashSchema #source['schema']['sql'] = strCreate #src['schema_version'] = hashSchema['version'] #strCreate = source['schema'] #puts "strCreate: #{strCreate}" if call_migrate db.update_into_table('sources', {"schema"=>strCreate},{"name"=>source['name']}) #::Rho::RHO.get_user_db().update_into_table('sources', {"schema"=>strCreate},{"name"=>source['name']}) if db != ::Rho::RHO.get_user_db() source['migrate_version'] = hash_migrate[ source['name'] ] source['schema']['sql'] = strCreate else db.execute_batch_sql(strCreate) db.update_into_table('sources', {"schema"=>strCreate, "schema_version"=>source['schema_version']},{"name"=>source['name']}) #::Rho::RHO.get_user_db().update_into_table('sources', {"schema"=>strCreate, "schema_version"=>source['schema_version']},{"name"=>source['name']}) if db != ::Rho::RHO.get_user_db() end end System.update_blob_attribs(partition, -1 ) end |
.init_sync_source_properties(uniq_sources) ⇒ Object
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/framework/rho/rho.rb', line 526 def self.init_sync_source_properties(uniq_sources) if defined?(RHOCONNECT_CLIENT_PRESENT) uniq_sources.each do|src| ['pass_through', 'full_update'].each do |prop| next unless src.has_key?(prop) Rho::RhoConnectClient.set_source_property(src['source_id'], prop, src[prop] ? src[prop].to_s() : '' ) end end uniq_sources.each do|src| if src.has_key?('freezed') || !src['schema'].nil? hash_props = !src['schema'].nil? ? src['schema']["property"] : src["property"] if (!hash_props.nil?) str_props = hash_props.keys.join(',') Rho::RhoConnectClient.set_source_property(src['source_id'], 'freezed', str_props ) end end end end end |
.load_all_sources ⇒ Object
358 359 360 361 362 |
# File 'lib/framework/rho/rho.rb', line 358 def self.load_all_sources unless @@use_new_orm Rho::RHO.get_instance().load_all_sync_sources() end end |
.make_createsql_script(name, schema_attr) ⇒ Object
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/framework/rho/rho.rb', line 647 def self.make_createsql_script(name,schema_attr) strCreate = schema_attr['sql'] strCreate = "" unless strCreate if schema_attr['property'] arCols = schema_attr['property'] puts " we are here in arcols : #{arCols.class.name}, #{arCols.inspect}" strCols = arCols.collect do |col, type| "\"#{col}\" " + case type[0] when :integer 'integer' when :float 'float' when :date 'integer' when :time 'integer' else 'varchar' end + " default null" end.join(',') strCols += ',' if strCols.length() > 0 strCols += "\"object\" varchar(255) PRIMARY KEY" strCreate = "CREATE TABLE \"#{name}\" ( #{strCols} )" end strCreate += ";\r\n" if strCreate && strCreate.length() > 0 strCreate += processIndexes(schema_attr['index'], name, false) strCreate += ";\r\n" if strCreate && strCreate.length() > 0 strCreate += processIndexes(schema_attr['unique_index'], name, true) strCreate end |
.processIndexes(index_param, src_name, is_unique) ⇒ Object
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/framework/rho/rho.rb', line 547 def self.processIndexes(index_param, src_name, is_unique) return "" unless index_param strUnique = 'UNIQUE' if is_unique strRes = "" if index_param.is_a?( String ) strRes = index_param else nInd = 0 index_param.each do |index_name, index_cols| strCols = "" if index_cols.is_a?(String) index_cols = index_cols.split(',') end index_cols.each do |col| strCols += ',' if strCols.length() > 0 strCols += "\"#{col}\"" end #strIndName = "rhoIndex" + (is_unique ? "U" : "" ) + "_#{nInd}" strIndex = "CREATE #{strUnique} INDEX \"#{index_name}\" ON \"#{src_name}\" (#{strCols});\r\n" strRes += strIndex nInd += 1 end end strRes end |
.use_new_orm ⇒ Object
66 67 68 |
# File 'lib/framework/rho/rho.rb', line 66 def self.use_new_orm return @@use_new_orm end |
Instance Method Details
#_load_models_from_file(f) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/framework/rho/rho.rb', line 230 def _load_models_from_file(f) f.each do |line| str = line.chomp if str != nil and str.length > 0 puts "model file: #{str}" model_name = File.basename(File.dirname(str)) Rho::RhoConfig::add_source(model_name, {:loaded => false, :file_path => str}) end end end |
#activate_app ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/framework/rho/rho.rb', line 156 def activate_app begin get_app(APPNAME).on_activate_app rescue Exception => e trace_msg = e.backtrace.join("\n") puts 'Application activate failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#deactivate_app ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/framework/rho/rho.rb', line 165 def deactivate_app begin get_app(APPNAME).on_deactivate_app rescue Exception => e trace_msg = e.backtrace.join("\n") puts 'Application deactivate failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#find_src_byname(db_sources, name) ⇒ Object
447 448 449 450 451 452 453 |
# File 'lib/framework/rho/rho.rb', line 447 def find_src_byname(uniq_sources, src_name) uniq_sources.each do |source| return source if src_name == source['name'] end nil end |
#get_app(appname) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/framework/rho/rho.rb', line 201 def get_app(appname) if (APPLICATIONS[appname].nil?) require 'application' Object.const_get('AppApplication').new unless APPLICATIONS[appname].initialized? msg = "RhoApplication was not correctly initialized (forget to call 'super' in AppApplication.initialize ?)" puts msg raise msg end end APPLICATIONS[appname] end |
#get_start_id(db_sources, db_partition) ⇒ Object
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/framework/rho/rho.rb', line 713 def get_start_id(db_sources, db_partition) start_id = 0 db_sources.each do |db_src| next unless db_partition == db_src['partition'] src_id = db_src['source_id'] start_id = src_id if src_id > start_id end if start_id < Rho::RhoConfig.max_config_srcid()[db_partition] start_id = Rho::RhoConfig.max_config_srcid()[db_partition]+2 else start_id += 1 end puts "start_id: #{start_id}" start_id end |
#init_app ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/framework/rho/rho.rb', line 125 def init_app puts "init_app" begin get_app(APPNAME) rescue Exception => e trace_msg = e.backtrace.join("\n") puts 'Application initialize failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#init_db_sources(db, uniq_sources, db_partition, hash_migrate) ⇒ Object
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/framework/rho/rho.rb', line 740 def init_db_sources(db, uniq_sources, db_partition, hash_migrate) puts "init_db_sources" db_sources = db.select_from_table('sources','sync_priority,source_id,partition, sync_type, schema_version, associations, source_attribs, blob_attribs, name') start_id = get_start_id(db_sources, db_partition) uniq_sources.each do |source| partition = source['partition'] next unless partition == db_partition #puts "init_db_sources(#{source['name']}) : #{source}" name = source['name'] sync_priority = source['sync_priority'] sync_type = source['sync_type'] schema_version = source['schema_version'] associations = source['str_associations'] blob_attribs = process_blob_attribs(source, db) # TODO: the same for :full_update option source_attribs = '' if source['pass_through'] source_attribs = 'pass_through' puts "init_db_sources: store :pass_through option into sources table for #{name} model" end # TODO: the same for :full_update option #puts "blob_attribs : #{blob_attribs}" #attribs = db.select_from_table('sources','sync_priority,source_id,partition, sync_type, schema_version, associations, blob_attribs', {'name'=>name}) attribs = find_src_byname(db_sources,name) if attribs if attribs['sync_priority'].to_i != sync_priority.to_i db.update_into_table('sources', {"sync_priority"=>sync_priority},{"name"=>name}) end if attribs['sync_type'] != sync_type db.update_into_table('sources', {"sync_type"=>sync_type},{"name"=>name}) end if attribs['schema_version'] != schema_version if db_partition == partition hash_migrate[name] = attribs['schema_version'] else db.update_into_table('sources', {"schema_version"=>schema_version},{"name"=>name}) end end if attribs['partition'] != partition db.update_into_table('sources', {"partition"=>partition},{"name"=>name}) end if attribs['associations'] != associations db.update_into_table('sources', {"associations"=>associations},{"name"=>name}) end if attribs['blob_attribs'] != blob_attribs db.update_into_table('sources', {"blob_attribs"=>blob_attribs},{"name"=>name}) end if attribs['source_attribs'] != source_attribs db.update_into_table('sources', {"source_attribs" => source_attribs},{"name" => name}) end if !source['source_id'] source['source_id'] = attribs['source_id'].to_i Rho::RhoConfig::sources[name]['source_id'] = attribs['source_id'].to_i end else #puts "Rho::RhoConfig.use_bulk_model : #{Rho::RhoConfig.use_bulk_model}" if Rho::RhoConfig.use_bulk_model.to_s != 'true' && Rho::RhoConfig.use_bulk_model.to_s != '1' if !source['source_id'] source['source_id'] = start_id Rho::RhoConfig::sources[name]['source_id'] = start_id start_id += 1 end db.insert_into_table('sources', {"source_id"=>source['source_id'],"name"=>name, "sync_priority"=>sync_priority, "sync_type"=>sync_type, "partition"=>partition, "schema_version"=>source['schema_version'], 'associations'=>associations, 'blob_attribs'=>blob_attribs, 'source_attribs' => source_attribs}) end end end end |
#init_nativebar ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/framework/rho/rho.rb', line 135 def return if @@native_bar_initialized begin get_app(APPNAME). rescue Exception => e trace_msg = e.backtrace.join("\n"); puts "Application's native bar initialization failed: #{e.inspect}; Trace: #{trace_msg}" end @@native_bar_initialized = true end |
#init_response(status, message, body) ⇒ Object
944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/framework/rho/rho.rb', line 944 def init_response(status=200,="OK",body="") res = Hash.new res['status'] = status res['message'] = res['headers'] = { 'Date' => make_httpdate(Time.now),#.httpdate, 'Content-Type' => 'text/html; charset=utf-8', 'Content-Length' => 0, 'Connection' => 'close' } res['request-body'] = body res end |
#init_sources ⇒ Object
setup the sources table and model attributes for all applications
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/framework/rho/rho.rb', line 456 def init_sources() return unless defined? Rho::RhoConfig::sources @all_models_loaded = true uniq_sources = Rho::RhoConfig::sources.values puts 'init_sources: ' #+ uniq_sources.inspect uniq_sources.each do |source| source['str_associations'] = "" end uniq_sources.each do |source| partition = source['partition'] @db_partitions[partition] = nil unless @db_partitions[partition] if source['belongs_to'] source['belongs_to'].each do |hash_pair| attrib = hash_pair.keys[0] src_name = hash_pair.values[0] associationsSrc = find_src_byname(uniq_sources, src_name) if !associationsSrc puts "Error: belongs_to '#{source['name']}' : source name '#{src_name}' does not exist." next end str_associations = associationsSrc['str_associations'] str_associations = "" unless str_associations str_associations += ',' if str_associations.length() > 0 str_associations += source['name'] + ',' + attrib associationsSrc['str_associations'] = str_associations end end end #user partition should alwayse exist @db_partitions['user'] = nil unless @db_partitions['user'] hash_migrate = {} puts "@db_partitions : #{@db_partitions}" @db_partitions.each do |partition, db| db = Rhom::RhomDbAdapter.new(Rho::RhoFSConnector::get_db_fullpathname(partition), partition) unless db db.start_transaction begin init_db_sources(db, uniq_sources, partition,hash_migrate) #SyncEngine.update_blob_attribs(partition, -1 ) db.commit rescue Exception => e trace_msg = e.backtrace.join("\n") puts "exception when init_db_sources: #{e}; Trace:" + trace_msg db.rollback end @db_partitions[partition] = db end puts "Migrate schema sources: #{hash_migrate}" ::Rho::RHO.init_schema_sources(hash_migrate) ::Rho::RHO.check_sources_migration(uniq_sources) #@db_partitions.each do |partition, db| # SyncEngine.update_blob_attribs(partition, -1 ) #end ::Rho::RHO.init_sync_source_properties(uniq_sources) end |
#load_all_sync_sources ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/framework/rho/rho.rb', line 365 def load_all_sync_sources() unless Rho::RHO.use_new_orm return if @all_models_loaded puts "load_all_sync_sources" begin Rho::RhoConfig.sources.values.each do |src| next if src[:loaded] load_model(src['name'],false) end init_sources() rescue Exception => e puts "Error load_all_sync_sources: #{e}" puts "Trace: #{e.backtrace}" end else @all_models_loaded = true end end |
#load_model(modelName, init_db) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/framework/rho/rho.rb', line 388 def load_model(modelName, init_db = true) return nil if !Rho::RhoConfig.sources.has_key?(modelName) || Rho::RhoConfig.sources[modelName][:loaded] Rho::RhoConfig.sources[modelName][:loaded] = true puts "load_model: #{modelName}" Rhom::RhomObjectFactory.init_object(modelName) require "#{Rho::RhoConfig.sources[modelName][:file_path]}" puts "model name: #{modelName}" modelClass = nil modelClass = Object.const_get(modelName) if Object.const_defined?(modelName) if modelClass puts "model class found" if modelClass.respond_to?( :get_model_params ) Rho::RhoConfig::add_loaded_source(modelName,modelClass.get_model_params()) modelClass.reset_model_params() partition = Rho::RhoConfig::sources[modelName]['partition'] db = ::Rho::RHO.get_db_partitions()[partition] if !db db = Rhom::RhomDbAdapter.new(Rho::RhoFSConnector::get_db_fullpathname(partition), partition) ::Rho::RHO.get_db_partitions()[partition] = db end if init_db hash_migrate = {} db.start_transaction begin uniq_sources = [Rho::RhoConfig::sources[modelName]] init_db_sources(db, uniq_sources, partition, hash_migrate) puts "Migrate schema sources: #{hash_migrate}" ::Rho::RHO.init_schema_sources_partition(uniq_sources, hash_migrate, partition, db) ::Rho::RHO.check_sources_migration(uniq_sources) ::Rho::RHO.init_sync_source_properties(uniq_sources) #SyncEngine.update_blob_attribs(partition, Rho::RhoConfig::sources[modelName]['source_id'].to_i() ) db.commit rescue Exception => e trace_msg = e.backtrace.join("\n") puts "exception when init_db_sources: #{e}; Trace:" + trace_msg db.rollback end end else puts "ERROR: Invalid model definition. Add 'include Rhom::PropertyBag' or 'include Rhom::FixedSchema' to model class" end else puts "ERROR: cannot load model : #{modelClass}" end modelClass end |
#load_models_from_file(app_manifest_filename) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/framework/rho/rho.rb', line 215 def load_models_from_file(app_manifest_filename=nil) require 'rhoappmanifest' fappManifest = Rho::AppManifest.enumerate_models(Rho::RhoFSConnector.get_app_path('app').chop) _load_models_from_file(fappManifest) fappManifest.close end |
#load_server_sources(data) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/framework/rho/rho.rb', line 271 def load_server_sources(data) puts "load_server_sources : #{data}" begin res = Rho::JSON.parse(data) skip_schema = false if res['skip_schema'] skip_schema = res['skip_schema'].to_i() > 0 end puts "skip_schema = #{skip_schema}" if res['partition'] str_partition = res['partition'] puts "reload sources for partition: #{str_partition}" db = @db_partitions[ str_partition ] #puts "sources before: #{Rho::RhoConfig::sources()}" db.start_transaction begin mapProps = {} mapFreezed = {} Rho::RhoConfig::sources().each do |key,value| if value['partition']==str_partition mapProps[key] = value['property'] mapFreezed[key] = value['freezed'] end end Rho::RhoConfig::sources().delete_if {|key, value| value['partition']==str_partition } arSrcs = db.select_from_table('sources','source_id, name, sync_priority, partition, sync_type, schema, schema_version, associations, blob_attribs', {'partition'=>str_partition} ) arSrcs.each do |src| if src if src['schema'] && src['schema'].length() > 0 if !skip_schema #puts "src['schema'] : #{src['schema']}" hashSchema = Rho::JSON.parse(src['schema']) #puts "hashSchema : #{hashSchema}" src['schema'] = hashSchema src['schema']['sql'] = ::Rho::RHO.make_createsql_script( src['name'], hashSchema) src['schema_version'] = hashSchema['version'] db.update_into_table('sources', {"schema"=>src['schema']['sql'], "schema_version"=>src['schema_version']},{"name"=>src['name']}) #if str_partition != 'user' # @db_partitions['user'].update_into_table('sources', {"schema"=>src['schema']['sql'], "schema_version"=>src['schema_version']},{"name"=>src['name']}) #end end else props = mapProps[src['name']] if props src['property'] = props end freezed = mapFreezed[src['name']] if freezed src['freezed'] = freezed end end end src[:loaded] = true Rho::RhoConfig::sources()[ src['name'] ] = src end db.commit rescue Exception => e db.rollback raise end ::Rho::RHO.init_sync_source_properties(Rho::RhoConfig::sources().values()) #puts "sources after: #{Rho::RhoConfig::sources()}" return end rescue Exception => e puts "Error load_server_sources: #{e}" puts "Trace: #{e.backtrace}" end raise ArgumentError, "load_server_sources should be called only from bulk sync with partition parameter!" end |
#make_httpdate(t) ⇒ Object
929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'lib/framework/rho/rho.rb', line 929 def make_httpdate(t) _RFC2822_DAY_NAME = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ] _RFC2822_MONTH_NAME = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] sprintf('%s, %02d %s %d %02d:%02d:%02d GMT', _RFC2822_DAY_NAME[t.wday], t.day, _RFC2822_MONTH_NAME[t.mon-1], t.year, t.hour, t.min, t.sec) end |
#on_config_conflicts(conflicts) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/framework/rho/rho.rb', line 147 def on_config_conflicts(conflicts) begin get_app(APPNAME).on_reinstall_config_update(conflicts) rescue Exception => e trace_msg = e.backtrace.join("\n") puts 'Application on_reinstall_config_update failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#process_blob_attribs(source, db) ⇒ Object
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'lib/framework/rho/rho.rb', line 682 def process_blob_attribs(source, db) return source['str_blob_attribs'] if source['str_blob_attribs'] source['str_blob_attribs'] = "" if source['schema'] props = source['schema']['property'] else props = source['property'] end if props str = "" props.each do |name, ar_type| if ar_type && ar_type.is_a?(String) ar_type = ar_type.split(',') end if ar_type && ar_type[0].to_s == 'blob' str += ',' if str.length()>0 str += name.to_s() + ',' str += (ar_type[1].to_s() == 'overwrite' ? '1' : '0') end end source['str_blob_attribs'] = str end source['str_blob_attribs'] end |
#process_model_dirs(app_manifest_filename) ⇒ Object
279 280 |
# File 'lib/framework/autocomplete/Rho.rb', line 279 def process_model_dirs(app_manifest_filename) end |
#raise_rhoerror(errCode) ⇒ Object
193 194 195 |
# File 'lib/framework/rho/rho.rb', line 193 def raise_rhoerror(errCode) raise Rho::RhoError.new(errCode) end |
#reset_db_on_sync_user_changed ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'lib/framework/rho/rho.rb', line 261 def reset_db_on_sync_user_changed() puts "reset_db_on_sync_user_changed" begin get_app(APPNAME).on_sync_user_changed rescue Exception => e trace_msg = e.backtrace.join("\n") puts 'Application reset_db_on_sync_user_changed failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#send_error(exception, status, hash) ⇒ Object
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/framework/rho/rho.rb', line 1003 def send_error(exception=nil,status=500,hash=false) if exception trace_msg = exception.backtrace.join("\n") puts "App error: #{exception.}\n #{trace_msg}" end body='' err_page = nil if exception && exception.is_a?(::Rhom::RecordNotFound) err_page = RhoApplication::get_app_path(APPNAME) + 'E400' + RHO_ERB_EXT err_page = nil unless ::Rho::file_exist?(err_page) elsif exception err_page = RhoApplication::get_app_path(APPNAME) + 'E500' + RHO_ERB_EXT err_page = nil unless ::Rho::file_exist?(err_page) end if err_page @@current_exception = exception puts 'show error: ' + @@current_exception.inspect body = RhoController::renderfile(err_page) return send_response_hash(init_response(200,"OK",body)) if hash return send_response(init_response(200,"OK",body)) end body << <<-_HTML_STRING_ <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=320"/> </head> <body> <h2>Server Error</h2> <p> _HTML_STRING_ body << 'Error: ' << exception. << "<br/>" if exception body << "Trace: <br/>\n" << exception.backtrace.join("<br/>\n") if exception body << <<-_HTML_STRING_ </p> </body> </html> _HTML_STRING_ if ( hash ) send_response_hash(init_response(status,"Server error",body)) else send_response(init_response(status,"Server error",body)) end end |
#send_response(res) ⇒ Object
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
# File 'lib/framework/rho/rho.rb', line 963 def send_response(res) res['headers']['Content-Length'] = !res['request-body'].nil? && res['request-body'].is_a?(String) ? res['request-body'].bytesize : 0 data = "HTTP/1.1 #{res['status'].to_s} #{res['message']}" + CRLF res['headers'].each{|key, value| tmp = key.gsub(/\bwww|^te$|\b\w/){|s| s.upcase } data << "#{tmp}: #{value}" << CRLF } data << "Pragma: no-cache" << CRLF data << "Cache-Control: must-revalidate" << CRLF data << "Cache-Control: no-cache" << CRLF data << "Cache-Control: no-store" << CRLF data << "Expires: 0" << CRLF data << CRLF if ( !res['request-body'].nil? && res['request-body'].is_a?(String)) data << res['request-body'] end data end |
#send_response_hash(res) ⇒ Object
984 985 986 987 988 989 990 991 992 993 994 995 996 |
# File 'lib/framework/rho/rho.rb', line 984 def send_response_hash(res) resp = Hash.new res['headers']['Content-Length'] = !res['request-body'].nil? && res['request-body'].is_a?(String) ? res['request-body'].bytesize : 0 res['headers'].each{|key, value| tmp = key.gsub(/\bwww|^te$|\b\w/){|s| s.upcase } resp[tmp] = value } resp['request-body'] = !res['request-body'].nil? && res['request-body'].is_a?(String) ? res['request-body'] : "" resp['status'] = res['status'] resp['message'] = res['message'] resp end |
#serve(req) ⇒ Object
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'lib/framework/rho/rho.rb', line 822 def serve(req) begin RhoProfiler.start_counter('CTRL_ACTION') res = init_response if (req['proc']) @params = RhoSupport::query_params req RhoController.process_rho_object(@params) req['proc'].call( @params['body'] ) else puts "RHO serve: " + (req ? "#{req['request-uri']}" : '') get_app(req['application']).send :serve, req, res Rho::RhoController.() Rho::RhoConfig.clean_cached_changed end ret = send_response(res) RhoProfiler.stop_counter('CTRL_ACTION') return ret rescue Exception => e ret = send_error(e) RhoProfiler.stop_counter('CTRL_ACTION') return ret ensure RhoApplication::set_current_controller(nil) end end |
#serve_hash(req) ⇒ Object
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
# File 'lib/framework/rho/rho.rb', line 856 def serve_hash(req) begin RhoProfiler.start_counter('CTRL_ACTION') puts "RHO serve: " + (req ? "#{req['request-uri']}" : '') res = init_response get_app(req['application']).send :serve, req, res Rho::RhoController.() Rho::RhoConfig.clean_cached_changed ret = send_response_hash(res) RhoProfiler.stop_counter('CTRL_ACTION') return ret rescue Exception => e ret = send_error(e,500,true) RhoProfiler.stop_counter('CTRL_ACTION') return ret ensure RhoApplication::set_current_controller(nil) end end |
#serve_index(index_name, req) ⇒ Object
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
# File 'lib/framework/rho/rho.rb', line 879 def serve_index(index_name, req) begin RhoProfiler.start_counter('INDEX_ACTION') # TODO: Removed hardcoded appname get_app(APPNAME). puts "RHO serve_index: " + (req ? "#{req['request-uri']}" : '') res = init_response res['request-body'] = RhoController::renderfile(index_name, req, res) Rho::RhoController.() Rho::RhoConfig.clean_cached_changed ret = send_response(res) RhoProfiler.stop_counter('INDEX_ACTION') return ret rescue Exception => e ret = send_error(e) RhoProfiler.stop_counter('INDEX_ACTION') return ret end end |
#serve_index_hash(index_name, req) ⇒ Object
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'lib/framework/rho/rho.rb', line 903 def serve_index_hash(index_name, req) begin RhoProfiler.start_counter('INDEX_ACTION') # TODO: Removed hardcoded appname get_app(APPNAME). puts "RHO serve_index: " + (req ? "#{req['request-uri']}" : '') res = init_response res['request-body'] = RhoController::renderfile(index_name, req, res) Rho::RhoController.() Rho::RhoConfig.clean_cached_changed ret = send_response_hash(res) RhoProfiler.stop_counter('INDEX_ACTION') return ret rescue Exception => e ret = send_error(e, 500, true) RhoProfiler.stop_counter('INDEX_ACTION') return ret end end |
#set_app(appname, app) ⇒ Object
197 198 199 |
# File 'lib/framework/rho/rho.rb', line 197 def set_app(appname, app) APPLICATIONS[appname] = app end |
#ui_created ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/framework/rho/rho.rb', line 174 def ui_created begin get_app(APPNAME).on_ui_created rescue Exception => e trace_msg = e.backtrace.join("\n") puts '"UI created" callback failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |
#ui_destroyed ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/framework/rho/rho.rb', line 183 def ui_destroyed begin get_app(APPNAME).on_ui_destroyed @@native_bar_initialized = false rescue Exception => e trace_msg = e.backtrace.join("\n"); puts '"UI destroyed" callback failed: ' + e.inspect + ";Trace: #{trace_msg}" end end |