Skip to content

Commit e4a5e55

Browse files
committed
Add DatasetInfo, DatasetId, TableId and Acl models and tests
1 parent 120fe12 commit e4a5e55

8 files changed

Lines changed: 1343 additions & 0 deletions

File tree

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

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 com.google.api.services.bigquery.model.DatasetReference;
20+
import static com.google.common.base.Preconditions.checkNotNull;
21+
22+
import java.io.Serializable;
23+
import java.util.Objects;
24+
25+
/**
26+
* Google BigQuery Dataset identity.
27+
*/
28+
public class DatasetId implements Serializable {
29+
30+
private static final long serialVersionUID = -6186254820908152300L;
31+
32+
private final String project;
33+
private final String dataset;
34+
35+
/**
36+
* Returns project's user-defined id
37+
*/
38+
public String project() {
39+
return project;
40+
}
41+
42+
/**
43+
* Returns dataset's user-defined id.
44+
*/
45+
public String dataset() {
46+
return dataset;
47+
}
48+
49+
private DatasetId(String project, String dataset) {
50+
this.project = project;
51+
this.dataset = dataset;
52+
}
53+
54+
/**
55+
* Creates a dataset identity given project's and dataset's user-defined ids.
56+
*/
57+
public static DatasetId of(String project, String dataset) {
58+
return new DatasetId(checkNotNull(project), checkNotNull(dataset));
59+
}
60+
61+
/**
62+
* Creates a dataset identity given only its user-defined id.
63+
*/
64+
public static DatasetId of(String dataset) {
65+
return new DatasetId(null, checkNotNull(dataset));
66+
}
67+
68+
@Override
69+
public boolean equals(Object obj) {
70+
return obj instanceof DatasetId && Objects.equals(toPb(), ((DatasetId) obj).toPb());
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(project, dataset);
76+
}
77+
78+
@Override
79+
public String toString() {
80+
return toPb().toString();
81+
}
82+
83+
public DatasetReference toPb() {
84+
return new DatasetReference().setProjectId(project).setDatasetId(dataset);
85+
}
86+
87+
public static DatasetId fromPb(DatasetReference datasetRef) {
88+
return new DatasetId(
89+
datasetRef.getProjectId(),
90+
datasetRef.getDatasetId());
91+
}
92+
}

0 commit comments

Comments
 (0)