aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/data/rest-access/rest-store.js
blob: 28dbd6508aac7e373f610ab922a65a6a844e2263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
120
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
190
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
/* <copyright>
 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
 (c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
 </copyright> */
/**
 @module montage/data/rest-access/rest-store
 @requires montage/core/core
 @requires montage/data/store
 @requires montage/core/logger
 @requires montage/core/promise
 @requires data/rest-access/rest-mapping
 */
var Montage = require("montage").Montage;
var Store = require("data/store").Store;
var Promise = require("core/promise").Promise;
var RestBinderMapping = require("data/rest-access/rest-mapping").RestBinderMapping;
var RestBlueprintMapping = require("data/rest-access/rest-mapping").RestBlueprintMapping;
var RestAttributeMapping = require("data/rest-access/rest-mapping").RestAttributeMapping;
var RestAssociationMapping = require("data/rest-access/rest-mapping").RestAssociationMapping;

var logger = require("core/logger").logger("rest-store");

/**
 @class module:montage/data/rest-access/rest-store.RestStore
 @extends module:montage/data/store.Store
 */
var RestStore = exports.RestStore = Montage.create(Store, /** @lends module:montage/data/rest-access/rest-store.RestStore# */ {

    /**
     Create a new binder mapping.
     @function
     @returns binder mapping
     */
    createBinderMapping:{
        get:function () {
            return RestBinderMapping.create();
        }
    },

    /**
     Create a new blueprint mapping.
     @function
     @returns blueprint mapping
     */
    createBlueprintMapping:{
        get:function () {
            return RestBlueprintMapping.create();
        }
    },

    /**
     Create a new attribute mapping.
     @function
     @returns attribute mapping
     */
    createAttributeMapping:{
        get:function () {
            return RestAttributeMapping.create();
        }
    },

    /**
     Create a new association mapping.
     @function
     @returns association mapping
     */
    createAssociationMapping:{
        get:function () {
            return RestAssociationMapping.create();
        }
    },

    /**
     Description TODO
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} Promise.ref(object.objectId) or Promise.ref(null)
     */
    permanentIdForObjectId$Implementation:{
        value:function (object, context, transactionId) {
            // TODO [PJYF Apr 28 2011] We need to implement it.
            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 {Property} transactionId TODO
     @returns {Function} Promise.ref(null)
     */
    pledgeForObjectId$Implementation:{
        value:function (objectId, context, transactionId) {
            // TODO [PJYF Apr 28 2011] We need to implement it.
            return Promise.ref(null);
        }
    },

    /**
     Description TODO
     @function
     @param {Object} sourceObject TODO
     @param {Property} relationship TODO
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} Promise.ref(null)
     */
    pledgeForSourceObjectAssociation$Implementation:{
        value:function (sourceObject, relationship, context, transactionId) {
            // TODO [PJYF Apr 28 2011] We need to implement it.
            return Promise.ref(null);
        }
    },

    /**
     Description TODO
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} 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().initWithBlueprint(object.blueprint);
            }
            return Promise.ref(object);
        }
    },

    /**
     Description TODO
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} 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);
            }
            return Promise.ref(object);
        }

    },

    /**
     Called on each store before a save.<br>
     Upon receiving this message the store should take steps to prepare the commit and insure it will succeed.<br>
     If the commit cannot succeed it should return a rejected promise.
     @function
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} 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 to prepare a save.<br>
     Any step taken to prepare the save should be rolled back.
     @function
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} 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.<br>
     Any failure during this step will cause the store to be left an inconsistent state.
     @function
     @param {Property} context TODO
     @param {Property} transactionId TODO
     @returns {Function} 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 {Property} transactionId TODO
     @returns {Function} Promise.ref([])
     */
    queryInContext$Implementation:{
        value:function (query, context, transactionID) {
            // TODO [PJYF Sept 4 2011] This needs to be implemented
            return Promise.ref([]);
        }
    }


});