Skip to content

Commit

Permalink
Refactor Datastore example, add example on embedded entities (#980)
Browse files Browse the repository at this point in the history
* Refactor Datastore example, add example on embedded entities

* Minor refactoring of examples
- Favor printf over println
- Rename Action argument from request to arg
  • Loading branch information
mziccard committed May 13, 2016
1 parent 8fc4f7a commit af79f8f
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 258 deletions.
1 change: 1 addition & 0 deletions gcloud-java-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ To run examples from your command line:
mvn exec:java -Dexec.mainClass="com.google.cloud.examples.datastore.DatastoreExample" -Dexec.args="your-project-id my_name add my\ comment"
mvn exec:java -Dexec.mainClass="com.google.cloud.examples.datastore.DatastoreExample" -Dexec.args="your-project-id my_name display"
mvn exec:java -Dexec.mainClass="com.google.cloud.examples.datastore.DatastoreExample" -Dexec.args="your-project-id my_name delete"
mvn exec:java -Dexec.mainClass="com.google.cloud.examples.datastore.DatastoreExample" -Dexec.args="your-project-id my_name set [email protected] 1234"
```
* Here's an example run of `DnsExample`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class BigQueryExample {

private abstract static class BigQueryAction<T> {

abstract void run(BigQuery bigquery, T request) throws Exception;
abstract void run(BigQuery bigquery, T arg) throws Exception;

abstract T parse(String... args) throws Exception;

Expand Down Expand Up @@ -775,18 +775,18 @@ public static void main(String... args) throws Exception {
return;
}
BigQuery bigquery = optionsBuilder.build().service();
Object request;
Object arg;
try {
request = action.parse(args);
arg = action.parse(args);
} catch (IllegalArgumentException ex) {
System.out.println("Invalid input for action '" + actionName + "'. " + ex.getMessage());
System.out.println("Expected: " + action.params());
System.out.printf("Invalid input for action '%s'. %s%n", actionName, ex.getMessage());
System.out.printf("Expected: %s%n", action.params());
return;
} catch (Exception ex) {
System.out.println("Failed to parse request.");
System.out.println("Failed to parse arguments.");
ex.printStackTrace();
return;
}
action.run(bigquery, request);
action.run(bigquery, arg);
}
}
Loading

0 comments on commit af79f8f

Please sign in to comment.