From 89a23dc0f5c3d24edc9b31e585ab2153754dd84e Mon Sep 17 00:00:00 2001 From: "Barry M. Caceres" Date: Thu, 7 Dec 2023 10:51:17 -0800 Subject: [PATCH 1/2] - Added `com.senzing.sql.SQLUtilities.UTC_CALENDAR` to provide a reusable `Calendar` instance for working with UTC timestmaps in SQL databases for JDBC `getTimestamp()` function. - Added additional constructors for `MissingDependenciesException`. - Added new functions to `JsonUtilities`: - `JsonUtilities.add(JsonObjectBuilder,String,JsonObjectBuilder)` - `JsonUtilities.add(JsonObjectBuilder,String,JsonArrayBuilder)` - `JsonUtilities.add(JsonObjectBuilder,String,JsonValue)` - `JsonUtilities.add(JsonArrayBuilder,JsonObjectBuilder)` - `JsonUtilities.add(JsonArrayBuilder,JsonArrayBuilder)` - `JsonUtilities.add(JsonArrayBuilder,JsonValue)` - Changed `sqlite-jdbc` dependency to version `3.42.0.1` to avoid the problematic version `3.43.x.x` which carelessly breaks backwards compatibility by removing functionality that has been supported for sixteen (16) years. - Updated runtime and build dependencies. --- CHANGELOG.md | 20 +++ pom.xml | 10 +- .../cmdline/MissingDependenciesException.java | 51 +++++- .../java/com/senzing/sql/SQLUtilities.java | 9 +- .../java/com/senzing/util/JsonUtilities.java | 147 ++++++++++++++++++ 5 files changed, 224 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d02842..4163b4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [markdownlint](https://dlaa.me/markdownlint/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.1.4] - 2023-12-07 + +### Changed in 3.1.4 + +- Added `com.senzing.sql.SQLUtilities.UTC_CALENDAR` to provide a reusable `Calendar` + instance for working with UTC timestmaps in SQL databases for JDBC `getTimestamp()` + function. +- Added additional constructors for `MissingDependenciesException`. +- Added new functions to `JsonUtilities`: + - `JsonUtilities.add(JsonObjectBuilder,String,JsonObjectBuilder)` + - `JsonUtilities.add(JsonObjectBuilder,String,JsonArrayBuilder)` + - `JsonUtilities.add(JsonObjectBuilder,String,JsonValue)` + - `JsonUtilities.add(JsonArrayBuilder,JsonObjectBuilder)` + - `JsonUtilities.add(JsonArrayBuilder,JsonArrayBuilder)` + - `JsonUtilities.add(JsonArrayBuilder,JsonValue)` +- Changed `sqlite-jdbc` dependency to version `3.42.0.1` to avoid the problematic + version `3.43.x.x` which carelessly breaks backwards compatibility by removing + functionality that has been supported for sixteen (16) years. +- Updated runtime and build dependencies. + ## [3.1.3] - 2023-10-16 ### Changed in 3.1.3 diff --git a/pom.xml b/pom.xml index a18ef09..2b51e5c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.senzing senzing-commons jar - 3.1.3 + 3.1.4 Senzing Commons Utility classes and functions common to multiple Senzing projects. http://github.com/Senzing/senzing-commons-java @@ -71,13 +71,13 @@ org.junit.jupiter junit-jupiter - 5.10.0 + 5.10.1 test org.xerial sqlite-jdbc - 3.41.2.2 + 3.42.0.1 test @@ -107,7 +107,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.2 ${project.build.directory} @@ -139,7 +139,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.2 attach-javadocs diff --git a/src/main/java/com/senzing/cmdline/MissingDependenciesException.java b/src/main/java/com/senzing/cmdline/MissingDependenciesException.java index fdfaa5a..f2a8b0b 100644 --- a/src/main/java/com/senzing/cmdline/MissingDependenciesException.java +++ b/src/main/java/com/senzing/cmdline/MissingDependenciesException.java @@ -31,7 +31,41 @@ public MissingDependenciesException(CommandLineSource source, Set specifiedOptions) { super(source, option, specifier, - buildErrorMessage(source, option, specifier, specifiedOptions)); + buildErrorMessage(source, + option, + option.getDependencies(), + specifier, + specifiedOptions)); + } + + /** + * Constructs with the specified parameters. + * + * @param source The {@link CommandLineSource} describing how the option + * was specified. + * @param option The {@link CommandLineOption} that was missing required + * parameters. + * @param dependencySets The {@link Set} of {@link CommandLineOption} + * {@link Set} values representing the missing + * dependencies to report. + * @param specifier The command-line flag or environment variable used to + * specify the option, or null if specified as a + * default value. + * @param specifiedOptions The {@link Set} of {@link CommandLineOption} + * instances that were specified. + */ + public MissingDependenciesException(CommandLineSource source, + CommandLineOption option, + Set> dependencySets, + String specifier, + Set specifiedOptions) + { + super(source, option, specifier, + buildErrorMessage(source, + option, + dependencySets, + specifier, + specifiedOptions)); } /** @@ -41,6 +75,9 @@ public MissingDependenciesException(CommandLineSource source, * was specified. * @param option The {@link CommandLineOption} that was missing required * parameters. + * @param dependencySets The {@link Set} of {@link CommandLineOption} + * {@link Set} values representing the missing + * dependencies to report. * @param specifier The command-line flag or environment variable used to * specify the option, or null if specified as a * default value. @@ -56,10 +93,11 @@ public MissingDependenciesException(CommandLineSource source, */ @SuppressWarnings("unchecked") public static String buildErrorMessage( - CommandLineSource source, - CommandLineOption option, - String specifier, - Set specifiedOptions) + CommandLineSource source, + CommandLineOption option, + Set> dependencySets, + String specifier, + Set specifiedOptions) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); @@ -71,9 +109,8 @@ public static String buildErrorMessage( + " are missing."); pw.println("The " + sourceDescriptor + " also requires:"); - Set> dependencies = option.getDependencies(); String prefix = null; - for (Set dependencySet : dependencies) { + for (Set dependencySet : dependencySets) { boolean conflicting = false; // ignore dependency sets that conflict with other specified options for (CommandLineOption specifiedOption: specifiedOptions) { diff --git a/src/main/java/com/senzing/sql/SQLUtilities.java b/src/main/java/com/senzing/sql/SQLUtilities.java index d057da4..98c31a8 100644 --- a/src/main/java/com/senzing/sql/SQLUtilities.java +++ b/src/main/java/com/senzing/sql/SQLUtilities.java @@ -3,11 +3,18 @@ import java.math.BigDecimal; import java.sql.*; import java.util.Calendar; - +import java.util.TimeZone; /** * Utilities for using the JDBC API to work with SQL databases. */ public class SQLUtilities { + /** + * A {@link Calendar} that can be used for retrieving timestamps + * from the database. + */ + public static final Calendar UTC_CALENDAR + = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + /** * Private constructor. */ diff --git a/src/main/java/com/senzing/util/JsonUtilities.java b/src/main/java/com/senzing/util/JsonUtilities.java index 1356c9b..39f2d81 100644 --- a/src/main/java/com/senzing/util/JsonUtilities.java +++ b/src/main/java/com/senzing/util/JsonUtilities.java @@ -1020,6 +1020,84 @@ public static JsonObject getJsonObject(JsonArray arr, int index) { } } + /** + * Adds the specified key/value pair to the specified {@link + * JsonObjectBuilder}. If the specified value is null then + * {@link JsonObjectBuilder#addNull(String)} is used, otherwise + * {@link JsonObjectBuilder#add(String,JsonObjectBuilder)} is used. + * + * @param job The {@link JsonObjectBuilder} to add the key/value pair to. + * + * @param key The {@link String} key. + * + * @param val The {@link JsonObjectBuilder} value, or null. + * + * @return The first {@link JsonObjectBuilder} that was specified. + */ + public static JsonObjectBuilder add(JsonObjectBuilder job, + String key, + JsonObjectBuilder val) + { + if (val == null) { + job.addNull(key); + } else { + job.add(key, val); + } + return job; + } + + /** + * Adds the specified key/value pair to the specified {@link + * JsonObjectBuilder}. If the specified value is null then + * {@link JsonObjectBuilder#addNull(String)} is used, otherwise + * {@link JsonObjectBuilder#add(String,JsonArrayBuilder)} is used. + * + * @param job The {@link JsonObjectBuilder} to add the key/value pair to. + * + * @param key The {@link String} key. + * + * @param val The {@link JsonArrayBuilder} value, or null. + * + * @return The {@link JsonObjectBuilder} that was specified. + */ + public static JsonObjectBuilder add(JsonObjectBuilder job, + String key, + JsonArrayBuilder val) + { + if (val == null) { + job.addNull(key); + } else { + job.add(key, val); + } + return job; + } + + /** + * Adds the specified key/value pair to the specified {@link + * JsonObjectBuilder}. If the specified value is null then + * {@link JsonObjectBuilder#addNull(String)} is used, otherwise + * {@link JsonObjectBuilder#add(String,JsonValue)} is used. + * + * @param job The {@link JsonObjectBuilder} to add the key/value pair to. + * + * @param key The {@link String} key. + * + * @param val The {@link JsonValue} value, or null. + * + * @return The {@link JsonObjectBuilder} that was specified. + */ + public static JsonObjectBuilder add(JsonObjectBuilder job, + String key, + JsonValue val) + { + if (val == null) { + job.addNull(key); + } else { + job.add(key, val); + } + return job; + } + /** * Adds the specified key/value pair to the specified {@link * JsonObjectBuilder}. If the specified value is null then @@ -1206,6 +1284,75 @@ public static JsonObjectBuilder add(JsonObjectBuilder job, String key, Boolean v return job; } + /** + * Adds the specified key/value pair to the specified {@link + * JsonArrayBuilder}. If the specified value is null then + * {@link JsonArrayBuilder#addNull()} is used, otherwise + * {@link JsonArrayBuilder#add(JsonObjectBuilder)} is used. + * + * @param job The {@link JsonArrayBuilder} to add the key/value pair to. + * + * @param val The {@link JsonObjectBuilder} value, or null. + * + * @return The {@link JsonArrayBuilder} that was specified. + */ + public static JsonArrayBuilder add(JsonArrayBuilder job, + JsonObjectBuilder val) + { + if (val == null) { + job.addNull(); + } else { + job.add(val); + } + return job; + } + + /** + * Adds the specified key/value pair to the specified {@link + * JsonArrayBuilder}. If the specified value is null then + * {@link JsonArrayBuilder#addNull()} is used, otherwise + * {@link JsonArrayBuilder#add(JsonArrayBuilder)} is used. + * + * @param job The {@link JsonArrayBuilder} to add the key/value pair to. + * + * @param val The {@link JsonArrayBuilder} value, or null. + * + * @return The first {@link JsonArrayBuilder} that was specified. + */ + public static JsonArrayBuilder add(JsonArrayBuilder job, + JsonArrayBuilder val) + { + if (val == null) { + job.addNull(); + } else { + job.add(val); + } + return job; + } + + /** + * Adds the specified key/value pair to the specified {@link + * JsonArrayBuilder}. If the specified value is null then + * {@link JsonArrayBuilder#addNull()} is used, otherwise + * {@link JsonArrayBuilder#add(JsonValue)} is used. + * + * @param job The {@link JsonArrayBuilder} to add the key/value pair to. + * + * @param val The {@link JsonValue} value, or null. + * + * @return The {@link JsonArrayBuilder} that was specified. + */ + public static JsonArrayBuilder add(JsonArrayBuilder job, + JsonValue val) + { + if (val == null) { + job.addNull(); + } else { + job.add(val); + } + return job; + } + /** * Adds the specified key/value pair to the specified {@link * JsonArrayBuilder}. If the specified value is null then From 9dd2201c22cb49b184605633a7062a6d3d1b525e Mon Sep 17 00:00:00 2001 From: "Barry M. Caceres" Date: Thu, 7 Dec 2023 11:08:59 -0800 Subject: [PATCH 2/2] Fixed merge conflicts still present in file --- pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pom.xml b/pom.xml index 607d0c9..35dfc86 100644 --- a/pom.xml +++ b/pom.xml @@ -107,11 +107,7 @@ org.apache.maven.plugins maven-surefire-plugin -<<<<<<< HEAD 3.2.2 -======= - 3.2.1 ->>>>>>> origin/main ${project.build.directory} @@ -143,11 +139,7 @@ org.apache.maven.plugins maven-javadoc-plugin -<<<<<<< HEAD 3.6.2 -======= - 3.6.0 ->>>>>>> origin/main attach-javadocs