This is an automated email from the ASF dual-hosted git repository.
mattyb149 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new c84f438 NIFI-9800: Unwrap SQLException in PutDatabaseRecord when
table does not exist
c84f438 is described below
commit c84f43878205726a4e7b891ebd64068516bcfe68
Author: Matthew Burgess <[email protected]>
AuthorDate: Wed Mar 16 11:12:07 2022 -0400
NIFI-9800: Unwrap SQLException in PutDatabaseRecord when table does not
exist
Signed-off-by: Matthew Burgess <[email protected]>
This closes #5871
---
.../processors/standard/PutDatabaseRecord.java | 31 +++++++++++++++-------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
index 4756d80..34d90ec 100644
---
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
@@ -604,17 +604,28 @@ public class PutDatabaseRecord extends AbstractProcessor {
}
final SchemaKey schemaKey = new PutDatabaseRecord.SchemaKey(catalog,
schemaName, tableName);
- final TableSchema tableSchema = schemaCache.get(schemaKey, key -> {
- try {
- final TableSchema schema = TableSchema.from(con, catalog,
schemaName, tableName, settings.translateFieldNames, updateKeys, log);
- getLogger().debug("Fetched Table Schema {} for table name {}",
schema, tableName);
- return schema;
- } catch (SQLException e) {
- throw new ProcessException(e);
+ final TableSchema tableSchema;
+ try {
+ tableSchema = schemaCache.get(schemaKey, key -> {
+ try {
+ final TableSchema schema = TableSchema.from(con, catalog,
schemaName, tableName, settings.translateFieldNames, updateKeys, log);
+ getLogger().debug("Fetched Table Schema {} for table name
{}", schema, tableName);
+ return schema;
+ } catch (SQLException e) {
+ // Wrap this in a runtime exception, it is unwrapped in
the outer try
+ throw new ProcessException(e);
+ }
+ });
+ if (tableSchema == null) {
+ throw new IllegalArgumentException("No table schema
specified!");
+ }
+ } catch (ProcessException pe) {
+ // Unwrap the SQLException if one occurred
+ if (pe.getCause() instanceof SQLException) {
+ throw (SQLException) pe.getCause();
+ } else {
+ throw pe;
}
- });
- if (tableSchema == null) {
- throw new IllegalArgumentException("No table schema specified!");
}
// build the fully qualified table name