Guest User

Untitled

a guest
Apr 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dojo.provide("karma.kernel.factory.storemodel.Store");
  2.  
  3. dojo.require("karma.kernel.factory.storemodel.Transports");
  4. dojo.require("dojo.store.Observable");
  5. dojo.require("dojo.data.ObjectStore");
  6. dojo.require("dojo.store.Cache");
  7. dojo.require("dojo.store.Memory");
  8. dojo.require("karma.kernel.factory.store.Cache");
  9. dojo.require("karma.kernel.factory.store.Memory");
  10.  
  11. //>>excludeStart("excludeRql", kwArgs.excludeRql)
  12. dojo.require("rql.query");
  13. dojo.require("rql.parser");
  14. //>>excludeEnd("excludeRql")
  15.  
  16. dojo.declare("karma.kernel.factory.storemodel.Store", null, {
  17.  
  18.     tableName: null,
  19.     _dictLegacyWrappers: null, // Collection of legacy wrappers for this store
  20.     constructor: function(args){
  21.         // summary:
  22.         //  args: have the following defined
  23.         //      tableName:
  24.         //          The name of the database table that this store will represent
  25.         //      idProperty:
  26.         //          The name of the ID column in the table
  27.        
  28.         this._dictLegacyWrappers = new dojox.collections.Dictionary();
  29.        
  30.         this.tableName = args.tableName;
  31.        
  32.         console.log("creating store for table: " + args.tableName);
  33.        
  34.         // Create a JSON transport object
  35.         var transports = new karma.kernel.factory.storemodel.Transports();
  36.         args = dojo.mixin(args, {
  37.             target: kernel.config.restServerUrl + args.tableName + "/"
  38.         });
  39.         var transport = transports.get(args);
  40.        
  41.         // Create an in-memory store
  42.         var memory = new dojo.store.Memory(args);
  43.         memory.queryEngine = rql['js-array'].query;
  44.        
  45.         //wrap the in-memory store with our "observable fix" in-memory store
  46.         var observableMemory = new karma.kernel.factory.store.Memory(memory);
  47.        
  48.         // Wrap the transport and in-memory (observable fixed) objects in a queryable cache object
  49.         var cache = new dojo.store.Cache(transport, observableMemory);
  50.         var queryableCache = new karma.kernel.factory.store.Cache(cache,observableMemory);
  51.        
  52.         // Make our store observable
  53.         var store = new dojo.store.Observable(queryableCache);
  54.        
  55.         dojo.mixin(this, store);
  56.     },
  57.    
  58.     getLegacyStore: function(labelProperty){
  59.         //  summary:
  60.         //      Wraps the store in a legacyStore wrapper (based on the labelProperty), if the legacyStore does not yet exist, and then
  61.         //      returns the legacyStore that corresponds to the labelProperty.
  62.         //      If this store has already been wrapped in a LegacyStore with this labelProperty, the existing LegacyStore is returned.
  63.         //
  64.         //  labelProperty:
  65.         //      The name of the column in the table that will be used as the label in legacy widgets
  66.        
  67.         // If this is a new labelProperty for this store, create a new wrapper, and save it to the dictLegacyStores dictionary.
  68.         if (!this._dictLegacyWrappers.containsKey(labelProperty)) {
  69.        
  70.             var legacyStore = new dojo.data.ObjectStore({
  71.                 objectStore: this,
  72.                 labelProperty: labelProperty
  73.             });
  74.            
  75.             this._dictLegacyWrappers.add(labelProperty, legacyStore);
  76.         }
  77.        
  78.         return this._dictLegacyWrappers.item(labelProperty);
  79.     }
  80. });
Add Comment
Please, Sign In to add comment