From 17b8327c3a9a26e023576ed00e181630abf145ce Mon Sep 17 00:00:00 2001 From: karin_pettersen <karinep@stud.ntnu.no> Date: Thu, 3 Mar 2022 10:40:43 +0100 Subject: [PATCH] Created getBuilder --- src/main/java/com/application/DB/DB.java | 20 +++++++++++++------- src/main/java/com/application/DB/Sort.java | 5 +++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/application/DB/Sort.java diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java index 4eed14a..d275e8f 100644 --- a/src/main/java/com/application/DB/DB.java +++ b/src/main/java/com/application/DB/DB.java @@ -9,6 +9,7 @@ import com.google.cloud.bigquery.Job; import com.google.cloud.bigquery.JobInfo; import com.google.cloud.bigquery.QueryJobConfiguration; import com.google.cloud.bigquery.TableResult; +import com.sun.media.jfxmedia.AudioClip; import java.io.File; import java.io.FileInputStream; @@ -28,16 +29,20 @@ public class DB { return credentials; } - public static void getFromExistingTable() throws Exception { - - // Step 1: Initialize BigQuery service - // Here we set our project ID and get the `BigQuery` service object - // this is the interface to our BigQuery instance that - // we use to execute jobs on + // Step 1: Initialize BigQuery service + // Here we set our project ID and get the `BigQuery` service object + // this is the interface to our BigQuery instance that + // we use to execute jobs on + private static BigQuery getBuilder() throws Exception { BigQuery bigquery = BigQueryOptions.newBuilder(). setCredentials(getCredentials()). setProjectId("sf-drying-optimization") .build().getService(); + return bigquery; + } + + public static void getFromExistingTable() throws Exception { + // Step 2: Prepare query job // A "QueryJob" is a type of job that executes SQL queries @@ -50,7 +55,8 @@ public class DB { // Step 3: Run the job on BigQuery // create a `Job` instance from the job configuration using the BigQuery service // the job starts executing once the `create` method executes - Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).build()); + + Job queryJob = getBuilder().create(JobInfo.newBuilder(queryConfig).build()); queryJob = queryJob.waitFor(); // the waitFor method blocks until the job completes // and returns `null` if the job doesn't exist anymore diff --git a/src/main/java/com/application/DB/Sort.java b/src/main/java/com/application/DB/Sort.java new file mode 100644 index 0000000..2527342 --- /dev/null +++ b/src/main/java/com/application/DB/Sort.java @@ -0,0 +1,5 @@ +package com.application.DB; + +public class Sort { + +} -- GitLab