Skip to content

Commit

Permalink
Merge pull request #97 from GoogleCloudPlatform/update-datastore-snip…
Browse files Browse the repository at this point in the history
…pets

Set source/target to jdk 1.7 and use latest gcloud-java release features
  • Loading branch information
ajkannan committed Feb 22, 2016
2 parents 2604810 + 7b59256 commit 27944b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
6 changes: 3 additions & 3 deletions datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.1.3</version>
<version>0.1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -31,8 +31,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- // [END maven]-->
Expand Down
44 changes: 21 additions & 23 deletions datastore/src/main/java/com/google/datastore/snippets/Concepts.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class Concepts {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!LocalGcdHelper.isActive(PROJECT_ID, PORT)) {
gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT);
gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT, 1.0);
}
}

Expand Down Expand Up @@ -232,8 +232,8 @@ public void testProperties() {
public void testArrayValue() {
// [START array_value]
Entity task = Entity.builder(taskKey)
.set("tags", StringValue.of("fun"), StringValue.of("programming"))
.set("collaborators", StringValue.of("alice"), StringValue.of("bob"))
.set("tags", "fun", "programming")
.set("collaborators", "alice", "bob")
.build();
// [END array_value]
assertValidEntity(task);
Expand Down Expand Up @@ -374,7 +374,7 @@ private void setUpQueryTests() {
.set("created", includedDate)
.set("percent_complete", 10.0)
.set("description", StringValue.builder("Learn Cloud Datastore").indexed(false).build())
.set("tag", StringValue.of("fun"), StringValue.of("l"), StringValue.of("programming"))
.set("tag", "fun", "l", "programming")
.build());
}

Expand Down Expand Up @@ -748,9 +748,8 @@ public void testUnindexedPropertyQuery() {
public void testExplodingProperties() {
// [START exploding_properties]
Entity task = Entity.builder(taskKey)
.set("tags", StringValue.of("fun"), StringValue.of("programming"), StringValue.of("learn"))
.set("collaborators", StringValue.of("alice"), StringValue.of("bob"),
StringValue.of("charlie"))
.set("tags", "fun", "programming", "learn")
.set("collaborators", "alice", "bob", "charlie")
.set("created", DateTime.now())
.build();
// [END exploding_properties]
Expand Down Expand Up @@ -912,12 +911,12 @@ public void testPropertyRunQuery() {
setUpQueryTests();
// [START property_run_query]
Query<Key> query = Query.keyQueryBuilder().kind("__property__").build();
QueryResults<Key> results = datastore.run(query);
QueryResults<Key> keys = datastore.run(query);
Map<String, Collection<String>> propertiesByKind = new HashMap<>();
while (results.hasNext()) {
Key property = results.next();
String kind = property.ancestors().get(property.ancestors().size() - 1).name();
String propertyName = property.name();
while (keys.hasNext()) {
Key key = keys.next();
String kind = key.parent().name();
String propertyName = key.name();
Collection<String> properties = propertiesByKind.get(kind);
if (properties == null) {
properties = new HashSet<>();
Expand All @@ -943,10 +942,9 @@ public void testPropertyByKindRunQuery() {
QueryResults<Entity> results = datastore.run(query);
Map<String, Collection<String>> representationsByProperty = new HashMap<>();
while (results.hasNext()) {
Entity property = results.next();
String propertyName = property.key().name();
List<StringValue> representations =
(List<StringValue>) property.getList("property_representation");
Entity result = results.next();
String propertyName = result.key().name();
List<StringValue> representations = result.getList("property_representation");
Collection<String> currentRepresentations = representationsByProperty.get(propertyName);
if (currentRepresentations == null) {
currentRepresentations = new HashSet<>();
Expand All @@ -973,20 +971,20 @@ public void testPropertyByKindRunQuery() {
public void testPropertyFilteringRunQuery() {
setUpQueryTests();
// [START property_filtering_run_query]
Key key = datastore.newKeyFactory()
Key startKey = datastore.newKeyFactory()
.kind("__property__")
.ancestors(PathElement.of("__kind__", "Task"))
.newKey("priority");
Query<Key> query = Query.keyQueryBuilder()
.kind("__property__")
.filter(PropertyFilter.ge("__key__", key))
.filter(PropertyFilter.ge("__key__", startKey))
.build();
Map<String, Collection<String>> propertiesByKind = new HashMap<>();
QueryResults<Key> results = datastore.run(query);
while (results.hasNext()) {
Key property = results.next();
String kind = property.ancestors().get(property.ancestors().size() - 1).name();
String propertyName = property.name();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
Key key = keys.next();
String kind = key.parent().name();
String propertyName = key.name();
Collection<String> properties = propertiesByKind.get(kind);
if (properties == null) {
properties = new HashSet<String>();
Expand Down

0 comments on commit 27944b7

Please sign in to comment.