Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: lib/src/db/model_db_impl.dart

Issue 1774183002: Throw a StateError in case no model was registered for a given kind (Closed) Base URL: git@github.com:dart-lang/gcloud.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// An implementation of [ModelDB] based on model class annotations. 7 /// An implementation of [ModelDB] based on model class annotations.
8 /// 8 ///
9 /// The two constructors will scan loaded dart libraries for classes with a 9 /// The two constructors will scan loaded dart libraries for classes with a
10 /// [Kind] annotation. 10 /// [Kind] annotation.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ModelDBImpl.fromLibrary(Symbol librarySymbol) { 54 ModelDBImpl.fromLibrary(Symbol librarySymbol) {
55 _initialize([mirrors.currentMirrorSystem().findLibrary(librarySymbol)]); 55 _initialize([mirrors.currentMirrorSystem().findLibrary(librarySymbol)]);
56 } 56 }
57 57
58 /// Converts a [datastore.Key] to a [Key]. 58 /// Converts a [datastore.Key] to a [Key].
59 Key fromDatastoreKey(datastore.Key datastoreKey) { 59 Key fromDatastoreKey(datastore.Key datastoreKey) {
60 var namespace = new Partition(datastoreKey.partition.namespace); 60 var namespace = new Partition(datastoreKey.partition.namespace);
61 Key key = namespace.emptyKey; 61 Key key = namespace.emptyKey;
62 for (var element in datastoreKey.elements) { 62 for (var element in datastoreKey.elements) {
63 var type = _type2ModelDesc[_kind2ModelDesc[element.kind]]; 63 var type = _type2ModelDesc[_kind2ModelDesc[element.kind]];
64 assert (type != null); 64 if (type == null) {
65 throw new StateError(
66 'Could not find a model associated with kind "${element.kind}". '
67 'Please ensure a model class was annotated with '
68 '`@Kind(name: "${element.kind}")`.');
69 }
65 key = key.append(type, id: element.id); 70 key = key.append(type, id: element.id);
66 } 71 }
67 return key; 72 return key;
68 } 73 }
69 74
70 /// Converts a [Key] to a [datastore.Key]. 75 /// Converts a [Key] to a [datastore.Key].
71 datastore.Key toDatastoreKey(Key dbKey) { 76 datastore.Key toDatastoreKey(Key dbKey) {
72 List<datastore.KeyElement> elements = []; 77 List<datastore.KeyElement> elements = [];
73 var currentKey = dbKey; 78 var currentKey = dbKey;
74 while (!currentKey.isEmpty) { 79 while (!currentKey.isEmpty) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 enforceFieldExists: false); 543 enforceFieldExists: false);
539 // If superclass can't encode field, we return value here (and assume 544 // If superclass can't encode field, we return value here (and assume
540 // it's primitive) 545 // it's primitive)
541 // NOTE: Implicit assumption: 546 // NOTE: Implicit assumption:
542 // If value != null then superclass will return != null. 547 // If value != null then superclass will return != null.
543 // TODO: Ensure [value] is primitive in this case. 548 // TODO: Ensure [value] is primitive in this case.
544 if (primitiveValue == null) primitiveValue = value; 549 if (primitiveValue == null) primitiveValue = value;
545 return primitiveValue; 550 return primitiveValue;
546 } 551 }
547 } 552 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698