Skip to content

Commit aaec995

Browse files
committed
---
yaml --- r: 2211 b: refs/heads/pubsub-alpha c: 48cb27f h: refs/heads/master i: 2209: 562619b 2207: 46c5013
1 parent 17ca848 commit aaec995

6 files changed

Lines changed: 171 additions & 62 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: f287462fd9edda07a34658be91f04421357f6519
6+
refs/heads/pubsub-alpha: 48cb27f0f7d84e24cb72a4cb97e448080e6f4194
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Google Cloud Java Contributions
2+
===============================
3+
4+
Packages that provide higher-level abstraction/functionality for common gcloud-java use cases.
5+
6+
[//]: # (commented out because there isn't any code yet, so this won't work)
7+
[//]: #
8+
[//]: # (Quickstart)
9+
[//]: # (----------)
10+
[//]: # (If you are using Maven, add this to your pom.xml file)
11+
[//]: # (```xml)
12+
[//]: # (<dependency>)
13+
[//]: # ( <groupId>com.google.gcloud</groupId>)
14+
[//]: # ( <artifactId>gcloud-java-contrib</artifactId>)
15+
[//]: # ( <version>0.1.2</version>)
16+
[//]: # (</dependency>)
17+
[//]: # (```)
18+
[//]: # (If you are using Gradle, add this to your dependencies)
19+
[//]: # (```Groovy)
20+
[//]: # (compile 'com.google.gcloud:gcloud-java-contrib:0.1.2')
21+
[//]: # (```)
22+
[//]: # (If you are using SBT, add this to your dependencies)
23+
[//]: # (```Scala)
24+
[//]: # (libraryDependencies += "com.google.gcloud" % "gcloud-java-contrib" % "0.1.2")
25+
[//]: # (```)
26+
27+
28+
Java Versions
29+
-------------
30+
31+
Java 7 or above is required for using this client.
32+
33+
Versioning
34+
----------
35+
36+
This library follows [Semantic Versioning] (http://semver.org/).
37+
38+
It is currently in major version zero (``0.y.z``), which means that anything
39+
may change at any time and the public API should not be considered
40+
stable.
41+
42+
Contributing
43+
------------
44+
45+
Contributions to this library are always welcome and highly encouraged.
46+
47+
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.
48+
49+
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
50+
51+
License
52+
-------
53+
54+
Apache 2.0 - See [LICENSE] for more information.
55+
56+
57+
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
58+
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
59+
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
60+
[cloud-platform]: https://cloud.google.com/
61+
[developers-console]:https://console.developers.google.com/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.gcloud</groupId>
5+
<artifactId>gcloud-java-contrib</artifactId>
6+
<packaging>jar</packaging>
7+
<name>GCloud Java contributions</name>
8+
<description>
9+
Contains packages that provide higher-level abstraction/functionality for common gcloud-java use cases.
10+
</description>
11+
<parent>
12+
<groupId>com.google.gcloud</groupId>
13+
<artifactId>gcloud-java-pom</artifactId>
14+
<version>0.1.3-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>gcloud-java-contrib</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>gcloud-java</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
</dependencies>
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.codehaus.mojo</groupId>
30+
<artifactId>exec-maven-plugin</artifactId>
31+
<configuration>
32+
<skip>false</skip>
33+
</configuration>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
</project>

branches/pubsub-alpha/gcloud-java-examples/README.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,54 +39,54 @@ To run examples from your command line:
3939

4040
4. Run an example using Maven from command line.
4141

42-
Here's an example run of `BigQueryExample`.
43-
44-
Before running the example, go to the [Google Developers Console][developers-console] to ensure
45-
that BigQuery API is enabled. You can upload a CSV file `my_csv_file` to the `my_bucket` bucket
46-
(replace `my_csv_file` and `my_bucket` with actual file and bucket names) using the GCS
47-
[web browser](https://console.developers.google.com/storage/browser). The CSV file will be used to
48-
load data into a BigQuery table and should look something like:
49-
```csv
50-
value1
51-
value2
52-
value3
53-
```
54-
Then you are ready to run the following example:
55-
```
56-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create dataset new_dataset_id"
57-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create table new_dataset_id new_table_id field_name:string"
58-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="list tables new_dataset_id"
59-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="load new_dataset_id new_table_id CSV gs://my_bucket/my_csv_file"
60-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="query 'select * from new_dataset_id.new_table_id'"
61-
```
62-
63-
Here's an example run of `DatastoreExample`.
42+
* Here's an example run of `BigQueryExample`.
43+
44+
Before running the example, go to the [Google Developers Console][developers-console] to ensure
45+
that BigQuery API is enabled. You can upload a CSV file `my_csv_file` to the `my_bucket` bucket
46+
(replace `my_csv_file` and `my_bucket` with actual file and bucket names) using the GCS
47+
[web browser](https://console.developers.google.com/storage/browser). The CSV file will be used to
48+
load data into a BigQuery table and should look something like:
49+
```csv
50+
value1
51+
value2
52+
value3
53+
```
54+
Then you are ready to run the following example:
55+
```
56+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create dataset new_dataset_id"
57+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create table new_dataset_id new_table_id field_name:string"
58+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="list tables new_dataset_id"
59+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="load new_dataset_id new_table_id CSV gs://my_bucket/my_csv_file"
60+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="query 'select * from new_dataset_id.new_table_id'"
61+
```
62+
63+
* Here's an example run of `DatastoreExample`.
6464
65-
Note that you have to enable the Google Cloud Datastore API on the [Google Developers Console][developers-console] before running the following commands.
66-
```
67-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name add my\ comment"
68-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name display"
69-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name delete"
70-
```
71-
72-
Here's an example run of `ResourceManagerExample`.
73-
74-
Be sure to change the placeholder project ID "my-project-id" with your own globally unique project ID.
75-
```
76-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="create my-project-id"
77-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="list"
78-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="get my-project-id"
79-
```
80-
81-
Here's an example run of `StorageExample`.
82-
83-
Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud Storage API is enabled and that you have a bucket. Also ensure that you have a test file (`test.txt` is chosen here) to upload to Cloud Storage stored locally on your machine.
84-
```
85-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt <bucket_name>"
86-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list <bucket_name>"
87-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download <bucket_name> test.txt"
88-
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete <bucket_name> test.txt"
89-
```
65+
Be sure to change the placeholder project ID "your-project-id" with your own project ID. Also note that you have to enable the Google Cloud Datastore API on the [Google Developers Console][developers-console] before running the following commands.
66+
```
67+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="your-project-id my_name add my\ comment"
68+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="your-project-id my_name display"
69+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="your-project-id my_name delete"
70+
```
71+
72+
* Here's an example run of `ResourceManagerExample`.
73+
74+
Be sure to change the placeholder project ID "your-project-id" with your own globally unique project ID.
75+
```
76+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="create your-project-id"
77+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="list"
78+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="get your-project-id"
79+
```
80+
81+
* Here's an example run of `StorageExample`.
82+
83+
Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud Storage API is enabled and that you have a bucket. Also ensure that you have a test file (`test.txt` is chosen here) to upload to Cloud Storage stored locally on your machine.
84+
```
85+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt <bucket_name>"
86+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list <bucket_name>"
87+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download <bucket_name> test.txt"
88+
mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete <bucket_name> test.txt"
89+
```
9090
9191
Troubleshooting
9292
---------------

branches/pubsub-alpha/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import com.google.gcloud.datastore.Key;
2626
import com.google.gcloud.datastore.KeyFactory;
2727
import com.google.gcloud.datastore.Query;
28-
import com.google.gcloud.datastore.Query.ResultType;
2928
import com.google.gcloud.datastore.QueryResults;
29+
import com.google.gcloud.datastore.StructuredQuery;
3030
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
3131
import com.google.gcloud.datastore.Transaction;
3232

@@ -100,21 +100,31 @@ public void run(Transaction tx, Key userKey, String... args) {
100100
return;
101101
}
102102
System.out.printf("User '%s' has %d comment[s].%n", userKey.name(), user.getLong("count"));
103-
// ORDER BY timestamp";
104-
String gql = "SELECT * FROM " + COMMENT_KIND + " WHERE __key__ HAS ANCESTOR @1";
105-
Query<Entity> query = Query.gqlQueryBuilder(ResultType.ENTITY, gql)
106-
.namespace(NAMESPACE)
107-
.addBinding(userKey)
108-
.build();
109-
QueryResults<Entity> results = tx.run(query);
110-
// We could have added "ORDER BY timestamp" to the query to avoid the sorting bellow
111-
// but that would require adding an ancestor index for timestamp
112-
// see: https://cloud.google.com/datastore/docs/tools/indexconfig
103+
int limit = 200;
113104
Map<DateTime, String> sortedComments = new TreeMap<>();
114-
while (results.hasNext()) {
115-
Entity result = results.next();
116-
sortedComments.put(result.getDateTime("timestamp"), result.getString("content"));
105+
StructuredQuery<Entity> query =
106+
Query.entityQueryBuilder()
107+
.namespace(NAMESPACE)
108+
.kind(COMMENT_KIND)
109+
.filter(PropertyFilter.hasAncestor(userKey))
110+
.limit(limit)
111+
.build();
112+
while (true) {
113+
QueryResults<Entity> results = tx.run(query);
114+
int resultCount = 0;
115+
while (results.hasNext()) {
116+
Entity result = results.next();
117+
sortedComments.put(result.getDateTime("timestamp"), result.getString("content"));
118+
resultCount++;
119+
}
120+
if (resultCount < limit) {
121+
break;
122+
}
123+
query = query.toBuilder().startCursor(results.cursorAfter()).build();
117124
}
125+
// We could have added "ORDER BY timestamp" to the query to avoid sorting, but that would
126+
// require adding an ancestor index for timestamp.
127+
// See: https://cloud.google.com/datastore/docs/tools/indexconfig
118128
for (Map.Entry<DateTime, String> entry : sortedComments.entrySet()) {
119129
System.out.printf("\t%s: %s%n", entry.getKey(), entry.getValue());
120130
}

branches/pubsub-alpha/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<modules>
6969
<module>gcloud-java</module>
7070
<module>gcloud-java-bigquery</module>
71+
<module>gcloud-java-contrib</module>
7172
<module>gcloud-java-core</module>
7273
<module>gcloud-java-datastore</module>
7374
<module>gcloud-java-examples</module>

0 commit comments

Comments
 (0)