Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename load to get in functional classes #535

Merged
merged 1 commit into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ import java.nio.channels.WritableByteChannel;

Storage storage = StorageOptions.defaultInstance().service();
BlobId blobId = BlobId.of("bucket", "blob_name");
Blob blob = Blob.load(storage, blobId);
Blob blob = Blob.get(storage, blobId);
if (blob == null) {
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Dataset(BigQuery bigquery, DatasetInfo info) {
* @return the {@code Dataset} object or {@code null} if not found
* @throws BigQueryException upon failure
*/
public static Dataset load(BigQuery bigquery, String dataset, BigQuery.DatasetOption... options) {
public static Dataset get(BigQuery bigquery, String dataset, BigQuery.DatasetOption... options) {
DatasetInfo info = bigquery.getDataset(dataset, options);
return info != null ? new Dataset(bigquery, info) : null;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ public boolean exists() {
* @throws BigQueryException upon failure
*/
public Dataset reload(BigQuery.DatasetOption... options) {
return Dataset.load(bigquery, info.datasetId().dataset(), options);
return Dataset.get(bigquery, info.datasetId().dataset(), options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Job(BigQuery bigquery, JobInfo info) {
* @return the {@code Job} object or {@code null} if not found
* @throws BigQueryException upon failure
*/
public static Job load(BigQuery bigquery, String job, BigQuery.JobOption... options) {
public static Job get(BigQuery bigquery, String job, BigQuery.JobOption... options) {
JobInfo info = bigquery.getJob(job, options);
return info != null ? new Job(bigquery, info) : null;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public boolean isDone() {
* @throws BigQueryException upon failure
*/
public Job reload(BigQuery.JobOption... options) {
return Job.load(bigquery, info.jobId().job(), options);
return Job.get(bigquery, info.jobId().job(), options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public Table(BigQuery bigquery, BaseTableInfo info) {
* @return the {@code Table} object or {@code null} if not found
* @throws BigQueryException upon failure
*/
public static Table load(BigQuery bigquery, String dataset, String table,
public static Table get(BigQuery bigquery, String dataset, String table,
BigQuery.TableOption... options) {
return load(bigquery, TableId.of(dataset, table), options);
return get(bigquery, TableId.of(dataset, table), options);
}

/**
Expand All @@ -76,7 +76,7 @@ public static Table load(BigQuery bigquery, String dataset, String table,
* @return the {@code Table} object or {@code null} if not found
* @throws BigQueryException upon failure
*/
public static Table load(BigQuery bigquery, TableId table, BigQuery.TableOption... options) {
public static Table get(BigQuery bigquery, TableId table, BigQuery.TableOption... options) {
BaseTableInfo info = bigquery.getTable(table, options);
return info != null ? new Table(bigquery, info) : null;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public boolean exists() {
* @throws BigQueryException upon failure
*/
public Table reload(BigQuery.TableOption... options) {
return Table.load(bigquery, info.tableId(), options);
return Table.get(bigquery, info.tableId(), options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,27 @@ public void testCreateExternalTableWithOptions() throws Exception {
}

@Test
public void testLoad() throws Exception {
public void testStaticGet() throws Exception {
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset())).andReturn(DATASET_INFO);
replay(bigquery);
Dataset loadedDataset = Dataset.load(bigquery, DATASET_INFO.datasetId().dataset());
Dataset loadedDataset = Dataset.get(bigquery, DATASET_INFO.datasetId().dataset());
assertNotNull(loadedDataset);
assertEquals(DATASET_INFO, loadedDataset.info());
}

@Test
public void testLoadNull() throws Exception {
public void testStaticGetNull() throws Exception {
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset())).andReturn(null);
replay(bigquery);
assertNull(Dataset.load(bigquery, DATASET_INFO.datasetId().dataset()));
assertNull(Dataset.get(bigquery, DATASET_INFO.datasetId().dataset()));
}

@Test
public void testLoadWithOptions() throws Exception {
public void testStaticGetWithOptions() throws Exception {
expect(bigquery.getDataset(DATASET_INFO.datasetId().dataset(), BigQuery.DatasetOption.fields()))
.andReturn(DATASET_INFO);
replay(bigquery);
Dataset loadedDataset = Dataset.load(bigquery, DATASET_INFO.datasetId().dataset(),
Dataset loadedDataset = Dataset.get(bigquery, DATASET_INFO.datasetId().dataset(),
BigQuery.DatasetOption.fields());
assertNotNull(loadedDataset);
assertEquals(DATASET_INFO, loadedDataset.info());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,27 @@ public void testCancel() throws Exception {
}

@Test
public void testLoad() throws Exception {
public void testGet() throws Exception {
expect(bigquery.getJob(JOB_INFO.jobId().job())).andReturn(JOB_INFO);
replay(bigquery);
Job loadedJob = Job.load(bigquery, JOB_INFO.jobId().job());
Job loadedJob = Job.get(bigquery, JOB_INFO.jobId().job());
assertNotNull(loadedJob);
assertEquals(JOB_INFO, loadedJob.info());
}

@Test
public void testLoadNull() throws Exception {
public void testGetNull() throws Exception {
expect(bigquery.getJob(JOB_INFO.jobId().job())).andReturn(null);
replay(bigquery);
assertNull(Job.load(bigquery, JOB_INFO.jobId().job()));
assertNull(Job.get(bigquery, JOB_INFO.jobId().job()));
}

@Test
public void testLoadWithOptions() throws Exception {
public void testGetWithOptions() throws Exception {
expect(bigquery.getJob(JOB_INFO.jobId().job(), BigQuery.JobOption.fields()))
.andReturn(JOB_INFO);
replay(bigquery);
Job loadedJob = Job.load(bigquery, JOB_INFO.jobId().job(), BigQuery.JobOption.fields());
Job loadedJob = Job.get(bigquery, JOB_INFO.jobId().job(), BigQuery.JobOption.fields());
assertNotNull(loadedJob);
assertEquals(JOB_INFO, loadedJob.info());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,54 +292,54 @@ public void testExtractDataUris() throws Exception {
}

@Test
public void testLoadFromId() throws Exception {
public void testGetFromId() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(TABLE_INFO);
replay(bigquery);
Table loadedTable = Table.load(bigquery, TABLE_INFO.tableId());
Table loadedTable = Table.get(bigquery, TABLE_INFO.tableId());
assertNotNull(loadedTable);
assertEquals(TABLE_INFO, loadedTable.info());
}

@Test
public void testLoadFromStrings() throws Exception {
public void testGetFromStrings() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(TABLE_INFO);
replay(bigquery);
Table loadedTable = Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table());
Table loadedTable = Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table());
assertNotNull(loadedTable);
assertEquals(TABLE_INFO, loadedTable.info());
}

@Test
public void testLoadFromIdNull() throws Exception {
public void testGetFromIdNull() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(null);
replay(bigquery);
assertNull(Table.load(bigquery, TABLE_INFO.tableId()));
assertNull(Table.get(bigquery, TABLE_INFO.tableId()));
}

@Test
public void testLoadFromStringsNull() throws Exception {
public void testGetFromStringsNull() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId())).andReturn(null);
replay(bigquery);
assertNull(Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table()));
assertNull(Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table()));
}

@Test
public void testLoadFromIdWithOptions() throws Exception {
public void testGetFromIdWithOptions() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId(), BigQuery.TableOption.fields()))
.andReturn(TABLE_INFO);
replay(bigquery);
Table loadedTable = Table.load(bigquery, TABLE_INFO.tableId(), BigQuery.TableOption.fields());
Table loadedTable = Table.get(bigquery, TABLE_INFO.tableId(), BigQuery.TableOption.fields());
assertNotNull(loadedTable);
assertEquals(TABLE_INFO, loadedTable.info());
}

@Test
public void testLoadFromStringsWithOptions() throws Exception {
public void testGetFromStringsWithOptions() throws Exception {
expect(bigquery.getTable(TABLE_INFO.tableId(), BigQuery.TableOption.fields()))
.andReturn(TABLE_INFO);
replay(bigquery);
Table loadedTable =
Table.load(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table(), BigQuery.TableOption.fields());
Table.get(bigquery, TABLE_ID1.dataset(), TABLE_ID1.table(), BigQuery.TableOption.fields());
assertNotNull(loadedTable);
assertEquals(TABLE_INFO, loadedTable.info());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ public void run(Storage storage, BlobId... blobIds) {
if (blobIds.length == 1) {
if (blobIds[0].name().isEmpty()) {
// get Bucket
Bucket bucket = Bucket.load(storage, blobIds[0].bucket());
Bucket bucket = Bucket.get(storage, blobIds[0].bucket());
if (bucket == null) {
System.out.println("No such bucket");
return;
}
System.out.println("Bucket info: " + bucket.info());
} else {
// get Blob
Blob blob = Blob.load(storage, blobIds[0]);
Blob blob = Blob.get(storage, blobIds[0]);
if (blob == null) {
System.out.println("No such object");
return;
Expand All @@ -151,7 +151,7 @@ public void run(Storage storage, BlobId... blobIds) {
}
} else {
// use batch to get multiple blobs.
List<Blob> blobs = Blob.get(storage, blobIds);
List<Blob> blobs = Blob.get(storage, Arrays.asList(blobIds));
for (Blob blob : blobs) {
if (blob != null) {
System.out.println(blob.info());
Expand Down Expand Up @@ -225,7 +225,7 @@ public void run(Storage storage, String bucketName) {
}
} else {
// list a bucket's blobs
Bucket bucket = Bucket.load(storage, bucketName);
Bucket bucket = Bucket.get(storage, bucketName);
if (bucket == null) {
System.out.println("No such bucket");
return;
Expand Down Expand Up @@ -312,7 +312,7 @@ public void run(Storage storage, Tuple<BlobId, Path> tuple) throws IOException {
}

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

private void run(Storage storage, BlobId blobId, Map<String, String> metadata) {
Blob blob = Blob.load(storage, blobId);
Blob blob = Blob.get(storage, blobId);
if (blob == null) {
System.out.println("No such object");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public Project(ResourceManager resourceManager, ProjectInfo projectInfo) {
}

/**
* Constructs a Project object that contains project information loaded from the server.
* Constructs a Project object that contains project information got from the server.
*
* @return Project object containing the project's metadata or {@code null} if not found
* @throws ResourceManagerException upon failure
*/
public static Project load(ResourceManager resourceManager, String projectId) {
public static Project get(ResourceManager resourceManager, String projectId) {
ProjectInfo projectInfo = resourceManager.get(projectId);
return projectInfo != null ? new Project(resourceManager, projectInfo) : null;
}
Expand All @@ -72,7 +72,7 @@ public ResourceManager resourceManager() {
* @throws ResourceManagerException upon failure
*/
public Project reload() {
return Project.load(resourceManager, info.projectId());
return Project.get(resourceManager, info.projectId());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void tearDown() throws Exception {
public void testLoad() {
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(PROJECT_INFO);
replay(resourceManager);
Project loadedProject = Project.load(resourceManager, PROJECT_INFO.projectId());
Project loadedProject = Project.get(resourceManager, PROJECT_INFO.projectId());
assertEquals(PROJECT_INFO, loadedProject.info());
}

Expand All @@ -84,15 +84,15 @@ public void testReload() {
public void testLoadNull() {
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
replay(resourceManager);
assertNull(Project.load(resourceManager, PROJECT_INFO.projectId()));
assertNull(Project.get(resourceManager, PROJECT_INFO.projectId()));
}

@Test
public void testReloadDeletedProject() {
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(PROJECT_INFO);
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
replay(resourceManager);
Project loadedProject = Project.load(resourceManager, PROJECT_INFO.projectId());
Project loadedProject = Project.get(resourceManager, PROJECT_INFO.projectId());
assertNotNull(loadedProject);
Project reloadedProject = loadedProject.reload();
assertNull(reloadedProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gcloud.spi.StorageRpc;
import com.google.gcloud.storage.Storage.BlobTargetOption;
Expand Down Expand Up @@ -165,9 +166,9 @@ public Blob(Storage storage, BlobInfo info) {
* @return the {@code Blob} object or {@code null} if not found
* @throws StorageException upon failure
*/
public static Blob load(Storage storage, String bucket, String blob,
public static Blob get(Storage storage, String bucket, String blob,
Storage.BlobGetOption... options) {
return load(storage, BlobId.of(bucket, blob), options);
return get(storage, BlobId.of(bucket, blob), options);
}

/**
Expand All @@ -180,7 +181,7 @@ public static Blob load(Storage storage, String bucket, String blob,
* @return the {@code Blob} object or {@code null} if not found
* @throws StorageException upon failure
*/
public static Blob load(Storage storage, BlobId blobId, Storage.BlobGetOption... options) {
public static Blob get(Storage storage, BlobId blobId, Storage.BlobGetOption... options) {
BlobInfo info = storage.get(blobId, options);
return info != null ? new Blob(storage, info) : null;
}
Expand Down Expand Up @@ -231,7 +232,7 @@ public byte[] content(Storage.BlobSourceOption... options) {
* @throws StorageException upon failure
*/
public Blob reload(BlobSourceOption... options) {
return Blob.load(storage, info.blobId(), toGetOptions(info, options));
return Blob.get(storage, info.blobId(), toGetOptions(info, options));
}

/**
Expand Down Expand Up @@ -369,18 +370,40 @@ public Storage storage() {
* Gets the requested blobs. A batch request is used to fetch blobs.
*
* @param storage the storage service used to issue the request
* @param blobs the blobs to get
* @param first the first blob to get
* @param second the second blob to get
* @param other other blobs to get
* @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has
* been denied the corresponding item in the list is {@code null}
* @throws StorageException upon failure
*/
public static List<Blob> get(final Storage storage, BlobId... blobs) {
public static List<Blob> get(Storage storage, BlobId first, BlobId second, BlobId... other) {
checkNotNull(storage);
checkNotNull(first);
checkNotNull(second);
checkNotNull(other);
ImmutableList<BlobId> blobs = ImmutableList.<BlobId>builder()
.add(first)
.add(second)
.addAll(Arrays.asList(other))
.build();
return get(storage, blobs);
}

/**
* Gets the requested blobs. A batch request is used to fetch blobs.
*
* @param storage the storage service used to issue the request
* @param blobs list of blobs to get
* @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has
* been denied the corresponding item in the list is {@code null}
* @throws StorageException upon failure
*/
public static List<Blob> get(final Storage storage, List<BlobId> blobs) {
checkNotNull(storage);
checkNotNull(blobs);
if (blobs.length == 0) {
return Collections.emptyList();
}
return Collections.unmodifiableList(Lists.transform(storage.get(blobs),
BlobId[] blobArray = blobs.toArray(new BlobId[blobs.size()]);
return Collections.unmodifiableList(Lists.transform(storage.get(blobArray),
new Function<BlobInfo, Blob>() {
@Override
public Blob apply(BlobInfo blobInfo) {
Expand Down
Loading