Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Allow insight into the exception thrown by the odata controller. #218

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
36 changes: 36 additions & 0 deletions JayDataModules/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ angular.module('jaydata', ['ng', ['$provide', function ($provide) {
return Object.prototype.hasOwnProperty.apply(this, arguments);
}


$data.Queryable.prototype.toLiveArrayEx = function (options, resultHolder) {
if (Array.isArray(options)) {
resultHolder = options;
otions = undefined;
}
resultHolder = resultHolder || [];
options = options || {};
var self = this, scope = options.scope || $rootScope;

function thunk(newDefer) {
self.toArray()
.then(function (items) {
resultHolder.length = 0;
items.forEach(function (item) {
resultHolder.push(item);
})
newDefer.resolve(resultHolder);
})
.fail(newDefer.reject)
.then(function () {
scope.$apply();
});
}

function refresh() {
var defer = $.Deferred(thunk);
defer.promise(resultHolder);
return resultHolder;
}
resultHolder.refresh = refresh;

return refresh();
}


$data.Queryable.prototype.toLiveArray = function (cb) {
var _this = this;

Expand Down
46 changes: 29 additions & 17 deletions JaySvcUtil/JaySvcUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,26 @@ $data.Class.define('$data.MetadataLoaderClass', null, null, {

return resultDocument.textContent;
} else if (typeof module !== 'undefined' && typeof require !== 'undefined') {
var xslt = require('node_xslt');

return xslt.transform(xslt.readXsltString(transformXslt), xslt.readXmlString(metadata), [
'SerivceUri', "'" + cnf.SerivceUri + "'",
'EntityBaseClass', "'" + cnf.EntityBaseClass + "'",
'ContextBaseClass', "'" + cnf.ContextBaseClass + "'",
'AutoCreateContext', "'" + cnf.AutoCreateContext + "'",
'ContextInstanceName', "'" + cnf.ContextInstanceName + "'",
'EntitySetBaseClass', "'" + cnf.EntitySetBaseClass + "'",
'CollectionBaseClass', "'" + cnf.CollectionBaseClass + "'",
'DefaultNamespace', "'" + cnf.DefaultNamespace + "'",
'MaxDataserviceVersion', "'" + (versionInfo.maxVersion || '3.0') + "'",
'AllowedTypesList', "'" + cnf.typeFilter + "'",
'GenerateNavigationProperties', "'" + cnf.navigation + "'"
]);
var xslt4node = require('xslt4node');
var config = {
xslt: transformXslt,
source: metadata,
result: String,
params: {
'SerivceUri': cnf.SerivceUri,
'EntityBaseClass': cnf.EntityBaseClass ,
'ContextBaseClass': cnf.ContextBaseClass ,
'AutoCreateContext': cnf.AutoCreateContext ,
'ContextInstanceName': cnf.ContextInstanceName ,
'EntitySetBaseClass': cnf.EntitySetBaseClass ,
'CollectionBaseClass': cnf.CollectionBaseClass ,
'DefaultNamespace': cnf.DefaultNamespace ,
'MaxDataserviceVersion': (versionInfo.maxVersion || '3.0') ,
'AllowedTypesList': cnf.typeFilter ,
'GenerateNavigationProperties': cnf.navigation
}
};
return xslt4node.transformSync(config);
}
},
_prepareTypeFilter: function (doc, versionInfo, cnf) {
Expand Down Expand Up @@ -612,7 +617,8 @@ $data.Class.define('$data.MetadataLoaderClass', null, null, {
"http://schemas.microsoft.com/ado/2008/09/edm": "V2",
"http://schemas.microsoft.com/ado/2009/11/edm": "V3",
"http://schemas.microsoft.com/ado/2007/05/edm": "V11",
"http://schemas.microsoft.com/ado/2009/08/edm": "V22"
"http://schemas.microsoft.com/ado/2009/08/edm": "V22",
"http://docs.oasis-open.org/odata/ns/edm": "V4"
}
},
_maxDataServiceVersions: {
Expand All @@ -621,7 +627,8 @@ $data.Class.define('$data.MetadataLoaderClass', null, null, {
"http://schemas.microsoft.com/ado/2008/09/edm": "2.0",
"http://schemas.microsoft.com/ado/2009/11/edm": "3.0",
"http://schemas.microsoft.com/ado/2007/05/edm": "2.0",
"http://schemas.microsoft.com/ado/2009/08/edm": "2.0"
"http://schemas.microsoft.com/ado/2009/08/edm": "2.0",
"http://docs.oasis-open.org/odata/ns/edm": "4.0"
}
},
_supportedODataVersionXSLT: {
Expand Down Expand Up @@ -1109,6 +1116,7 @@ $data.Class.define('$data.MetadataLoaderClass', null, null, {
" <xsl:variable name=\"memberDefinition\">\r\n" +
" <xsl:if test=\"parent::edm:EntityType/edm:Key/edm:PropertyRef[@Name = current()/@Name]\"><attribute name=\"key\">true</attribute></xsl:if>\r\n" +
" <xsl:apply-templates select=\"@*[local-name() != 'Name']\" mode=\"render-field\" />\r\n" +
" <xsl:if test=\"local-name() = 'NavigationProperty' and current()[not(@Partner) and current()/@Type]\"><attribute name=\"inverseProperty\">'$$unbound'</attribute></xsl:if>\r\n" +
" </xsl:variable>'<xsl:value-of select=\"@Name\"/>': { <xsl:choose><xsl:when test=\"function-available('msxsl:node-set')\"><xsl:for-each select=\"msxsl:node-set($memberDefinition)/*\">'<xsl:if test=\"@extended = 'true'\">$</xsl:if><xsl:value-of select=\"@name\"/>':<xsl:value-of select=\".\"/>\r\n" +
" <xsl:if test=\"position() != last()\">,<xsl:text> </xsl:text>\r\n" +
" </xsl:if> </xsl:for-each></xsl:when>\r\n" +
Expand All @@ -1121,6 +1129,10 @@ $data.Class.define('$data.MetadataLoaderClass', null, null, {
" <xsl:template match=\"@Name\" mode=\"render-field\">\r\n" +
" </xsl:template>\r\n" +
"\r\n" +
" <xsl:template match=\"@Partner\" mode=\"render-field\">\r\n" +
" <attribute name=\"inverseProperty\">'<xsl:value-of select=\".\"/>'</attribute>\r\n" +
" </xsl:template>\r\n" +
"\r\n" +
" <xsl:template match=\"@Type\" mode=\"render-field\">\r\n" +
" <xsl:choose>\r\n" +
" <xsl:when test=\"starts-with(., 'Collection')\">\r\n" +
Expand Down
2 changes: 1 addition & 1 deletion Types/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ $data.Entity = Entity = $data.Class.define("$data.Entity", null, null, {
}
},
_setPropertyChanged: function (memberDefinition) {
if (memberDefinition.monitorChanges != false) {
if (memberDefinition.monitorChanges != false && memberDefinition.name != "ValidationErrors") {
if (!this.changedProperties) {
this.changedProperties = [];
}
Expand Down
13 changes: 10 additions & 3 deletions Types/EntityContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,19 +945,23 @@ $data.Class.define('$data.EntityContext', null, null,
success: function (results) {
var batchResult = [];
var hasError = false;
var errorValue = null;
for (var i = 0; i < results.length && !hasError; i++) {
var query = results[i];
self.executeQuerySuccess(self, returnTransaction, {
success: function (result) {
batchResult.push(result);
},
error: function () {
error: function (err) {
hasError = true;
errorValue = err;
}
})(query);
}
if (!hasError) {
self._applyTransaction(cbWrapper, cbWrapper.success, [batchResult], batchExecuteQuery.transaction, returnTransaction);
} else {
cbWrapper.error(errorValue);
}

},
Expand Down Expand Up @@ -1051,6 +1055,9 @@ $data.Class.define('$data.EntityContext', null, null,
entityCachedItem.skipSave = true;
skipItems.push(entityCachedItem.data);
}
} else {
entityCachedItem.skipSave = true;
skipItems.push(entityCachedItem.data);
}
}
}
Expand Down Expand Up @@ -1424,9 +1431,9 @@ $data.Class.define('$data.EntityContext', null, null,
},
discoverDependentItemEntityState: function (data) {
if (data.storeToken === this.storeToken) {
data.entityState = $data.EntityState.Modified;
data.entityState = (data.changedProperties && data.changedProperties.length) ? $data.EntityState.Modified : $data.EntityState.Unchanged;
} else if (data.storeToken && this.storeToken && data.storeToken.typeName === this.storeToken.typeName && JSON.stringify(data.storeToken.args) === JSON.stringify(this.storeToken.args)) {
data.entityState = $data.EntityState.Modified;
data.entityState = (data.changedProperties && data.changedProperties.length) ? $data.EntityState.Modified : $data.EntityState.Unchanged;
} else {
data.entityState = $data.EntityState.Added;
}
Expand Down
3 changes: 3 additions & 0 deletions Types/Queryable.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ $data.Class.define('$data.Queryable', null, null,
var inlineCountExp = Container.createInlineCountExpression(this.expression, constExp);
return Container.createQueryable(this, inlineCountExp);
},
withCount: function (selector) {
return this.withInlineCount(selector);
},

removeAll: function (onResult, transaction) {
/// <summary>Delete the query result and returns the number of deleted entities in a query as the callback parameter.</summary>
Expand Down
2 changes: 1 addition & 1 deletion Types/StorageProviders/modelBinderConfigCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ $C('$data.modelBinder.ModelBinderConfigCompiler', $data.Expressions.EntityExpres
var builder = Container.createqueryBuilder();
builder.modelBinderConfig['$type'] = $data.Array;
if (this._isoDataProvider) {
builder.modelBinderConfig['$selector'] = ['json:d.results', 'json:d', 'json:results'];
builder.modelBinderConfig['$selector'] = ['json:d.results', 'json:d', 'json:results', 'json:value'];
}
builder.modelBinderConfig['$item'] = {};
builder.selectModelBinderProperty('$item');
Expand Down
10 changes: 7 additions & 3 deletions Types/StorageProviders/oData/oDataCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $C('$data.storageProviders.oData.oDataCompiler', $data.Expressions.EntityExpress
query.postData = queryFragments.postData;
var result = {
queryText: queryText,
withInlineCount: '$inlinecount' in queryFragments,
withInlineCount: '$inlinecount' in queryFragments || '$count' in queryFragments,
method: queryFragments.method || 'GET',
postData: queryFragments.postData,
isBatchExecuteQuery: queryFragments._isBatchExecuteQuery,
Expand Down Expand Up @@ -144,7 +144,11 @@ $C('$data.storageProviders.oData.oDataCompiler', $data.Expressions.EntityExpress
},
VisitInlineCountExpression: function (expression, context) {
this.Visit(expression.source, context);
context["$inlinecount"] = expression.selector.value;
if (this.provider.providerConfiguration.maxDataServiceVersion === "4.0") {
context["$count"] = expression.selector.value === 'allpages';
} else {
context["$inlinecount"] = expression.selector.value;
}
},
VisitEntitySetExpression: function (expression, context) {
context.urlText += "/" + expression.instance.tableName;
Expand Down Expand Up @@ -235,5 +239,5 @@ $C('$data.storageProviders.oData.oDataCompiler', $data.Expressions.EntityExpress
headers: compiled.headers
});
}
},
}
}, {});
Loading