Skip to content

Commit 4f05b98

Browse files
committed
Merge pull request #417 from mziccard/bigquery
DatasetInfo, DatasetId, TableId and Acl models and tests
2 parents 762fa58 + 3f0d511 commit 4f05b98

9 files changed

Lines changed: 1514 additions & 0 deletions

File tree

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

Lines changed: 436 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.api.services.bigquery.model.DatasetReference;
22+
23+
import java.io.Serializable;
24+
import java.util.Objects;
25+
26+
/**
27+
* Google BigQuery Dataset identity.
28+
*/
29+
public class DatasetId implements Serializable {
30+
31+
private static final long serialVersionUID = -6186254820908152300L;
32+
33+
private final String project;
34+
private final String dataset;
35+
36+
/**
37+
* Returns project's user-defined id
38+
*/
39+
public String project() {
40+
return project;
41+
}
42+
43+
/**
44+
* Returns dataset's user-defined id.
45+
*/
46+
public String dataset() {
47+
return dataset;
48+
}
49+
50+
private DatasetId(String project, String dataset) {
51+
this.project = project;
52+
this.dataset = dataset;
53+
}
54+
55+
/**
56+
* Creates a dataset identity given project's and dataset's user-defined ids.
57+
*/
58+
public static DatasetId of(String project, String dataset) {
59+
return new DatasetId(checkNotNull(project), checkNotNull(dataset));
60+
}
61+
62+
/**
63+
* Creates a dataset identity given only its user-defined id.
64+
*/
65+
public static DatasetId of(String dataset) {
66+
return new DatasetId(null, checkNotNull(dataset));
67+
}
68+
69+
@Override
70+
public boolean equals(Object obj) {
71+
return obj instanceof DatasetId && Objects.equals(toPb(), ((DatasetId) obj).toPb());
72+
}
73+
74+
@Override
75+
public int hashCode() {
76+
return Objects.hash(project, dataset);
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return toPb().toString();
82+
}
83+
84+
public DatasetReference toPb() {
85+
return new DatasetReference().setProjectId(project).setDatasetId(dataset);
86+
}
87+
88+
public static DatasetId fromPb(DatasetReference datasetRef) {
89+
return new DatasetId(
90+
datasetRef.getProjectId(),
91+
datasetRef.getDatasetId());
92+
}
93+
}

0 commit comments

Comments
 (0)