Skip to content

Commit 0c11be7

Browse files
committed
---
yaml --- r: 1141 b: refs/heads/master c: 73d379b h: refs/heads/master i: 1139: 76d82f2 v: v3
1 parent 67e9de7 commit 0c11be7

14 files changed

Lines changed: 128 additions & 162 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: 561af74f9d47fb01cad66dfc47dfe4b53fa1b758
2+
refs/heads/master: 73d379ba5afd65fa0a112093f48eace1e5acb931
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ This client supports the following Google Cloud Platform services:
2020
2121
Quickstart
2222
----------
23-
Add this to your pom.xml file
23+
If you are using Maven, add this to your pom.xml file
2424
```xml
2525
<dependency>
2626
<groupId>com.google.gcloud</groupId>
2727
<artifactId>gcloud-java</artifactId>
2828
<version>0.0.10</version>
2929
</dependency>
3030
```
31+
If you are using Gradle, add this to your dependencies
32+
```Groovy
33+
compile 'com.google.gcloud:gcloud-java:jar:0.0.10'
34+
```
35+
If you are using SBT, add this to your dependencies
36+
```Scala
37+
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.0.10"
38+
```
3139

3240
Example Applications
3341
--------------------

trunk/gcloud-java-core/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ This module provides common functionality required by service-specific modules o
1212

1313
Quickstart
1414
----------
15-
Add this to your pom.xml file
15+
If you are using Maven, add this to your pom.xml file
1616
```xml
1717
<dependency>
1818
<groupId>com.google.gcloud</groupId>
1919
<artifactId>gcloud-java-core</artifactId>
2020
<version>0.0.10</version>
2121
</dependency>
2222
```
23+
If you are using Gradle, add this to your dependencies
24+
```Groovy
25+
compile 'com.google.gcloud:gcloud-java-core:jar:0.0.10'
26+
```
27+
If you are using SBT, add this to your dependencies
28+
```Scala
29+
libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.10"
30+
```
2331

2432
Java Versions
2533
-------------

trunk/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

trunk/gcloud-java-core/src/test/java/com/google/gcloud/BaseServiceExceptionTest.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

