|
19 | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | 20 |
|
21 | 21 | import com.google.api.services.bigquery.model.JobReference; |
22 | | -import com.google.auto.value.AutoValue; |
| 22 | + |
23 | 23 | import java.io.Serializable; |
| 24 | +import java.util.Objects; |
24 | 25 | import java.util.UUID; |
25 | | -import javax.annotation.Nullable; |
26 | 26 |
|
27 | | -/** Google BigQuery Job identity. */ |
28 | | -@AutoValue |
29 | | -public abstract class JobId implements Serializable { |
| 27 | +/** |
| 28 | + * Google BigQuery Job identity. |
| 29 | + */ |
| 30 | +public final class JobId implements Serializable { |
30 | 31 |
|
31 | | - private static final long serialVersionUID = 1225914835379688977L; |
| 32 | + private static final long serialVersionUID = 1225914835379688976L; |
32 | 33 |
|
33 | | - JobId() { |
34 | | - // Users cannot extend this, but AutoValue can. |
35 | | - } |
| 34 | + private final String project; |
| 35 | + private final String job; |
36 | 36 |
|
37 | | - /** |
38 | | - * Returns job's project id. |
39 | | - * |
40 | | - * <p>When sending requests with null project, the client will attempt to infer the project name |
41 | | - * from the environment. |
42 | | - */ |
43 | | - @Nullable |
44 | | - public abstract String getProject(); |
45 | 37 |
|
46 | 38 | /** |
47 | | - * Returns the job's id. |
48 | | - * |
49 | | - * <p>The server returns null job id for dry-run queries. |
| 39 | + * Returns project's user-defined id. |
50 | 40 | */ |
51 | | - @Nullable |
52 | | - public abstract String getJob(); |
| 41 | + public String getProject() { |
| 42 | + return project; |
| 43 | + } |
| 44 | + |
53 | 45 |
|
54 | 46 | /** |
55 | | - * Returns the job's location. |
56 | | - * |
57 | | - * <p>When sending requests, the location must be specified for jobs whose location not "US" or |
58 | | - * "EU". |
| 47 | + * Returns the job's user-defined id. |
59 | 48 | */ |
60 | | - @Nullable |
61 | | - abstract String getLocation(); |
62 | | - |
63 | | - public abstract Builder toBuilder(); |
64 | | - |
65 | | - public static Builder newBuilder() { |
66 | | - return new AutoValue_JobId.Builder(); |
| 49 | + public String getJob() { |
| 50 | + return job; |
67 | 51 | } |
68 | 52 |
|
69 | | - @AutoValue.Builder |
70 | | - public abstract static class Builder { |
71 | | - public abstract Builder setProject(String project); |
72 | | - |
73 | | - public abstract Builder setJob(String job); |
74 | | - |
75 | | - /** {@code setJob} to a pseudo-random string. */ |
76 | | - public Builder setRandomJob() { |
77 | | - return setJob(UUID.randomUUID().toString()); |
78 | | - } |
79 | | - |
80 | | - abstract Builder setLocation(String location); |
81 | | - |
82 | | - public abstract JobId build(); |
| 53 | + private JobId(String project, String job) { |
| 54 | + this.project = project; |
| 55 | + this.job = job; |
83 | 56 | } |
84 | 57 |
|
85 | 58 | /** |
86 | 59 | * Creates a job identity given project's and job's user-defined id. |
87 | 60 | */ |
88 | 61 | public static JobId of(String project, String job) { |
89 | | - return newBuilder().setProject(checkNotNull(project)).setJob(checkNotNull(job)).build(); |
| 62 | + return new JobId(checkNotNull(project), checkNotNull(job)); |
90 | 63 | } |
91 | 64 |
|
92 | 65 | /** |
93 | 66 | * Creates a job identity given only its user-defined id. |
94 | 67 | */ |
95 | 68 | public static JobId of(String job) { |
96 | | - return newBuilder().setJob(checkNotNull(job)).build(); |
| 69 | + return new JobId(null, checkNotNull(job)); |
97 | 70 | } |
98 | 71 |
|
99 | 72 | /** |
100 | 73 | * Creates a job identity with autogenerated id and no project specified. |
101 | 74 | */ |
102 | 75 | public static JobId of() { |
103 | | - return newBuilder().setRandomJob().build(); |
| 76 | + return new JobId(null, UUID.randomUUID().toString()); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean equals(Object obj) { |
| 81 | + return obj == this |
| 82 | + || obj instanceof JobId |
| 83 | + && Objects.equals(toPb(), ((JobId) obj).toPb()); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public int hashCode() { |
| 88 | + return Objects.hash(project, job); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public String toString() { |
| 93 | + return toPb().toString(); |
104 | 94 | } |
105 | 95 |
|
106 | 96 | JobId setProjectId(String projectId) { |
107 | | - return getProject() != null ? this : toBuilder().setProject(projectId).build(); |
| 97 | + return getProject() != null ? this : JobId.of(projectId, getJob()); |
108 | 98 | } |
109 | 99 |
|
110 | 100 | JobReference toPb() { |
111 | | - return new JobReference() |
112 | | - .setProjectId(getProject()) |
113 | | - .setJobId(getJob()) |
114 | | - .setLocation(getLocation()); |
| 101 | + return new JobReference().setProjectId(project).setJobId(job); |
115 | 102 | } |
116 | 103 |
|
117 | 104 | static JobId fromPb(JobReference jobRef) { |
118 | | - return newBuilder() |
119 | | - .setProject(jobRef.getProjectId()) |
120 | | - .setJob(jobRef.getJobId()) |
121 | | - .setLocation(jobRef.getLocation()) |
122 | | - .build(); |
| 105 | + return new JobId(jobRef.getProjectId(), jobRef.getJobId()); |
123 | 106 | } |
124 | 107 | } |
0 commit comments