Java Code Examples for com.google.cloud.bigquery.BigQueryException#getCause()

The following examples show how to use com.google.cloud.bigquery.BigQueryException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobSnippets.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
/** Example usage of {@code waitFor()}. */
// [TARGET waitFor(RetryOption...)]
public boolean waitFor() throws InterruptedException {
  try {
    // [START ]
    Job completedJob = job.waitFor();
    if (completedJob == null) {
      // job no longer exists
    } else if (completedJob.getStatus().getError() != null) {
      // job failed, handle error
    } else {
      // job completed successfully
    }
    // [END ]
  } catch (BigQueryException e) {
    // Timeouts shouldn't happen without a timeout option.
    if (e.getCause() instanceof PollException) {
      return false;
    }
    throw e;
  }
  return true;
}
 
Example 2
Source File: JobSnippets.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
/** Example usage of {@code waitFor()} with checking period and timeout. */
// [TARGET waitFor(RetryOption...)]
public boolean waitForWithOptions() throws InterruptedException {
  try {
    // [START ]
    Job completedJob =
        job.waitFor(
            RetryOption.initialRetryDelay(Duration.ofSeconds(1)),
            RetryOption.totalTimeout(Duration.ofMinutes(1)));
    if (completedJob == null) {
      // job no longer exists
    } else if (completedJob.getStatus().getError() != null) {
      // job failed, handle error
    } else {
      // job completed successfully
    }
    // [END ]
  } catch (BigQueryException e) {
    if (e.getCause() instanceof PollException) {
      return false;
    }
    throw e;
  }
  return true;
}