/
BigQueryPlatformFactory.java
32 lines (23 loc) · 1.21 KB
/
BigQueryPlatformFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package org.jumpmind.db.platform.bigquery;
import java.io.FileInputStream;
import org.jumpmind.db.sql.SqlTemplateSettings;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.http.HttpTransportOptions;
public class BigQueryPlatformFactory {
public BigQueryPlatformFactory() {
}
public BigQueryPlatform createDatabasePlatform(SqlTemplateSettings settings, String projectId, String location, String filePath) {
try {
HttpTransportOptions transportOptions = BigQueryOptions.getDefaultHttpTransportOptions();
transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
BigQuery bigquery = BigQueryOptions.newBuilder().setProjectId(projectId).setLocation(location)
.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(filePath)))
.setTransportOptions(transportOptions).build().getService();
return new BigQueryPlatform(settings, bigquery);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}