From 8fe92b94ce5e1e2857d088752d94e19db7e3d8a8 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Sun, 17 Jun 2012 22:31:44 -0700 Subject: montage v11 merge into ninja Signed-off-by: Valerio Virgillito --- node_modules/montage/data/store.js | 1421 ++++++++++++++++++------------------ 1 file changed, 705 insertions(+), 716 deletions(-) (limited to 'node_modules/montage/data/store.js') diff --git a/node_modules/montage/data/store.js b/node_modules/montage/data/store.js index 5057826d..6a713758 100755 --- a/node_modules/montage/data/store.js +++ b/node_modules/montage/data/store.js @@ -1,192 +1,158 @@ /* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. + */ /** - @module montage/data/store - @requires montage/core/core - @requires montage/data/blueprint - @requires montage/data/query - @requires montage/data/restriction - @requires montage/data/transactionid - @requires montage/data/objectid - @requires montage/data/controllistener - @requires montage/core/serializer - @requires montage/core/deserializer - @requires montage/core/promise - @requires montage/core/logger -*/ + @module montage/data/store + @requires montage/core/core + @requires montage/data/blueprint + @requires montage/data/mapping + @requires montage/data/query + @requires montage/data/restriction + @requires montage/data/transaction-id + @requires montage/data/object-id + @requires montage/data/control-listener + @requires montage/core/serializer + @requires montage/core/deserializer + @requires montage/core/promise + @requires montage/core/logger + */ var Montage = require("montage").Montage; var Blueprint = require("data/blueprint").Blueprint; var BlueprintBinder = require("data/blueprint").BlueprintBinder; +var BinderMapping = require("data/mapping").BinderMapping; +var BlueprintMapping = require("data/mapping").BlueprintMapping; +var AttributeMapping = require("data/mapping").AttributeMapping; +var AssociationMapping = require("data/mapping").AssociationMapping; +var StoreConnectionInformation = require("data/store-connection-information").StoreConnectionInformation; var Query = require("data/query").Query; var Restriction = require("data/restriction").Restriction; -var TransactionId = require("data/transactionid").TransactionId; -var ObjectId = require("data/objectid").ObjectId; -var TemporaryObjectId = require("data/objectid").TemporaryObjectId; -var ControlListener = require("data/controllistener").ControlListener; +var TransactionId = require("data/transaction-id").TransactionId; +var ObjectId = require("data/object-id").ObjectId; +var TemporaryObjectId = require("data/object-id").TemporaryObjectId; var Serializer = require("core/serializer").Serializer; var Deserializer = require("core/deserializer").Deserializer; var Promise = require("core/promise").Promise; var logger = require("core/logger").logger("store"); /** - Description TODO - @private -*/ + Description TODO + @private + */ var _defaultStoreManager = null; /** - @class module:montage/data/store.Store - @extends module:montage/core/core.Montage -*/ -var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/data/store.Store# */ { -/** - Description TODO - @type {Property} Function - @default {Array} new Array(10) - */ - blueprintBinders: { - serializable: true, - writable: false, - distinct: true, - value: new Array(10) - }, -/** - Description TODO - @function - @param {Property} binder TODO - */ - addBlueprintBinder: { - value: function(binder) { - if (binder !== null) { - var index = this.blueprintBinders.indexOf(binder); - if (index < 0) { - this.blueprintBinders.push(binder); - } - } - } - }, -/** - Description TODO - @function - @param {Property} binder TODO - */ - removeBlueprintBinder: { - value: function(binder) { - if (binder !== null) { - var index = this.blueprintBinders.indexOf(binder); - if (index >= 0) { - this.blueprintBinders.splice(index, 1); - } - } - } + @class module:montage/data/store.Store + @extends module:montage/core/core.Montage + */ +var Store = exports.Store = Montage.create(Montage, /** @lends module:montage/data/store.Store# */ { + + /* + * @private + */ + _connectionInfo:{ + serializable:true, + enumerable:false, + value:null }, -/** - Description TODO - @function - @param {Property} name TODO - @returns null - */ - blueprintBinderForName: { - value: function(name) { - var binder, index; - for (index = 0; typeof (binder = this.blueprintBinders[index]) !== "undefined"; index++) { - if (binder.name === name) { - return binder; - } - } - return null; + + /* + * Connection information for the store + */ + connectionInfo:{ + get:function () { + return this._connectionInfo; + }, + set:function (info) { + // TODO [PJYF May 15 2012] We need to check that the connection info is valid for this store. + this._connectionInfo = info; } }, -/** - Description TODO - @type {Property} - @default {Array} new Array(10) - */ - restrictions: { - serializable: true, - writable: false, - distinct: true, - value: new Array(10) + + /** + Description TODO + @type {Property} + @default {Array} new Array(10) + */ + restrictions:{ + serializable:true, + writable:false, + distinct:true, + value:new Array(10) }, -/** - Description TODO - @private -*/ - _parent: { - serializable: true, - enumerable: false, - value: null + + /** + @private + */ + _parent:{ + serializable:true, + enumerable:false, + value:null }, - /** - Returns the parent store. - @function - @returns this._parent - */ - parent: { - get: function() { + /** + Returns the parent store. + @function + @returns this._parent + */ + parent:{ + get:function () { return this._parent; } }, - - /* - * - * + /** + Returns the default store manager.
+ If none is defined it will create one that will then be reused for subsequent calls. + @function + @returns _defaultStoreManager */ - - /** - Returns the default store manager.
- If none is defined it will create one that will then be reused for subsequent calls. - @function - @returns _defaultStoreManager - */ - defaultManager: { - get: function() { + defaultManager:{ + get:function () { if (_defaultStoreManager === null) { _defaultStoreManager = StoreManager.create().init(); } return _defaultStoreManager; }, // This is used only for testing. - set: function(storeManager) { + set:function (storeManager) { _defaultStoreManager = storeManager; } }, -/** - @function - @returns this.initWithParentAndRestrictions(null, null) - */ - init: { - serializable: false, - enumerable: false, - value: function() { + + /** + @function + @returns this.initWithParentAndRestrictions(null, null) + */ + init:{ + serializable:false, + enumerable:false, + value:function () { return this.initWithParentAndRestrictions(null, null); } }, -/** - @function - @param {Property} parent TODO - @returns this.initWithParentAndRestrictions(parent, null) - */ - initWithParent: { - serializable: false, - enumerable: false, - value: function(parent) { + + /** + @function + @param {Property} parent TODO + @returns this.initWithParentAndRestrictions(parent, null) + */ + initWithParent:{ + serializable:false, + enumerable:false, + value:function (parent) { return this.initWithParentAndRestrictions(parent, null); } }, -/** - Description TODO - @function - @param {Property} parent TODO - @param {Property} restrictions TODO - @returns itself - */ - initWithParentAndRestrictions: { - serializable: false, - value: function(parent, restrictions) { + /** + Description TODO + @function + @param {Property} parent TODO + @param {Property} restrictions TODO + @returns itself + */ + initWithParentAndRestrictions:{ + serializable:false, + value:function (parent, restrictions) { if (this.parent !== null) { this.parent.remove(this); } @@ -202,35 +168,16 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat return this; } }, -/** - Description TODO - @function - @param {Prototyoe} prototypeName TODO - @param {Id} moduleId TODO - @returns null - */ - blueprintForPrototype$Implementation: { - serializable: false, - value: function(prototypeName, moduleId) { - var binder, blueprint, index; - for (index = 0; typeof (binder = this.blueprintBinders[index]) !== "undefined"; index++) { - blueprint = binder.blueprintForPrototype(prototypeName, moduleId); - if (blueprint !== null) { - return blueprint; - } - } - return null; - } - }, -/** - Description TODO - @function - @param {Prototyoe} prototypeName TODO - @param {Id} moduleId TODO - @returns null - */ - blueprintForPrototype: { - value: function(prototypeName, moduleId) { + + /** + Description TODO + @function + @param {Prototyoe} prototypeName TODO + @param {Id} moduleId TODO + @returns null + */ + blueprintForPrototype:{ + value:function (prototypeName, moduleId) { if (this.parent !== null) { return this.parent.blueprintForPrototype(prototypeName, moduleId); } @@ -238,14 +185,58 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, - /** - Add a store to the cooperating objects stores. - @function - @param {Property} store TODO - @returns store - */ - addStore: { - value: function(store) { + /** + Create a new binder mapping.
This is intended to be subclassed by concrete store to create the right mapping for their store. + @function + @returns binder mapping + */ + createBinderMapping:{ + get:function () { + return BinderMapping.create(); + } + }, + + /** + Create a new blueprint mapping.
This is intended to be subclassed by concrete store to create the right mapping for their store. + @function + @returns blueprint mapping + */ + createBlueprintMapping:{ + get:function () { + return BlueprintMapping.create(); + } + }, + + /** + Create a new attribute mapping.
This is intended to be subclassed by concrete store to create the right mapping for their store. + @function + @returns attribute mapping + */ + createAttributeMapping:{ + get:function () { + return AttributeMapping.create(); + } + }, + + /** + Create a new association mapping.
This is intended to be subclassed by concrete store to create the right mapping for their store. + @function + @returns association mapping + */ + createAssociationMapping:{ + get:function () { + return AssociationMapping.create(); + } + }, + + /** + Add a store to the cooperating objects stores. + @function + @param {Property} store TODO + @returns store + */ + addStore:{ + value:function (store) { if (this.parent !== null) { return this.parent.addStore(store); } @@ -253,14 +244,14 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Remove a store to the cooperating objects stores. - @function - @param {Property} store TODO - @returns store - */ - removeStore: { - value: function(store) { + /** + Remove a store to the cooperating objects stores. + @function + @param {Property} store TODO + @returns store + */ + removeStore:{ + value:function (store) { if (this.parent !== null) { return this.parent.removeStore(store); } @@ -268,92 +259,78 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Id} objectId TODO - @returns {Boolean} false - */ - ownsObject: { - value: function(objectId) { - if ((objectId !== null) && (typeof (objectId.blueprint) === "object")) { - return this.blueprintBinders.indexOf(objectId.blueprint.binder) >= 0; + /** + Load a blueprint in the store manager.
+ This will force the loading of the corresponding store if not already in memory. + @function + @param {Property} blueprint Either a binder object or a serialized representation of a binder object. + @param {Property} transactionId current transaction identifier + @returns this.parent.requireStoreForBlueprint(binder) + */ + requireStoreForBlueprint:{ + value:function (blueprint, transactionId) { + if (this.parent !== null) { + return this.parent.requireStoreForBlueprint(blueprint, transactionId); } - return false; } }, -/** - Description TODO - @function - @param {Property} blueprint TODO - @returns {Boolean} false - */ - ownsBlueprint: { - value: function(blueprint) { - var binder, index; - for (index = 0; typeof (binder = this.blueprintBinders[index]) !== "undefined"; index++) { - if (binder.blueprints.indexOf(blueprint) >= 0) { - return true; - } + /** + Check if the referenced blueprint can be serviced by the target store. + @function + @param {Property} blueprint TODO + @param {Property} transactionId current transaction identifier + @returns true if the current store can service that binder. + */ + canServiceBlueprint:{ + value:function (blueprint, transactionId) { + var blueprintMapping = blueprint.mappingForName(transactionId.mappingFolderName); + if (!blueprintMapping) { + return false; } - return false; - } - }, - -/** - Load a binder in the store manager.
- This will force the loading of the corresponding store if not already in memory. - @function - @param {Property} binder Either a binder object or a serialized representation of a binder object. - @returns this.parent.requireStoreForBlueprintBinder(binder) - */ - requireStoreForBlueprintBinder: { - value : function(binder) { - if (this.parent !== null) { - return this.parent.requireStoreForBlueprintBinder(binder); + var binderMapping = blueprintMapping.parent; + if (!binderMapping) { + return false; } - } - }, - -/** - Check if the referenced binder can be serviced by the target store. - @function - @param {Property} binder TODO - @returns (binder.storeModuleId === metadata.moduleId) && (binder.storePrototypeName === metadata.objectName) - */ - canServiceBlueprintBinder: { - value: function(binder) { - // TODO [PJYF May 10 2011] This unsufficient for most stores we should actually check the connection info var metadata = Montage.getInfoForObject(this); - return (binder.storeModuleId === metadata.moduleId) && (binder.storePrototypeName === metadata.objectName); + if ((binderMapping.storePrototypeName === metadata.objectName) && (binderMapping.storeModuleId === metadata.moduleId)) { + if (this.connectionInfo) { + var connectionInfo = binderMapping.connectionInformationForName(this.connectionInfo.name); + return this.connectionInfo.equals(connectionInfo); + } + // TODO [PJYF May 15 2012] I am not sure this is correct it may be a bit bizarre. + return true; + } + return false; } }, -/** - Check if the query blueprint can be serviced by this store. - @function - @param {Property} query TODO - @returns {Boolean} false - */ - canServiceQuery: { - value: function(query) { + /** + Check if the query blueprint can be serviced by this store. + @function + @param {Property} query TODO + @param {Property} transactionId TODO + @returns {Boolean} true if the current store can service the query + */ + canServiceQuery:{ + value:function (query, transactionId) { if (query != null) { - return this.ownsBlueprint(query.blueprint); + return this.canServiceBlueprint(query.blueprint, transactionId); } return false; } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.permanentIdForObjectId$Implementation(objectId, context, aTransactionId) - */ - permanentIdForObjectId: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.permanentIdForObjectId$Implementation(objectId, context, aTransactionId) + */ + permanentIdForObjectId:{ + value:function (object, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -362,7 +339,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } return this.permanentIdForObjectId$Implementation(objectId, context, aTransactionId); @@ -373,32 +350,33 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns Promise.ref(null) - */ - permanentIdForObjectId$Implementation: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns Promise.ref(null) + */ + permanentIdForObjectId$Implementation:{ + value:function (object, context, transactionId) { if (typeof object.objectId !== "undefined") { return Promise.ref(object.objectId); } return Promise.ref(null); } }, -/** - Description TODO - @function - @param {Object} objectId TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.pledgeForObjectId$Implementation(objectId, context, aTransactionId) - */ - pledgeForObjectId: { - value: function(objectId, context, transactionId) { + /** + Description TODO + @function + @param {Object} objectId TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.pledgeForObjectId$Implementation(objectId, context, aTransactionId) + */ + pledgeForObjectId:{ + value:function (objectId, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -407,7 +385,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } return this.pledgeForObjectId$Implementation(objectId, context, aTransactionId); @@ -418,31 +396,32 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } } }, -/** - Description TODO - @function - @param {Object} objectId TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns Promise.ref(null) - */ - pledgeForObjectId$Implementation: { - value: function(objectId, context, transactionId) { + /** + Description TODO + @function + @param {Object} objectId TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns Promise.ref(null) + */ + pledgeForObjectId$Implementation:{ + value:function (objectId, context, transactionId) { // TODO [PJYF May 17 2011] This needs to be reimplemented return Promise.ref(null); } }, -/** - Description TODO - @function - @param {Object} sourceObject TODO - @param {Property} relationshipName TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.pledgeForSourceObjectRelationshipNamed$Implementation(sourceObject, relationshipName, context, aTransactionId) - */ - pledgeForSourceObjectRelationshipNamed: { - value: function(sourceObject, relationshipName, context, transactionId) { + /** + Description TODO + @function + @param {Object} sourceObject TODO + @param {Property} relationshipName TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, aTransactionId) + */ + pledgeForSourceObjectAssociationNamed:{ + value:function (sourceObject, relationshipName, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -451,10 +430,10 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } - return this.pledgeForSourceObjectRelationshipNamed$Implementation(sourceObject, relationshipName, context, aTransactionId); + return this.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, aTransactionId); } finally { if (!hadOpenTransaction) { TransactionId.manager.closeTransaction(aTransactionId); @@ -462,37 +441,38 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } } }, -/** - Description TODO - @function - @param {Object} sourceObject TODO - @param {Property} relationshipName TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns Promise.ref(null) - */ - pledgeForSourceObjectRelationshipNamed$Implementation: { - value: function(sourceObject, relationshipName, context, transactionId) { + /** + Description TODO + @function + @param {Object} sourceObject TODO + @param {Property} relationshipName TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns Promise.ref(null) + */ + pledgeForSourceObjectAssociationNamed$Implementation:{ + value:function (sourceObject, relationshipName, context, transactionId) { if (this.parent !== null) { - return this.parent.pledgeForSourceObjectRelationshipNamed$Implementation(sourceObject, relationshipName, context, transactionId); + return this.parent.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, transactionId); } return Promise.ref(null); } }, -/** - Returns a pledge for the source object and the relationship referenced.
- The resulting pledge can be a simple one or an array pledge depending on the type of relationship.
- Note: The source object may not be in the current data source. The destination object is. - @function - @param {Object} sourceObject TODO - @param {Property} relationship TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.pledgeForSourceObjectRelationship$Implementation(sourceObject, relationship, context, aTransactionId) - */ - pledgeForSourceObjectRelationship: { - value: function(sourceObject, relationship, context, transactionId) { + /** + Returns a pledge for the source object and the relationship referenced.
+ The resulting pledge can be a simple one or an array pledge depending on the type of relationship.
+ Note: The source object may not be in the current data source. The destination object is. + @function + @param {Object} sourceObject TODO + @param {Property} relationship TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, aTransactionId) + */ + pledgeForSourceObjectAssociation:{ + value:function (sourceObject, relationship, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -501,10 +481,10 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } - return this.pledgeForSourceObjectRelationship$Implementation(sourceObject, relationship, context, aTransactionId); + return this.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, aTransactionId); } finally { if (!hadOpenTransaction) { TransactionId.manager.closeTransaction(aTransactionId); @@ -513,33 +493,34 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Object} sourceObject TODO - @param {Property} relationship TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.parent.pledgeForSourceObjectRelationship$Implementation(sourceObject, relationship, context, transactionId) - */ - pledgeForSourceObjectRelationship$Implementation: { - value: function(sourceObject, relationship, context, transactionId) { + /** + Description TODO + @function + @param {Object} sourceObject TODO + @param {Property} relationship TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns this.parent.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, transactionId) + */ + pledgeForSourceObjectAssociation$Implementation:{ + value:function (sourceObject, relationship, context, transactionId) { if (this.parent !== null) { - return this.parent.pledgeForSourceObjectRelationship$Implementation(sourceObject, relationship, context, transactionId); + return this.parent.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, transactionId); } } }, -/** - Called by the framework whenever a new object is inserted, or a pledge is fired. - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.initializeObject$Implementation(object, context, aTransactionId) - */ - initializeObject: { - value: function(object, context, transactionId) { + /** + Called by the framework whenever a new object is inserted, or a pledge is fired. + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.initializeObject$Implementation(object, context, aTransactionId) + */ + initializeObject:{ + value:function (object, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -548,7 +529,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } return this.initializeObject$Implementation(object, context, aTransactionId); @@ -560,34 +541,35 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns Promise.ref(object) - */ - initializeObject$Implementation: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns Promise.ref(object) + */ + initializeObject$Implementation:{ + value:function (object, context, transactionId) { if (typeof object.objectId === "undefined") { - // TODO [PJYF June 17 2011] This will need to be revisited. + // TODO [PJYF June 17 2011] This will need to be revisited.p object.objectId = TemporaryObjectId.create().init(); } return Promise.ref(object); } }, -/** - Description TODO - @function - @param {Object} target TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.repledgeObject$Implementation(target, context, aTransactionId) - */ - repledgeObject: { - value: function(target, context, transactionId) { + /** + Description TODO + @function + @param {Object} target TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.repledgeObject$Implementation(target, context, aTransactionId) + */ + repledgeObject:{ + value:function (target, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -596,7 +578,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } if (Array.isArray(target)) { @@ -618,16 +600,16 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns Promise.ref(object) - */ - repledgeObject$Implementation: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns Promise.ref(object) + */ + repledgeObject$Implementation:{ + value:function (object, context, transactionId) { if (typeof object.objectId !== "undefined") { return this.pledgeForObjectId(object.objectId, context, transactionId); } @@ -636,14 +618,15 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat }, -/** - Description TODO - @function - @param {Property} context TODO - @param {Id} transactionId TODO - */ - saveChangesInContext: { - value: function(context, transactionId) { + /** + Description TODO + @function + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + */ + saveChangesInContext:{ + value:function (context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -652,7 +635,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } this.saveChangesInContext$Implementation(context, aTransactionId); @@ -664,77 +647,78 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.parent.saveChangesInContext$Implementation(context, transactionId) - */ - saveChangesInContext$Implementation: { - value: function(context, transactionId) { + /** + Description TODO + @function + @param {Property} context TODO + @param {Id} transactionId TODO + @returns this.parent.saveChangesInContext$Implementation(context, transactionId) + */ + saveChangesInContext$Implementation:{ + value:function (context, transactionId) { if (this.parent !== null) { return this.parent.saveChangesInContext$Implementation(context, transactionId); } } }, -/** - Called on each store before a save.
- Upon receiving this message the store should take steps to prepare the commit and insure it will succeed.
- If the commit cannot succeed it should return a rejected promise. - @function - @param {Property} context TODO - @param {Id} transactionId TODO - @returns {Boolean} Promise.ref(true) - */ - prepareToSaveChangesInContext$Implementation: { - value: function(context, transactionId) { + /** + Called on each store before a save.
+ Upon receiving this message the store should take steps to prepare the commit and insure it will succeed.
+ If the commit cannot succeed it should return a rejected promise. + @function + @param {Property} context TODO + @param {Id} transactionId TODO + @returns {Boolean} Promise.ref(true) + */ + prepareToSaveChangesInContext$Implementation:{ + value:function (context, transactionId) { // TODO [PJYF Sep 27 2011] This needs to be reimplemented return Promise.ref(true); } }, -/** - Called on each store before a revert a prepare to save.
- Any step taken to prepare the save should be rolled back. - @function - @param {Property} context TODO - @param {Id} transactionId TODO - @returns {Boolean} Promise.ref(true) - */ - cancelSaveChangesInContext$Implementation: { - value: function(context, transactionId) { + /** + Called on each store before a revert a prepare to save.
+ Any step taken to prepare the save should be rolled back. + @function + @param {Property} context TODO + @param {Id} transactionId TODO + @returns {Boolean} Promise.ref(true) + */ + cancelSaveChangesInContext$Implementation:{ + value:function (context, transactionId) { // TODO [PJYF Sep 27 2011] This needs to be reimplemented return Promise.ref(true); } }, -/** - Commits the transaction.
- Any failure during this step will cause the store to be left an inconsistent state. - @function - @param {Property} context TODO - @param {Id} transactionId TODO - @returns {Boolean} Promise.ref(true) - */ - commitChangesInContext$Implementation: { - value: function(context, transactionId) { + /** + Commits the transaction.
+ Any failure during this step will cause the store to be left an inconsistent state. + @function + @param {Property} context TODO + @param {Id} transactionId TODO + @returns {Boolean} Promise.ref(true) + */ + commitChangesInContext$Implementation:{ + value:function (context, transactionId) { // TODO [PJYF Sep 27 2011] This needs to be reimplemented return Promise.ref(true); } }, -/** - Description TODO - @function - @param {Property} query TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns this.queryInContext$Implementation(query, context, aTransactionId) - */ - queryInContext: { - value: function(query, context, transactionId) { + /** + Description TODO + @function + @param {Property} query TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @param {name} Mapping folder name used for this transaction + @returns this.queryInContext$Implementation(query, context, aTransactionId) + */ + queryInContext:{ + value:function (query, context, transactionId, name) { var aTransactionId = transactionId; var hadOpenTransaction = false; try { @@ -743,7 +727,7 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat if (hadOpenTransaction) { aTransactionId = TransactionId.manager.currentTransaction(); } else { - aTransactionId = TransactionId.manager.startTransaction(); + aTransactionId = TransactionId.manager.startTransaction(name); } } return this.queryInContext$Implementation(query, context, aTransactionId); @@ -755,16 +739,16 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat } }, -/** - Description TODO - @function - @param {Property} query TODO - @param {Property} context TODO - @param {Id} transactionId TODO - @returns {Array} Promise.ref([]) - */ - queryInContext$Implementation: { - value: function(query, context, transactionID) { + /** + Description TODO + @function + @param {Property} query TODO + @param {Property} context TODO + @param {Id} transactionId TODO + @returns {Array} Promise.ref([]) + */ + queryInContext$Implementation:{ + value:function (query, context, transactionID) { // TODO [PJYF Sept 4 2011] This needs to be implemented return Promise.ref([]); } @@ -774,50 +758,50 @@ var Store = exports.Store = Montage.create(Montage,/** @lends module:montage/dat }); /** - @class module:montage/data/store.StoreManager -*/ -var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module:montage/data/store.StoreManager# */ { -/** - Description TODO - @type {Property} - @default {Array} new Array(10) - */ - stores: { - serializable: true, - writable: false, - distinct: true, - value: new Array(10) + @class module:montage/data/store.StoreManager + */ +var StoreManager = exports.StoreManager = Montage.create(Store, /** @lends module:montage/data/store.StoreManager# */ { + /** + Description TODO + @type {Property} + @default {Array} new Array(10) + */ + stores:{ + serializable:true, + writable:false, + distinct:true, + value:new Array(10) }, -/** - Description TODO - @function - @returns itself - */ - parent: { - get: function() { + /** + Description TODO + @function + @returns itself + */ + parent:{ + get:function () { return this; } }, -/** - Description TODO - @function - @returns itself - */ - init: { - serializable: false, - enumerable: false, - value: function() { + /** + Description TODO + @function + @returns itself + */ + init:{ + serializable:false, + enumerable:false, + value:function () { return this; } }, -/** - Description TODO - @function - @param {Property} store Store to be added. - @returns store - */ - addStore: { - value: function(store) { + /** + Description TODO + @function + @param {Property} store Store to be added. + @returns store + */ + addStore:{ + value:function (store) { if ((store !== null) && (store !== this)) { var index = this.stores.indexOf(store); if (index < 0) { @@ -827,14 +811,14 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module return store; } }, -/** - Description TODO - @function - @param {Property} store Store to be removed. - @returns store - */ - removeStore: { - value: function(store) { + /** + Description TODO + @function + @param {Property} store Store to be removed. + @returns store + */ + removeStore:{ + value:function (store) { if (store !== null) { var index = this.stores.indexOf(store); if (index >= 0) { @@ -845,37 +829,31 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, - /** - Search through the stores for a blueprint that extends that prototype. - @function - @param {Property} prototypeName TODO - @param {Property} moduleId TODO - @returns The requested blueprint or null if this prototype is not managed. - */ - blueprintForPrototype: { - value: function(prototypeName, moduleId) { - var store, blueprint, index; - for (index = 0; typeof (store = this.stores[index]) !== "undefined"; index++) { - blueprint = store.blueprintForPrototype$Implementation(prototypeName, moduleId); - if (blueprint !== null) { - return blueprint; - } - } - return null; + /** + Search through the binders for a blueprint that extends that prototype. + @function + @param {Property} prototypeName TODO + @param {Property} moduleId TODO + @returns The requested blueprint or null if this prototype is not managed. + */ + blueprintForPrototype:{ + value:function (prototypeName, moduleId) { + return BlueprintBinder.manager.blueprintForPrototype(prototypeName, moduleId); } }, -/** - Description TODO - @function - @param {Object} blueprint The blueprint object. - @returns store or null - */ - storeForBlueprint: { - value: function(blueprint) { + /** + Description TODO + @function + @param {Object} blueprint The blueprint object. + @param {Property} transactionId TODO + @returns store or null + */ + storeForBlueprint:{ + value:function (blueprint, transactionId) { var store, index; for (index = 0; typeof (store = this.stores[index]) !== "undefined"; index++) { - if (store.ownsBlueprint(blueprint)) { + if (store.canServiceBlueprint(blueprint, transactionId)) { return store; } } @@ -883,32 +861,32 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, -/** - Search for existing store that can service this blueprint binder. - @function - @param {Property} binder The blueprint binder to test for. - @returns Promise.ref(store) A store that can service that blueprint binder or null if none was found. - */ - findStoreForBlueprintBinder: { - value: function(binder) { - var store = this._findStoreForBlueprintBinder(binder); + /** + Search for existing store that can service this blueprint. + @function + @param {Property} blueprint The blueprint to test for. + @param {Property} transactionId TODO + @returns Promise.ref(store) A store that can service that blueprint or null if none was found. + */ + findStoreForBlueprint:{ + value:function (blueprint, transactionId) { + var store = this._findStoreForBlueprint(blueprint, transactionId); if (store == null) { - store = this.requireStoreForBlueprintBinder(binder); + store = this.requireStoreForBlueprint(blueprint, transactionId); } return Promise.ref(store); } }, -/** - Description TODO - @private -*/ - _findStoreForBlueprintBinder: { - value: function(binder) { + /** + Description TODO + @private + */ + _findStoreForBlueprint:{ + value:function (blueprint, transactionId) { var store, index; for (index = 0; typeof (store = this.stores[index]) !== "undefined"; index++) { - if (store.canServiceBlueprintBinder(binder)) { - store.addBlueprintBinder(binder); + if (store.canServiceBlueprint(blueprint, transactionId)) { return store; } } @@ -916,78 +894,89 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, -/** - Search for existing store that can service this blueprint binder. - @function - @param {Property} binder The blueprint binder to test for. - @returns Promise.ref(null) or Deserializer.create().initWithString(binder).deserialize(function(binder) or this._requireStoreForBlueprintBinder(binder) or this._requireStoreForBlueprintBinder(binder) - */ - requireStoreForBlueprintBinder: { - value: function(binder) { - if ((binder === null) || (typeof binder === "undefined")) { + /** + Search for existing store that can service this blueprint. + @function + @param {Property} blueprint The blueprint to test for. + @param {Property} transactionId TODO + @returns Promise for the store + */ + requireStoreForBlueprint:{ + value:function (blueprint, transactionId) { + if ((blueprint === null) || (typeof blueprint === "undefined")) { return Promise.ref(null); } - if (typeof binder === "string") { - return Deserializer.create().initWithString(binder).deserializeObject(function(binder) { - return this._requireStoreForBlueprintBinder(binder); - }, require); - } - return this._requireStoreForBlueprintBinder(binder); + // if (typeof blueprint === "string") { + // var self = this; + // return Deserializer.create().initWithString(blueprint).deserializeObject(function (binder) { + // return self._requireStoreForBlueprint(binder, transactionId); + // }, require); + // } + return this._requireStoreForBlueprint(blueprint, transactionId); } }, -/** - Description TODO - @private -*/ - _requireStoreForBlueprintBinder: { - value: function(binder) { - if ((binder === null) || (typeof binder === "undefined")) { + /** + Description TODO + @private + */ + _requireStoreForBlueprint:{ + value:function (blueprint, transactionId) { + if ((blueprint === null) || (typeof blueprint === "undefined")) { return Promise.ref(null); } var store = null; var aStore, index; for (index = 0; typeof (aStore = this.stores[index]) !== "undefined"; index++) { - if (aStore.blueprintBinders.indexOf(binder) >= 0) { + if (aStore.canServiceBlueprint(blueprint, transactionId)) { store = aStore; } } + if (store == null) { - var results = Promise.defer(); - require.async(binder.storeModuleId, - function(exports) { - results.resolve(exports); - }); - var self = this; - return results.promise.then(function(exports) { - var storePrototype = exports[binder.storePrototypeName], store; - if ((typeof storePrototype !== "undefined") && (storePrototype !== null)) { - store = storePrototype.create().initWithParent(self); - store.addBlueprintBinder(binder); - } else { - return Promise.reject("No Store found " + binder.storePrototypeName); + var blueprintMapping = blueprint.mappingForName(transactionId.mappingFolderName); + var binderMapping = (blueprintMapping ? blueprintMapping.parent : null); + if (binderMapping) { + var results = Promise.defer(); + require.async(binderMapping.storeModuleId, + function (exports) { + results.resolve(exports); + }); + var self = this; + return results.promise.then(function (exports) { + var storePrototype = exports[binderMapping.storePrototypeName], store; + if ((typeof storePrototype !== "undefined") && (storePrototype !== null)) { + store = storePrototype.create().initWithParent(self); + // We need to set the connection information + store.connectionInfo = binderMapping.defaultConnectionInformation; + } else { + return Promise.reject("No Store found " + binderMapping.storePrototypeName); + } + return store; } - return store; - } - ); + ); + } else { + return Promise.ref(store); + } } else { return Promise.ref(store); } } }, -/** - Description TODO - @function - @param {object} objectId TODO - @returns store or null - */ - storeForObjectId: { - value: function(objectId) { + /** + Description TODO + @function + @param {object} objectId TODO + @param {Property} transactionId TODO + @returns store or null + */ + storeForObjectId:{ + value:function (objectId, transactionId) { var store, index; for (index = 0; typeof (store = this.stores[index]) !== "undefined"; index++) { - if (store.ownsObject(objectId)) { + if (store.canServiceBlueprint(objectId.blueprint, transactionId)) { return store; } } @@ -995,17 +984,17 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, -/** - Description TODO - @function - @param {Object} sourceObject TODO - @param {Property} relationshipName TODO - @param {Property} context TODO - @param {Property} transactionId TODO - @returns store.pledgeForSourceObjectRelationship(sourceObject, relationship, context, transactionId) or Promise.ref(null) - */ - pledgeForSourceObjectRelationshipNamed$Implementation: { - value: function(sourceObject, relationshipName, context, transactionId) { + /** + Description TODO + @function + @param {Object} sourceObject TODO + @param {Property} relationshipName TODO + @param {Property} context TODO + @param {Property} transactionId TODO + @returns store.pledgeForSourceObjectAssociation(sourceObject, relationship, context, transactionId) or Promise.ref(null) + */ + pledgeForSourceObjectAssociationNamed$Implementation:{ + value:function (sourceObject, relationshipName, context, transactionId) { var store = null; var relationship = null; var metadata = Montage.getInfoForObject(sourceObject); @@ -1013,29 +1002,29 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module if (sourceBlueprint !== null) { relationship = sourceBlueprint.attributeForName(relationshipName); if ((relationship !== null) && (relationship.targetBlueprint !== null)) { - store = this.storeForBlueprint(relationship.targetBlueprint); + store = this.storeForBlueprint(relationship.targetBlueprint, transactionId); } else { logger.error("No relationship named " + relationshipName + " for " + sourceObject); } } if (store !== null) { - return store.pledgeForSourceObjectRelationship(sourceObject, relationship, context, transactionId); + return store.pledgeForSourceObjectAssociation(sourceObject, relationship, context, transactionId); } return Promise.ref(null); } }, -/** - Description TODO - @function - @param {Object} objectId TODO - @param {Property} context TODO - @param {Property} transactionId TODO - @returns store.pledgeForObjectId$Implementation(objectId, context, transactionId) or Promise.ref(null) - */ - pledgeForObjectId$Implementation: { - value: function(objectId, context, transactionId) { - var store = this.storeForObjectId(objectId); + /** + Description TODO + @function + @param {Object} objectId TODO + @param {Property} context TODO + @param {Property} transactionId TODO + @returns store.pledgeForObjectId$Implementation(objectId, context, transactionId) or Promise.ref(null) + */ + pledgeForObjectId$Implementation:{ + value:function (objectId, context, transactionId) { + var store = this.storeForObjectId(objectId, transactionId); if (store !== null) { return store.pledgeForObjectId$Implementation(objectId, context, transactionId); } @@ -1043,31 +1032,31 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, -/** - Description TODO - @function - @param {Object} sourceObject TODO - @param {Property} relationship TODO - @param {Property} context TODO - @param {Property} transactionId TODO - @returns Promise.ref(null) - */ - pledgeForSourceObjectRelationship$Implementation: { - value: function(sourceObject, relationship, context, transactionId) { + /** + Description TODO + @function + @param {Object} sourceObject TODO + @param {Property} relationship TODO + @param {Property} context TODO + @param {Property} transactionId TODO + @returns Promise.ref(null) + */ + pledgeForSourceObjectAssociation$Implementation:{ + value:function (sourceObject, relationship, context, transactionId) { return Promise.ref(null); } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Property} transactionId TODO - @returns Promise.ref(object) - */ - initializeObject$Implementation: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Property} transactionId TODO + @returns Promise.ref(object) + */ + initializeObject$Implementation:{ + value:function (object, context, transactionId) { if (typeof object.objectId === "undefined") { // TODO [PJYF June 17 2011] This will need to be revisited. object.objectId = TemporaryObjectId.create().init(); @@ -1076,16 +1065,16 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module } }, -/** - Description TODO - @function - @param {Object} object TODO - @param {Property} context TODO - @param {Property} transactionId TODO - @returns this.pledgeForObjectId(object.objectId, context, transactionId) or Promise.ref(object) - */ - repledgeObject$Implementation: { - value: function(object, context, transactionId) { + /** + Description TODO + @function + @param {Object} object TODO + @param {Property} context TODO + @param {Property} transactionId TODO + @returns this.pledgeForObjectId(object.objectId, context, transactionId) or Promise.ref(object) + */ + repledgeObject$Implementation:{ + value:function (object, context, transactionId) { if (typeof object.objectId !== "undefined") { return this.pledgeForObjectId(object.objectId, context, transactionId); } @@ -1094,20 +1083,20 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module }, -/** - The default is a 2 step commit.
- In the first step we call prepareForSave on each managed store.
- The second step calls commitChanges on each store.
- prepareToSave should return a rejected promise if the commit will fail.
- If any store return a reject all store will receive a cancelSave message.
- Any failure during the commitChanges will result in an inconsistent state of the stores. - @function - @param {Property} context TODO - @param {Property} transactionId TODO - @returns Promise.when(Promise.all(secondStep), function() or Promise.ref(true) or Promise.when(Promise.all(secondStep), function() or return Promise.reject("Could not save the transaction: " + transactionId) - */ - saveChangesInContext$Implementation: { - value: function(context, transactionId) { + /** + The default is a 2 step commit.
+ In the first step we call prepareForSave on each managed store.
+ The second step calls commitChanges on each store.
+ prepareToSave should return a rejected promise if the commit will fail.
+ If any store return a reject all store will receive a cancelSave message.
+ Any failure during the commitChanges will result in an inconsistent state of the stores. + @function + @param {Property} context TODO + @param {Property} transactionId TODO + @returns Promise.when(Promise.all(secondStep), function() or Promise.ref(true) or Promise.when(Promise.all(secondStep), function() or return Promise.reject("Could not save the transaction: " + transactionId) + */ + saveChangesInContext$Implementation:{ + value:function (context, transactionId) { // TODO [PJYF Sept 27 2011] We need to post notification to the observing context. // We do a 2 step commit. We need to prepare all stores for commit. If nothing raises than we can commit for real and hopefully we don't raise then. var aStore, index; @@ -1116,23 +1105,23 @@ var StoreManager = exports.StoreManager = Montage.create(Store,/** @lends module for (index = 0; typeof (aStore = this.stores[index]) !== "undefined"; index++) { firstStep[index] = aStore.prepareToSaveChangesInContext$Implementation(context, transactionId); } - Promise.when(Promise.all(firstStep), function() { + Promise.when(Promise.all(firstStep), function () { for (index = 0; typeof (aStore = this.stores[index]) !== "undefined"; index++) { secondStep[index] = aStore.commitChangesInContext$Implementation(context, transactionId); } - return Promise.when(Promise.all(secondStep), function() { + return Promise.when(Promise.all(secondStep), function () { return Promise.ref(true); - }, function() { + }, function () { throw Exception.create().initWithMessageTargetAndMethod('Failed to revert prepare for save transaction: ' + transactionId, this, "saveChangesInContext"); } ); - }, function() { + }, function () { for (index = 0; typeof (aStore = this.stores[index]) !== "undefined"; index++) { secondStep[index] = aStore.cancelSaveChangesInContext$Implementation(context, transactionId); } - return Promise.when(Promise.all(secondStep), function() { + return Promise.when(Promise.all(secondStep), function () { return Promise.reject("Could not save the transaction: " + transactionId); - }, function() { + }, function () { throw Exception.create().initWithMessageTargetAndMethod('Commit failed for transaction: ' + transactionId, this, "saveChangesInContext"); } ); @@ -1140