Skip to content

Commit 2aaa4e7

Browse files
committed
---
yaml --- r: 2357 b: refs/heads/update-datastore c: bea0157 h: refs/heads/master i: 2355: 5a4bc6c
1 parent 0bc5a9e commit 2aaa4e7

7 files changed

Lines changed: 283 additions & 192 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: deecc14fe1015d7f3e62323da57471f9d7dd8ec1
8+
refs/heads/update-datastore: bea01573f3aec62ff7c96867467089eebf872975
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2

branches/update-datastore/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
21-
import static com.google.gcloud.storage.Blob.BlobSourceOption.convert;
21+
import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions;
2222
import static com.google.gcloud.storage.Blob.BlobSourceOption.toGetOptions;
2323

2424
import com.google.common.base.Function;
@@ -58,7 +58,7 @@ private BlobSourceOption(StorageRpc.Option rpcOption) {
5858
super(rpcOption, null);
5959
}
6060

61-
private Storage.BlobSourceOption convert(BlobInfo blobInfo) {
61+
private Storage.BlobSourceOption toSourceOptions(BlobInfo blobInfo) {
6262
switch (rpcOption()) {
6363
case IF_GENERATION_MATCH:
6464
return Storage.BlobSourceOption.generationMatch(blobInfo.generation());
@@ -104,11 +104,12 @@ public static BlobSourceOption metagenerationNotMatch() {
104104
return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
105105
}
106106

107-
static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption... options) {
107+
static Storage.BlobSourceOption[] toSourceOptions(BlobInfo blobInfo,
108+
BlobSourceOption... options) {
108109
Storage.BlobSourceOption[] convertedOptions = new Storage.BlobSourceOption[options.length];
109110
int index = 0;
110111
for (BlobSourceOption option : options) {
111-
convertedOptions[index++] = option.convert(blobInfo);
112+
convertedOptions[index++] = option.toSourceOptions(blobInfo);
112113
}
113114
return convertedOptions;
114115
}
@@ -126,7 +127,7 @@ static Storage.BlobGetOption[] toGetOptions(BlobInfo blobInfo, BlobSourceOption.
126127
/**
127128
* Constructs a {@code Blob} object for the provided {@code BlobInfo}. The storage service is used
128129
* to issue requests.
129-
*
130+
*
130131
* @param storage the storage service used for issuing requests
131132
* @param info blob's info
132133
*/
@@ -138,7 +139,7 @@ public Blob(Storage storage, BlobInfo info) {
138139
/**
139140
* Creates a {@code Blob} object for the provided bucket and blob names. Performs an RPC call to
140141
* get the latest blob information.
141-
*
142+
*
142143
* @param storage the storage service used for issuing requests
143144
* @param bucket bucket's name
144145
* @param blob blob's name
@@ -152,7 +153,7 @@ public static Blob load(Storage storage, String bucket, String blob) {
152153
/**
153154
* Creates a {@code Blob} object for the provided {@code blobId}. Performs an RPC call to get the
154155
* latest blob information.
155-
*
156+
*
156157
* @param storage the storage service used for issuing requests
157158
* @param blobId blob's identifier
158159
* @return the {@code Blob} object or {@code null} if not found.
@@ -253,7 +254,7 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
253254
*/
254255
public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
255256
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
256-
.sourceOptions(convert(info, options)).target(targetBlob).build();
257+
.sourceOptions(toSourceOptions(info, options)).target(targetBlob).build();
257258
return storage.copy(copyRequest);
258259
}
259260

@@ -265,7 +266,7 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
265266
* @throws StorageException upon failure
266267
*/
267268
public boolean delete(BlobSourceOption... options) {
268-
return storage.delete(info.blobId(), convert(info, options));
269+
return storage.delete(info.blobId(), toSourceOptions(info, options));
269270
}
270271

271272
/**
@@ -304,7 +305,7 @@ public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOptio
304305
* @throws StorageException upon failure
305306
*/
306307
public BlobReadChannel reader(BlobSourceOption... options) {
307-
return storage.reader(info.blobId(), convert(info, options));
308+
return storage.reader(info.blobId(), toSourceOptions(info, options));
308309
}
309310

310311
/**

branches/update-datastore/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import com.google.common.collect.Iterators;
2525
import com.google.gcloud.PageImpl;
2626
import com.google.gcloud.Page;
27+
import com.google.gcloud.spi.StorageRpc;
2728
import com.google.gcloud.storage.Storage.BlobGetOption;
2829
import com.google.gcloud.storage.Storage.BlobTargetOption;
2930
import com.google.gcloud.storage.Storage.BlobWriteOption;
30-
import com.google.gcloud.storage.Storage.BucketSourceOption;
3131
import com.google.gcloud.storage.Storage.BucketTargetOption;
3232

3333
import java.io.IOException;
@@ -119,6 +119,66 @@ public boolean equals(Object obj) {
119119
}
120120
}
121121

122+
public static class BucketSourceOption extends Option {
123+
124+
private static final long serialVersionUID = 6928872234155522371L;
125+
126+
private BucketSourceOption(StorageRpc.Option rpcOption) {
127+
super(rpcOption, null);
128+
}
129+
130+
private Storage.BucketSourceOption toSourceOptions(BucketInfo bucketInfo) {
131+
switch (rpcOption()) {
132+
case IF_METAGENERATION_MATCH:
133+
return Storage.BucketSourceOption.metagenerationMatch(bucketInfo.metageneration());
134+
case IF_METAGENERATION_NOT_MATCH:
135+
return Storage.BucketSourceOption.metagenerationNotMatch(bucketInfo.metageneration());
136+
default:
137+
throw new AssertionError("Unexpected enum value");
138+
}
139+
}
140+
141+
private Storage.BucketGetOption toGetOption(BucketInfo bucketInfo) {
142+
switch (rpcOption()) {
143+
case IF_METAGENERATION_MATCH:
144+
return Storage.BucketGetOption.metagenerationMatch(bucketInfo.metageneration());
145+
case IF_METAGENERATION_NOT_MATCH:
146+
return Storage.BucketGetOption.metagenerationNotMatch(bucketInfo.metageneration());
147+
default:
148+
throw new AssertionError("Unexpected enum value");
149+
}
150+
}
151+
152+
public static BucketSourceOption metagenerationMatch() {
153+
return new BucketSourceOption(StorageRpc.Option.IF_METAGENERATION_MATCH);
154+
}
155+
156+
public static BucketSourceOption metagenerationNotMatch() {
157+
return new BucketSourceOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
158+
}
159+
160+
static Storage.BucketSourceOption[] toSourceOptions(BucketInfo bucketInfo,
161+
BucketSourceOption... options) {
162+
Storage.BucketSourceOption[] convertedOptions =
163+
new Storage.BucketSourceOption[options.length];
164+
int index = 0;
165+
for (BucketSourceOption option : options) {
166+
convertedOptions[index++] = option.toSourceOptions(bucketInfo);
167+
}
168+
return convertedOptions;
169+
}
170+
171+
static Storage.BucketGetOption[] toGetOptions(BucketInfo bucketInfo,
172+
BucketSourceOption... options) {
173+
Storage.BucketGetOption[] convertedOptions = new Storage.BucketGetOption[options.length];
174+
int index = 0;
175+
for (BucketSourceOption option : options) {
176+
convertedOptions[index++] = option.toGetOption(bucketInfo);
177+
}
178+
return convertedOptions;
179+
}
180+
}
181+
122182
/**
123183
* Constructs a {@code Bucket} object for the provided {@code BucketInfo}. The storage service is
124184
* used to issue requests.
@@ -170,7 +230,8 @@ public boolean exists() {
170230
* @throws StorageException upon failure
171231
*/
172232
public Bucket reload(BucketSourceOption... options) {
173-
return new Bucket(storage, storage.get(info.name(), options));
233+
return new Bucket(storage, storage.get(info.name(),
234+
BucketSourceOption.toGetOptions(info, options)));
174235
}
175236

176237
/**
@@ -198,7 +259,7 @@ public Bucket update(BucketInfo bucketInfo, BucketTargetOption... options) {
198259
* @throws StorageException upon failure
199260
*/
200261
public boolean delete(BucketSourceOption... options) {
201-
return storage.delete(info.name(), options);
262+
return storage.delete(info.name(), BucketSourceOption.toSourceOptions(info, options));
202263
}
203264

204265
/**

0 commit comments

Comments
 (0)