Class: Rhom::Rhom
- Defined in:
- lib/framework/rhom/rhom.rb,
lib/framework/newrhom/newrhom.rb,
lib/framework/autocomplete/Rhom.rb
Constant Summary collapse
- @@orm_instance =
nil
- @@newrhom =
nil
Instance Attribute Summary collapse
-
#factory ⇒ Object
Returns the value of attribute factory.
-
#models ⇒ Object
Returns the value of attribute models.
Class Method Summary collapse
- .client_id ⇒ Object
- .database_client_reset(reset_local_models) ⇒ Object
- .database_export(partition) ⇒ Object
- .database_full_reset(reset_client_info, reset_local_models) ⇒ Object
- .database_full_reset_and_logout ⇒ Object
- .database_full_reset_ex(args) ⇒ Object
- .database_fullclient_reset_and_logout ⇒ Object
- .database_import(partition, zipName) ⇒ Object
- .database_local_reset ⇒ Object
- .get_instance ⇒ Object
- .getModel(modelname) ⇒ Object
- .have_local_changes ⇒ Object
- .search(args) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Rhom
constructor
A new instance of Rhom.
- #load_all_sources ⇒ Object
- #load_models(app_manifest_filename = nil) ⇒ Object
Constructor Details
#initialize ⇒ Rhom
Returns a new instance of Rhom.
45 46 47 |
# File 'lib/framework/rhom/rhom.rb', line 45 def initialize @factory = RhomObjectFactory.new end |
Instance Attribute Details
#factory ⇒ Object
Returns the value of attribute factory.
38 39 40 |
# File 'lib/framework/rhom/rhom.rb', line 38 def factory @factory end |
#models ⇒ Object
Returns the value of attribute models.
8 9 10 |
# File 'lib/framework/newrhom/newrhom.rb', line 8 def models @models end |
Class Method Details
.client_id ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/framework/rhom/rhom.rb', line 50 def client_id if ::Rho::RHO.use_new_orm ::Rho::NewORM.getClientId else c_id = ::Rho::RHO.get_user_db().select_from_table('client_info','client_id')[0] c_id.nil? ? nil : c_id['client_id'] end end |
.database_client_reset(reset_local_models) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/framework/rhom/rhom.rb', line 89 def database_client_reset(reset_local_models=true) #load all partitions Rho::RHO.load_all_sources if defined?(RHOCONNECT_CLIENT_PRESENT) old_interval = Rho::RhoConnectClient.set_pollinterval(0) Rho::RhoConnectClient.stop_sync end params = ["", "", 0] ::Rho::RHO.get_user_db().execute_sql("UPDATE client_info SET client_id=?, token=?, token_sent=?", params) if ( Rho::RhoConfig.exists?('bulksync_state') ) Rho::RhoConfig.bulksync_state='0' end ::Rho::RHO.get_db_partitions().each do |partition, db| next if !reset_local_models && partition == 'local' db.execute_sql("UPDATE sources SET token=0") db.destroy_tables( :exclude => (['sources','client_info']) ) end hash_migrate = {} ::Rho::RHO.init_schema_sources(hash_migrate) if defined?(RHOCONNECT_CLIENT_PRESENT) Rho::RhoConnectClient.set_pollinterval(old_interval) end end |
.database_export(partition) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/framework/rhom/rhom.rb', line 241 def database_export(partition) db = ::Rho::RHO::get_db_partitions[partition] if db db.export end end |
.database_full_reset(reset_client_info, reset_local_models) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/framework/rhom/rhom.rb', line 191 def database_full_reset(reset_client_info=false, reset_local_models=true) puts "database_full_reset : reset_client_info=#{reset_client_info}, reset_local_models=#{reset_local_models}" #load all partitions Rho::RHO.load_all_sources if defined?(RHOCONNECT_CLIENT_PRESENT) old_interval = Rho::RhoConnectClient.pollInterval = 0 Rho::RhoConnectClient.stop_sync end ::Rho::RHO.get_user_db().execute_sql("UPDATE client_info SET reset=1") if ( Rho::RhoConfig.exists?('bulksync_state') ) Rho::RhoConfig.bulksync_state='0' end ::Rho::RHO.get_db_partitions().each do |partition, db| next if !reset_local_models && partition == 'local' db.execute_sql("UPDATE sources SET token=0") db.destroy_tables( :exclude => (reset_client_info ? ['sources'] : ['sources','client_info']) ) end if ( reset_client_info && Rho::RhoConfig.exists?('push_pin') ) Rho::RhoConfig.push_pin='' end hash_migrate = {} ::Rho::RHO.init_schema_sources(hash_migrate) if defined?(RHOCONNECT_CLIENT_PRESENT) Rho::RhoConnectClient.pollInterval = old_interval end end |
.database_full_reset_and_logout ⇒ Object
227 228 229 230 231 232 |
# File 'lib/framework/rhom/rhom.rb', line 227 def database_full_reset_and_logout database_full_reset if defined?(RHOCONNECT_CLIENT_PRESENT) Rho::RhoConnectClient.logout end end |
.database_full_reset_ex(args) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/framework/rhom/rhom.rb', line 121 def database_full_reset_ex(*args) puts "database_full_reset_ex #{args}" if (args.count == 0 || !args[0][:models]) database_full_reset( args.count > 0 && !args[0][:reset_client_info].nil?() ? args[0][:reset_client_info] : false, args.count > 0 && !args[0][:reset_local_models].nil?() ? args[0][:reset_local_models] : true ) return end raise ArgumentError, "reset_client_info should not be true if reset selected models" if args.count > 0 && args[0][:reset_client_info] #load all partitions Rho::RHO.load_all_sources if defined?(RHOCONNECT_CLIENT_PRESENT) old_interval = Rho::RhoConnectClient.pollInterval Rho::RhoConnectClient.pollInterval = 0 Rho::RhoConnectClient.stop_sync end ::Rho::RHO.get_user_db().execute_sql("UPDATE client_info SET reset=1") Rho::RhoConfig.reset_models = "" args[0][:models].each do |src_name| db = ::Rho::RHO.get_src_db(src_name) src_partition = Rho::RhoConfig.sources[src_name]['partition'] is_schema_source = !Rho::RhoConfig.sources[src_name]['schema'].nil? next if !args[0][:reset_local_models] && src_partition == 'local' if (src_partition != 'local') # build comma-separated string of models Rho::RhoConfig.reset_models += "," unless Rho::RhoConfig.reset_models.size == 0 Rho::RhoConfig.reset_models += "#{src_name}" end begin db.start_transaction db.execute_sql("UPDATE sources SET token=0 WHERE name = ?", src_name ) if is_schema_source db.execute_sql("DELETE FROM #{src_name}") else db.execute_sql("DELETE FROM object_values WHERE source_id=?", Rho::RhoConfig.sources[src_name]['source_id'].to_i) end db.commit rescue Exception => e puts 'database_full_reset_ex Exception: ' + e.inspect db.rollback raise end end #hash_migrate = {} #::Rho::RHO.init_schema_sources(hash_migrate) if defined?(RHOCONNECT_CLIENT_PRESENT) Rho::RhoConnectClient.pollInterval = old_interval end end |
.database_fullclient_reset_and_logout ⇒ Object
234 235 236 237 238 239 |
# File 'lib/framework/rhom/rhom.rb', line 234 def database_fullclient_reset_and_logout database_full_reset(true) if defined?(RHOCONNECT_CLIENT_PRESENT) Rho::RhoConnectClient.logout end end |
.database_import(partition, zipName) ⇒ Object
248 249 250 251 252 253 |
# File 'lib/framework/rhom/rhom.rb', line 248 def database_import(partition, zipName) db = ::Rho::RHO::get_db_partitions[partition] if db db.import(zipName) end end |
.database_local_reset ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/framework/rhom/rhom.rb', line 69 def database_local_reset() puts "database_local_reset" #load all partitions unless ::Rho::RHO.use_new_orm Rho::RHO.load_all_sources ::Rho::RHO.get_db_partitions().each do |partition, db| next if partition != 'local' db.destroy_tables( :exclude => ['sources','client_info'] ) end hash_migrate = {} ::Rho::RHO.init_schema_sources(hash_migrate) else ::Rho::NewORM.databaseLocalReset end end |
.get_instance ⇒ Object
41 42 43 |
# File 'lib/framework/rhom/rhom.rb', line 41 def self.get_instance @@orm_instance ||= self.new end |
.getModel(modelname) ⇒ Object
125 126 127 |
# File 'lib/framework/newrhom/newrhom.rb', line 125 def getModel(modelname) ::Rho::NewORMModel.getModel(modelname) end |
.have_local_changes ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/framework/rhom/rhom.rb', line 59 def have_local_changes if ::Rho::RHO.use_new_orm ::Rho::NewORM.haveLocalChanges else #TODO: enumerate all sync sources, create array of partitions and run query for all partition. res = ::Rho::RHO.get_user_db().execute_sql("SELECT object FROM changed_values WHERE sent<=1 LIMIT 1 OFFSET 0") return res.length > 0 end end |
.search(args) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/framework/rhom/rhom.rb', line 255 def search(args) #TODO : remove it, use Rho::RhoConnectClient.search if defined?(RHOCONNECT_CLIENT_PRESENT) src_ar = args[:sources] #check sources raise ArgumentError, "no sources on search" if src_ar.nil? or src_ar.length == 0 src_ar.each do |src_name| raise ArgumentError, "no sources on search" if Rho::RhoConfig::sources[src_name].nil? end Rho::RhoConnectClient.search(args) end end |
Instance Method Details
#load_all_sources ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/framework/newrhom/newrhom.rb', line 28 def load_all_sources() return if @all_models_loaded begin models.values.each do |src| next if src.loaded _load_model(src.model_name) end _init_models rescue Exception => e puts "Error load_all_sources: #{e}" puts "Trace: #{e.backtrace}" end end |
#load_models(app_manifest_filename = nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/framework/newrhom/newrhom.rb', line 19 def load_models(app_manifest_filename = nil) if app_manifest_filename _load_models(app_manifest_filename) else _load_models(Rho::RhoFSConnector::get_app_manifest_filename) end end |