Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of gcloud.db; | 5 part of gcloud.db; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function definition for transactional functions. | 8 * A function definition for transactional functions. |
| 9 * | 9 * |
| 10 * The function will be given a [Transaction] object which can be used to make | 10 * The function will be given a [Transaction] object which can be used to make |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 } | 240 } |
| 241 return propertyName; | 241 return propertyName; |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 class DatastoreDB { | 245 class DatastoreDB { |
| 246 final datastore.Datastore datastore; | 246 final datastore.Datastore datastore; |
| 247 final ModelDB _modelDB; | 247 final ModelDB _modelDB; |
| 248 Partition _defaultPartition; | 248 Partition _defaultPartition; |
| 249 | 249 |
| 250 DatastoreDB(this.datastore, {ModelDB modelDB}) | 250 DatastoreDB(this.datastore, {ModelDB modelDB, Partition defaultPartition}) : |
| 251 : _modelDB = modelDB != null ? modelDB : new ModelDBImpl() { | 251 _modelDB = modelDB != null ? modelDB : new ModelDBImpl() { |
| 252 _defaultPartition = new Partition(null); | 252 _defaultPartition = |
| 253 defaultPartition != null ? defaultPartition : new Partition(null); | |
| 253 } | 254 } |
| 254 | 255 |
| 255 /** | 256 /** |
| 256 * The [ModelDB] used to serialize/deserialize objects. | 257 * The [ModelDB] used to serialize/deserialize objects. |
| 257 */ | 258 */ |
| 258 ModelDB get modelDB => _modelDB; | 259 ModelDB get modelDB => _modelDB; |
| 259 | 260 |
| 260 /** | 261 /** |
| 261 * Gets the empty key using the default [Partition]. | 262 * Gets the empty key using the default [Partition]. |
| 262 * | 263 * |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 * The order of inserts and deletes is not specified. When the commit is done | 319 * The order of inserts and deletes is not specified. When the commit is done |
| 319 * direct lookups will see the effect but non-ancestor queries will see the | 320 * direct lookups will see the effect but non-ancestor queries will see the |
| 320 * change in an eventual consistent way. | 321 * change in an eventual consistent way. |
| 321 * | 322 * |
| 322 * For transactions, please use `beginTransaction` and it's returned | 323 * For transactions, please use `beginTransaction` and it's returned |
| 323 * [Transaction] object. | 324 * [Transaction] object. |
| 324 */ | 325 */ |
| 325 Future commit({List<Model> inserts, List<Key> deletes}) { | 326 Future commit({List<Model> inserts, List<Key> deletes}) { |
| 326 return _commitHelper(this, inserts: inserts, deletes: deletes); | 327 return _commitHelper(this, inserts: inserts, deletes: deletes); |
| 327 } | 328 } |
| 329 | |
| 330 /** | |
| 331 * Returns a new [DatastoreDB] with the given [defaultPartition]. | |
| 332 */ | |
| 333 DatastoreDB replace({Partition defaultPartition}) { | |
|
Søren Gjesse
2015/02/19 11:59:51
The method name 'replace' seems somewhat overloade
kustermann
2015/02/19 12:17:11
Another constructor is of no value, since the exis
| |
| 334 return new DatastoreDB( | |
| 335 datastore, modelDB: modelDB, defaultPartition: defaultPartition); | |
| 336 } | |
| 328 } | 337 } |
| 329 | 338 |
| 330 Future _commitHelper(DatastoreDB db, | 339 Future _commitHelper(DatastoreDB db, |
| 331 {List<Model> inserts, | 340 {List<Model> inserts, |
| 332 List<Key> deletes, | 341 List<Key> deletes, |
| 333 datastore.Transaction datastoreTransaction}) { | 342 datastore.Transaction datastoreTransaction}) { |
| 334 var entityInserts, entityAutoIdInserts, entityDeletes; | 343 var entityInserts, entityAutoIdInserts, entityDeletes; |
| 335 var autoIdModelInserts; | 344 var autoIdModelInserts; |
| 336 if (inserts != null) { | 345 if (inserts != null) { |
| 337 entityInserts = []; | 346 entityInserts = []; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 382 |
| 374 Future<List<Model>> _lookupHelper( | 383 Future<List<Model>> _lookupHelper( |
| 375 DatastoreDB db, List<Key> keys, | 384 DatastoreDB db, List<Key> keys, |
| 376 {datastore.Transaction datastoreTransaction}) { | 385 {datastore.Transaction datastoreTransaction}) { |
| 377 var entityKeys = keys.map(db.modelDB.toDatastoreKey).toList(); | 386 var entityKeys = keys.map(db.modelDB.toDatastoreKey).toList(); |
| 378 return db.datastore.lookup(entityKeys, transaction: datastoreTransaction) | 387 return db.datastore.lookup(entityKeys, transaction: datastoreTransaction) |
| 379 .then((List<datastore.Entity> entities) { | 388 .then((List<datastore.Entity> entities) { |
| 380 return entities.map(db.modelDB.fromDatastoreEntity).toList(); | 389 return entities.map(db.modelDB.fromDatastoreEntity).toList(); |
| 381 }); | 390 }); |
| 382 } | 391 } |
| OLD | NEW |