3838import com .google .gcloud .ExceptionHandler .Interceptor ;
3939import com .google .gcloud .Page ;
4040import com .google .gcloud .PageImpl ;
41+ import com .google .gcloud .PageImpl .NextPageFetcher ;
4142import com .google .gcloud .RetryHelper ;
4243import com .google .gcloud .bigquery .InsertAllRequest .RowToInsert ;
4344import com .google .gcloud .spi .BigQueryRpc ;
@@ -69,36 +70,17 @@ public RetryResult beforeEval(Exception exception) {
6970 static final ExceptionHandler EXCEPTION_HANDLER = ExceptionHandler .builder ()
7071 .abortOn (RuntimeException .class ).interceptor (EXCEPTION_HANDLER_INTERCEPTOR ).build ();
7172
72- private abstract static class BasePageFetcher < T > implements PageImpl . NextPageFetcher <T > {
73+ private static class DatasetPageFetcher implements NextPageFetcher <DatasetInfo > {
7374
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 ;
9878
9979 DatasetPageFetcher (BigQueryOptions serviceOptions , String cursor ,
10080 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 ;
10284 }
10385
10486 @ Override
@@ -107,14 +89,18 @@ public Page<DatasetInfo> nextPage() {
10789 }
10890 }
10991
110- private static class TablePageFetcher extends BasePageFetcher <BaseTableInfo > {
92+ private static class TablePageFetcher implements NextPageFetcher <BaseTableInfo > {
11193
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 ;
11397 private final String dataset ;
11498
11599 TablePageFetcher (String dataset , BigQueryOptions serviceOptions , String cursor ,
116100 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 ;
118104 this .dataset = dataset ;
119105 }
120106
@@ -124,13 +110,17 @@ public Page<BaseTableInfo> nextPage() {
124110 }
125111 }
126112
127- private static class JobPageFetcher extends BasePageFetcher <JobInfo > {
113+ private static class JobPageFetcher implements NextPageFetcher <JobInfo > {
128114
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 ;
130118
131119 JobPageFetcher (BigQueryOptions serviceOptions , String cursor ,
132120 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 ;
134124 }
135125
136126 @ Override
@@ -139,14 +129,18 @@ public Page<JobInfo> nextPage() {
139129 }
140130 }
141131
142- private static class TableDataPageFetcher extends BasePageFetcher <List <FieldValue >> {
132+ private static class TableDataPageFetcher implements NextPageFetcher <List <FieldValue >> {
143133
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 ;
145137 private final TableId table ;
146138
147139 TableDataPageFetcher (TableId table , BigQueryOptions serviceOptions , String cursor ,
148140 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 ;
150144 this .table = table ;
151145 }
152146
@@ -156,15 +150,19 @@ public Page<List<FieldValue>> nextPage() {
156150 }
157151 }
158152
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 {
161155
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 ;
163159 private final JobId job ;
164160
165161 QueryResultsPageFetcherImpl (JobId job , BigQueryOptions serviceOptions , String cursor ,
166162 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 ;
168166 this .job = job ;
169167 }
170168
0 commit comments