38
38
import com .google .gcloud .ExceptionHandler .Interceptor ;
39
39
import com .google .gcloud .Page ;
40
40
import com .google .gcloud .PageImpl ;
41
+ import com .google .gcloud .PageImpl .NextPageFetcher ;
41
42
import com .google .gcloud .RetryHelper ;
42
43
import com .google .gcloud .bigquery .InsertAllRequest .RowToInsert ;
43
44
import com .google .gcloud .spi .BigQueryRpc ;
@@ -66,39 +67,20 @@ public RetryResult beforeEval(Exception exception) {
66
67
return Interceptor .RetryResult .CONTINUE_EVALUATION ;
67
68
}
68
69
};
69
- static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler .builder ()
70
+ private static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler .builder ()
70
71
.abortOn (RuntimeException .class ).interceptor (EXCEPTION_HANDLER_INTERCEPTOR ).build ();
71
72
72
- private abstract static class BasePageFetcher < T > implements PageImpl . NextPageFetcher <T > {
73
+ private static class DatasetPageFetcher implements NextPageFetcher <DatasetInfo > {
73
74
74
- private static final long serialVersionUID = -338124488600215401L ;
75
-
76
- protected final Map <BigQueryRpc .Option , ?> requestOptions ;
77
- protected final BigQueryOptions serviceOptions ;
78
-
79
- BasePageFetcher (BigQueryOptions serviceOptions , String cursor ,
80
- Map <BigQueryRpc .Option , ?> optionMap ) {
81
- this .serviceOptions = serviceOptions ;
82
- ImmutableMap .Builder <BigQueryRpc .Option , Object > builder = ImmutableMap .builder ();
83
- if (cursor != null ) {
84
- builder .put (BigQueryRpc .Option .PAGE_TOKEN , cursor );
85
- }
86
- for (Map .Entry <BigQueryRpc .Option , ?> option : optionMap .entrySet ()) {
87
- if (option .getKey () != BigQueryRpc .Option .PAGE_TOKEN ) {
88
- builder .put (option .getKey (), option .getValue ());
89
- }
90
- }
91
- this .requestOptions = builder .build ();
92
- }
93
- }
94
-
95
- private static class DatasetPageFetcher extends BasePageFetcher <DatasetInfo > {
96
-
97
- private static final long serialVersionUID = 3030824397616608646L ;
75
+ private static final long serialVersionUID = -3057564042439021278L ;
76
+ private final Map <BigQueryRpc .Option , ?> requestOptions ;
77
+ private final BigQueryOptions serviceOptions ;
98
78
99
79
DatasetPageFetcher (BigQueryOptions serviceOptions , String cursor ,
100
80
Map <BigQueryRpc .Option , ?> optionMap ) {
101
- super (serviceOptions , cursor , optionMap );
81
+ this .requestOptions =
82
+ PageImpl .nextRequestOptions (BigQueryRpc .Option .PAGE_TOKEN , cursor , optionMap );
83
+ this .serviceOptions = serviceOptions ;
102
84
}
103
85
104
86
@ Override
@@ -107,14 +89,18 @@ public Page<DatasetInfo> nextPage() {
107
89
}
108
90
}
109
91
110
- private static class TablePageFetcher extends BasePageFetcher <BaseTableInfo > {
92
+ private static class TablePageFetcher implements NextPageFetcher <BaseTableInfo > {
111
93
112
- private static final long serialVersionUID = 5908129355985236115L ;
94
+ private static final long serialVersionUID = 8611248840504201187L ;
95
+ private final Map <BigQueryRpc .Option , ?> requestOptions ;
96
+ private final BigQueryOptions serviceOptions ;
113
97
private final String dataset ;
114
98
115
99
TablePageFetcher (String dataset , BigQueryOptions serviceOptions , String cursor ,
116
100
Map <BigQueryRpc .Option , ?> optionMap ) {
117
- super (serviceOptions , cursor , optionMap );
101
+ this .requestOptions =
102
+ PageImpl .nextRequestOptions (BigQueryRpc .Option .PAGE_TOKEN , cursor , optionMap );
103
+ this .serviceOptions = serviceOptions ;
118
104
this .dataset = dataset ;
119
105
}
120
106
@@ -124,13 +110,17 @@ public Page<BaseTableInfo> nextPage() {
124
110
}
125
111
}
126
112
127
- private static class JobPageFetcher extends BasePageFetcher <JobInfo > {
113
+ private static class JobPageFetcher implements NextPageFetcher <JobInfo > {
128
114
129
- private static final long serialVersionUID = -4984845360519279880L ;
115
+ private static final long serialVersionUID = 8536533282558245472L ;
116
+ private final Map <BigQueryRpc .Option , ?> requestOptions ;
117
+ private final BigQueryOptions serviceOptions ;
130
118
131
119
JobPageFetcher (BigQueryOptions serviceOptions , String cursor ,
132
120
Map <BigQueryRpc .Option , ?> optionMap ) {
133
- super (serviceOptions , cursor , optionMap );
121
+ this .requestOptions =
122
+ PageImpl .nextRequestOptions (BigQueryRpc .Option .PAGE_TOKEN , cursor , optionMap );
123
+ this .serviceOptions = serviceOptions ;
134
124
}
135
125
136
126
@ Override
@@ -139,14 +129,18 @@ public Page<JobInfo> nextPage() {
139
129
}
140
130
}
141
131
142
- private static class TableDataPageFetcher extends BasePageFetcher <List <FieldValue >> {
132
+ private static class TableDataPageFetcher implements NextPageFetcher <List <FieldValue >> {
143
133
144
- private static final long serialVersionUID = 1281938239570262432L ;
134
+ private static final long serialVersionUID = -8501991114794410114L ;
135
+ private final Map <BigQueryRpc .Option , ?> requestOptions ;
136
+ private final BigQueryOptions serviceOptions ;
145
137
private final TableId table ;
146
138
147
139
TableDataPageFetcher (TableId table , BigQueryOptions serviceOptions , String cursor ,
148
140
Map <BigQueryRpc .Option , ?> optionMap ) {
149
- super (serviceOptions , cursor , optionMap );
141
+ this .requestOptions =
142
+ PageImpl .nextRequestOptions (BigQueryRpc .Option .PAGE_TOKEN , cursor , optionMap );
143
+ this .serviceOptions = serviceOptions ;
150
144
this .table = table ;
151
145
}
152
146
@@ -156,15 +150,19 @@ public Page<List<FieldValue>> nextPage() {
156
150
}
157
151
}
158
152
159
- private static class QueryResultsPageFetcherImpl extends BasePageFetcher < List < FieldValue >>
160
- implements QueryResult .QueryResultsPageFetcher {
153
+ private static class QueryResultsPageFetcherImpl
154
+ implements NextPageFetcher < List < FieldValue >>, QueryResult .QueryResultsPageFetcher {
161
155
162
- private static final long serialVersionUID = 6713948754731557486L ;
156
+ private static final long serialVersionUID = -9198905840550459803L ;
157
+ private final Map <BigQueryRpc .Option , ?> requestOptions ;
158
+ private final BigQueryOptions serviceOptions ;
163
159
private final JobId job ;
164
160
165
161
QueryResultsPageFetcherImpl (JobId job , BigQueryOptions serviceOptions , String cursor ,
166
162
Map <BigQueryRpc .Option , ?> optionMap ) {
167
- super (serviceOptions , cursor , optionMap );
163
+ this .requestOptions =
164
+ PageImpl .nextRequestOptions (BigQueryRpc .Option .PAGE_TOKEN , cursor , optionMap );
165
+ this .serviceOptions = serviceOptions ;
168
166
this .job = job ;
169
167
}
170
168
0 commit comments