1+ /*
2+ * Copyright 2016 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+
117package com .google .gcloud .bigquery ;
218
319import static com .google .common .base .Preconditions .checkNotNull ;
420
521import com .google .api .services .bigquery .model .JobConfigurationTableCopy ;
6- import com .google .common .base .MoreObjects ;
22+ import com .google .common .base .MoreObjects . ToStringHelper ;
723import com .google .common .collect .ImmutableList ;
824import com .google .common .collect .Lists ;
925
10- import java .io .Serializable ;
1126import java .util .List ;
1227import java .util .Objects ;
1328
1429/**
15- * Google BigQuery Copy Job configuration. A Copy Job copies an existing table to another new or
16- * existing table.
30+ * Google BigQuery copy job configuration. A copy job copies an existing table to another new or
31+ * existing table. Copy job configurations have {@link JobConfiguration.Type#COPY} type.
1732 */
18- public final class CopyJobConfiguration implements JobConfiguration , Serializable {
33+ public final class CopyJobConfiguration extends JobConfiguration {
1934
2035 private static final long serialVersionUID = 1140509641399762967L ;
2136
@@ -24,23 +39,28 @@ public final class CopyJobConfiguration implements JobConfiguration, Serializabl
2439 private final JobInfo .CreateDisposition createDisposition ;
2540 private final JobInfo .WriteDisposition writeDisposition ;
2641
27- public static final class Builder {
42+ public static final class Builder
43+ extends JobConfiguration .Builder <CopyJobConfiguration , Builder > {
2844
2945 private List <TableId > sourceTables ;
3046 private TableId destinationTable ;
3147 private JobInfo .CreateDisposition createDisposition ;
3248 private JobInfo .WriteDisposition writeDisposition ;
3349
34- private Builder () {}
50+ private Builder () {
51+ super (Type .COPY );
52+ }
3553
3654 private Builder (CopyJobConfiguration jobConfiguration ) {
55+ super (Type .COPY );
3756 this .sourceTables = jobConfiguration .sourceTables ;
3857 this .destinationTable = jobConfiguration .destinationTable ;
3958 this .createDisposition = jobConfiguration .createDisposition ;
4059 this .writeDisposition = jobConfiguration .writeDisposition ;
4160 }
4261
4362 private Builder (com .google .api .services .bigquery .model .JobConfiguration configurationPb ) {
63+ super (Type .COPY );
4464 JobConfigurationTableCopy copyConfigurationPb = configurationPb .getCopy ();
4565 this .destinationTable = TableId .fromPb (copyConfigurationPb .getDestinationTable ());
4666 if (copyConfigurationPb .getSourceTables () != null ) {
@@ -103,17 +123,13 @@ public CopyJobConfiguration build() {
103123 }
104124
105125 private CopyJobConfiguration (Builder builder ) {
126+ super (builder );
106127 this .sourceTables = checkNotNull (builder .sourceTables );
107128 this .destinationTable = checkNotNull (builder .destinationTable );
108129 this .createDisposition = builder .createDisposition ;
109130 this .writeDisposition = builder .writeDisposition ;
110131 }
111132
112- @ Override
113- public Type type () {
114- return Type .COPY ;
115- }
116-
117133 /**
118134 * Returns the source tables to copy.
119135 */
@@ -148,29 +164,29 @@ public JobInfo.WriteDisposition writeDisposition() {
148164 return writeDisposition ;
149165 }
150166
167+ @ Override
151168 public Builder toBuilder () {
152169 return new Builder (this );
153170 }
154171
155172 @ Override
156- public String toString () {
157- return MoreObjects .toStringHelper (this )
173+ protected ToStringHelper toStringHelper () {
174+ return super .toStringHelper ()
158175 .add ("sourceTables" , sourceTables )
159176 .add ("destinationTable" , destinationTable )
160177 .add ("createDisposition" , createDisposition )
161- .add ("writeDisposition" , writeDisposition )
162- .toString ();
178+ .add ("writeDisposition" , writeDisposition );
163179 }
164180
165181 @ Override
166182 public boolean equals (Object obj ) {
167- return obj instanceof CopyJobConfiguration
168- && Objects .equals (toPb (), ((CopyJobConfiguration ) obj ).toPb ());
183+ return obj instanceof CopyJobConfiguration && baseEquals ((CopyJobConfiguration ) obj );
169184 }
170185
171186 @ Override
172187 public int hashCode () {
173- return Objects .hash (sourceTables , destinationTable , createDisposition , writeDisposition );
188+ return Objects .hash (baseHashCode (), sourceTables , destinationTable , createDisposition ,
189+ writeDisposition );
174190 }
175191
176192 com .google .api .services .bigquery .model .JobConfiguration toPb () {
@@ -218,6 +234,7 @@ public static CopyJobConfiguration of(TableId destinationTable, List<TableId> so
218234 return builder (destinationTable , sourceTables ).build ();
219235 }
220236
237+ @ SuppressWarnings ("unchecked" )
221238 static CopyJobConfiguration fromPb (
222239 com .google .api .services .bigquery .model .JobConfiguration jobPb ) {
223240 return new Builder (jobPb ).build ();
0 commit comments