trunk/gcloud-java-datastore/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ Java idiomatic client for [Google Cloud Datastore] (https://cloud.google.com/dat
1515
1616
Quickstart
1717
----------
18-
Add this to your pom.xml file
18+
If you are using Maven, add this to your pom.xml file
1919
```xml
2020
<dependency>
2121
<groupId>com.google.gcloud</groupId>
2222
<artifactId>gcloud-java-datastore</artifactId>
2323
<version>0.0.10</version>
2424
</dependency>
2525
```
26+
If you are using Gradle, add this to your dependencies
27+
```Groovy
28+
compile 'com.google.gcloud:gcloud-java-datastore:jar:0.0.10'
29+
```
30+
If you are using SBT, add this to your dependencies
31+
```Scala
32+
libraryDependencies += "com.google.gcloud" % "gcloud-java-datastore" % "0.0.10"
33+
```
2634

2735
Example Application
2836
--------------------

trunk/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.google.common.base.MoreObjects;
2020
import com.google.common.collect.ImmutableMap;
21-
import com.google.gcloud.BaseServiceException;
2221
import com.google.gcloud.RetryHelper;
2322
import com.google.gcloud.RetryHelper.RetryHelperException;
2423
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
@@ -27,21 +26,21 @@
2726
import java.util.HashMap;
2827
import java.util.Map;
2928

30-
public class DatastoreException extends BaseServiceException {
29+
public class DatastoreException extends RuntimeException {
3130

32-
private static final long serialVersionUID = -2336749234060754893L;
33-
private static final ImmutableMap<String, DatastoreError> REASON_TO_ERROR;
34-
private static final ImmutableMap<Integer, DatastoreError> HTTP_TO_ERROR;
31+
private static final long serialVersionUID = 8170357898917041899L;
32+
private static final ImmutableMap<String, Code> REASON_TO_CODE;
33+
private static final ImmutableMap<Integer, Code> HTTP_TO_CODE;
3534

36-
private final DatastoreError error;
35+
private final Code code;
3736

3837
/**
39-
* Represents Datastore errors.
38+
* An error code to represent the failure.
4039
*
4140
* @see <a href="https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes">Google Cloud
4241
* Datastore error codes</a>
4342
*/
44-
public enum DatastoreError {
43+
public enum Code {
4544

4645
ABORTED(Reason.ABORTED),
4746
DEADLINE_EXCEEDED(Reason.DEADLINE_EXCEEDED),
@@ -58,25 +57,29 @@ public enum DatastoreError {
5857
private final String description;
5958
private final int httpStatus;
6059

61-
DatastoreError(Reason reason) {
60+
Code(Reason reason) {
6261
this(reason.retryable(), reason.description(), reason.httpStatus());
6362
}
6463

65-
DatastoreError(boolean retryable, String description, int httpStatus) {
64+
Code(boolean retryable, String description, int httpStatus) {
6665
this.retryable = retryable;
6766
this.description = description;
6867
this.httpStatus = httpStatus;
6968
}
7069

71-
String description() {
70+
public String description() {
7271
return description;
7372
}
7473

75-
int httpStatus() {
74+
public int httpStatus() {
7675
return httpStatus;
7776
}
7877

79-
boolean retryable() {
78+
/**
79+
* Returns {@code true} if this exception is transient and the same request could be retried.
80+
* For any retry it is highly recommended to apply an exponential backoff.
81+
*/
82+
public boolean retryable() {
8083
return retryable;
8184
}
8285

@@ -86,31 +89,30 @@ DatastoreException translate(DatastoreRpcException exception, String message) {
8689
}
8790

8891
static {
89-
ImmutableMap.Builder<String, DatastoreError> builder = ImmutableMap.builder();
90-
Map<Integer, DatastoreError> httpCodes = new HashMap<>();
91-
for (DatastoreError error : DatastoreError.values()) {
92-
builder.put(error.name(), error);
93-
httpCodes.put(error.httpStatus(), error);
92+
ImmutableMap.Builder<String, Code> builder = ImmutableMap.builder();
93+
Map<Integer, Code> httpCodes = new HashMap<>();
94+
for (Code code : Code.values()) {
95+
builder.put(code.name(), code);
96+
httpCodes.put(code.httpStatus(), code);
9497
}
95-
REASON_TO_ERROR = builder.build();
96-
HTTP_TO_ERROR = ImmutableMap.copyOf(httpCodes);
98+
REASON_TO_CODE = builder.build();
99+
HTTP_TO_CODE = ImmutableMap.copyOf(httpCodes);
97100
}
98101

99-
public DatastoreException(DatastoreError error, String message, Exception cause) {
100-
super(error.httpStatus(), MoreObjects.firstNonNull(message, error.description),
101-
error.retryable(), cause);
102-
this.error = error;
102+
public DatastoreException(Code code, String message, Exception cause) {
103+
super(MoreObjects.firstNonNull(message, code.description), cause);
104+
this.code = code;
103105
}
104106

105-
public DatastoreException(DatastoreError error, String message) {
106-
this(error, message, null);
107+
public DatastoreException(Code code, String message) {
108+
this(code, message, null);
107109
}
108110

109111
/**
110-
* Returns the DatastoreError associated with this exception.
112+
* Returns the code associated with this exception.
111113
*/
112-
public DatastoreError datastoreError() {
113-
return error;
114+
public Code code() {
115+
return code;
114116
}
115117

116118
static DatastoreException translateAndThrow(RetryHelperException ex) {
@@ -120,36 +122,35 @@ static DatastoreException translateAndThrow(RetryHelperException ex) {
120122
if (ex instanceof RetryHelper.RetryInterruptedException) {
121123
RetryHelper.RetryInterruptedException.propagate();
122124
}
123-
throw new DatastoreException(DatastoreError.UNKNOWN, ex.getMessage(), ex);
125+
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
124126
}
125127

126128
/**
127-
* Translate DatastoreRpcExceptions to DatastoreExceptions based on their
129+
* Translate DatastoreException to DatastoreException based on their
128130
* HTTP error codes. This method will always throw a new DatastoreException.
129131
*
130132
* @throws DatastoreException every time
131133
*/
132134
static DatastoreException translateAndThrow(DatastoreRpcException exception) {
133135
String message = exception.getMessage();
134-
DatastoreError error = REASON_TO_ERROR.get(exception.reason());
135-
if (error == null) {
136-
error = MoreObjects.firstNonNull(
137-
HTTP_TO_ERROR.get(exception.httpStatus()), DatastoreError.UNKNOWN);
136+
Code code = REASON_TO_CODE.get(exception.reason());
137+
if (code == null) {
138+
code = MoreObjects.firstNonNull(HTTP_TO_CODE.get(exception.httpStatus()), Code.UNKNOWN);
138139
}
139-
throw error.translate(exception, message);
140+
throw code.translate(exception, message);
140141
}
141142

142143
/**
143-
* Throw a DatastoreException with {@code FAILED_PRECONDITION} error and the {@code message}
144+
* Throw a DatastoreException with {@code FAILED_PRECONDITION} code and the {@code message}
144145
* in a nested exception.
145146
*
146147
* @throws DatastoreException every time
147148
*/
148149
static DatastoreException throwInvalidRequest(String massage, Object... params) {
149-
throw new DatastoreException(DatastoreError.FAILED_PRECONDITION, String.format(massage, params));
150+
throw new DatastoreException(Code.FAILED_PRECONDITION, String.format(massage, params));
150151
}
151152

152153
static DatastoreException propagateUserException(Exception ex) {
153-
throw new DatastoreException(DatastoreError.UNKNOWN, ex.getMessage(), ex);
154+
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
154155
}
155156
}

trunk/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreExceptionTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.fail;
2121

22-
import com.google.gcloud.datastore.DatastoreException.DatastoreError;
22+
import com.google.gcloud.datastore.DatastoreException.Code;
2323
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
2424
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
2525

@@ -28,16 +28,16 @@
2828
public class DatastoreExceptionTest {
2929

3030
@Test
31-
public void testDatastoreError() throws Exception {
31+
public void testCode() throws Exception {
3232
for (Reason reason : Reason.values()) {
33-
DatastoreError error = DatastoreError.valueOf(reason.name());
34-
assertEquals(reason.retryable(), error.retryable());
35-
assertEquals(reason.description(), error.description());
36-
assertEquals(reason.httpStatus(), error.httpStatus());
33+
Code code = Code.valueOf(reason.name());
34+
assertEquals(reason.retryable(), code.retryable());
35+
assertEquals(reason.description(), code.description());
36+
assertEquals(reason.httpStatus(), code.httpStatus());
3737
}
3838

39-
DatastoreException exception = new DatastoreException(DatastoreError.ABORTED, "bla");
40-
assertEquals(DatastoreError.ABORTED, exception.datastoreError());
39+
DatastoreException exception = new DatastoreException(Code.ABORTED, "bla");
40+
assertEquals(Code.ABORTED, exception.code());
4141
}
4242

4343
@Test
@@ -47,7 +47,7 @@ public void testTranslateAndThrow() throws Exception {
4747
DatastoreException.translateAndThrow(new DatastoreRpcException(reason));
4848
fail("Exception expected");
4949
} catch (DatastoreException ex) {
50-
assertEquals(reason.name(), ex.datastoreError().name());
50+
assertEquals(reason.name(), ex.code().name());
5151
}
5252
}
5353
}
@@ -58,7 +58,7 @@ public void testThrowInvalidRequest() throws Exception {
5858
DatastoreException.throwInvalidRequest("message %s %d", "a", 1);
5959
fail("Exception expected");
6060
} catch (DatastoreException ex) {
61-
assertEquals(DatastoreError.FAILED_PRECONDITION, ex.datastoreError());
61+
assertEquals(Code.FAILED_PRECONDITION, ex.code());
6262
assertEquals("message a 1", ex.getMessage());
6363
}
6464
}

0 commit comments

Comments
 (0)