Skip to content

Commit a2c8b39

Browse files
committed
Fix comments. Make JobConfiguration an abstract class
1 parent 84402ac commit a2c8b39

23 files changed

Lines changed: 808 additions & 437 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
666666

667667
/**
668668
* Returns a channel to write data to be inserted into a BigQuery table. Data format and other
669-
* options can be configured using the {@link LoadConfiguration} parameter.
669+
* options can be configured using the {@link WriteChannelConfiguration} parameter.
670670
*
671671
* @throws BigQueryException upon failure
672672
*/
673-
TableDataWriteChannel writer(LoadConfiguration loadConfiguration);
673+
TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration);
674674
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ private static QueryResult.Builder transformQueryResults(JobId jobId, List<Table
596596
.results(transformTableData(rowsPb));
597597
}
598598

599-
public TableDataWriteChannel writer(LoadConfiguration loadConfiguration) {
600-
return new TableDataWriteChannel(options(), setProjectId(loadConfiguration));
599+
public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration) {
600+
return new TableDataWriteChannel(options(), setProjectId(writeChannelConfiguration));
601601
}
602602

603603
private Map<BigQueryRpc.Option, ?> optionMap(Option... options) {
@@ -681,7 +681,7 @@ public TableId apply(TableId tableId) {
681681
break;
682682
case LOAD:
683683
LoadJobConfiguration loadConfiguration = (LoadJobConfiguration) configuration;
684-
jobBuilder.configuration((LoadJobConfiguration) setProjectId(loadConfiguration));
684+
jobBuilder.configuration(setProjectId(loadConfiguration));
685685
break;
686686
default:
687687
// never reached
@@ -698,9 +698,10 @@ private QueryRequest setProjectId(QueryRequest request) {
698698
return builder.build();
699699
}
700700

701-
private LoadConfiguration setProjectId(LoadConfiguration configuration) {
701+
@SuppressWarnings("unchecked")
702+
private <T extends LoadConfiguration> T setProjectId(T configuration) {
702703
LoadConfiguration.Builder builder = configuration.toBuilder();
703704
builder.destinationTable(setProjectId(configuration.destinationTable()));
704-
return builder.build();
705+
return (T) builder.build();
705706
}
706707
}

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
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+
117
package com.google.gcloud.bigquery;
218

319
import static com.google.common.base.Preconditions.checkNotNull;
420

521
import com.google.api.services.bigquery.model.JobConfigurationTableCopy;
6-
import com.google.common.base.MoreObjects;
22+
import com.google.common.base.MoreObjects.ToStringHelper;
723
import com.google.common.collect.ImmutableList;
824
import com.google.common.collect.Lists;
925

10-
import java.io.Serializable;
1126
import java.util.List;
1227
import 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();

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Google Inc. All Rights Reserved.
2+
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,19 +19,18 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

2121
import com.google.api.services.bigquery.model.JobConfigurationExtract;
22-
import com.google.common.base.MoreObjects;
22+
import com.google.common.base.MoreObjects.ToStringHelper;
2323
import com.google.common.collect.ImmutableList;
2424

25-
import java.io.Serializable;
2625
import java.util.List;
2726
import java.util.Objects;
2827

2928
/**
30-
* Google BigQuery Extract Job configuration. An Extract Job exports a BigQuery table to Google
29+
* Google BigQuery extract job configuration. An extract job exports a BigQuery table to Google
3130
* Cloud Storage. The extract destination provided as URIs that point to objects in Google Cloud
32-
* Storage.
31+
* Storage. Extract job configurations have {@link JobConfiguration.Type#EXTRACT} type.
3332
*/
34-
public final class ExtractJobConfiguration implements JobConfiguration, Serializable {
33+
public final class ExtractJobConfiguration extends JobConfiguration {
3534

3635
private static final long serialVersionUID = 4147749733166593761L;
3736

@@ -42,7 +41,8 @@ public final class ExtractJobConfiguration implements JobConfiguration, Seriali
4241
private final String format;
4342
private final String compression;
4443

45-
public static final class Builder {
44+
public static final class Builder
45+
extends JobConfiguration.Builder<ExtractJobConfiguration, Builder> {
4646

4747
private TableId sourceTable;
4848
private List<String> destinationUris;
@@ -51,9 +51,12 @@ public static final class Builder {
5151
private String format;
5252
private String compression;
5353

54-
private Builder() {}
54+
private Builder() {
55+
super(Type.EXTRACT);
56+
}
5557

5658
private Builder(ExtractJobConfiguration jobInfo) {
59+
super(Type.EXTRACT);
5760
this.sourceTable = jobInfo.sourceTable;
5861
this.destinationUris = jobInfo.destinationUris;
5962
this.printHeader = jobInfo.printHeader;
@@ -63,6 +66,7 @@ private Builder(ExtractJobConfiguration jobInfo) {
6366
}
6467

6568
private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
69+
super(Type.EXTRACT);
6670
JobConfigurationExtract extractConfigurationPb = configurationPb.getExtract();
6771
this.sourceTable = TableId.fromPb(extractConfigurationPb.getSourceTable());
6872
this.destinationUris = extractConfigurationPb.getDestinationUris();
@@ -134,6 +138,7 @@ public ExtractJobConfiguration build() {
134138
}
135139

136140
private ExtractJobConfiguration(Builder builder) {
141+
super(builder);
137142
this.sourceTable = checkNotNull(builder.sourceTable);
138143
this.destinationUris = checkNotNull(builder.destinationUris);
139144
this.printHeader = builder.printHeader;
@@ -142,11 +147,6 @@ private ExtractJobConfiguration(Builder builder) {
142147
this.compression = builder.compression;
143148
}
144149

145-
@Override
146-
public Type type() {
147-
return Type.EXTRACT;
148-
}
149-
150150
/**
151151
* Returns the table to export.
152152
*/
@@ -193,31 +193,30 @@ public String compression() {
193193
return compression;
194194
}
195195

196+
@Override
196197
public Builder toBuilder() {
197198
return new Builder(this);
198199
}
199200

200201
@Override
201-
public String toString() {
202-
return MoreObjects.toStringHelper(this)
202+
protected ToStringHelper toStringHelper() {
203+
return super.toStringHelper()
203204
.add("sourceTable", sourceTable)
204205
.add("destinationUris", destinationUris)
205206
.add("format", format)
206207
.add("printHeader", printHeader)
207208
.add("fieldDelimiter", fieldDelimiter)
208-
.add("compression", compression)
209-
.toString();
209+
.add("compression", compression);
210210
}
211211

212212
@Override
213213
public boolean equals(Object obj) {
214-
return obj instanceof ExtractJobConfiguration
215-
&& Objects.equals(toPb(), ((ExtractJobConfiguration) obj).toPb());
214+
return obj instanceof ExtractJobConfiguration && baseEquals((ExtractJobConfiguration) obj);
216215
}
217216

218217
@Override
219218
public int hashCode() {
220-
return Objects.hash(sourceTable, destinationUris, printHeader, fieldDelimiter,
219+
return Objects.hash(baseHashCode(), sourceTable, destinationUris, printHeader, fieldDelimiter,
221220
format, compression);
222221
}
223222

@@ -281,6 +280,7 @@ public static ExtractJobConfiguration of(TableId sourceTable, List<String> desti
281280
return builder(sourceTable, destinationUris).format(format).build();
282281
}
283282

283+
@SuppressWarnings("unchecked")
284284
static ExtractJobConfiguration fromPb(
285285
com.google.api.services.bigquery.model.JobConfiguration confPb) {
286286
return new Builder(confPb).build();

0 commit comments

Comments
 (0)