@@ -123,15 +123,15 @@ Google Cloud BigQuery (Alpha)
123123
124124Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
125125must [supply credentials](# authentication) and a project ID if running this snippet elsewhere.
126+ Complete source code can be found at
127+ [gcloud-java-examples:com.google.gcloud.examples.bigquery.snippets.CreateTableAndLoadData](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/bigquery/snippets/CreateTableAndLoadData.java).
126128
127129` ` ` java
128130import com.google.gcloud.bigquery.BigQuery;
129131import com.google.gcloud.bigquery.BigQueryOptions;
130132import com.google.gcloud.bigquery.Field;
133+ import com.google.gcloud.bigquery.FormatOptions;
131134import com.google.gcloud.bigquery.Job;
132- import com.google.gcloud.bigquery.JobStatus;
133- import com.google.gcloud.bigquery.JobInfo;
134- import com.google.gcloud.bigquery.LoadJobConfiguration;
135135import com.google.gcloud.bigquery.Schema;
136136import com.google.gcloud.bigquery.StandardTableDefinition;
137137import com.google.gcloud.bigquery.Table;
@@ -145,19 +145,17 @@ if (table == null) {
145145 System.out.println(" Creating table " + tableId);
146146 Field integerField = Field.of(" fieldName" , Field.Type.integer ());
147147 Schema schema = Schema.of(integerField);
148- bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
148+ table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
149+ }
150+ System.out.println(" Loading data into table " + tableId);
151+ Job loadJob = table.load(FormatOptions.csv (), " gs://bucket/path" );
152+ while (! loadJob.isDone()) {
153+ Thread.sleep(1000L);
154+ }
155+ if (loadJob.status().error() ! = null) {
156+ System.out.println(" Job completed with errors" );
149157} else {
150- System.out.println(" Loading data into table " + tableId);
151- LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, " gs://bucket/path" );
152- Job loadJob = bigquery.create(JobInfo.of(configuration));
153- while (! loadJob.isDone()) {
154- Thread.sleep(1000L);
155- }
156- if (loadJob.status().error() ! = null) {
157- System.out.println(" Job completed with errors" );
158- } else {
159- System.out.println(" Job succeeded" );
160- }
158+ System.out.println(" Job succeeded" );
161159}
162160` ` `
163161
@@ -171,7 +169,11 @@ Google Cloud Datastore
171169
172170# ### Preview
173171
174- Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](# authentication) and a project ID if running this snippet elsewhere.
172+ Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](# authentication) and a project ID if running this snippet elsewhere.
173+
174+ The first snippet shows how to get a Datastore entity and create it if it does not exist. Complete
175+ source code can be found at
176+ [gcloud-java-examples:com.google.gcloud.examples.datastore.snippets.GetOrCreateEntity](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/GetOrCreateEntity.java).
175177
176178` ` ` java
177179import com.google.gcloud.datastore.Datastore;
@@ -182,8 +184,8 @@ import com.google.gcloud.datastore.Key;
182184import com.google.gcloud.datastore.KeyFactory;
183185
184186Datastore datastore = DatastoreOptions.defaultInstance().service ();
185- KeyFactory keyFactory = datastore.newKeyFactory ().kind(KIND );
186- Key key = keyFactory.newKey(keyName);
187+ KeyFactory keyFactory = datastore.newKeyFactory ().kind(" keyKind " );
188+ Key key = keyFactory.newKey(" keyName" );
187189Entity entity = datastore.get(key);
188190if (entity == null) {
189191 entity = Entity.builder(key)
@@ -192,7 +194,24 @@ if (entity == null) {
192194 .set(" access_time" , DateTime.now ())
193195 .build ();
194196 datastore.put(entity);
195- } else {
197+ }
198+ ` ` `
199+ The second snippet shows how to update a Datastore entity if it exists. Complete source code can be
200+ found at
201+ [gcloud-java-examples:com.google.gcloud.examples.datastore.snippets.UpdateEntity](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/UpdateEntity.java).
202+ ` ` ` java
203+ import com.google.gcloud.datastore.Datastore;
204+ import com.google.gcloud.datastore.DatastoreOptions;
205+ import com.google.gcloud.datastore.DateTime;
206+ import com.google.gcloud.datastore.Entity;
207+ import com.google.gcloud.datastore.Key;
208+ import com.google.gcloud.datastore.KeyFactory;
209+
210+ Datastore datastore = DatastoreOptions.defaultInstance().service ();
211+ KeyFactory keyFactory = datastore.newKeyFactory ().kind(" keyKind" );
212+ Key key = keyFactory.newKey(" keyName" );
213+ Entity entity = datastore.get(key);
214+ if (entity ! = null) {
196215 System.out.println(" Updating access_time for " + entity.getString(" name" ));
197216 entity = Entity.builder(entity)
198217 .set(" access_time" , DateTime.now ())
@@ -210,7 +229,8 @@ Google Cloud Resource Manager (Alpha)
210229# ### Preview
211230
212231Here is a code snippet showing a simple usage example. Note that you must supply Google SDK credentials for this service, not other forms of authentication listed in the [Authentication section](# authentication).
213-
232+ Complete source code can be found at
233+ [gcloud-java-examples:com.google.gcloud.examples.resourcemanager.snippets.UpdateAndListProjects](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/resourcemanager/snippets/UpdateAndListProjects.java).
214234` ` ` java
215235import com.google.gcloud.resourcemanager.Project;
216236import com.google.gcloud.resourcemanager.ResourceManager;
@@ -244,13 +264,36 @@ Google Cloud Storage
244264
245265#### Preview
246266
247- Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
267+ Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
268+
269+ The first snippet shows how to get a Storage blob and create it if it does not exist. Complete
270+ source code can be found at
271+ [gcloud-java-examples:com.google.gcloud.examples.storage.snippets.GetOrCreateBlob](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/GetOrCreateBlob.java).
248272
249273```java
250274import static java.nio.charset.StandardCharsets.UTF_8;
251275
252276import com.google.gcloud.storage.Blob;
277+ import com.google.gcloud.storage.BlobId;
253278import com.google.gcloud.storage.BlobInfo;
279+ import com.google.gcloud.storage.Storage;
280+ import com.google.gcloud.storage.StorageOptions;
281+
282+ Storage storage = StorageOptions.defaultInstance().service();
283+ BlobId blobId = BlobId.of("bucket", "blob_name");
284+ Blob blob = storage.get(blobId);
285+ if (blob == null) {
286+ BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
287+ blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
288+ }
289+ ```
290+ The second snippet shows how to update a Storage blob if it exists. Complete source code can be
291+ found at
292+ [gcloud-java-examples:com.google.gcloud.examples.storage.snippets.UpdateBlob](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/UpdateBlob.java).
293+ ```java
294+ import static java.nio.charset.StandardCharsets.UTF_8;
295+
296+ import com.google.gcloud.storage.Blob;
254297import com.google.gcloud.storage.BlobId;
255298import com.google.gcloud.storage.Storage;
256299import com.google.gcloud.storage.StorageOptions;
@@ -261,11 +304,7 @@ import java.nio.channels.WritableByteChannel;
261304Storage storage = StorageOptions.defaultInstance().service();
262305BlobId blobId = BlobId.of("bucket", "blob_name");
263306Blob blob = storage.get(blobId);
264- if (blob == null) {
265- BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
266- storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
267- } else {
268- System.out.println("Updating content for " + blobId.name());
307+ if (blob != null) {
269308 byte[] prevContent = blob.content();
270309 System.out.println(new String(prevContent, UTF_8));
271310 WritableByteChannel channel = blob.writer();
0 commit comments