Skip to content

Commit dbdb887

Browse files
committed
move exception logging to exception
1 parent bf5c1b5 commit dbdb887

21 files changed

Lines changed: 142 additions & 223 deletions

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryConversionException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616

1717
package com.google.cloud.bigquery.exception;
1818

19+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
1920
import java.sql.SQLException;
2021

2122
/**
2223
* Exception for errors that occur when the driver cannot convert a value from one type to another.
2324
*/
2425
public class BigQueryConversionException extends SQLException {
26+
private static final BigQueryJdbcCustomLogger LOG =
27+
new BigQueryJdbcCustomLogger(BigQueryConversionException.class.getName());
2528

2629
public BigQueryConversionException(String message, Throwable cause) {
2730
super(message, cause);
31+
LOG.severe(this, message);
2832
}
2933
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcCoercionException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
package com.google.cloud.bigquery.exception;
1818

1919
import com.google.api.core.InternalApi;
20+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
2021

2122
/**
2223
* Thrown to indicate that the coercion was attempted but couldn't be performed successfully because
2324
* of some error.
2425
*/
2526
@InternalApi
2627
public class BigQueryJdbcCoercionException extends RuntimeException {
28+
private static final BigQueryJdbcCustomLogger LOG =
29+
new BigQueryJdbcCustomLogger(BigQueryJdbcCoercionException.class.getName());
2730

2831
/**
2932
* Construct a new exception with the specified cause.
@@ -32,5 +35,6 @@ public class BigQueryJdbcCoercionException extends RuntimeException {
3235
*/
3336
public BigQueryJdbcCoercionException(Exception cause) {
3437
super("Coercion error", cause);
38+
LOG.severe(this, "Coercion error");
3539
}
3640
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcCoercionNotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
package com.google.cloud.bigquery.exception;
1818

1919
import com.google.api.core.InternalApi;
20+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
2021

2122
/**
2223
* Thrown to indicate that the current TypeCoercer can not perform the coercion as the Coercion
2324
* implementation is not registered for the mentioned source and target type.
2425
*/
2526
@InternalApi
2627
public class BigQueryJdbcCoercionNotFoundException extends RuntimeException {
28+
private static final BigQueryJdbcCustomLogger LOG =
29+
new BigQueryJdbcCustomLogger(BigQueryJdbcCoercionNotFoundException.class.getName());
2730

2831
/**
2932
* Construct a new exception.
@@ -36,5 +39,6 @@ public BigQueryJdbcCoercionNotFoundException(Class<?> source, Class<?> target) {
3639
String.format(
3740
"Coercion not found for [%s -> %s] conversion",
3841
source.getCanonicalName(), target.getCanonicalName()));
42+
LOG.severe(this, this.getMessage());
3943
}
4044
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
package com.google.cloud.bigquery.exception;
1818

1919
import com.google.cloud.bigquery.BigQueryException;
20+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
2021
import java.sql.SQLException;
2122

2223
public class BigQueryJdbcException extends SQLException {
24+
private static final BigQueryJdbcCustomLogger LOG =
25+
new BigQueryJdbcCustomLogger(BigQueryJdbcException.class.getName());
2326
private BigQueryException bigQueryException = null;
2427

2528
/**
@@ -29,6 +32,7 @@ public class BigQueryJdbcException extends SQLException {
2932
*/
3033
public BigQueryJdbcException(String message) {
3134
super(message);
35+
LOG.severe(this, message);
3236
}
3337

3438
/**
@@ -38,6 +42,7 @@ public BigQueryJdbcException(String message) {
3842
*/
3943
public BigQueryJdbcException(InterruptedException ex) {
4044
super(ex);
45+
LOG.severe(this, ex.getMessage());
4146
}
4247

4348
/**
@@ -48,6 +53,7 @@ public BigQueryJdbcException(InterruptedException ex) {
4853
public BigQueryJdbcException(BigQueryException ex) {
4954
super(ex);
5055
this.bigQueryException = ex;
56+
LOG.severe(this, ex.getMessage());
5157
}
5258

5359
/**
@@ -58,6 +64,7 @@ public BigQueryJdbcException(BigQueryException ex) {
5864
*/
5965
public BigQueryJdbcException(String message, Throwable cause) {
6066
super(message, cause);
67+
LOG.severe(this, message);
6168
}
6269

6370
/**
@@ -68,6 +75,7 @@ public BigQueryJdbcException(String message, Throwable cause) {
6875
*/
6976
public BigQueryJdbcException(Throwable cause) {
7077
super(cause);
78+
LOG.severe(this, cause.getMessage());
7179
}
7280

7381
public BigQueryException getBigQueryException() {

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcRuntimeException.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@
1616

1717
package com.google.cloud.bigquery.exception;
1818

19+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
20+
1921
public class BigQueryJdbcRuntimeException extends RuntimeException {
2022

23+
private static final BigQueryJdbcCustomLogger LOG =
24+
new BigQueryJdbcCustomLogger(BigQueryJdbcRuntimeException.class.getName());
25+
2126
/**
2227
* Constructs a new BigQueryJdbcRuntimeException with the given message.
2328
*
2429
* @param message The detail message.
2530
*/
2631
public BigQueryJdbcRuntimeException(String message) {
2732
super(message);
33+
LOG.severe(this, message);
2834
}
2935

3036
/**
@@ -34,6 +40,7 @@ public BigQueryJdbcRuntimeException(String message) {
3440
*/
3541
public BigQueryJdbcRuntimeException(Throwable ex) {
3642
super(ex);
43+
LOG.severe(this, ex.getMessage());
3744
}
3845

3946
/**
@@ -44,9 +51,11 @@ public BigQueryJdbcRuntimeException(Throwable ex) {
4451
*/
4552
public BigQueryJdbcRuntimeException(String message, InterruptedException ex) {
4653
super(message, ex);
54+
LOG.severe(this, message);
4755
}
4856

4957
public BigQueryJdbcRuntimeException(String message, Throwable ex) {
5058
super(message, ex);
59+
LOG.severe(this, message);
5160
}
5261
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcSqlFeatureNotSupportedException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717
package com.google.cloud.bigquery.exception;
1818

1919
import com.google.cloud.bigquery.BigQueryException;
20+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
2021
import java.sql.SQLFeatureNotSupportedException;
2122

2223
public class BigQueryJdbcSqlFeatureNotSupportedException extends SQLFeatureNotSupportedException {
24+
private static final BigQueryJdbcCustomLogger LOG =
25+
new BigQueryJdbcCustomLogger(BigQueryJdbcSqlFeatureNotSupportedException.class.getName());
26+
2327
/**
2428
* Constructs a new BigQueryJdbcSqlFeatureNotSupportedException with the given message.
2529
*
2630
* @param message The detail message.
2731
*/
2832
public BigQueryJdbcSqlFeatureNotSupportedException(String message) {
2933
super(message);
34+
LOG.severe(this, message);
3035
}
3136

3237
/**
@@ -36,5 +41,6 @@ public BigQueryJdbcSqlFeatureNotSupportedException(String message) {
3641
*/
3742
public BigQueryJdbcSqlFeatureNotSupportedException(BigQueryException ex) {
3843
super(ex);
44+
LOG.severe(this, ex.getMessage());
3945
}
4046
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcSqlSyntaxErrorException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.bigquery.exception;
1818

1919
import com.google.cloud.bigquery.BigQueryException;
20+
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
2021
import java.sql.SQLSyntaxErrorException;
2122

2223
/**
@@ -25,16 +26,21 @@
2526
* rules.
2627
*/
2728
public class BigQueryJdbcSqlSyntaxErrorException extends SQLSyntaxErrorException {
29+
private static final BigQueryJdbcCustomLogger LOG =
30+
new BigQueryJdbcCustomLogger(BigQueryJdbcSqlSyntaxErrorException.class.getName());
31+
2832
/**
2933
* Constructs a new BigQueryJdbcSqlSyntaxErrorException from BigQueryException
3034
*
3135
* @param ex The BigQueryException to be thrown.
3236
*/
3337
public BigQueryJdbcSqlSyntaxErrorException(BigQueryException ex) {
3438
super(ex.getMessage(), "Incorrect SQL syntax.");
39+
LOG.severe(this, ex.getMessage());
3540
}
3641

3742
public BigQueryJdbcSqlSyntaxErrorException(String message, BigQueryException ex) {
3843
super(message, ex);
44+
LOG.severe(this, message);
3945
}
4046
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSet.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ private BigQueryArrowResultSet(
108108
try {
109109
this.arrowDeserializer = new ArrowDeserializer(arrowSchema);
110110
} catch (IOException ex) {
111-
BigQueryJdbcException e =
112-
new BigQueryJdbcException("IOException during ArrowDeserializer creation", ex);
113-
LOG.severe(e, e.getMessage());
114-
throw e;
111+
throw new BigQueryJdbcException("IOException during ArrowDeserializer creation", ex);
115112
}
116113
}
117114
}
@@ -244,10 +241,7 @@ public boolean next() throws SQLException {
244241
// Advance the cursor. Potentially blocking operation.
245242
BigQueryArrowBatchWrapper batchWrapper = this.buffer.take();
246243
if (batchWrapper.getException() != null) {
247-
BigQueryJdbcRuntimeException ex =
248-
new BigQueryJdbcRuntimeException(batchWrapper.getException());
249-
LOG.severe(ex, ex.getMessage());
250-
throw ex;
244+
throw new BigQueryJdbcRuntimeException(batchWrapper.getException());
251245
}
252246
if (batchWrapper.isLast()) {
253247
/* Marks the end of the records */
@@ -276,12 +270,9 @@ else if (this.currentBatchRowIndex < this.vectorSchemaRoot.getRowCount()) {
276270
return true;
277271
}
278272
} catch (InterruptedException | SQLException ex) {
279-
BigQueryJdbcException e =
280-
new BigQueryJdbcException(
281-
"Error occurred while advancing the cursor. This could happen when connection is closed while the next method is being called.",
282-
ex);
283-
LOG.severe(e, e.getMessage());
284-
throw e;
273+
throw new BigQueryJdbcException(
274+
"Error occurred while advancing the cursor. This could happen when connection is closed while the next method is being called.",
275+
ex);
285276
}
286277
}
287278
return false;

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseArray.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,24 @@ public final int getBaseType() {
7171

7272
@Override
7373
public final Object getArray(Map<String, Class<?>> map) throws SQLException {
74-
BigQueryJdbcSqlFeatureNotSupportedException ex =
75-
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
76-
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
77-
throw ex;
74+
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
7875
}
7976

8077
@Override
8178
public final Object getArray(long index, int count, Map<String, Class<?>> map)
8279
throws SQLException {
83-
BigQueryJdbcSqlFeatureNotSupportedException ex =
84-
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
85-
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
86-
throw ex;
80+
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
8781
}
8882

8983
@Override
9084
public final ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
91-
BigQueryJdbcSqlFeatureNotSupportedException ex =
92-
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
93-
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
94-
throw ex;
85+
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
9586
}
9687

9788
@Override
9889
public final ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
9990
throws SQLException {
100-
BigQueryJdbcSqlFeatureNotSupportedException ex =
101-
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
102-
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
103-
throw ex;
91+
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
10492
}
10593

10694
protected Object getArrayInternal(int fromIndex, int toIndexExclusive) {

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public void close() {
109109

110110
protected SQLException createCoercionException(
111111
int columnIndex, Class<?> targetClass, Exception cause) throws SQLException {
112-
LOG.severe(cause, "Coercion failed");
113112
checkClosed();
114113
StandardSQLTypeName type;
115114
String typeName;
@@ -127,7 +126,7 @@ protected SQLException createCoercionException(
127126
SQLException ex =
128127
new SQLException(
129128
"For a nested ResultSet from an Array, columnIndex must be 1 or 2.", cause);
130-
LOG.severe(ex, "For a nested ResultSet from an Array, columnIndex must be 1 or 2.");
129+
LOG.severe(ex, ex.getMessage());
131130
throw ex;
132131
}
133132
} else {

0 commit comments

Comments
 (0)