|
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.BasePageFetcher; |
41 | 42 | import com.google.gcloud.RetryHelper; |
42 | 43 | import com.google.gcloud.bigquery.InsertAllRequest.RowToInsert; |
43 | 44 | import com.google.gcloud.spi.BigQueryRpc; |
@@ -69,108 +70,93 @@ public RetryResult beforeEval(Exception exception) { |
69 | 70 | 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 extends BasePageFetcher<DatasetInfo, BigQueryOptions> { |
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 = 8049465230453759547L; |
98 | 76 |
|
99 | 77 | DatasetPageFetcher(BigQueryOptions serviceOptions, String cursor, |
100 | 78 | Map<BigQueryRpc.Option, ?> optionMap) { |
101 | | - super(serviceOptions, cursor, optionMap); |
| 79 | + super(serviceOptions, BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
102 | 80 | } |
103 | 81 |
|
| 82 | + @SuppressWarnings("unchecked") |
104 | 83 | @Override |
105 | 84 | public Page<DatasetInfo> nextPage() { |
106 | | - return listDatasets(serviceOptions, requestOptions); |
| 85 | + return listDatasets(serviceOptions, (Map<BigQueryRpc.Option, ?>) requestOptions); |
107 | 86 | } |
108 | 87 | } |
109 | 88 |
|
110 | | - private static class TablePageFetcher extends BasePageFetcher<BaseTableInfo> { |
| 89 | + private static class TablePageFetcher extends BasePageFetcher<BaseTableInfo, BigQueryOptions> { |
111 | 90 |
|
112 | | - private static final long serialVersionUID = 5908129355985236115L; |
| 91 | + private static final long serialVersionUID = 6542604186608591265L; |
113 | 92 | private final String dataset; |
114 | 93 |
|
115 | 94 | TablePageFetcher(String dataset, BigQueryOptions serviceOptions, String cursor, |
116 | 95 | Map<BigQueryRpc.Option, ?> optionMap) { |
117 | | - super(serviceOptions, cursor, optionMap); |
| 96 | + super(serviceOptions, BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
118 | 97 | this.dataset = dataset; |
119 | 98 | } |
120 | 99 |
|
| 100 | + @SuppressWarnings("unchecked") |
121 | 101 | @Override |
122 | 102 | public Page<BaseTableInfo> nextPage() { |
123 | | - return listTables(dataset, serviceOptions, requestOptions); |
| 103 | + return listTables(dataset, serviceOptions, (Map<BigQueryRpc.Option, ?>) requestOptions); |
124 | 104 | } |
125 | 105 | } |
126 | 106 |
|
127 | | - private static class JobPageFetcher extends BasePageFetcher<JobInfo> { |
| 107 | + private static class JobPageFetcher extends BasePageFetcher<JobInfo, BigQueryOptions> { |
128 | 108 |
|
129 | | - private static final long serialVersionUID = -4984845360519279880L; |
| 109 | + private static final long serialVersionUID = 1983484324002958994L; |
130 | 110 |
|
131 | 111 | JobPageFetcher(BigQueryOptions serviceOptions, String cursor, |
132 | 112 | Map<BigQueryRpc.Option, ?> optionMap) { |
133 | | - super(serviceOptions, cursor, optionMap); |
| 113 | + super(serviceOptions, BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
134 | 114 | } |
135 | 115 |
|
| 116 | + @SuppressWarnings("unchecked") |
136 | 117 | @Override |
137 | 118 | public Page<JobInfo> nextPage() { |
138 | | - return listJobs(serviceOptions, requestOptions); |
| 119 | + return listJobs(serviceOptions, (Map<BigQueryRpc.Option, ?>) requestOptions); |
139 | 120 | } |
140 | 121 | } |
141 | 122 |
|
142 | | - private static class TableDataPageFetcher extends BasePageFetcher<List<FieldValue>> { |
| 123 | + private static class TableDataPageFetcher |
| 124 | + extends BasePageFetcher<List<FieldValue>, BigQueryOptions> { |
143 | 125 |
|
144 | | - private static final long serialVersionUID = 1281938239570262432L; |
| 126 | + private static final long serialVersionUID = 7767953898927019188L; |
145 | 127 | private final TableId table; |
146 | 128 |
|
147 | 129 | TableDataPageFetcher(TableId table, BigQueryOptions serviceOptions, String cursor, |
148 | 130 | Map<BigQueryRpc.Option, ?> optionMap) { |
149 | | - super(serviceOptions, cursor, optionMap); |
| 131 | + super(serviceOptions, BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
150 | 132 | this.table = table; |
151 | 133 | } |
152 | 134 |
|
| 135 | + @SuppressWarnings("unchecked") |
153 | 136 | @Override |
154 | 137 | public Page<List<FieldValue>> nextPage() { |
155 | | - return listTableData(table, serviceOptions, requestOptions); |
| 138 | + return listTableData(table, serviceOptions, (Map<BigQueryRpc.Option, ?>) requestOptions); |
156 | 139 | } |
157 | 140 | } |
158 | 141 |
|
159 | | - private static class QueryResultsPageFetcherImpl extends BasePageFetcher<List<FieldValue>> |
| 142 | + private static class QueryResultsPageFetcherImpl |
| 143 | + extends BasePageFetcher<List<FieldValue>, BigQueryOptions> |
160 | 144 | implements QueryResult.QueryResultsPageFetcher { |
161 | 145 |
|
162 | | - private static final long serialVersionUID = 6713948754731557486L; |
| 146 | + private static final long serialVersionUID = 6377034420634949203L; |
163 | 147 | private final JobId job; |
164 | 148 |
|
165 | 149 | QueryResultsPageFetcherImpl(JobId job, BigQueryOptions serviceOptions, String cursor, |
166 | 150 | Map<BigQueryRpc.Option, ?> optionMap) { |
167 | | - super(serviceOptions, cursor, optionMap); |
| 151 | + super(serviceOptions, BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
168 | 152 | this.job = job; |
169 | 153 | } |
170 | 154 |
|
| 155 | + @SuppressWarnings("unchecked") |
171 | 156 | @Override |
172 | 157 | public QueryResult nextPage() { |
173 | | - return getQueryResults(job, serviceOptions, requestOptions).result(); |
| 158 | + return getQueryResults(job, serviceOptions, (Map<BigQueryRpc.Option, ?>) requestOptions) |
| 159 | + .result(); |
174 | 160 | } |
175 | 161 | } |
176 | 162 |
|
|
0 commit comments