| 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 library gcloud.datastore_impl; | 5 library gcloud.datastore_impl; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
| 10 | 10 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 return apiEntity; | 204 return apiEntity; |
| 205 } | 205 } |
| 206 | 206 |
| 207 static Map<datastore.FilterRelation, String> relationMapping = const { | 207 static Map<datastore.FilterRelation, String> relationMapping = const { |
| 208 datastore.FilterRelation.LessThan: 'LESS_THAN', | 208 datastore.FilterRelation.LessThan: 'LESS_THAN', |
| 209 datastore.FilterRelation.LessThanOrEqual: 'LESS_THAN_OR_EQUAL', | 209 datastore.FilterRelation.LessThanOrEqual: 'LESS_THAN_OR_EQUAL', |
| 210 datastore.FilterRelation.Equal: 'EQUAL', | 210 datastore.FilterRelation.Equal: 'EQUAL', |
| 211 datastore.FilterRelation.GreatherThan: 'GREATER_THAN', | 211 datastore.FilterRelation.GreatherThan: 'GREATER_THAN', |
| 212 datastore.FilterRelation.GreatherThanOrEqual: 'GREATER_THAN_OR_EQUAL', | 212 datastore.FilterRelation.GreatherThanOrEqual: 'GREATER_THAN_OR_EQUAL', |
| 213 // TODO(Issue #5): IN operator not supported currently. | |
| 214 }; | 213 }; |
| 215 | 214 |
| 216 api.Filter _convertDatastore2ApiFilter(datastore.Filter filter) { | 215 api.Filter _convertDatastore2ApiFilter(datastore.Filter filter) { |
| 217 var pf = new api.PropertyFilter(); | 216 var pf = new api.PropertyFilter(); |
| 218 var operator = relationMapping[filter.relation]; | 217 var operator = relationMapping[filter.relation]; |
| 219 // FIXME(Issue #5): Is this OK? | |
| 220 if (filter.relation == datastore.FilterRelation.In) { | |
| 221 operator = 'EQUAL'; | |
| 222 } | |
| 223 | |
| 224 if (operator == null) { | 218 if (operator == null) { |
| 225 throw new ArgumentError('Unknown filter relation: ${filter.relation}.'); | 219 throw new ArgumentError('Unknown filter relation: ${filter.relation}.'); |
| 226 } | 220 } |
| 227 pf.op = operator; | 221 pf.op = operator; |
| 228 pf.property = new api.PropertyReference()..name = filter.name; | 222 pf.property = new api.PropertyReference()..name = filter.name; |
| 229 | 223 pf.value = _convertDatastore2ApiPropertyValue( |
| 230 // FIXME(Issue #5): Is this OK? | 224 filter.value, true, lists: false); |
| 231 var value = filter.value; | |
| 232 if (filter.relation == datastore.FilterRelation.In) { | |
| 233 if (value is List && value.length == 1) { | |
| 234 value = value.first; | |
| 235 } else { | |
| 236 throw new ArgumentError('List values not supported (was: $value).'); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 pf.value = _convertDatastore2ApiPropertyValue(value, true, lists: false); | |
| 241 return new api.Filter()..propertyFilter = pf; | 225 return new api.Filter()..propertyFilter = pf; |
| 242 } | 226 } |
| 243 | 227 |
| 244 api.Filter _convertDatastoreAncestorKey2ApiFilter(datastore.Key key) { | 228 api.Filter _convertDatastoreAncestorKey2ApiFilter(datastore.Key key) { |
| 245 var pf = new api.PropertyFilter(); | 229 var pf = new api.PropertyFilter(); |
| 246 pf.op = 'HAS_ANCESTOR'; | 230 pf.op = 'HAS_ANCESTOR'; |
| 247 pf.property = new api.PropertyReference()..name = '__key__'; | 231 pf.property = new api.PropertyReference()..name = '__key__'; |
| 248 pf.value = new api.Value() | 232 pf.value = new api.Value() |
| 249 ..keyValue = _convertDatastore2ApiKey(key, enforceId: true); | 233 ..keyValue = _convertDatastore2ApiKey(key, enforceId: true); |
| 250 return new api.Filter()..propertyFilter = pf; | 234 return new api.Filter()..propertyFilter = pf; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 return new Future.sync(() { | 612 return new Future.sync(() { |
| 629 throw new ArgumentError('Cannot call next() on last page.'); | 613 throw new ArgumentError('Cannot call next() on last page.'); |
| 630 }); | 614 }); |
| 631 } | 615 } |
| 632 | 616 |
| 633 return QueryPageImpl.runQuery( | 617 return QueryPageImpl.runQuery( |
| 634 _api, _project, _nextRequest, _remainingNumberOfEntities) | 618 _api, _project, _nextRequest, _remainingNumberOfEntities) |
| 635 .catchError(DatastoreImpl._handleError); | 619 .catchError(DatastoreImpl._handleError); |
| 636 } | 620 } |
| 637 } | 621 } |
| OLD | NEW |