From 78247586288b8546154e36ac708755b0c8a58ab1 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Fri, 28 Feb 2025 20:43:13 -0600 Subject: [PATCH 01/13] Initial commit --- recipes/hikari-ucp/.gitignore | 42 +++++++ recipes/hikari-ucp/pom.xml | 77 ++++++++++++ .../ConvertMsToSecondsInPropertiesRecipe.java | 57 +++++++++ .../ConvertMsToSecondsInYamlRecipe.java | 68 +++++++++++ .../resources/META-INF/rewrite/rewrite.yml | 113 ++++++++++++++++++ 5 files changed, 357 insertions(+) create mode 100644 recipes/hikari-ucp/.gitignore create mode 100644 recipes/hikari-ucp/pom.xml create mode 100644 recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java create mode 100644 recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java create mode 100644 recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml diff --git a/recipes/hikari-ucp/.gitignore b/recipes/hikari-ucp/.gitignore new file mode 100644 index 00000000..dc9153d0 --- /dev/null +++ b/recipes/hikari-ucp/.gitignore @@ -0,0 +1,42 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +*.log + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +.idea +.idea/** + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +/.jpb/** + +### Mac OS ### +.DS_Store diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml new file mode 100644 index 00000000..d9af0a71 --- /dev/null +++ b/recipes/hikari-ucp/pom.xml @@ -0,0 +1,77 @@ + + + + + 4.0.0 + + atael.example + hikari-ucp + 1.0-SNAPSHOT + + + 17 + 17 + 17 + UTF-8 + 8.47.2 + + + + + org.openrewrite + rewrite-java + ${rewrite.version} + + + + org.openrewrite + rewrite-properties + ${rewrite.version} + + + + org.openrewrite + rewrite-yaml + ${rewrite.version} + + + + org.openrewrite + rewrite-java + ${rewrite.version} + + + + org.openrewrite + rewrite-maven + ${rewrite.version} + + + + + + + org.openrewrite.maven + rewrite-maven-plugin + 6.2.1 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java b/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java new file mode 100644 index 00000000..f4cc38d8 --- /dev/null +++ b/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java @@ -0,0 +1,57 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + +package oracle.com.cloud.recipes.hikariucp; + +import org.openrewrite.NlsRewrite; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.properties.PropertiesVisitor; +import org.openrewrite.properties.tree.Properties; + +public class ConvertMsToSecondsInPropertiesRecipe extends Recipe { + + private final String keyRegex; + + // Takes a keyRegex parameter to specify which property keys to target (e.g., Hikari timeout properties). + public ConvertMsToSecondsInPropertiesRecipe(String keyRegex) { + this.keyRegex = keyRegex; + } + + // Extends PropertiesVisitor to process each Properties.Entry (key-value pair) in application.properties. + @Override + public TreeVisitor getVisitor() { + + return new PropertiesVisitor() { + + @Override + public Properties visitEntry(Properties.Entry entry, ExecutionContext ctx) { + if (entry.getKey().matches(keyRegex)) { + String value = entry.getValue().getText().trim(); + try { + long ms = Long.parseLong(value); + double seconds = ms / 1000.0; + String newValue = String.valueOf(seconds); + Properties.Value updatedValue = entry.getValue().withText(newValue); + return entry.withValue(updatedValue); + } catch (NumberFormatException e) { + // If the value isn't a valid number, ignore it. + } + } + return super.visitEntry(entry, ctx); + } + + }; + } + + @Override + public @NlsRewrite.DisplayName String getDisplayName() { + return "Convert milliseconds to seconds for Hikari properties"; + } + + @Override + public @NlsRewrite.Description String getDescription() { + return "Transforms millisecond values to seconds for Hikari connection pool properties matching the given regex."; + } +} diff --git a/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java b/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java new file mode 100644 index 00000000..f2327e93 --- /dev/null +++ b/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java @@ -0,0 +1,68 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + +package oracle.com.cloud.recipes.hikariucp; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.NlsRewrite; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.yaml.YamlVisitor; +import org.openrewrite.yaml.tree.Yaml; + +import java.util.regex.Pattern; + +public class ConvertMsToSecondsInYamlRecipe extends Recipe { + + private final String pathRegex; + + public ConvertMsToSecondsInYamlRecipe(String pathRegex) { + this.pathRegex = pathRegex; + } + + @Override + public TreeVisitor getVisitor() { + + Pattern pattern = Pattern.compile(pathRegex); + + return new YamlVisitor() { + private String currentPath = ""; + + @Override + public Yaml visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { + String previousPath = currentPath; + currentPath += (currentPath.isEmpty() ? "" : ".") + entry.getKey().getValue(); + Yaml.Mapping.Entry updatedEntry = (Yaml.Mapping.Entry) super.visitMappingEntry(entry, ctx); + currentPath = previousPath; + return updatedEntry; + } + + @Override + public Yaml visitScalar(Yaml.Scalar scalar, ExecutionContext ctx) { + if (pattern.matcher(currentPath).matches()) { + String value = scalar.getValue().trim(); + try { + long ms = Long.parseLong(value); + double seconds = ms / 1000.0; + String newValue = String.valueOf(seconds); + return scalar.withValue(newValue); + } catch (NumberFormatException e) { + // If the value isn't a valid number, ignore it. + } + } + return super.visitScalar(scalar, ctx); + } + }; + + } + + @Override + public @NlsRewrite.DisplayName String getDisplayName() { + return ""; + } + + @Override + public @NlsRewrite.Description String getDescription() { + return ""; + } +} diff --git a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml new file mode 100644 index 00000000..796db09e --- /dev/null +++ b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml @@ -0,0 +1,113 @@ +# +# Copyright © 2025, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +# Source for the recipe: +# https://github.com/brettwooldridge/HikariCP?tab=readme-ov-file#gear-configuration-knobs-baby +--- +type: specs.openrewrite.org/v1beta/recipe +name: oracle.com.cloud.recipes.hikariucp.ConvertHikariToUCP +displayName: Migrate Hikari CP to Oracle UCP +description: Migrate Hikari Connection Pool to Oracle Universal Connection Pool +tags: + - spring + - oracle + - ucp + - hikari +recipeList: + + # For pom.xml + - org.openrewrite.java.dependencies.RemoveDependency: + groupId: com.zaxxer* + artifactId: HikariCP* + - org.openrewrite.java.dependencies.AddDependency: + groupId: com.oracle.database.spring + artifactId: oracle-spring-boot-starter-ucp + version: 25.0.0 + + # spring.datasource.oracleucp.connection-factory-class: oracle.jdbc.pool.OracleDataSource + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.data-source-class-name + newPropertyKey: spring.datasource.oracleucp.connection-factory-class-name + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.oracleucp.connection-factory-class-name + newValue: oracle.jdbc.pool.OracleDataSource + + # spring.datasource.driver-class-name: OracleDriver + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.driver-class-name + newValue: oracle.jdbc.OracleDriver + + # spring.datasource.type: oracle.ucp.jdbc.PoolDataSource + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.type + newValue: oracle.ucp.jdbc.PoolDataSource + + # spring.datasource.oracleucp.connection-pool-name + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.pool-name + newPropertyKey: spring.datasource.oracleucp.connection-pool-name + + # spring.datasource.oracleucp.max-pool-size + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.maximum-pool-size + newPropertyKey: spring.datasource.oracleucp.max-pool-size + + # spring.datasource.oracleucp.min-pool-size + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.minimum-idle + newPropertyKey: spring.datasource.oracleucp.min-pool-size + + # spring.datasource.oracleucp.connection-validation-timeout + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.connection-timeout + newPropertyKey: spring.datasource.oracleucp.connection-wait-timeout + + # spring.datasource.oracleucp.inactive-connection-timeout + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.idle-timeout + newPropertyKey: spring.datasource.oracleucp.inactive-connection-timeout + + # spring.datasource.oracleucp.s-q-l-for-validate-connection + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.connection-test-query + newPropertyKey: spring.datasource.oracleucp.s-q-l-for-validate-connection + + # spring.datasource.oracleucp.max-connection-reuse-time + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.max-lifetime + newPropertyKey: spring.datasource.oracleucp.max-connection-reuse-time + + # spring.datasource.oracleucp.max-connection-reuse-time + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.validation-timeout + newPropertyKey: spring.datasource.oracleucp.connection-validation-timeout + + # spring.datasource.oracleucp.initial-pool-size + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.initial-pool-size + value: 5 + comment: "Specifies the number of available connections created after the pool is initiated" + + # HikariCP properties that don’t have identical UCP properties + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.auto-commit + comment: "Use Oracle JDBC driver connection property autoCommit." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.register-mbeans + comment: "UCP always attempts registration." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.thread-factory + comment: "UCP supports setTaskManager instead." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.scheduled-executor + comment: "UCP supports setTaskManager instead." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.keepalive-time + comment: "Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE" + + # Convert milliseconds to seconds + - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInPropertiesRecipe: + keyRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' + - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInYamlRecipe: + pathRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' \ No newline at end of file From dffe359df11e4c5d7d04bbcf8401e91116415282 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 08:49:08 -0600 Subject: [PATCH 02/13] pom updates --- recipes/hikari-ucp/pom.xml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index d9af0a71..c33e1535 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -16,6 +16,8 @@ 17 UTF-8 8.47.2 + 3.3.0 + 5.12.0 @@ -39,17 +41,36 @@ org.openrewrite - rewrite-java + rewrite-maven ${rewrite.version} - org.openrewrite - rewrite-maven - ${rewrite.version} + org.junit.jupiter + junit-jupiter + test + + + + org.openrewrite.recipe + rewrite-recipe-bom + ${rewrite.recipe.version} + pom + import + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + From aee63c44e26d704048505135ec2eadd758050881 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 09:18:12 -0600 Subject: [PATCH 03/13] Test skeleton --- recipes/hikari-ucp/pom.xml | 20 +++++++++++------- .../hikariucp/ChangePropertyValueTest.java | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index c33e1535..747a2ce1 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -50,6 +50,12 @@ junit-jupiter test + + + org.openrewrite + rewrite-test + test + @@ -83,13 +89,13 @@ - - - - - - - + + + org.openrewrite.recipe + rewrite-spring + 5.24.1 + + diff --git a/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java b/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java new file mode 100644 index 00000000..cf9866a6 --- /dev/null +++ b/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java @@ -0,0 +1,21 @@ +package oracle.com.cloud.recipes.hikariucp; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.properties.Assertions.properties; +import static org.openrewrite.yaml.Assertions.yaml; + +class ChangeSpringPropertyValueTest implements RewriteTest { + + // @DocumentExample + // @Test + // void propFile() { + // rewriteRun( + // spec -> spec.recipe(new ChangeSpringPropertyValue("server.port", "8081", null, null, null)), + // properties("server.port=8080", "server.port=8081") + // ); + + +} \ No newline at end of file From 7857069bae481d28af54e4ca3dc66fe1a65492b0 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 09:34:39 -0600 Subject: [PATCH 04/13] fixes --- recipes/hikari-ucp/README.md | 39 +++++++++++++++++++ recipes/hikari-ucp/pom.xml | 22 +++++++++-- .../hikariucp/ChangePropertyValueTest.java | 5 ++- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 recipes/hikari-ucp/README.md diff --git a/recipes/hikari-ucp/README.md b/recipes/hikari-ucp/README.md new file mode 100644 index 00000000..bf5b67ee --- /dev/null +++ b/recipes/hikari-ucp/README.md @@ -0,0 +1,39 @@ +# Hikari to UCP Open Rewrite Recipe + +## Build the Open Rewrite Recipe + +The repo is using maven. To build the recipe run the following command: + +```shell +mvn install +``` + +## To use the Recipe + + In the repository you want to test your recipe against, update the pom.xml to include the following: + + ```xml + + + + + org.openrewrite.maven + rewrite-maven-plugin + 6.2.2 + + + ConvertHikariToUCP + + + + + java.oracle.com.cloud.recipes + hikariucp + 0.0.1-SNAPSHOT + + + + + + +``` \ No newline at end of file diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index 747a2ce1..ffc052e4 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -6,9 +6,25 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - atael.example - hikari-ucp - 1.0-SNAPSHOT + java.oracle.com.cloud.recipes + hikariucp + 0.0.1-SNAPSHOT + hikari-ucp + Openrewrite Recipe to convert Hikari Connection Pool to Oracle UCP + + + + + + + + + + + + + + 17 diff --git a/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java b/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java index cf9866a6..1bff0c75 100644 --- a/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java +++ b/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java @@ -1,3 +1,6 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + package oracle.com.cloud.recipes.hikariucp; import org.junit.jupiter.api.Test; @@ -8,7 +11,7 @@ import static org.openrewrite.yaml.Assertions.yaml; class ChangeSpringPropertyValueTest implements RewriteTest { - + // @DocumentExample // @Test // void propFile() { From 1a48118974f5b64dcf89e636afaf4ff1fb8986de Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 10:56:51 -0600 Subject: [PATCH 05/13] Legal stuff --- recipes/hikari-ucp/pom.xml | 48 ++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index ffc052e4..134fa566 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -12,28 +12,42 @@ hikari-ucp Openrewrite Recipe to convert Hikari Connection Pool to Oracle UCP - - - - - - - - - - - - - + https://github.com/oracle/spring-cloud-oracle/tree/hikari-ucp-recipe/recipes/hikari-ucp + + + Oracle America, Inc. + https://www.oracle.com + + + + The Universal Permissive License (UPL), Version 1.0 + https://oss.oracle.com/licenses/upl/ + repo + + + + + Oracle + obaas_ww at oracle.com + Oracle America, Inc. + https://www.oracle.com + + + + https://github.com/oracle/spring-cloud-oracle + scm:git:https://github.com/oracle/spring-cloud-oracle.git + scm:git:git@github.com:oracle/spring-cloud-oracle.git + 17 17 17 UTF-8 - 8.47.2 - 3.3.0 - 5.12.0 + 8.47.2 + 3.3.0 + 6.2.1 + 5.12.0 @@ -98,7 +112,7 @@ org.openrewrite.maven rewrite-maven-plugin - 6.2.1 + ${maven.rewrite.plugin.version} From dc396150215bb67bacfeb36b14f3be4b745d079a Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 11:48:49 -0600 Subject: [PATCH 06/13] Recipe and README updates --- recipes/hikari-ucp/README.md | 80 ++++++++++++++++++- .../resources/META-INF/rewrite/rewrite.yml | 6 +- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/recipes/hikari-ucp/README.md b/recipes/hikari-ucp/README.md index bf5b67ee..fc86eb0e 100644 --- a/recipes/hikari-ucp/README.md +++ b/recipes/hikari-ucp/README.md @@ -1,4 +1,80 @@ -# Hikari to UCP Open Rewrite Recipe +# Hikari to UCP Open Rewrite Recipe + +Current Version is `0.0.1-SNAPSHOT` and is under development. Please file GitHub issues for issues, enhancements and more. + +## Hikari to UCP rewrite Recipe + +> **_NOTE:_** In the pre release the rewrite works best with `properties` files. `YAML` files works too but the formatting of the outcome isn't pretty. + +This recipe will change the Hikare connection pool parameters and dependency from Hikari to Oracle Universal Connection Pooling (UCP). The [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html). + +The following properties are rewritten: + +### Maven dependencies `pom.xml + +The Hikari dependency is removed and replaced with SPring Boot starters for Oracle UCP and Oracle Wallet (commonly used to connect to an autonomous database (ADB)). + +```xml + + com.zaxxer + HikariCP + +``` + +is changed to: + +```xml + + com.oracle.database.spring + oracle-spring-boot-starter-ucp + 25.1.0 + +``` + +And the following dependency is added, as it is commonly used to connect to an autonomous database (ADB): + +```xml + + com.oracle.database.spring + oracle-spring-boot-starter-wallet + 25.1.0 + +``` + +### Spring Boot Connection Pooling configuration `application.properties` + +> **_NOTE:_** The recipe will change Hikari's milliseconds to seconds. + +The following properties are rewritten. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) + +| Hikari Property | Oracle UCP Property | Notes | +|-----------------|---------------------|-------| +| N/A | `spring.datasource.driver-class-name` | Will be set to `oracle.jdbc.OracleDriver` | +| N/A | `spring.datasource.type` | Will be set to `oracle.ucp.jdbc.PoolDataSource` | +| `spring.datasource.hikari.pool-name` | `spring.datasource.oracleucp.connection-pool-name` | | +| `spring.datasource.hikari.maximum-pool-size` | `spring.datasource.oracleucp.max-pool-size` | | +| `spring.datasource.hikari.minimum-idle` | `spring.datasource.oracleucp.min-pool-size` | | +| `spring.datasource.hikari.connection-timeout` | `spring.datasource.oracleucp.connection-wait-timeout` | | +| `spring.datasource.hikari.idle-timeout` | `spring.datasource.oracleucp.inactive-connection-timeout` | | +| `spring.datasource.hikari.connection-test-query` | `spring.datasource.oracleucp.s-q-l-for-validate-connection` | | +| `spring.datasource.hikari.max-lifetime` | `spring.datasource.oracleucp.max-connection-reuse-time` | | +| `spring.datasource.hikari.validation-timeout` | `pring.datasource.oracleucp.connection-validation-timeout` | | + +The following UCP properties are added: + +| Oracle UCP Property | Value | Notes | +|---------------------|-------|-------| +| `spring.datasource.oracleucp.initial-pool-size` | 5 | [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) | + +The following Hikari Properties do not have identical UCP properties and will be commented out in the rewritten properties file. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) + +| Hikari UCP Property | Notes | +|---------------------|-------| +| `spring.datasource.hikari.auto-commit` | Use Oracle JDBC driver connection property autoCommit | +| `spring.datasource.hikari.register-mbeans` | UCP always attempts registration | +| `spring.datasource.hikari.thread-factory` | UCP supports setTaskManager instead | +| `spring.datasource.hikari.scheduled-executor` | UCP supports setTaskManager instead | +| `spring.datasource.hikari.keepalive-time` | Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE | ## Build the Open Rewrite Recipe @@ -36,4 +112,4 @@ mvn install -``` \ No newline at end of file +``` diff --git a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml index 796db09e..fbf5d762 100644 --- a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml @@ -23,7 +23,11 @@ recipeList: - org.openrewrite.java.dependencies.AddDependency: groupId: com.oracle.database.spring artifactId: oracle-spring-boot-starter-ucp - version: 25.0.0 + version: 25.1.0 + - org.openrewrite.java.dependencies.AddDependency: + groupId: com.oracle.database.spring + artifactId: oracle-spring-boot-starter-wallet + version: 25.1.0 # spring.datasource.oracleucp.connection-factory-class: oracle.jdbc.pool.OracleDataSource - org.openrewrite.java.spring.ChangeSpringPropertyKey: From 847ac9dea257719a392f98524a097ca99de1bc0a Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 13:07:10 -0600 Subject: [PATCH 07/13] Refactoring Signed-off-by: Andy Tael --- recipes/hikari-ucp/README.md | 4 ++-- recipes/hikari-ucp/pom.xml | 2 +- .../hikariucp/ConvertMsToSecondsInPropertiesRecipe.java | 0 .../recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java | 0 .../com/cloud/recipes/hikariucp/ChangePropertyValueTest.java | 2 -- 5 files changed, 3 insertions(+), 5 deletions(-) rename recipes/hikari-ucp/src/main/{java => }/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java (100%) rename recipes/hikari-ucp/src/main/{java => }/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java (100%) rename recipes/hikari-ucp/src/test/{java => }/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java (90%) diff --git a/recipes/hikari-ucp/README.md b/recipes/hikari-ucp/README.md index fc86eb0e..672699bf 100644 --- a/recipes/hikari-ucp/README.md +++ b/recipes/hikari-ucp/README.md @@ -10,7 +10,7 @@ This recipe will change the Hikare connection pool parameters and dependency fro The following properties are rewritten: -### Maven dependencies `pom.xml +### Maven dependencies `pom.xml` The Hikari dependency is removed and replaced with SPring Boot starters for Oracle UCP and Oracle Wallet (commonly used to connect to an autonomous database (ADB)). @@ -86,7 +86,7 @@ mvn install ## To use the Recipe - In the repository you want to test your recipe against, update the pom.xml to include the following: + In the repository you want to test your recipe against, update the `pom.xml` to include the following: ```xml diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index 134fa566..cde3ea66 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - java.oracle.com.cloud.recipes + oracle.com.cloud.recipes.hikariucp hikariucp 0.0.1-SNAPSHOT hikari-ucp diff --git a/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java b/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java similarity index 100% rename from recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java rename to recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java diff --git a/recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java b/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java similarity index 100% rename from recipes/hikari-ucp/src/main/java/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java rename to recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java diff --git a/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java b/recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java similarity index 90% rename from recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java rename to recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java index 1bff0c75..71bb8187 100644 --- a/recipes/hikari-ucp/src/test/java/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java +++ b/recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java @@ -3,8 +3,6 @@ package oracle.com.cloud.recipes.hikariucp; -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; import org.openrewrite.test.RewriteTest; import static org.openrewrite.properties.Assertions.properties; From 28fa1d99fb1a345c29ae47051d47d652fdf07635 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 13:19:51 -0600 Subject: [PATCH 08/13] Refactoring Signed-off-by: Andy Tael --- recipes/hikari-ucp/README.md | 2 +- recipes/hikari-ucp/pom.xml | 2 +- .../recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java | 2 +- .../cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java | 2 +- .../hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename recipes/hikari-ucp/src/main/{oracle/com => com/oracle}/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java (97%) rename recipes/hikari-ucp/src/main/{oracle/com => com/oracle}/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java (97%) diff --git a/recipes/hikari-ucp/README.md b/recipes/hikari-ucp/README.md index 672699bf..67d37b88 100644 --- a/recipes/hikari-ucp/README.md +++ b/recipes/hikari-ucp/README.md @@ -103,7 +103,7 @@ mvn install - java.oracle.com.cloud.recipes + com.oracle.cloud.recipes hikariucp 0.0.1-SNAPSHOT diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml index cde3ea66..4eae1fdd 100644 --- a/recipes/hikari-ucp/pom.xml +++ b/recipes/hikari-ucp/pom.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - oracle.com.cloud.recipes.hikariucp + com.oracle.cloud.recipes.hikariucp hikariucp 0.0.1-SNAPSHOT hikari-ucp diff --git a/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java similarity index 97% rename from recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java rename to recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java index f4cc38d8..ed9004ef 100644 --- a/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java +++ b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java @@ -1,7 +1,7 @@ // Copyright (c) 2025, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -package oracle.com.cloud.recipes.hikariucp; +package com.oracle.cloud.recipes.hikariucp; import org.openrewrite.NlsRewrite; import org.openrewrite.ExecutionContext; diff --git a/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java similarity index 97% rename from recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java rename to recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java index f2327e93..b605cda9 100644 --- a/recipes/hikari-ucp/src/main/oracle/com/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java +++ b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java @@ -1,7 +1,7 @@ // Copyright (c) 2025, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -package oracle.com.cloud.recipes.hikariucp; +package com.oracle.cloud.recipes.hikariucp; import org.openrewrite.ExecutionContext; import org.openrewrite.NlsRewrite; diff --git a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml index fbf5d762..772a9ff4 100644 --- a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml @@ -6,7 +6,7 @@ # https://github.com/brettwooldridge/HikariCP?tab=readme-ov-file#gear-configuration-knobs-baby --- type: specs.openrewrite.org/v1beta/recipe -name: oracle.com.cloud.recipes.hikariucp.ConvertHikariToUCP +name: com.oracle.cloud.recipes.hikariucp.ConvertHikariToUCP displayName: Migrate Hikari CP to Oracle UCP description: Migrate Hikari Connection Pool to Oracle Universal Connection Pool tags: From 156eac6478490f4e86eef7e820b23c077e865855 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 13:22:11 -0600 Subject: [PATCH 09/13] Typo in package --- recipes/hikariucp/.gitignore | 42 ++++++ recipes/hikariucp/README.md | 115 +++++++++++++++ recipes/hikariucp/pom.xml | 134 ++++++++++++++++++ .../ConvertMsToSecondsInPropertiesRecipe.java | 57 ++++++++ .../ConvertMsToSecondsInYamlRecipe.java | 68 +++++++++ .../resources/META-INF/rewrite/rewrite.yml | 117 +++++++++++++++ .../hikariucp/ChangePropertyValueTest.java | 22 +++ 7 files changed, 555 insertions(+) create mode 100644 recipes/hikariucp/.gitignore create mode 100644 recipes/hikariucp/README.md create mode 100644 recipes/hikariucp/pom.xml create mode 100644 recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java create mode 100644 recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java create mode 100644 recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml create mode 100644 recipes/hikariucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java diff --git a/recipes/hikariucp/.gitignore b/recipes/hikariucp/.gitignore new file mode 100644 index 00000000..dc9153d0 --- /dev/null +++ b/recipes/hikariucp/.gitignore @@ -0,0 +1,42 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +*.log + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +.idea +.idea/** + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +/.jpb/** + +### Mac OS ### +.DS_Store diff --git a/recipes/hikariucp/README.md b/recipes/hikariucp/README.md new file mode 100644 index 00000000..67d37b88 --- /dev/null +++ b/recipes/hikariucp/README.md @@ -0,0 +1,115 @@ +# Hikari to UCP Open Rewrite Recipe + +Current Version is `0.0.1-SNAPSHOT` and is under development. Please file GitHub issues for issues, enhancements and more. + +## Hikari to UCP rewrite Recipe + +> **_NOTE:_** In the pre release the rewrite works best with `properties` files. `YAML` files works too but the formatting of the outcome isn't pretty. + +This recipe will change the Hikare connection pool parameters and dependency from Hikari to Oracle Universal Connection Pooling (UCP). The [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html). + +The following properties are rewritten: + +### Maven dependencies `pom.xml` + +The Hikari dependency is removed and replaced with SPring Boot starters for Oracle UCP and Oracle Wallet (commonly used to connect to an autonomous database (ADB)). + +```xml + + com.zaxxer + HikariCP + +``` + +is changed to: + +```xml + + com.oracle.database.spring + oracle-spring-boot-starter-ucp + 25.1.0 + +``` + +And the following dependency is added, as it is commonly used to connect to an autonomous database (ADB): + +```xml + + com.oracle.database.spring + oracle-spring-boot-starter-wallet + 25.1.0 + +``` + +### Spring Boot Connection Pooling configuration `application.properties` + +> **_NOTE:_** The recipe will change Hikari's milliseconds to seconds. + +The following properties are rewritten. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) + +| Hikari Property | Oracle UCP Property | Notes | +|-----------------|---------------------|-------| +| N/A | `spring.datasource.driver-class-name` | Will be set to `oracle.jdbc.OracleDriver` | +| N/A | `spring.datasource.type` | Will be set to `oracle.ucp.jdbc.PoolDataSource` | +| `spring.datasource.hikari.pool-name` | `spring.datasource.oracleucp.connection-pool-name` | | +| `spring.datasource.hikari.maximum-pool-size` | `spring.datasource.oracleucp.max-pool-size` | | +| `spring.datasource.hikari.minimum-idle` | `spring.datasource.oracleucp.min-pool-size` | | +| `spring.datasource.hikari.connection-timeout` | `spring.datasource.oracleucp.connection-wait-timeout` | | +| `spring.datasource.hikari.idle-timeout` | `spring.datasource.oracleucp.inactive-connection-timeout` | | +| `spring.datasource.hikari.connection-test-query` | `spring.datasource.oracleucp.s-q-l-for-validate-connection` | | +| `spring.datasource.hikari.max-lifetime` | `spring.datasource.oracleucp.max-connection-reuse-time` | | +| `spring.datasource.hikari.validation-timeout` | `pring.datasource.oracleucp.connection-validation-timeout` | | + +The following UCP properties are added: + +| Oracle UCP Property | Value | Notes | +|---------------------|-------|-------| +| `spring.datasource.oracleucp.initial-pool-size` | 5 | [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) | + +The following Hikari Properties do not have identical UCP properties and will be commented out in the rewritten properties file. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) + +| Hikari UCP Property | Notes | +|---------------------|-------| +| `spring.datasource.hikari.auto-commit` | Use Oracle JDBC driver connection property autoCommit | +| `spring.datasource.hikari.register-mbeans` | UCP always attempts registration | +| `spring.datasource.hikari.thread-factory` | UCP supports setTaskManager instead | +| `spring.datasource.hikari.scheduled-executor` | UCP supports setTaskManager instead | +| `spring.datasource.hikari.keepalive-time` | Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE | + +## Build the Open Rewrite Recipe + +The repo is using maven. To build the recipe run the following command: + +```shell +mvn install +``` + +## To use the Recipe + + In the repository you want to test your recipe against, update the `pom.xml` to include the following: + + ```xml + + + + + org.openrewrite.maven + rewrite-maven-plugin + 6.2.2 + + + ConvertHikariToUCP + + + + + com.oracle.cloud.recipes + hikariucp + 0.0.1-SNAPSHOT + + + + + + +``` diff --git a/recipes/hikariucp/pom.xml b/recipes/hikariucp/pom.xml new file mode 100644 index 00000000..4eae1fdd --- /dev/null +++ b/recipes/hikariucp/pom.xml @@ -0,0 +1,134 @@ + + + + + 4.0.0 + + com.oracle.cloud.recipes.hikariucp + hikariucp + 0.0.1-SNAPSHOT + hikari-ucp + Openrewrite Recipe to convert Hikari Connection Pool to Oracle UCP + + https://github.com/oracle/spring-cloud-oracle/tree/hikari-ucp-recipe/recipes/hikari-ucp + + + Oracle America, Inc. + https://www.oracle.com + + + + The Universal Permissive License (UPL), Version 1.0 + https://oss.oracle.com/licenses/upl/ + repo + + + + + Oracle + obaas_ww at oracle.com + Oracle America, Inc. + https://www.oracle.com + + + + https://github.com/oracle/spring-cloud-oracle + scm:git:https://github.com/oracle/spring-cloud-oracle.git + scm:git:git@github.com:oracle/spring-cloud-oracle.git + + + + 17 + 17 + 17 + UTF-8 + 8.47.2 + 3.3.0 + 6.2.1 + 5.12.0 + + + + + org.openrewrite + rewrite-java + ${rewrite.version} + + + + org.openrewrite + rewrite-properties + ${rewrite.version} + + + + org.openrewrite + rewrite-yaml + ${rewrite.version} + + + + org.openrewrite + rewrite-maven + ${rewrite.version} + + + + org.junit.jupiter + junit-jupiter + test + + + + org.openrewrite + rewrite-test + test + + + + + + + org.openrewrite.recipe + rewrite-recipe-bom + ${rewrite.recipe.version} + pom + import + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + + + + + org.openrewrite.maven + rewrite-maven-plugin + ${maven.rewrite.plugin.version} + + + + + + + + + org.openrewrite.recipe + rewrite-spring + 5.24.1 + + + + + + + + \ No newline at end of file diff --git a/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java b/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java new file mode 100644 index 00000000..ed9004ef --- /dev/null +++ b/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java @@ -0,0 +1,57 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + +package com.oracle.cloud.recipes.hikariucp; + +import org.openrewrite.NlsRewrite; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.properties.PropertiesVisitor; +import org.openrewrite.properties.tree.Properties; + +public class ConvertMsToSecondsInPropertiesRecipe extends Recipe { + + private final String keyRegex; + + // Takes a keyRegex parameter to specify which property keys to target (e.g., Hikari timeout properties). + public ConvertMsToSecondsInPropertiesRecipe(String keyRegex) { + this.keyRegex = keyRegex; + } + + // Extends PropertiesVisitor to process each Properties.Entry (key-value pair) in application.properties. + @Override + public TreeVisitor getVisitor() { + + return new PropertiesVisitor() { + + @Override + public Properties visitEntry(Properties.Entry entry, ExecutionContext ctx) { + if (entry.getKey().matches(keyRegex)) { + String value = entry.getValue().getText().trim(); + try { + long ms = Long.parseLong(value); + double seconds = ms / 1000.0; + String newValue = String.valueOf(seconds); + Properties.Value updatedValue = entry.getValue().withText(newValue); + return entry.withValue(updatedValue); + } catch (NumberFormatException e) { + // If the value isn't a valid number, ignore it. + } + } + return super.visitEntry(entry, ctx); + } + + }; + } + + @Override + public @NlsRewrite.DisplayName String getDisplayName() { + return "Convert milliseconds to seconds for Hikari properties"; + } + + @Override + public @NlsRewrite.Description String getDescription() { + return "Transforms millisecond values to seconds for Hikari connection pool properties matching the given regex."; + } +} diff --git a/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java b/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java new file mode 100644 index 00000000..b605cda9 --- /dev/null +++ b/recipes/hikariucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java @@ -0,0 +1,68 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + +package com.oracle.cloud.recipes.hikariucp; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.NlsRewrite; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.yaml.YamlVisitor; +import org.openrewrite.yaml.tree.Yaml; + +import java.util.regex.Pattern; + +public class ConvertMsToSecondsInYamlRecipe extends Recipe { + + private final String pathRegex; + + public ConvertMsToSecondsInYamlRecipe(String pathRegex) { + this.pathRegex = pathRegex; + } + + @Override + public TreeVisitor getVisitor() { + + Pattern pattern = Pattern.compile(pathRegex); + + return new YamlVisitor() { + private String currentPath = ""; + + @Override + public Yaml visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { + String previousPath = currentPath; + currentPath += (currentPath.isEmpty() ? "" : ".") + entry.getKey().getValue(); + Yaml.Mapping.Entry updatedEntry = (Yaml.Mapping.Entry) super.visitMappingEntry(entry, ctx); + currentPath = previousPath; + return updatedEntry; + } + + @Override + public Yaml visitScalar(Yaml.Scalar scalar, ExecutionContext ctx) { + if (pattern.matcher(currentPath).matches()) { + String value = scalar.getValue().trim(); + try { + long ms = Long.parseLong(value); + double seconds = ms / 1000.0; + String newValue = String.valueOf(seconds); + return scalar.withValue(newValue); + } catch (NumberFormatException e) { + // If the value isn't a valid number, ignore it. + } + } + return super.visitScalar(scalar, ctx); + } + }; + + } + + @Override + public @NlsRewrite.DisplayName String getDisplayName() { + return ""; + } + + @Override + public @NlsRewrite.Description String getDescription() { + return ""; + } +} diff --git a/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml new file mode 100644 index 00000000..772a9ff4 --- /dev/null +++ b/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml @@ -0,0 +1,117 @@ +# +# Copyright © 2025, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +# Source for the recipe: +# https://github.com/brettwooldridge/HikariCP?tab=readme-ov-file#gear-configuration-knobs-baby +--- +type: specs.openrewrite.org/v1beta/recipe +name: com.oracle.cloud.recipes.hikariucp.ConvertHikariToUCP +displayName: Migrate Hikari CP to Oracle UCP +description: Migrate Hikari Connection Pool to Oracle Universal Connection Pool +tags: + - spring + - oracle + - ucp + - hikari +recipeList: + + # For pom.xml + - org.openrewrite.java.dependencies.RemoveDependency: + groupId: com.zaxxer* + artifactId: HikariCP* + - org.openrewrite.java.dependencies.AddDependency: + groupId: com.oracle.database.spring + artifactId: oracle-spring-boot-starter-ucp + version: 25.1.0 + - org.openrewrite.java.dependencies.AddDependency: + groupId: com.oracle.database.spring + artifactId: oracle-spring-boot-starter-wallet + version: 25.1.0 + + # spring.datasource.oracleucp.connection-factory-class: oracle.jdbc.pool.OracleDataSource + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.data-source-class-name + newPropertyKey: spring.datasource.oracleucp.connection-factory-class-name + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.oracleucp.connection-factory-class-name + newValue: oracle.jdbc.pool.OracleDataSource + + # spring.datasource.driver-class-name: OracleDriver + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.driver-class-name + newValue: oracle.jdbc.OracleDriver + + # spring.datasource.type: oracle.ucp.jdbc.PoolDataSource + - org.openrewrite.java.spring.ChangeSpringPropertyValue: + propertyKey: spring.datasource.type + newValue: oracle.ucp.jdbc.PoolDataSource + + # spring.datasource.oracleucp.connection-pool-name + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.pool-name + newPropertyKey: spring.datasource.oracleucp.connection-pool-name + + # spring.datasource.oracleucp.max-pool-size + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.maximum-pool-size + newPropertyKey: spring.datasource.oracleucp.max-pool-size + + # spring.datasource.oracleucp.min-pool-size + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.minimum-idle + newPropertyKey: spring.datasource.oracleucp.min-pool-size + + # spring.datasource.oracleucp.connection-validation-timeout + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.connection-timeout + newPropertyKey: spring.datasource.oracleucp.connection-wait-timeout + + # spring.datasource.oracleucp.inactive-connection-timeout + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.idle-timeout + newPropertyKey: spring.datasource.oracleucp.inactive-connection-timeout + + # spring.datasource.oracleucp.s-q-l-for-validate-connection + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.connection-test-query + newPropertyKey: spring.datasource.oracleucp.s-q-l-for-validate-connection + + # spring.datasource.oracleucp.max-connection-reuse-time + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.max-lifetime + newPropertyKey: spring.datasource.oracleucp.max-connection-reuse-time + + # spring.datasource.oracleucp.max-connection-reuse-time + - org.openrewrite.java.spring.ChangeSpringPropertyKey: + oldPropertyKey: spring.datasource.hikari.validation-timeout + newPropertyKey: spring.datasource.oracleucp.connection-validation-timeout + + # spring.datasource.oracleucp.initial-pool-size + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.initial-pool-size + value: 5 + comment: "Specifies the number of available connections created after the pool is initiated" + + # HikariCP properties that don’t have identical UCP properties + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.auto-commit + comment: "Use Oracle JDBC driver connection property autoCommit." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.register-mbeans + comment: "UCP always attempts registration." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.thread-factory + comment: "UCP supports setTaskManager instead." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.scheduled-executor + comment: "UCP supports setTaskManager instead." + - org.openrewrite.java.spring.CommentOutSpringPropertyKey: + propertyKey: spring.datasource.hikari.keepalive-time + comment: "Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE" + + # Convert milliseconds to seconds + - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInPropertiesRecipe: + keyRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' + - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInYamlRecipe: + pathRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' \ No newline at end of file diff --git a/recipes/hikariucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java b/recipes/hikariucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java new file mode 100644 index 00000000..71bb8187 --- /dev/null +++ b/recipes/hikariucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java @@ -0,0 +1,22 @@ +// Copyright (c) 2025, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + +package oracle.com.cloud.recipes.hikariucp; + +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.properties.Assertions.properties; +import static org.openrewrite.yaml.Assertions.yaml; + +class ChangeSpringPropertyValueTest implements RewriteTest { + + // @DocumentExample + // @Test + // void propFile() { + // rewriteRun( + // spec -> spec.recipe(new ChangeSpringPropertyValue("server.port", "8081", null, null, null)), + // properties("server.port=8080", "server.port=8081") + // ); + + +} \ No newline at end of file From 90388c237d28907941f32933dc9524820e520d33 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 13:22:15 -0600 Subject: [PATCH 10/13] Changed Package name --- recipes/hikari-ucp/.gitignore | 42 ------ recipes/hikari-ucp/README.md | 115 --------------- recipes/hikari-ucp/pom.xml | 134 ------------------ .../ConvertMsToSecondsInPropertiesRecipe.java | 57 -------- .../ConvertMsToSecondsInYamlRecipe.java | 68 --------- .../resources/META-INF/rewrite/rewrite.yml | 117 --------------- .../hikariucp/ChangePropertyValueTest.java | 22 --- 7 files changed, 555 deletions(-) delete mode 100644 recipes/hikari-ucp/.gitignore delete mode 100644 recipes/hikari-ucp/README.md delete mode 100644 recipes/hikari-ucp/pom.xml delete mode 100644 recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java delete mode 100644 recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java delete mode 100644 recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml delete mode 100644 recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java diff --git a/recipes/hikari-ucp/.gitignore b/recipes/hikari-ucp/.gitignore deleted file mode 100644 index dc9153d0..00000000 --- a/recipes/hikari-ucp/.gitignore +++ /dev/null @@ -1,42 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ -*.log - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -.idea -.idea/** - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ -/.jpb/** - -### Mac OS ### -.DS_Store diff --git a/recipes/hikari-ucp/README.md b/recipes/hikari-ucp/README.md deleted file mode 100644 index 67d37b88..00000000 --- a/recipes/hikari-ucp/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Hikari to UCP Open Rewrite Recipe - -Current Version is `0.0.1-SNAPSHOT` and is under development. Please file GitHub issues for issues, enhancements and more. - -## Hikari to UCP rewrite Recipe - -> **_NOTE:_** In the pre release the rewrite works best with `properties` files. `YAML` files works too but the formatting of the outcome isn't pretty. - -This recipe will change the Hikare connection pool parameters and dependency from Hikari to Oracle Universal Connection Pooling (UCP). The [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html). - -The following properties are rewritten: - -### Maven dependencies `pom.xml` - -The Hikari dependency is removed and replaced with SPring Boot starters for Oracle UCP and Oracle Wallet (commonly used to connect to an autonomous database (ADB)). - -```xml - - com.zaxxer - HikariCP - -``` - -is changed to: - -```xml - - com.oracle.database.spring - oracle-spring-boot-starter-ucp - 25.1.0 - -``` - -And the following dependency is added, as it is commonly used to connect to an autonomous database (ADB): - -```xml - - com.oracle.database.spring - oracle-spring-boot-starter-wallet - 25.1.0 - -``` - -### Spring Boot Connection Pooling configuration `application.properties` - -> **_NOTE:_** The recipe will change Hikari's milliseconds to seconds. - -The following properties are rewritten. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) - -| Hikari Property | Oracle UCP Property | Notes | -|-----------------|---------------------|-------| -| N/A | `spring.datasource.driver-class-name` | Will be set to `oracle.jdbc.OracleDriver` | -| N/A | `spring.datasource.type` | Will be set to `oracle.ucp.jdbc.PoolDataSource` | -| `spring.datasource.hikari.pool-name` | `spring.datasource.oracleucp.connection-pool-name` | | -| `spring.datasource.hikari.maximum-pool-size` | `spring.datasource.oracleucp.max-pool-size` | | -| `spring.datasource.hikari.minimum-idle` | `spring.datasource.oracleucp.min-pool-size` | | -| `spring.datasource.hikari.connection-timeout` | `spring.datasource.oracleucp.connection-wait-timeout` | | -| `spring.datasource.hikari.idle-timeout` | `spring.datasource.oracleucp.inactive-connection-timeout` | | -| `spring.datasource.hikari.connection-test-query` | `spring.datasource.oracleucp.s-q-l-for-validate-connection` | | -| `spring.datasource.hikari.max-lifetime` | `spring.datasource.oracleucp.max-connection-reuse-time` | | -| `spring.datasource.hikari.validation-timeout` | `pring.datasource.oracleucp.connection-validation-timeout` | | - -The following UCP properties are added: - -| Oracle UCP Property | Value | Notes | -|---------------------|-------|-------| -| `spring.datasource.oracleucp.initial-pool-size` | 5 | [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) | - -The following Hikari Properties do not have identical UCP properties and will be commented out in the rewritten properties file. [UCP documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/jjucp/index.html) - -| Hikari UCP Property | Notes | -|---------------------|-------| -| `spring.datasource.hikari.auto-commit` | Use Oracle JDBC driver connection property autoCommit | -| `spring.datasource.hikari.register-mbeans` | UCP always attempts registration | -| `spring.datasource.hikari.thread-factory` | UCP supports setTaskManager instead | -| `spring.datasource.hikari.scheduled-executor` | UCP supports setTaskManager instead | -| `spring.datasource.hikari.keepalive-time` | Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE | - -## Build the Open Rewrite Recipe - -The repo is using maven. To build the recipe run the following command: - -```shell -mvn install -``` - -## To use the Recipe - - In the repository you want to test your recipe against, update the `pom.xml` to include the following: - - ```xml - - - - - org.openrewrite.maven - rewrite-maven-plugin - 6.2.2 - - - ConvertHikariToUCP - - - - - com.oracle.cloud.recipes - hikariucp - 0.0.1-SNAPSHOT - - - - - - -``` diff --git a/recipes/hikari-ucp/pom.xml b/recipes/hikari-ucp/pom.xml deleted file mode 100644 index 4eae1fdd..00000000 --- a/recipes/hikari-ucp/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - 4.0.0 - - com.oracle.cloud.recipes.hikariucp - hikariucp - 0.0.1-SNAPSHOT - hikari-ucp - Openrewrite Recipe to convert Hikari Connection Pool to Oracle UCP - - https://github.com/oracle/spring-cloud-oracle/tree/hikari-ucp-recipe/recipes/hikari-ucp - - - Oracle America, Inc. - https://www.oracle.com - - - - The Universal Permissive License (UPL), Version 1.0 - https://oss.oracle.com/licenses/upl/ - repo - - - - - Oracle - obaas_ww at oracle.com - Oracle America, Inc. - https://www.oracle.com - - - - https://github.com/oracle/spring-cloud-oracle - scm:git:https://github.com/oracle/spring-cloud-oracle.git - scm:git:git@github.com:oracle/spring-cloud-oracle.git - - - - 17 - 17 - 17 - UTF-8 - 8.47.2 - 3.3.0 - 6.2.1 - 5.12.0 - - - - - org.openrewrite - rewrite-java - ${rewrite.version} - - - - org.openrewrite - rewrite-properties - ${rewrite.version} - - - - org.openrewrite - rewrite-yaml - ${rewrite.version} - - - - org.openrewrite - rewrite-maven - ${rewrite.version} - - - - org.junit.jupiter - junit-jupiter - test - - - - org.openrewrite - rewrite-test - test - - - - - - - org.openrewrite.recipe - rewrite-recipe-bom - ${rewrite.recipe.version} - pom - import - - - org.junit - junit-bom - ${junit.version} - pom - import - - - - - - - - org.openrewrite.maven - rewrite-maven-plugin - ${maven.rewrite.plugin.version} - - - - - - - - - org.openrewrite.recipe - rewrite-spring - 5.24.1 - - - - - - - - \ No newline at end of file diff --git a/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java deleted file mode 100644 index ed9004ef..00000000 --- a/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInPropertiesRecipe.java +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2025, Oracle and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -package com.oracle.cloud.recipes.hikariucp; - -import org.openrewrite.NlsRewrite; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; -import org.openrewrite.properties.PropertiesVisitor; -import org.openrewrite.properties.tree.Properties; - -public class ConvertMsToSecondsInPropertiesRecipe extends Recipe { - - private final String keyRegex; - - // Takes a keyRegex parameter to specify which property keys to target (e.g., Hikari timeout properties). - public ConvertMsToSecondsInPropertiesRecipe(String keyRegex) { - this.keyRegex = keyRegex; - } - - // Extends PropertiesVisitor to process each Properties.Entry (key-value pair) in application.properties. - @Override - public TreeVisitor getVisitor() { - - return new PropertiesVisitor() { - - @Override - public Properties visitEntry(Properties.Entry entry, ExecutionContext ctx) { - if (entry.getKey().matches(keyRegex)) { - String value = entry.getValue().getText().trim(); - try { - long ms = Long.parseLong(value); - double seconds = ms / 1000.0; - String newValue = String.valueOf(seconds); - Properties.Value updatedValue = entry.getValue().withText(newValue); - return entry.withValue(updatedValue); - } catch (NumberFormatException e) { - // If the value isn't a valid number, ignore it. - } - } - return super.visitEntry(entry, ctx); - } - - }; - } - - @Override - public @NlsRewrite.DisplayName String getDisplayName() { - return "Convert milliseconds to seconds for Hikari properties"; - } - - @Override - public @NlsRewrite.Description String getDescription() { - return "Transforms millisecond values to seconds for Hikari connection pool properties matching the given regex."; - } -} diff --git a/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java b/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java deleted file mode 100644 index b605cda9..00000000 --- a/recipes/hikari-ucp/src/main/com/oracle/cloud/recipes/hikariucp/ConvertMsToSecondsInYamlRecipe.java +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2025, Oracle and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -package com.oracle.cloud.recipes.hikariucp; - -import org.openrewrite.ExecutionContext; -import org.openrewrite.NlsRewrite; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; -import org.openrewrite.yaml.YamlVisitor; -import org.openrewrite.yaml.tree.Yaml; - -import java.util.regex.Pattern; - -public class ConvertMsToSecondsInYamlRecipe extends Recipe { - - private final String pathRegex; - - public ConvertMsToSecondsInYamlRecipe(String pathRegex) { - this.pathRegex = pathRegex; - } - - @Override - public TreeVisitor getVisitor() { - - Pattern pattern = Pattern.compile(pathRegex); - - return new YamlVisitor() { - private String currentPath = ""; - - @Override - public Yaml visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) { - String previousPath = currentPath; - currentPath += (currentPath.isEmpty() ? "" : ".") + entry.getKey().getValue(); - Yaml.Mapping.Entry updatedEntry = (Yaml.Mapping.Entry) super.visitMappingEntry(entry, ctx); - currentPath = previousPath; - return updatedEntry; - } - - @Override - public Yaml visitScalar(Yaml.Scalar scalar, ExecutionContext ctx) { - if (pattern.matcher(currentPath).matches()) { - String value = scalar.getValue().trim(); - try { - long ms = Long.parseLong(value); - double seconds = ms / 1000.0; - String newValue = String.valueOf(seconds); - return scalar.withValue(newValue); - } catch (NumberFormatException e) { - // If the value isn't a valid number, ignore it. - } - } - return super.visitScalar(scalar, ctx); - } - }; - - } - - @Override - public @NlsRewrite.DisplayName String getDisplayName() { - return ""; - } - - @Override - public @NlsRewrite.Description String getDescription() { - return ""; - } -} diff --git a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml deleted file mode 100644 index 772a9ff4..00000000 --- a/recipes/hikari-ucp/src/main/resources/META-INF/rewrite/rewrite.yml +++ /dev/null @@ -1,117 +0,0 @@ -# -# Copyright © 2025, Oracle and/or its affiliates. -# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. -# -# Source for the recipe: -# https://github.com/brettwooldridge/HikariCP?tab=readme-ov-file#gear-configuration-knobs-baby ---- -type: specs.openrewrite.org/v1beta/recipe -name: com.oracle.cloud.recipes.hikariucp.ConvertHikariToUCP -displayName: Migrate Hikari CP to Oracle UCP -description: Migrate Hikari Connection Pool to Oracle Universal Connection Pool -tags: - - spring - - oracle - - ucp - - hikari -recipeList: - - # For pom.xml - - org.openrewrite.java.dependencies.RemoveDependency: - groupId: com.zaxxer* - artifactId: HikariCP* - - org.openrewrite.java.dependencies.AddDependency: - groupId: com.oracle.database.spring - artifactId: oracle-spring-boot-starter-ucp - version: 25.1.0 - - org.openrewrite.java.dependencies.AddDependency: - groupId: com.oracle.database.spring - artifactId: oracle-spring-boot-starter-wallet - version: 25.1.0 - - # spring.datasource.oracleucp.connection-factory-class: oracle.jdbc.pool.OracleDataSource - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.data-source-class-name - newPropertyKey: spring.datasource.oracleucp.connection-factory-class-name - - org.openrewrite.java.spring.ChangeSpringPropertyValue: - propertyKey: spring.datasource.oracleucp.connection-factory-class-name - newValue: oracle.jdbc.pool.OracleDataSource - - # spring.datasource.driver-class-name: OracleDriver - - org.openrewrite.java.spring.ChangeSpringPropertyValue: - propertyKey: spring.datasource.driver-class-name - newValue: oracle.jdbc.OracleDriver - - # spring.datasource.type: oracle.ucp.jdbc.PoolDataSource - - org.openrewrite.java.spring.ChangeSpringPropertyValue: - propertyKey: spring.datasource.type - newValue: oracle.ucp.jdbc.PoolDataSource - - # spring.datasource.oracleucp.connection-pool-name - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.pool-name - newPropertyKey: spring.datasource.oracleucp.connection-pool-name - - # spring.datasource.oracleucp.max-pool-size - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.maximum-pool-size - newPropertyKey: spring.datasource.oracleucp.max-pool-size - - # spring.datasource.oracleucp.min-pool-size - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.minimum-idle - newPropertyKey: spring.datasource.oracleucp.min-pool-size - - # spring.datasource.oracleucp.connection-validation-timeout - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.connection-timeout - newPropertyKey: spring.datasource.oracleucp.connection-wait-timeout - - # spring.datasource.oracleucp.inactive-connection-timeout - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.idle-timeout - newPropertyKey: spring.datasource.oracleucp.inactive-connection-timeout - - # spring.datasource.oracleucp.s-q-l-for-validate-connection - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.connection-test-query - newPropertyKey: spring.datasource.oracleucp.s-q-l-for-validate-connection - - # spring.datasource.oracleucp.max-connection-reuse-time - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.max-lifetime - newPropertyKey: spring.datasource.oracleucp.max-connection-reuse-time - - # spring.datasource.oracleucp.max-connection-reuse-time - - org.openrewrite.java.spring.ChangeSpringPropertyKey: - oldPropertyKey: spring.datasource.hikari.validation-timeout - newPropertyKey: spring.datasource.oracleucp.connection-validation-timeout - - # spring.datasource.oracleucp.initial-pool-size - - org.openrewrite.java.spring.AddSpringProperty: - property: spring.datasource.oracleucp.initial-pool-size - value: 5 - comment: "Specifies the number of available connections created after the pool is initiated" - - # HikariCP properties that don’t have identical UCP properties - - org.openrewrite.java.spring.CommentOutSpringPropertyKey: - propertyKey: spring.datasource.hikari.auto-commit - comment: "Use Oracle JDBC driver connection property autoCommit." - - org.openrewrite.java.spring.CommentOutSpringPropertyKey: - propertyKey: spring.datasource.hikari.register-mbeans - comment: "UCP always attempts registration." - - org.openrewrite.java.spring.CommentOutSpringPropertyKey: - propertyKey: spring.datasource.hikari.thread-factory - comment: "UCP supports setTaskManager instead." - - org.openrewrite.java.spring.CommentOutSpringPropertyKey: - propertyKey: spring.datasource.hikari.scheduled-executor - comment: "UCP supports setTaskManager instead." - - org.openrewrite.java.spring.CommentOutSpringPropertyKey: - propertyKey: spring.datasource.hikari.keepalive-time - comment: "Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE" - - # Convert milliseconds to seconds - - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInPropertiesRecipe: - keyRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' - - oracle.com.cloud.recipes.hikariucp.ConvertMsToSecondsInYamlRecipe: - pathRegex: 'spring\.datasource\.hikari\.(connectionTimeout|idleTimeout|maxLifetime|leakDetectionThreshold)' \ No newline at end of file diff --git a/recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java b/recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java deleted file mode 100644 index 71bb8187..00000000 --- a/recipes/hikari-ucp/src/test/oracle/com/cloud/recipes/hikariucp/ChangePropertyValueTest.java +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2025, Oracle and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - -package oracle.com.cloud.recipes.hikariucp; - -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.properties.Assertions.properties; -import static org.openrewrite.yaml.Assertions.yaml; - -class ChangeSpringPropertyValueTest implements RewriteTest { - - // @DocumentExample - // @Test - // void propFile() { - // rewriteRun( - // spec -> spec.recipe(new ChangeSpringPropertyValue("server.port", "8081", null, null, null)), - // properties("server.port=8080", "server.port=8081") - // ); - - -} \ No newline at end of file From adb372d0173a38951cfe97606115c6e894b84ef6 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Sat, 1 Mar 2025 13:27:35 -0600 Subject: [PATCH 11/13] pom update --- recipes/hikariucp/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/hikariucp/pom.xml b/recipes/hikariucp/pom.xml index 4eae1fdd..b818cf1d 100644 --- a/recipes/hikariucp/pom.xml +++ b/recipes/hikariucp/pom.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.oracle.cloud.recipes.hikariucp + com.oracle.cloud.recipes hikariucp 0.0.1-SNAPSHOT hikari-ucp From 961088447a7ffcc05764b59d7ea584529701931b Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Wed, 19 Mar 2025 16:06:36 -0500 Subject: [PATCH 12/13] Update versions and recipe --- recipes/hikariucp/pom.xml | 8 +- .../resources/META-INF/rewrite/rewrite.yml | 83 +++++++++++++++++-- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/recipes/hikariucp/pom.xml b/recipes/hikariucp/pom.xml index b818cf1d..710aea3c 100644 --- a/recipes/hikariucp/pom.xml +++ b/recipes/hikariucp/pom.xml @@ -44,10 +44,10 @@ 17 17 UTF-8 - 8.47.2 - 3.3.0 - 6.2.1 - 5.12.0 + 8.48.1 + 3.3.0 + 6.3.2 + 5.12.1 diff --git a/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml b/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml index 772a9ff4..8d0964db 100644 --- a/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/recipes/hikariucp/src/main/resources/META-INF/rewrite/rewrite.yml @@ -17,6 +17,9 @@ tags: recipeList: # For pom.xml + - org.openrewrite.java.dependencies.RemoveDependency: + GroupId: com.oracle.database.jdbc + ArtifactId: ojdbc* - org.openrewrite.java.dependencies.RemoveDependency: groupId: com.zaxxer* artifactId: HikariCP* @@ -29,6 +32,80 @@ recipeList: artifactId: oracle-spring-boot-starter-wallet version: 25.1.0 + # https://docs.openrewrite.org/recipes/java/spring/addspringproperty + # Add a spring configuration property to a configuration file if it does not already exist in that file. + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.driver-class-name + value: oracle.jdbc.OracleDriver + comment: "JDBC driver class" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.type + value: oracle.ucp.jdbc.PoolDataSource + comment: specify the connection pool driver to use" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.connection-pool-name + value: UCPConnectionPool + comment: "Connection Pool Name" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.max-pool-size + value: 20 + comment: "Specifies the maximum number of available and borrowed connections that our pool is maintaining" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.min-pool-size + value: 5 + comment: "Specifies the minimum number of available and borrowed connections that our pool is maintaining" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.initial-pool-size + value: 10 + comment: "Specifies the number of available connections created after the pool is initiated" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.connection-wait-timeout + value: 3 + comment: "specifies how long an application request waits to obtain a connection if there are no longer any connections in the pool" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.inactive-connection-timeout + value: 0 + comment: "Specifies how long an available connection can remain idle before it is closed and removed from the pool" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.max-connection-reuse-time + value: 0 + comment: "Allows connections to be gracefully closed and removed from a connection pool after a specific amount of time" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.connection-validation-timeout + value: 15 + comment: "Specifies the duration within which a borrowed connection from the pool is validated" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.fast-connection-failover-enabled + value: false + comment: "Enables faster failover for connection attempts" + pathExpressions: ["**/application.properties"] + + - org.openrewrite.java.spring.AddSpringProperty: + property: spring.datasource.oracleucp.validate-connection-on-borrow + value: false + comment: "Whether to validate connections when borrowed from the pool" + pathExpressions: ["**/application.properties"] + # spring.datasource.oracleucp.connection-factory-class: oracle.jdbc.pool.OracleDataSource - org.openrewrite.java.spring.ChangeSpringPropertyKey: oldPropertyKey: spring.datasource.hikari.data-source-class-name @@ -87,12 +164,6 @@ recipeList: oldPropertyKey: spring.datasource.hikari.validation-timeout newPropertyKey: spring.datasource.oracleucp.connection-validation-timeout - # spring.datasource.oracleucp.initial-pool-size - - org.openrewrite.java.spring.AddSpringProperty: - property: spring.datasource.oracleucp.initial-pool-size - value: 5 - comment: "Specifies the number of available connections created after the pool is initiated" - # HikariCP properties that don’t have identical UCP properties - org.openrewrite.java.spring.CommentOutSpringPropertyKey: propertyKey: spring.datasource.hikari.auto-commit From 081f060b92212088815c2f1e308c78e87dea80b7 Mon Sep 17 00:00:00 2001 From: Andy Tael Date: Wed, 19 Mar 2025 16:16:28 -0500 Subject: [PATCH 13/13] README update --- recipes/hikariucp/README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/recipes/hikariucp/README.md b/recipes/hikariucp/README.md index 67d37b88..659fc487 100644 --- a/recipes/hikariucp/README.md +++ b/recipes/hikariucp/README.md @@ -31,6 +31,15 @@ is changed to: ``` +The following dependency is removed (all ojdbc* variants) and replaced by the UCP Starter: + +```xml + + com.oracle.database.jdbc + ojdbc* + +``` + And the following dependency is added, as it is commonly used to connect to an autonomous database (ADB): ```xml @@ -58,7 +67,7 @@ The following properties are rewritten. [UCP documentation](https://docs.oracle. | `spring.datasource.hikari.idle-timeout` | `spring.datasource.oracleucp.inactive-connection-timeout` | | | `spring.datasource.hikari.connection-test-query` | `spring.datasource.oracleucp.s-q-l-for-validate-connection` | | | `spring.datasource.hikari.max-lifetime` | `spring.datasource.oracleucp.max-connection-reuse-time` | | -| `spring.datasource.hikari.validation-timeout` | `pring.datasource.oracleucp.connection-validation-timeout` | | +| `spring.datasource.hikari.validation-timeout` | `spring.datasource.oracleucp.connection-validation-timeout` | | The following UCP properties are added: @@ -95,7 +104,7 @@ mvn install org.openrewrite.maven rewrite-maven-plugin - 6.2.2 + 6.3.2 ConvertHikariToUCP