12 Replies Latest reply on Oct 24, 2015 12:10 AM by BHAKTA RANJAN SATAPATHY

    NewORM

    Jon Tara

      I've been following activity in Rhodes master branch, and see that there appears to be some replacement for Rhom under construction. It's called NewORM.

       

      I've been using the master branch, and it seems (from looking at code and observation) that there's a "switch" that can be flipped to use either Rhom or NewORM and it currently defaults to Rhom.

       

      Any chance of getting a preview of what's to come? At least the general nature of the changes?

        • Re: NewORM
          Kutir Mobility

          Interesting to see this thread but this issue needs help from Motorola. We will raise this issue with them to get an answer.

          Visnupriya R

          Kutir Mobility

            • Re: NewORM
              Kutir Mobility

              Jon,

              FYI, The release notes for 5.0 mention the following:

               

              Usage Notes for New ORM Common API (Beta)

              New ORM API provides Ruby and JS access to the Rhodes mini database object mapper (ORM), performing database operation on Rhodes model objects. It replaces old Ruby and JS implementations and serve as a basis for new features and enhancements. For further information consult online Module Core API and Models API documents. Existing implementation (Old ORM) is kept in parallel at this moment to provide smooth transitioning to the new API. By default, existing Old ORM API will be enabled by default in RE 4.1.

              • To enable New ORM API for existing Rhodes app
                • Edit "rhoconfig.txt" file and add 'use_new_orm' option to it
                  • use_new_orm = 1
                • For JavaScript app make sure that your html file includes reference to "rhoapi-modules.js" file. Any references to "rhoapi-modules-ORM.js" should be commented or removed.
                • New ORM JS API uses different interface for 'addModel' like Rho.ORM.addModel(‘Product’, function(model){ /* ... */ }). Update your code properly.
              • To enable/continue usage of Old ORM API for existing Rhodes app
                • In "rhoconfig.txt" file remove 'use_new_orm' option or set it as use_new_orm = 0
                • Make sure that your main html file includes references to both files
                  • rhoapi-modules.js
                  • rhoapi-modules-ORM.js


              The above will let you start working with NewORM. Additionally:

              Known issues with New ORM Common API

              • Blob type is not supported
              • Ruby implementation for Property Bag models with advanced find options (:conditions, :select, :op, :order) is incomplete and should be avoided.

               

              Visnupriya R

              Kutir Mobility

              1 of 1 people found this helpful
                • Re: Re: NewORM
                  Jon Tara

                  It appears newORM no longer uses missing_method to reflect columns to the model object. This means that the standard generated ERB files (when you generate a model) will not work as created. It is easy to fix.

                   

                  Now you MUST refer to column values using .vars[] (No... but see comment below)

                   

                  I think this is a good thing, because with OldORM, you might easily create a column name that is the same as some common model method. The method will hid your column value if you use the dotted notation that replies on missing_method. So, the new design avoids that possibility. It is much more efficient, as well, to just access the vars hash rather than accessing it through the model object and going through method_missing.

                   

                  For collections, I do like this. I assign a local variable to make it easy to access venue.vars.

                   

                        <% @venues.each do |venue| v = venue.vars % >
                        <li>
                          <a href='<%= url_for(:action => :show, :id => venue.object) %>'>
                            <%= h v[:name] %>
                          </a>
                        </li>
                  
                  
                  
                  

                   

                  This code will work with either old or new ORM.

                    • Re: NewORM
                      Jon Tara

                      Sorry, but I was completely wrong about this!

                       

                      NewORM still uses method_missing, and still allows dotted notation access to variables directly from a model object instance. I had something wrong with my code.

                       

                      However, it is still prudent and efficient to alway access variables from the vars hash, rather than using the dotted notation.

                • Re: NewORM
                  Brendan Higgins

                  We've been using it for about a year (since 4.0.0 when the JS models were very weak), and frankly had forgotten it was beta.  Not sure it is offering anything new though.

                   

                  Here is the documentation:

                   

                  Rhomobile | NewORM

                   

                  Rhomobile | NewORMModel

                   

                  Funny... was talking to some Moto folks today about us using it and I just noticed the Beta Version note show up today.

                  1 of 1 people found this helpful
                    • Re: NewORM
                      Jon Tara

                      Thanks for the documentation link! It's not linked into the index, so you'd never know it was there.

                       

                      (Note this is also available in the 5.0 and edge docs.)

                       

                      There certainly are a lot of new methods. (45 in NewOrmModel vs 13 in old.) Have you run into any "guide" type documentation?

                       

                      It sounds like you have found it compatible (or largely compatible) with "old" ORM?

                       

                      I'll take a look at the docs and see if it offers anything exciting.

                       

                      Looks like some (but not all) method names have changed. Are the old methods aliased?

                       

                      It pretty much follows a pattern:

                       

                        find > findObject

                        save > saveObject

                        • Re: NewORM
                          Brendan Higgins

                          We use fixed schema and a lot of SQL, so I can't speak to the "find" type methods (which is why we went with the new ORM -- 4.0 didn't work with fixed schema).  But the rest of the object is pretty much the same.

                           

                          Unfortunately, onSyncCreateError, onSyncDeleteError, onSyncUpdateError methods are not implemented (at least in 4.1 anyway).  We would have found them most useful - we wrote our own -> How do I handle a create error in the sync notification callback (4.0 javascript)?

                           

                          Most of what we found was by trial and error, debugging, weinre, and scouring the rhoapi-modules.js.  From what I remember, we are using all new method/property names, but possibly some are aliased...  I don't remember.

                           

                          If you have specific questions, I'll try to answer.


                          Again, it seems to work just fine.  We have about 24 models in our app and we don't run into too many issues.

                            • Re: NewORM
                              Jon Tara
                              which is why we went with the new ORM -- 4.0 didn't work with fixed schema

                              Hmmm...

                               

                              We use fixed schema, and fairly recently moved from 2.2 to 4.1, and then while we were updating, 5.0 was released, so went to 5.0 before releasing the product(s) built with 5.0. We didn't have any problems. But, of course, we skipped early versions of 4.x which may have been buggy for fixed schema.

                              • Re: Re: NewORM
                                Jon Tara

                                Here are a couple of newORM gotchas I have discovered:

                                 

                                - Not really a "gotcha" but be aware of: object IDs look like integers in newORM, and like floats in oldORM. (But always returned as a string - haven't checked actual type in sqLite.)

                                 

                                - Old ORM (apparently) tolerates {} around object IDs. This is the convention used by Rhodes when passing IDs in URLs (don't understand why, because the period character is a legal character...). Not sure what version(s) of Rhodes this affects, because this is an old Rhodes bug. I work on a "mature" Rhodes product that sprinkles code like below all over the place as a work-around. I noticed on my new project it was no longer needed - until I tried to use newORM!

                                 

                                So, it seems that - at some point in Rhodes' evolution - Rhom .find() started ignoring {} around IDs, but newORM doesn't follow-through on that hack. (And it is a hack!)

                                 

                                    @venue = Venue.find @params['id'].to_s.gsub /[{}]/, ''
                                
                                

                                 

                                - Normal Rhodes try/catch handling seems disabled or broken when you use newORM. Simple errors like trying to do something with a nil will cause a segfault if using newORM. If not, they are caught and just logged.

                                 

                                I contrived a test of this by just forcing a value (that I dereference during some logging) to nil. Line 5 below will throw an error, because it tries to access the object member of @venue, which will not exist because I have forced the value of @venue to nil. (Note that the {{}} stuff is just some pre-processing I do on source files using {{mustache}}. It uses Rho::Log.)

                                 

                                    #@venue = Venue.find @params['id']
                                    @venue = nil
                                    #@venue = Venue.find @params['id'].to_s.gsub /[{}]/, ''
                                    {{#logInfo}} "@venue = #{@venue.inspect}"{{/logInfo}}
                                    {{#logInfo}} "@venue.object.class.name = #{@venue.object.class.name}"{{/logInfo}}
                                
                                

                                 

                                With new_orm = 0, I get this in the log:

                                 

                                2015-03-23 12:46:20.054 rhorunner[4554:5848327] I 03/23/2015 12:46:20:054 1e46a000      VenueController| [show](16) @venue = nil
                                2015-03-23 12:46:20.054 rhorunner[4554:5848327] I 03/23/2015 12:46:20:054 1e46a000                  APP| App error: undefined method `object' for nil:NilClass
                                apps/app/Venue/venue_controller.rb:17:in `show'
                                lib/rho/rhocontroller.rb:101:in `serve'
                                lib/rho/rhoapplication.rb:217:in `serve'
                                lib/rho/rho.rb:836:in `serve'
                                2015-03-23 12:46:20.054 rhorunner[4554:5848327] I 03/23/2015 12:46:20:054 1e46a000           HttpServer| GC Start.
                                
                                

                                 

                                With new_orm = 1, though, I get this:

                                 

                                 

                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] I 03/23/2015 12:53:06:604 59565000      VenueController| [show](16) @venue = nil
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] I 03/23/2015 12:53:06:604 59565000                  APP| App error: undefined method `object' for nil:NilClass
                                apps/app/Venue/venue_controller.rb:17:in `show'
                                lib/rho/rhocontroller.rb:101:in `serve'
                                lib/rho/rhoapplication.rb:217:in `serve'
                                lib/rho/rho.rb:836:in `serve'
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] I 03/23/2015 12:53:06:604 59565000                  APP| const_missing: RecordNotFound
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] E 03/23/2015 12:53:06:604 59565000               RubyVM| <main>:  [BUG]
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] E 03/23/2015 12:53:06:604 59565000               RubyVM| Segmentation fault
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] E 03/23/2015 12:53:06:604 59565000               RubyVM| Description: ruby 1.9.2p290 (2011-07-09) [x86_64-darwin10.7.0]
                                2015-03-23 12:53:06.604 rhorunner[4808:5855313] E 03/23/2015 12:53:06:604 59565000               RubyVM| -- control frame ----------
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| c:0001
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| p:0000
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| s:0002 b:0002
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| l:0009c8
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| d:0009c8
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM| TOP
                                2015-03-23 12:53:06.605 rhorunner[4808:5855313] E 03/23/2015 12:53:06:605 59565000               RubyVM|
                                
                                

                                 

                                So, this is a rather severe side-effect of enabling new_orm, which I am afraid makes it unusable to me at the present.

                                 

                                Still, I think it is useful to explore new_orm, and see what adaptations our code needs to make sure it will work with it when released.

                                  • Re: Re: Re: NewORM
                                    Jon Tara

                                    I would-up adding a simple helper to browser_helper.rb:

                                     

                                      # Removes the *&^! {} from around the ID parameter
                                      private
                                      PARAM_ID_REGEX = Regexp.new /[{}]/
                                      public
                                      def param_id
                                        @params['id'].to_s.gsub PARAM_ID_REGEX, ''
                                      end
                                    
                                    
                                    

                                     

                                    So, anywhere where the boilerplate code uses @params['id'], I just use params_id instead.

                            • Re: NewORM
                              Jon Tara

                              A year-later followup....

                               

                              I notice a LOT of newORM-related activity in the repo over the last month, so it looks like there is an effort recently to fix/complete this. Presume this will be in some upcoming release.

                               

                              I wonder if we will at some point get a SQLite update? What we have now is quite old.

                               

                              Rhodes currently uses SQLite 3.7.7.1 from 2011-06-28 (except for WP8, which uses 3.7.15.1).

                               

                              While there isn't much real new functionality between those versions and the current (3.8.10.2) reviewing SQLite release notes, there has been very significant performance improvement, and a huge number of bugs fixed. The most significant new features have been common table expressions and support for the WITH clause.

                              • Re: NewORM
                                BHAKTA RANJAN SATAPATHY

                                Hello,

                                 

                                RHOM is a complete ruby implementation.

                                ORM Javascript uses Opal (ruby to javascript compilation) to call ruby implementation.

                                 

                                NewOrm(still we can refer Rho.ORM for neworm also if use_new_orm=1 in rhoconfig.txt) is a common api implementation (logic in c++) to achieve RHOM functionality both in ruby and javascript.

                                NewOrm will support all the feature of RHOM, except complex query with property bag.

                                 

                                Updated docs will be available under edge section very soon.

                                 

                                Thanks