Skip to content

Commit ba5050b

Browse files
committed
Merge pull request #535 from mziccard/load-to-get
Rename load to get in functional classes
2 parents 824c46c + 1ab0ac5 commit ba5050b

File tree

15 files changed

+110
-81
lines changed

15 files changed

+110
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ import java.nio.channels.WritableByteChannel;
250250
251251
Storage storage = StorageOptions.defaultInstance().service();
252252
BlobId blobId = BlobId.of("bucket", "blob_name");
253-
Blob blob = Blob.load(storage, blobId);
253+
Blob blob = Blob.get(storage, blobId);
254254
if (blob == null) {
255255
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
256256
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Dataset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Dataset(BigQuery bigquery, DatasetInfo info) {
131131
* @return the {@code Dataset} object or {@code null} if not found
132132
* @throws BigQueryException upon failure
133133
*/
134-
public static Dataset load(BigQuery bigquery, String dataset, BigQuery.DatasetOption... options) {
134+
public static Dataset get(BigQuery bigquery, String dataset, BigQuery.DatasetOption... options) {
135135
DatasetInfo info = bigquery.getDataset(dataset, options);
136136
return info != null ? new Dataset(bigquery, info) : null;
137137
}
@@ -162,7 +162,7 @@ public boolean exists() {
162162
* @throws BigQueryException upon failure
163163
*/
164164
public Dataset reload(BigQuery.DatasetOption... options) {
165-
return Dataset.load(bigquery, info.datasetId().dataset(), options);
165+
return Dataset.get(bigquery, info.datasetId().dataset(), options);
166166
}
167167

168168
/**

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Job(BigQuery bigquery, JobInfo info) {
5252
* @return the {@code Job} object or {@code null} if not found
5353
* @throws BigQueryException upon failure
5454
*/
55-
public static Job load(BigQuery bigquery, String job, BigQuery.JobOption... options) {
55+
public static Job get(BigQuery bigquery, String job, BigQuery.JobOption... options) {
5656
JobInfo info = bigquery.getJob(job, options);
5757
return info != null ? new Job(bigquery, info) : null;
5858
}
@@ -103,7 +103,7 @@ public boolean isDone() {
103103
* @throws BigQueryException upon failure
104104
*/
105105
public Job reload(BigQuery.JobOption... options) {
106-
return Job.load(bigquery, info.jobId().job(), options);
106+
return Job.get(bigquery, info.jobId().job(), options);
107107
}
108108

109109
/**

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public Table(BigQuery bigquery, BaseTableInfo info) {
6161
* @return the {@code Table} object or {@code null} if not found
6262
* @throws BigQueryException upon failure
6363
*/
64-
public static Table load(BigQuery bigquery, String dataset, String table,
64+
public static Table get(BigQuery bigquery, String dataset, String table,
6565
BigQuery.TableOption... options) {
66-
return load(bigquery, TableId.of(dataset, table), options);
66+
return get(bigquery, TableId.of(dataset, table), options);
6767
}
6868

6969
/**
@@ -76,7 +76,7 @@ public static Table load(BigQuery bigquery, String dataset, String table,
7676
* @return the {@code Table} object or {@code null} if not found
7777
* @throws BigQueryException upon failure
7878
*/
79-
public static Table load(BigQuery bigquery, TableId table, BigQuery.TableOption... options) {
79+
public static Table get(BigQuery bigquery, TableId table, BigQuery.TableOption... options) {
8080
BaseTableInfo info = bigquery.getTable(table, options);
8181
return info != null ? new Table(bigquery, info) : null;
8282
}
@@ -106,7 +106,7 @@ public boolean exists() {
106106
* @throws BigQueryException upon failure
107107
*/
108108
public Table reload(BigQuery.TableOption... options) {
109-
return Table.load(bigquery, info.tableId(), options);
109+
return Table.get(bigquery, info.tableId(), options);
110110
}
111111

112112
/**

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,27 @@ public void testCreateExternalTableWithOptions() throws Exception {
304304
}
305305

306306
@Test
307-
public void testLoad() throws Exception {
307+
public void testStaticGet() throws Exception {
308308
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset())).andReturn(DATASET_INFO);
309309
replay(bigquery);
310-
Dataset loadedDataset = Dataset.load(bigquery, DATASET_INFO.datasetId().dataset());
310+
Dataset loadedDataset = Dataset.get(bigquery, DATASET_INFO.datasetId().dataset());
311311
assertNotNull(loadedDataset);
312312
assertEquals(DATASET_INFO, loadedDataset.info());
313313
}
314314

315315
@Test
316-
public void testLoadNull() throws Exception {
316+
public void testStaticGetNull() throws Exception {
317317
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset())).andReturn(null);
318318
replay(bigquery);
319-
assertNull(Dataset.load(bigquery, DATASET_INFO.datasetId().dataset()));
319+
assertNull(Dataset.get(bigquery, DATASET_INFO.datasetId().dataset()));
320320
}
321321

322322
@Test
323-
public void testLoadWithOptions() throws Exception {
323+
public void testStaticGetWithOptions() throws Exception {
324324
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset(), BigQuery.DatasetOption.fields()))
325325
.andReturn(DATASET_INFO);
326326
replay(bigquery);
327-
Dataset loadedDataset = Dataset.load(bigquery, DATASET_INFO.datasetId().dataset(),
327+
Dataset loadedDataset = Dataset.get(bigquery, DATASET_INFO.datasetId().dataset(),
328328
BigQuery.DatasetOption.fields());
329329
assertNotNull(loadedDataset);
330330
assertEquals(DATASET_INFO, loadedDataset.info());

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,27 @@ public void testCancel() throws Exception {
148148
}
149149

150150
@Test
151-
public void testLoad() throws Exception {
151+
public void testGet() throws Exception {
152152
expect(bigquery.getJob(JOB_INFO.jobId().job())).andReturn(JOB_INFO);
153153
replay(bigquery);
154-
Job loadedJob = Job.load(bigquery, JOB_INFO.jobId().job());
154+
Job loadedJob = Job.get(bigquery, JOB_INFO.jobId().job());
155155
assertNotNull(loadedJob);
156156
assertEquals(JOB_INFO, loadedJob.info());
157157
}
158158

159159
@Test
160-
public void testLoadNull() throws Exception {
160+
public void testGetNull() throws Exception {
161161
expect(bigquery.getJob(JOB_INFO.jobId().job())).andReturn(null);
162162
replay(bigquery);
163-
assertNull(Job.load(bigquery, JOB_INFO.jobId().job()));
163+
assertNull(Job.get(bigquery, JOB_INFO.jobId().job()));
164164
}
165165

166166
@Test
167-
public void testLoadWithOptions() throws Exception {
167+
public void testGetWithOptions() throws Exception {
168168
expect(bigquery.getJob(JOB_INFO.jobId().job(), BigQuery.JobOption.fields()))
169169
.andReturn(JOB_INFO);
170170
replay(bigquery);
171-
Job loadedJob = Job.load(bigquery, JOB_INFO.jobId().job(), BigQuery.JobOption.fields());
171+
Job loadedJob = Job.get(bigquery, JOB_INFO.jobId().job(), BigQuery.JobOption.fields());
172172
assertNotNull(loadedJob);
173173
assertEquals(JOB_INFO, loadedJob.info());
174174
}

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,54 +292,54 @@ public void testExtractDataUris() throws Exception {
292292
}
293293

294294
@Test
295-
public void testLoadFromId() throws Exception {
295+
public void testGetFromId() throws Exception {
296296
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(TABLE_INFO);
297297
replay(bigquery);
298-
Table loadedTable = Table.load(bigquery, TABLE_INFO.tableId());
298+
Table loadedTable = Table.get(bigquery, TABLE_INFO.tableId());
299299
assertNotNull(loadedTable);
300300
assertEquals(TABLE_INFO, loadedTable.info());
301301
}
302302

303303
@Test
304-
public void testLoadFromStrings() throws Exception {
304+
public void testGetFromStrings() throws Exception {
305305
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(TABLE_INFO);
306306
replay(bigquery);
307-
Table loadedTable = Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table());
307+
Table loadedTable = Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table());
308308
assertNotNull(loadedTable);
309309
assertEquals(TABLE_INFO, loadedTable.info());
310310
}
311311

312312
@Test
313-
public void testLoadFromIdNull() throws Exception {
313+
public void testGetFromIdNull() throws Exception {
314314
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(null);
315315
replay(bigquery);
316-
assertNull(Table.load(bigquery, TABLE_INFO.tableId()));
316+
assertNull(Table.get(bigquery, TABLE_INFO.tableId()));
317317
}
318318

319319
@Test
320-
public void testLoadFromStringsNull() throws Exception {
320+
public void testGetFromStringsNull() throws Exception {
321321
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(null);
322322
replay(bigquery);
323-
assertNull(Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table()));
323+
assertNull(Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table()));
324324
}
325325

326326
@Test
327-
public void testLoadFromIdWithOptions() throws Exception {
327+
public void testGetFromIdWithOptions() throws Exception {
328328
expect(bigquery.getTable(TABLE_INFO.tableId(), BigQuery.TableOption.fields()))
329329
.andReturn(TABLE_INFO);
330330
replay(bigquery);
331-
Table loadedTable = Table.load(bigquery, TABLE_INFO.tableId(), BigQuery.TableOption.fields());
331+
Table loadedTable = Table.get(bigquery, TABLE_INFO.tableId(), BigQuery.TableOption.fields());
332332
assertNotNull(loadedTable);
333333
assertEquals(TABLE_INFO, loadedTable.info());
334334
}
335335

336336
@Test
337-
public void testLoadFromStringsWithOptions() throws Exception {
337+
public void testGetFromStringsWithOptions() throws Exception {
338338
expect(bigquery.getTable(TABLE_INFO.tableId(), BigQuery.TableOption.fields()))
339339
.andReturn(TABLE_INFO);
340340
replay(bigquery);
341341
Table loadedTable =
342-
Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table(), BigQuery.TableOption.fields());
342+
Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table(), BigQuery.TableOption.fields());
343343
assertNotNull(loadedTable);
344344
assertEquals(TABLE_INFO, loadedTable.info());
345345
}

gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ public void run(Storage storage, BlobId... blobIds) {
134134
if (blobIds.length == 1) {
135135
if (blobIds[0].name().isEmpty()) {
136136
// get Bucket
137-
Bucket bucket = Bucket.load(storage, blobIds[0].bucket());
137+
Bucket bucket = Bucket.get(storage, blobIds[0].bucket());
138138
if (bucket == null) {
139139
System.out.println("No such bucket");
140140
return;
141141
}
142142
System.out.println("Bucket info: " + bucket.info());
143143
} else {
144144
// get Blob
145-
Blob blob = Blob.load(storage, blobIds[0]);
145+
Blob blob = Blob.get(storage, blobIds[0]);
146146
if (blob == null) {
147147
System.out.println("No such object");
148148
return;
@@ -151,7 +151,7 @@ public void run(Storage storage, BlobId... blobIds) {
151151
}
152152
} else {
153153
// use batch to get multiple blobs.
154-
List<Blob> blobs = Blob.get(storage, blobIds);
154+
List<Blob> blobs = Blob.get(storage, Arrays.asList(blobIds));
155155
for (Blob blob : blobs) {
156156
if (blob != null) {
157157
System.out.println(blob.info());
@@ -225,7 +225,7 @@ public void run(Storage storage, String bucketName) {
225225
}
226226
} else {
227227
// list a bucket's blobs
228-
Bucket bucket = Bucket.load(storage, bucketName);
228+
Bucket bucket = Bucket.get(storage, bucketName);
229229
if (bucket == null) {
230230
System.out.println("No such bucket");
231231
return;
@@ -312,7 +312,7 @@ public void run(Storage storage, Tuple<BlobId, Path> tuple) throws IOException {
312312
}
313313

314314
private void run(Storage storage, BlobId blobId, Path downloadTo) throws IOException {
315-
Blob blob = Blob.load(storage, blobId);
315+
Blob blob = Blob.get(storage, blobId);
316316
if (blob == null) {
317317
System.out.println("No such object");
318318
return;
@@ -439,7 +439,7 @@ public void run(Storage storage, Tuple<BlobId, Map<String, String>> tuple)
439439
}
440440

441441
private void run(Storage storage, BlobId blobId, Map<String, String> metadata) {
442-
Blob blob = Blob.load(storage, blobId);
442+
Blob blob = Blob.get(storage, blobId);
443443
if (blob == null) {
444444
System.out.println("No such object");
445445
return;

gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Project.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public Project(ResourceManager resourceManager, ProjectInfo projectInfo) {
4040
}
4141

4242
/**
43-
* Constructs a Project object that contains project information loaded from the server.
43+
* Constructs a Project object that contains project information got from the server.
4444
*
4545
* @return Project object containing the project's metadata or {@code null} if not found
4646
* @throws ResourceManagerException upon failure
4747
*/
48-
public static Project load(ResourceManager resourceManager, String projectId) {
48+
public static Project get(ResourceManager resourceManager, String projectId) {
4949
ProjectInfo projectInfo = resourceManager.get(projectId);
5050
return projectInfo != null ? new Project(resourceManager, projectInfo) : null;
5151
}
@@ -72,7 +72,7 @@ public ResourceManager resourceManager() {
7272
* @throws ResourceManagerException upon failure
7373
*/
7474
public Project reload() {
75-
return Project.load(resourceManager, info.projectId());
75+
return Project.get(resourceManager, info.projectId());
7676
}
7777

7878
/**

gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/ProjectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void tearDown() throws Exception {
6666
public void testLoad() {
6767
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(PROJECT_INFO);
6868
replay(resourceManager);
69-
Project loadedProject = Project.load(resourceManager, PROJECT_INFO.projectId());
69+
Project loadedProject = Project.get(resourceManager, PROJECT_INFO.projectId());
7070
assertEquals(PROJECT_INFO, loadedProject.info());
7171
}
7272

@@ -84,15 +84,15 @@ public void testReload() {
8484
public void testLoadNull() {
8585
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
8686
replay(resourceManager);
87-
assertNull(Project.load(resourceManager, PROJECT_INFO.projectId()));
87+
assertNull(Project.get(resourceManager, PROJECT_INFO.projectId()));
8888
}
8989

9090
@Test
9191
public void testReloadDeletedProject() {
9292
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(PROJECT_INFO);
9393
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
9494
replay(resourceManager);
95-
Project loadedProject = Project.load(resourceManager, PROJECT_INFO.projectId());
95+
Project loadedProject = Project.get(resourceManager, PROJECT_INFO.projectId());
9696
assertNotNull(loadedProject);
9797
Project reloadedProject = loadedProject.reload();
9898
assertNull(reloadedProject);

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions;
2323

2424
import com.google.common.base.Function;
25+
import com.google.common.collect.ImmutableList;
2526
import com.google.common.collect.Lists;
2627
import com.google.gcloud.spi.StorageRpc;
2728
import com.google.gcloud.storage.Storage.BlobTargetOption;
@@ -165,9 +166,9 @@ public Blob(Storage storage, BlobInfo info) {
165166
* @return the {@code Blob} object or {@code null} if not found
166167
* @throws StorageException upon failure
167168
*/
168-
public static Blob load(Storage storage, String bucket, String blob,
169+
public static Blob get(Storage storage, String bucket, String blob,
169170
Storage.BlobGetOption... options) {
170-
return load(storage, BlobId.of(bucket, blob), options);
171+
return get(storage, BlobId.of(bucket, blob), options);
171172
}
172173

173174
/**
@@ -180,7 +181,7 @@ public static Blob load(Storage storage, String bucket, String blob,
180181
* @return the {@code Blob} object or {@code null} if not found
181182
* @throws StorageException upon failure
182183
*/
183-
public static Blob load(Storage storage, BlobId blobId, Storage.BlobGetOption... options) {
184+
public static Blob get(Storage storage, BlobId blobId, Storage.BlobGetOption... options) {
184185
BlobInfo info = storage.get(blobId, options);
185186
return info != null ? new Blob(storage, info) : null;
186187
}
@@ -231,7 +232,7 @@ public byte[] content(Storage.BlobSourceOption... options) {
231232
* @throws StorageException upon failure
232233
*/
233234
public Blob reload(BlobSourceOption... options) {
234-
return Blob.load(storage, info.blobId(), toGetOptions(info, options));
235+
return Blob.get(storage, info.blobId(), toGetOptions(info, options));
235236
}
236237

237238
/**
@@ -369,18 +370,40 @@ public Storage storage() {
369370
* Gets the requested blobs. A batch request is used to fetch blobs.
370371
*
371372
* @param storage the storage service used to issue the request
372-
* @param blobs the blobs to get
373+
* @param first the first blob to get
374+
* @param second the second blob to get
375+
* @param other other blobs to get
373376
* @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has
374377
* been denied the corresponding item in the list is {@code null}
375378
* @throws StorageException upon failure
376379
*/
377-
public static List<Blob> get(final Storage storage, BlobId... blobs) {
380+
public static List<Blob> get(Storage storage, BlobId first, BlobId second, BlobId... other) {
381+
checkNotNull(storage);
382+
checkNotNull(first);
383+
checkNotNull(second);
384+
checkNotNull(other);
385+
ImmutableList<BlobId> blobs = ImmutableList.<BlobId>builder()
386+
.add(first)
387+
.add(second)
388+
.addAll(Arrays.asList(other))
389+
.build();
390+
return get(storage, blobs);
391+
}
392+
393+
/**
394+
* Gets the requested blobs. A batch request is used to fetch blobs.
395+
*
396+
* @param storage the storage service used to issue the request
397+
* @param blobs list of blobs to get
398+
* @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has
399+
* been denied the corresponding item in the list is {@code null}
400+
* @throws StorageException upon failure
401+
*/
402+
public static List<Blob> get(final Storage storage, List<BlobId> blobs) {
378403
checkNotNull(storage);
379404
checkNotNull(blobs);
380-
if (blobs.length == 0) {
381-
return Collections.emptyList();
382-
}
383-
return Collections.unmodifiableList(Lists.transform(storage.get(blobs),
405+
BlobId[] blobArray = blobs.toArray(new BlobId[blobs.size()]);
406+
return Collections.unmodifiableList(Lists.transform(storage.get(blobArray),
384407
new Function<BlobInfo, Blob>() {
385408
@Override
386409
public Blob apply(BlobInfo blobInfo) {

0 commit comments

Comments
 (0)