From c03d6997b42a4613a101b85811e087454d1f1bb0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:47:52 +0000 Subject: [PATCH 01/29] chore(deps): update dependency gradle to v8.6 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e093..a80b22ce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 165db72d10671abbd726af8a63d2658978259911 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:19:27 +0000 Subject: [PATCH 02/29] fix(deps): update junit to v5.10.2 --- build.gradle.kts | 4 ++-- sadu-testing/build.gradle.kts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index efd3af66..eb397f87 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -122,8 +122,8 @@ allprojects { dependencies { - testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.1") - testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.10.1") + testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.2") + testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.10.2") testImplementation("org.mockito", "mockito-core", "5.+") } diff --git a/sadu-testing/build.gradle.kts b/sadu-testing/build.gradle.kts index 34c04da0..504f1fa7 100644 --- a/sadu-testing/build.gradle.kts +++ b/sadu-testing/build.gradle.kts @@ -2,9 +2,9 @@ description = "SADU module for checking validity of updater files" dependencies { - api(platform("org.junit:junit-bom:5.10.1")) + api(platform("org.junit:junit-bom:5.10.2")) api("org.junit.jupiter:junit-jupiter") api(project(":sadu-core")) - testImplementation(platform("org.junit:junit-bom:5.10.1")) + testImplementation(platform("org.junit:junit-bom:5.10.2")) testImplementation("org.junit.jupiter:junit-jupiter") } From 71297f3ca0de9fe53fb8f512a396aca3b8d97277 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:06:27 +0100 Subject: [PATCH 03/29] fix(deps): update junit5 monorepo to v5.10.2 (#158) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5df9d64e..552fb06c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,7 +46,7 @@ dependencyResolutionManagement { } create("testlibs") { - version("junit", "5.10.1") + version("junit", "5.10.2") library("junit-jupiter", "org.junit.jupiter", "junit-jupiter").versionRef("junit") library("junit-params", "org.junit.jupiter", "junit-jupiter-params").versionRef("junit") bundle("junit", listOf("junit-jupiter", "junit-params")) From 78ac75023df3aa98dc1f66cefa3dbc02c3311ea2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:03:28 +0100 Subject: [PATCH 04/29] fix(deps): update dependency org.xerial:sqlite-jdbc to v3.45.1.0 (#155) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- sadu-examples/build.gradle.kts | 2 +- settings.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sadu-examples/build.gradle.kts b/sadu-examples/build.gradle.kts index 782c116e..3bc4db43 100644 --- a/sadu-examples/build.gradle.kts +++ b/sadu-examples/build.gradle.kts @@ -2,7 +2,7 @@ dependencies { compileOnly(project(":")) // database driver - compileOnly("org.xerial", "sqlite-jdbc", "3.45.0.0") + compileOnly("org.xerial", "sqlite-jdbc", "3.45.1.0") compileOnly("org.postgresql", "postgresql", "42.7.1") compileOnly("org.mariadb.jdbc", "mariadb-java-client", "3.3.2") compileOnly("mysql", "mysql-connector-java", "8.0.33") diff --git a/settings.gradle.kts b/settings.gradle.kts index 552fb06c..dc390fea 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -63,7 +63,7 @@ dependencyResolutionManagement { library("driver-postgres", "org.postgresql:postgresql:42.7.1") library("driver-mariadb", "org.mariadb.jdbc:mariadb-java-client:3.3.2") - library("driver-sqlite", "org.xerial:sqlite-jdbc:3.45.0.0") + library("driver-sqlite", "org.xerial:sqlite-jdbc:3.45.1.0") library("driver-mysql", "com.mysql:mysql-connector-j:8.3.0") bundle("database-postgres", listOf("testcontainers-junit", "testcontainers-core", "testcontainers-postgres", "driver-postgres")) From 43230d3444923dd661de8f69769799cbf30e7975 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:03:38 +0100 Subject: [PATCH 05/29] fix(deps): update testcontainers-java monorepo to v1.19.4 (#153) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index dc390fea..be5ec08b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -51,7 +51,7 @@ dependencyResolutionManagement { library("junit-params", "org.junit.jupiter", "junit-jupiter-params").versionRef("junit") bundle("junit", listOf("junit-jupiter", "junit-params")) - version("testcontainers", "1.19.3") + version("testcontainers", "1.19.4") library("testcontainers-postgres", "org.testcontainers", "postgresql").versionRef("testcontainers") library("testcontainers-mariadb", "org.testcontainers", "mariadb").versionRef("testcontainers") library("testcontainers-mysql", "org.testcontainers", "mysql").versionRef("testcontainers") From b9e2c345addd7fa6aa83b8ddc7f95296efc5b5f7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:06:44 +0100 Subject: [PATCH 06/29] fix(deps): update testcontainers-java monorepo to v1.19.5 (#160) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index be5ec08b..e2592df2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -51,7 +51,7 @@ dependencyResolutionManagement { library("junit-params", "org.junit.jupiter", "junit-jupiter-params").versionRef("junit") bundle("junit", listOf("junit-jupiter", "junit-params")) - version("testcontainers", "1.19.4") + version("testcontainers", "1.19.5") library("testcontainers-postgres", "org.testcontainers", "postgresql").versionRef("testcontainers") library("testcontainers-mariadb", "org.testcontainers", "mariadb").versionRef("testcontainers") library("testcontainers-mysql", "org.testcontainers", "mysql").versionRef("testcontainers") From 96aed4b3df2c9f64933b4d0cee3927076432a886 Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:08:00 +0100 Subject: [PATCH 07/29] Sadu Queries 2 (#42) --- .github/workflows/javadocs.yml | 4 +- .github/workflows/publish.yml | 4 +- .github/workflows/verify.yml | 4 +- build.gradle.kts | 10 +- .../sadu/exceptions/ThrowingBiConsumer.java | 30 ++ sadu-core/src/main/java/module-info.java | 13 + sadu-examples/build.gradle.kts | 5 +- .../de/chojo/sadu/mapper/MapperConfig.java | 3 + .../chojo/sadu/mapper/RowMapperRegistry.java | 3 + .../sadu/mapper/rowmapper/RowMapper.java | 3 +- .../sadu/mapper/rowmapper/RowMapping.java | 20 + sadu-mapper/src/main/java/module-info.java | 12 + sadu-mariadb/build.gradle.kts | 1 + sadu-mysql/build.gradle.kts | 1 + sadu-postgresql/build.gradle.kts | 1 + .../chojo/sadu/update/PostgreSqlUpdater.java | 7 +- .../sadu/update/PostgreSqlUpdaterBuilder.java | 4 +- sadu-queries2/build.gradle.kts | 11 + .../queries/api/base/ConnectionProvider.java | 18 + .../sadu/queries/api/base/QueryProvider.java | 35 ++ .../sadu/queries/api/base/package-info.java | 4 + .../de/chojo/sadu/queries/api/call/Call.java | 167 ++++++++ .../queries/api/call/adapter/Adapter.java | 111 +++++ .../api/call/adapter/AdapterMapping.java | 29 ++ .../api/call/adapter/package-info.java | 4 + .../sadu/queries/api/call/calls/Calls.java | 81 ++++ .../queries/api/call/calls/package-info.java | 4 + .../sadu/queries/api/call/package-info.java | 4 + .../queries/api/execution/package-info.java | 4 + .../queries/api/execution/reading/Reader.java | 67 +++ .../api/execution/reading/package-info.java | 4 + .../execution/writing/CalledBatchQuery.java | 37 ++ .../writing/CalledSingletonQuery.java | 68 +++ .../api/execution/writing/package-info.java | 4 + .../queries/api/parameter/BaseParameter.java | 17 + .../queries/api/parameter/package-info.java | 4 + .../sadu/queries/api/query/AppendedQuery.java | 22 + .../sadu/queries/api/query/ParsedQuery.java | 113 +++++ .../chojo/sadu/queries/api/query/Query.java | 44 ++ .../sadu/queries/api/query/package-info.java | 4 + .../queries/api/results/package-info.java | 4 + .../queries/api/results/reading/Result.java | 24 ++ .../api/results/reading/package-info.java | 4 + .../writing/ManipulationBatchResult.java | 34 ++ .../results/writing/ManipulationResult.java | 27 ++ .../api/results/writing/package-info.java | 4 + .../queries/api/storage/ResultStorage.java | 13 + .../queries/api/storage/package-info.java | 4 + .../de/chojo/sadu/queries/call/CallImpl.java | 405 ++++++++++++++++++ .../queries/call/adapter/StandardAdapter.java | 76 ++++ .../queries/call/adapter/UUIDAdapter.java | 33 ++ .../queries/call/adapter/package-info.java | 4 + .../chojo/sadu/queries/call/package-info.java | 4 + .../chojo/sadu/queries/calls/BatchCall.java | 77 ++++ .../sadu/queries/calls/CallSupplier.java | 15 + .../sadu/queries/calls/SingletonCall.java | 32 ++ .../sadu/queries/calls/package-info.java | 4 + .../ConnectedQueryConfiguration.java | 57 +++ .../configuration/QueryConfiguration.java | 158 +++++++ .../QueryConfigurationBuilder.java | 92 ++++ .../queries/configuration/package-info.java | 4 + .../exception/QueryExecutionException.java | 54 +++ .../WrappedQueryExecutionException.java | 64 +++ .../sadu/queries/exception/package-info.java | 4 + .../queries/parameter/IndexParameter.java | 29 ++ .../queries/parameter/TokenParameter.java | 34 ++ .../sadu/queries/parameter/package-info.java | 4 + .../sadu/queries/query/AppendedQueryImpl.java | 30 ++ .../sadu/queries/query/ParsedQueryImpl.java | 59 +++ .../chojo/sadu/queries/query/QueryImpl.java | 86 ++++ .../sadu/queries/query/TokenizedQuery.java | 62 +++ .../sadu/queries/query/package-info.java | 4 + .../stages/execution/package-info.java | 4 + .../execution/reading/AutoMappedQuery.java | 41 ++ .../stages/execution/reading/MappedQuery.java | 26 ++ .../stages/execution/reading/ReaderImpl.java | 123 ++++++ .../execution/reading/package-info.java | 4 + .../writing/CalledBatchQueryImpl.java | 65 +++ .../writing/CalledSingletonQueryImpl.java | 97 +++++ .../execution/writing/package-info.java | 4 + .../sadu/queries/stages/package-info.java | 4 + .../queries/stages/results/package-info.java | 4 + .../stages/results/reading/MultiResult.java | 38 ++ .../stages/results/reading/SingleResult.java | 37 ++ .../stages/results/reading/package-info.java | 4 + .../writing/ManipulationBatchQuery.java | 63 +++ .../writing/ManipulationResultImpl.java | 50 +++ .../stages/results/writing/package-info.java | 4 + .../queries/storage/ResultStorageImpl.java | 51 +++ .../sadu/queries/storage/package-info.java | 4 + sadu-queries2/src/main/java/module-info.java | 37 ++ .../java/de/chojo/sadu/PostgresDatabase.java | 46 ++ .../sadu/queries/TokenizedQueryTest.java | 49 +++ .../chojo/sadu/queries/examples/ReadTest.java | 115 +++++ .../queries/examples/TransactionTest.java | 73 ++++ .../sadu/queries/examples/WriteTest.java | 137 ++++++ .../chojo/sadu/queries/examples/dao/User.java | 17 + .../resources/database/postgresql/1/setup.sql | 16 + .../src/test/resources/database/version | 1 + sadu-sqlite/build.gradle.kts | 1 + sadu-updater/build.gradle.kts | 2 +- .../sadu/updater/BaseSqlUpdaterBuilder.java | 17 +- .../de/chojo/sadu/updater/SqlUpdater.java | 11 +- settings.gradle.kts | 1 + 104 files changed, 3591 insertions(+), 41 deletions(-) create mode 100644 sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java create mode 100644 sadu-core/src/main/java/module-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java create mode 100644 sadu-mapper/src/main/java/module-info.java create mode 100644 sadu-queries2/build.gradle.kts create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/UUIDAdapter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/CallSupplier.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/SingletonCall.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfigurationBuilder.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/IndexParameter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/TokenParameter.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/query/AppendedQueryImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/query/QueryImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/query/TokenizedQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/query/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/ResultStorageImpl.java create mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/package-info.java create mode 100644 sadu-queries2/src/main/java/module-info.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java create mode 100644 sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java create mode 100644 sadu-queries2/src/test/resources/database/postgresql/1/setup.sql create mode 100644 sadu-queries2/src/test/resources/database/version diff --git a/.github/workflows/javadocs.yml b/.github/workflows/javadocs.yml index ca80a2c1..f1cd1f5c 100644 --- a/.github/workflows/javadocs.yml +++ b/.github/workflows/javadocs.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up JDK 15 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: adopt - java-version: 15 + java-version: 17 - name: Build Javadocs run: | echo "Building javadocs with gradle" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index aa3bf3ed..5cc0f952 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,11 +15,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 15 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: adopt - java-version: 15 + java-version: 17 - name: Test with Gradle run: ./gradlew --build-cache test - name: Publish to Maven Central diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 16d78add..cb04d97e 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -9,10 +9,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 15 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: adopt - java-version: 15 + java-version: 17 - name: Test with Gradle run: ./gradlew --build-cache test diff --git a/build.gradle.kts b/build.gradle.kts index eb397f87..e84bbec9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -49,8 +49,8 @@ subprojects { indra { javaVersions { - target(15) - testWith(15) + target(17) + testWith(17) } github("rainbowdashlabs", "sadu") { @@ -79,8 +79,8 @@ subprojects { indra { javaVersions { - target(15) - testWith(15) + target(17) + testWith(17) } github("rainbowdashlabs", "sadu") { @@ -167,7 +167,7 @@ tasks { register("alljavadoc") { applyJavaDocOptions(options) - destinationDir = file("${layout.buildDirectory}/docs/javadoc") + setDestinationDir(file("${layout.buildDirectory}/docs/javadoc")) val projects = project.rootProject.allprojects.filter { p -> !p.name.contains("example") } setSource(projects.map { p -> p.sourceSets.main.get().allJava }) classpath = files(projects.map { p -> p.sourceSets.main.get().compileClasspath }) diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java b/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java new file mode 100644 index 00000000..c8541b38 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.exceptions; + +/** + * Represents an operation that accepts a single input argument and returns no + * result. Unlike most other functional interfaces, {@code Consumer} is expected + * to operate via side effects. + * + *

This is a functional interface + * whose functional method is {@link #accept(Object, Object)}. + * + * @param the type of the input to the operation + * @since 1.8 + */ +@FunctionalInterface +public interface ThrowingBiConsumer { + + /** + * Performs this operation on the given argument. + * + * @param t the input argument + * @throws E if something went wrong + */ + void accept(T t, U u) throws E; +} diff --git a/sadu-core/src/main/java/module-info.java b/sadu-core/src/main/java/module-info.java new file mode 100644 index 00000000..12e12d60 --- /dev/null +++ b/sadu-core/src/main/java/module-info.java @@ -0,0 +1,13 @@ +module sadu.sadu.core.main { + requires java.sql; + requires org.jetbrains.annotations; + + exports de.chojo.sadu.base; + exports de.chojo.sadu.conversion; + exports de.chojo.sadu.databases; + exports de.chojo.sadu.databases.exceptions; + exports de.chojo.sadu.exceptions; + exports de.chojo.sadu.jdbc; + exports de.chojo.sadu.types; + exports de.chojo.sadu.updater; +} diff --git a/sadu-examples/build.gradle.kts b/sadu-examples/build.gradle.kts index 3bc4db43..b107cd23 100644 --- a/sadu-examples/build.gradle.kts +++ b/sadu-examples/build.gradle.kts @@ -1,5 +1,8 @@ dependencies { - compileOnly(project(":")) + compileOnly(project(":sadu-queries")) + compileOnly(project(":sadu-datasource")) + compileOnly(project(":sadu-updater")) + compileOnly(project(":sadu-postgresql")) // database driver compileOnly("org.xerial", "sqlite-jdbc", "3.45.1.0") diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java index ab0b9af6..9d139a4b 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java @@ -19,6 +19,9 @@ public class MapperConfig implements Cloneable { private Map aliases = new HashMap<>(); private boolean strict = false; + public MapperConfig() { + } + public Map aliases() { return aliases; } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java index ba57371f..531bdaf7 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java @@ -27,6 +27,9 @@ public class RowMapperRegistry { private final Map, List>> mapper = new HashMap<>(); + public RowMapperRegistry() { + } + /** * Registers a new mapper for a class. *

diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java index 1e7c8c71..42811b84 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java @@ -25,7 +25,7 @@ * * @param type of returned object */ -public class RowMapper { +public class RowMapper implements RowMapping { private static final Logger log = getLogger(RowMapper.class); private final Class clazz; private final ThrowingFunction mapper; @@ -49,6 +49,7 @@ public Set columns() { return columns; } + @Override public T map(Row row) throws SQLException { return mapper.apply(row); } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java new file mode 100644 index 00000000..4d04139e --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.mapper.rowmapper; + +import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.wrapper.util.Row; + +import java.sql.SQLException; + +public interface RowMapping { + T map(Row row) throws SQLException; + + static RowMapping create(ThrowingFunction mapper){ + return mapper::apply; + } +} diff --git a/sadu-mapper/src/main/java/module-info.java b/sadu-mapper/src/main/java/module-info.java new file mode 100644 index 00000000..6a9f21ad --- /dev/null +++ b/sadu-mapper/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module sadu.sadu.mapper.main { + requires transitive java.sql; + requires org.slf4j; + requires transitive sadu.sadu.core.main; + requires transitive org.jetbrains.annotations; + + exports de.chojo.sadu.mapper; + exports de.chojo.sadu.mapper.exceptions; + exports de.chojo.sadu.mapper.rowmapper; + exports de.chojo.sadu.mapper.util; + exports de.chojo.sadu.wrapper.util; +} diff --git a/sadu-mariadb/build.gradle.kts b/sadu-mariadb/build.gradle.kts index 3fa40ce8..695947b9 100644 --- a/sadu-mariadb/build.gradle.kts +++ b/sadu-mariadb/build.gradle.kts @@ -2,6 +2,7 @@ description = "SADU module for interaction with a MariaDB database" dependencies { api(project(":sadu-updater")) + api(project(":sadu-mapper")) testImplementation(project(":sadu-queries")) testImplementation(project(":sadu-datasource")) diff --git a/sadu-mysql/build.gradle.kts b/sadu-mysql/build.gradle.kts index 30e9dd68..c69296c6 100644 --- a/sadu-mysql/build.gradle.kts +++ b/sadu-mysql/build.gradle.kts @@ -2,6 +2,7 @@ description = "SADU module for interaction with a MySQL database" dependencies { api(project(":sadu-updater")) + api(project(":sadu-mapper")) testImplementation(project(":sadu-datasource")) testImplementation(testlibs.bundles.database.mysql) testImplementation(testlibs.slf4j.noop) diff --git a/sadu-postgresql/build.gradle.kts b/sadu-postgresql/build.gradle.kts index ec8cc990..95cb5565 100644 --- a/sadu-postgresql/build.gradle.kts +++ b/sadu-postgresql/build.gradle.kts @@ -2,6 +2,7 @@ description = "SADU module for interaction with a PostgreSQL database" dependencies { api(project(":sadu-updater")) + api(project(":sadu-mapper")) testImplementation("org.postgresql", "postgresql", "42.7.1") testImplementation(testlibs.bundles.junit) diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java b/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java index cd8cff4b..9444da74 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java @@ -8,10 +8,9 @@ import de.chojo.sadu.databases.Database; import de.chojo.sadu.jdbc.PostgreSqlJdbc; -import de.chojo.sadu.updater.SqlUpdater; import de.chojo.sadu.updater.QueryReplacement; +import de.chojo.sadu.updater.SqlUpdater; import de.chojo.sadu.updater.SqlVersion; -import de.chojo.sadu.wrapper.QueryBuilderConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,8 +27,8 @@ public class PostgreSqlUpdater extends SqlUpdater type, String[] schemas, Map> preUpdateHook, Map> postUpdateHook, ClassLoader classLoader) { - super(source, config, versionTable, replacements, version, type, preUpdateHook, postUpdateHook, classLoader); + protected PostgreSqlUpdater(DataSource source, String versionTable, QueryReplacement[] replacements, SqlVersion version, Database type, String[] schemas, Map> preUpdateHook, Map> postUpdateHook, ClassLoader classLoader) { + super(source, versionTable, replacements, version, type, preUpdateHook, postUpdateHook, classLoader); this.schemas = schemas; } diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java b/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java index 619fd751..cfcaa1c0 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java @@ -17,7 +17,7 @@ public class PostgreSqlUpdaterBuilder extends BaseSqlUpdaterBuilder { - private String[] schemas; + private String[] schemas = new String[0]; public PostgreSqlUpdaterBuilder(Database type) { super(type); @@ -41,7 +41,7 @@ public PostgreSqlUpdaterBuilder setSchemas(String... schemas) { @Override public void execute() throws SQLException, IOException { if (version == null) version = SqlVersion.load(classLoader); - var updater = new PostgreSqlUpdater(source, config, versionTable, replacements, version, type, schemas, preUpdateHook, postUpdateHook, classLoader); + var updater = new PostgreSqlUpdater(source, versionTable, replacements, version, type, schemas, preUpdateHook, postUpdateHook, classLoader); updater.init(); } } diff --git a/sadu-queries2/build.gradle.kts b/sadu-queries2/build.gradle.kts new file mode 100644 index 00000000..5e59d3e4 --- /dev/null +++ b/sadu-queries2/build.gradle.kts @@ -0,0 +1,11 @@ +dependencies { + api(project(":sadu-core")) + api(project(":sadu-mapper")) + testImplementation("org.postgresql", "postgresql", "42.7.1") + testImplementation(testlibs.bundles.junit) + testImplementation(project(":sadu-datasource")) + testImplementation(project(":sadu-postgresql")) + + testImplementation(testlibs.bundles.database.postgres) + testImplementation(testlibs.slf4j.noop) +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java new file mode 100644 index 00000000..25edca1e --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.base; + +import de.chojo.sadu.base.DataSourceProvider; +import de.chojo.sadu.exceptions.ThrowingFunction; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.function.Supplier; + +public interface ConnectionProvider extends DataSourceProvider { + T callConnection(Supplier defaultResult, ThrowingFunction connectionConsumer); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java new file mode 100644 index 00000000..5ecd919a --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.base; + +import de.chojo.sadu.base.DataSourceProvider; +import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.query.QueryImpl; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.function.Supplier; + +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface QueryProvider extends ConnectionProvider, DataSourceProvider { + QueryImpl query(); + + @Override + default DataSource source() { + return query().source(); + } + + default QueryConfiguration configuration() { + return query().configuration(); + } + + default T callConnection(Supplier defaultResult, ThrowingFunction connectionConsumer) { + return query().callConnection(defaultResult, connectionConsumer); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java new file mode 100644 index 00000000..13b8d3e8 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java @@ -0,0 +1,4 @@ +/** + * api base module for general interfaces + */ +package de.chojo.sadu.queries.api.base; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java new file mode 100644 index 00000000..4bebe571 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java @@ -0,0 +1,167 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.call; + +import de.chojo.sadu.queries.api.call.adapter.Adapter; +import de.chojo.sadu.queries.call.CallImpl; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.calls.SingletonCall; +import de.chojo.sadu.types.SqlType; + +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.util.Collection; + +@SuppressWarnings("unused") +public sealed interface Call permits CallImpl { + /** + * Creates a new instance of the Call class. + * + * @return A new instance of the Call class. + */ + static Call of() { + return new CallImpl(); + } + + /** + * Creates a new instance of the Call class. + * + * @return A new instance of the Call class. + */ + static Call call() { + return of(); + } + + Call bind(String value); + + Call bind(String token, String value); + + Call bind(Enum value); + + Call bind(String token, Enum value); + + Call bind(short value); + + Call bind(String token, short value); + + Call bind(int value); + + Call bind(long value); + + Call bind(String token, long value); + + Call bind(String token, int value); + + Call bind(float value); + + Call bind(String token, float value); + + Call bind(double value); + + Call bind(String token, double value); + + Call bind(BigDecimal value); + + Call bind(String token, BigDecimal value); + + Call bind(boolean value); + + Call bind(String token, boolean value); + + Call bind(byte value); + + Call bind(String token, byte value); + + Call bind(byte[] value); + + Call bind(String token, byte[] value); + + Call bind(Date value); + + Call bind(String token, Date value); + + Call bind(LocalDate value); + + Call bind(String token, LocalDate value); + + Call bind(Time value); + + Call bind(String token, Time value); + + Call bind(LocalTime value); + + Call bind(String token, LocalTime value); + + Call bind(Timestamp value); + + Call bind(String token, Timestamp value); + + Call bind(LocalDateTime value); + + Call bind(String token, LocalDateTime value); + + Call bind(ZonedDateTime value); + + Call bind(String token, ZonedDateTime value); + + Call bind(OffsetDateTime value); + + Call bind(String token, OffsetDateTime value); + + Call bind(OffsetTime value); + + Call bind(String token, OffsetTime value); + + Call bind(Ref value); + + Call bind(String token, Ref value); + + Call bind(Blob value); + + Call bind(String token, Blob value); + + Call bind(Clob value); + + Call bind(String token, Clob value); + + Call bind(URL value); + + Call bind(String token, URL value); + + Call bind(RowId value); + + Call bind(String token, RowId value); + + Call bind(Collection value, SqlType type); + + Call bind(String token, Collection value, SqlType type); + + Call bind(Object[] value, SqlType type); + + Call bind(String token, Object[] value, SqlType type); + + Call bind(String token, T value, Adapter adapter); + + Call bind(T value, Adapter adapter); + + SingletonCall asSingleCall(); + + BatchCall asBatchCall(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java new file mode 100644 index 00000000..4a7514a0 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java @@ -0,0 +1,111 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.call.adapter; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.function.Function; + +/** + * The Adapter interface provides a way to map Java objects to a specific SQL data type and perform the necessary conversions when binding the objects to a PreparedStatement. + * + * @param the type of object to be adapted + */ +public interface Adapter { + /** + * Creates a new Adapter instance for the given class, mapping, and type. + * + * @param the type of object to be adapted + * @param clazz the class of the object to be adapted + * @param mapping the AdapterMapping implementation that performs the necessary conversions for binding the object to a PreparedStatement + * @param type the SQL type of the Adapter as defined by java.sql.Types + * @return a new Adapter instance + */ + static Adapter create(Class clazz, AdapterMapping mapping, int type) { + return new Adapter<>() { + @Override + public AdapterMapping mapping() { + return mapping; + } + + @Override + public int type() { + return type; + } + }; + } + + /** + * Creates a new Adapter instance for the given class, mapping, and type. + * + * @param the type of object to be adapted + * @param mapping the AdapterMapping implementation that performs the necessary conversions for binding the object to a PreparedStatement + * @param type the SQL type of the Adapter as defined by java.sql.Types + * @return a new Adapter instance + */ + static Adapter create(AdapterMapping mapping, int type, Function map) { + return new Adapter<>() { + @Override + public AdapterMapping mapping() { + return (stmt, index, value) -> mapping.apply(stmt, index, map.apply(value)); + } + + @Override + public int type() { + return type; + } + }; + } + + /** + * Creates a new Adapter instance for the given class, mapping, and type. + * + * @param the type of object to be adapted + * @param mapping the AdapterMapping implementation that performs the necessary conversions for binding the object to a PreparedStatement + * @param type the SQL type of the Adapter as defined by java.sql.Types + * @return a new Adapter instance + */ + static Adapter create(AdapterMapping mapping, int type) { + return new Adapter<>() { + @Override + public AdapterMapping mapping() { + return mapping; + } + + @Override + public int type() { + return type; + } + }; + } + + /** + * Returns the AdapterMapping for the given Adapter instance. + * + * @return the AdapterMapping for the Adapter instance. + */ + AdapterMapping mapping(); + + /** + * Returns the sql type of the Adapter as defined by {@link java.sql.Types} + * + * @return the type of the Adapter. + */ + int type(); + + /** + * Applies the given object to a PreparedStatement at the specified index using the provided mapping. + * + * @param stmt the PreparedStatement to apply the object to + * @param index the index at which to apply the object + * @param object the object to be applied + * @throws SQLException if a database access error occurs + */ + default void apply(PreparedStatement stmt, int index, T object) throws SQLException { + mapping().apply(stmt, index, object); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java new file mode 100644 index 00000000..b9648998 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.call.adapter; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +/** + * The AdapterMapping interface represents a functional interface used to map Java objects to a specific SQL data type + * and perform the necessary conversions when binding the objects to a PreparedStatement. + * + * @param the type of object to be adapted + */ +@FunctionalInterface +public interface AdapterMapping { + /** + * Applies the given value to a PreparedStatement at the specified index using the provided mapping. + * + * @param stmt the PreparedStatement to apply the value to + * @param index the index at which to apply the value + * @param value the value to be applied + * @throws SQLException if a database access error occurs + */ + void apply(PreparedStatement stmt, int index, T value) throws SQLException; +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java new file mode 100644 index 00000000..fa443bff --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for adding data to a statement + */ +package de.chojo.sadu.queries.api.call.adapter; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java new file mode 100644 index 00000000..0bb91c98 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java @@ -0,0 +1,81 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.call.calls; + +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.calls.SingletonCall; + +import java.util.List; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; + +/** + * The calls class represents the calls of the same query. + *

+ * A calls object can contain one or more calls on the same query. + */ +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface Calls { + + /** + * Returns an instance of the SingletonCall class that represents an empty call. + * + * @return An instance of SingletonCall representing an empty call. + */ + @SuppressWarnings("SameReturnValue") + static SingletonCall empty() { + return SingletonCall.EMPTY; + } + + /** + * Returns a collector that accumulates the input elements into a BatchCall object. + * The collector takes a stream of Call objects and produces a single BatchCall object. + * + * @return a collector for Call objects that produces a BatchCall object + */ + static Collector collect() { + return new Collector<>() { + @Override + public Supplier supplier() { + return BatchCall::new; + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + @Override + public BiConsumer accumulator() { + return BatchCall::add; + } + + @Override + public BinaryOperator combiner() { + return BatchCall::combine; + } + + @Override + public Function finisher() { + return t -> t; + } + + @Override + public Set characteristics() { + return Set.of(Characteristics.IDENTITY_FINISH); + } + }; + } + + /** + * Returns a list of Call objects representing the query calls. + * + * @return A list of Call objects. + */ + List calls(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java new file mode 100644 index 00000000..057f60a3 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for creating calls + */ +package de.chojo.sadu.queries.api.call.calls; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java new file mode 100644 index 00000000..54666bf4 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines pi for creating a query call + */ +package de.chojo.sadu.queries.api.call; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java new file mode 100644 index 00000000..8624354a --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for result executing queries + */ +package de.chojo.sadu.queries.api.execution; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java new file mode 100644 index 00000000..78c7c7fd --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java @@ -0,0 +1,67 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.execution.reading; + +import de.chojo.sadu.queries.api.query.AppendedQuery; +import de.chojo.sadu.queries.api.results.reading.Result; + +import java.util.List; +import java.util.Optional; + +/** + * Interface for retrieving data from a query. + * + * @param the type of the data to be retrieved + */ +public interface Reader { + /** + * Retrieves a single result from the query. + * + * @return the result of the query + */ + Result first(); + + /** + * Retrieves all the results of the query. + * + * @return a Result object containing a List of results + */ + Result> all(); + + /** + * Stores a query result and allows to create a new query. + * + * @param key the key used to identify the stored result + * @return an AppendedQuery object that can execute another query with the same chain + */ + AppendedQuery storeOneAndAppend(String key); + + /** + * Stores all query results and allows to create a new query. + * + * @param key the key used to identify the stored result + * @return an AppendedQuery object that can execute another query with the same chain + */ + AppendedQuery storeAllAndAppend(String key); + + /** + * Retrieves the first value from the query result and wraps it in an {@link Optional} object. + *

+ * If the query returns no results, an empty {@link Optional} object is returned. + * + * @return an {@link Optional} containing the first value from the query result, + * or an empty {@link Optional} if the query returns no results + */ + Optional oneAndGet(); + + /** + * Retrieves all elements from the Reader. + * + * @return a List of all elements + */ + List allAndGet(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java new file mode 100644 index 00000000..5c1b08da --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for reading data + */ +package de.chojo.sadu.queries.api.execution.reading; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java new file mode 100644 index 00000000..f1f31d72 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.execution.writing; + +import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; + +/** + * The CalledBatchQuery interface represents a batch query that can perform insert, update, and delete operations + * on a data source. + */ +public interface CalledBatchQuery { + /** + * Inserts the specified values into the table. + * + * @return The {@link ManipulationBatchResult} that represents the results of the insert operations. + */ + ManipulationBatchResult insert(); + + /** + * Executes update operations as part of a batch query. + * Returns the result of the update operation. + * + * @return The {@link ManipulationBatchResult} that represents the results of the update operations. + */ + ManipulationBatchResult update(); + + /** + * Deletes the selected items or records from the data source. + * + * @return The {@link ManipulationBatchResult} that represents the results of the delete operations. + */ + ManipulationBatchResult delete(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java new file mode 100644 index 00000000..681cf03d --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java @@ -0,0 +1,68 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.execution.writing; + +import de.chojo.sadu.mapper.MapperConfig; +import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.queries.api.execution.reading.Reader; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; + +/** + * Represents a query that can be executed as a singleton call. + */ +public interface CalledSingletonQuery { + + /** + * Maps the result of the query to a Reader of type V by applying the provided ThrowingFunction. + * + * @param the type of objects in the Reader + * @param row the function to apply on the result row + * @return a Reader of type V + */ + Reader map(RowMapping row); + + /** + * Maps the current result set to the specified class type and returns a Reader object. + * + * @param clazz the class type to map the result set to + * @param the type of the class to map the result set to + * @return a Reader object with the result set mapped to the specified class type + */ + Reader mapAs(Class clazz); + + /** + * Maps the result of a query to the specified class using the provided MapperConfig. + * + * @param the type to map the query result to + * @param clazz the class to map the query result to + * @param config the MapperConfig to use for mapping + * @return a Reader object that can be used to retrieve the mapped result + */ + Reader mapAs(Class clazz, MapperConfig config); + + /** + * Inserts a row into the database table represented by the initial symbol of the containing class, + * and returns the result of the manipulation operation. + * + * @return The result of the manipulation operation as a {@link ManipulationResult} object. + */ + ManipulationResult insert(); + + /** + * Updates the data in the database based on the provided query. + * + * @return The result of the manipulation operation as a {@link ManipulationResult} object. + */ + ManipulationResult update(); + + /** + * Deletes rows from the table based on the specified query. + * + * @return The result of the manipulation operation as a {@link ManipulationResult} object. + */ + ManipulationResult delete(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java new file mode 100644 index 00000000..cdd9c4cc --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for writing data + */ +package de.chojo.sadu.queries.api.execution.writing; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java new file mode 100644 index 00000000..d81e3ac6 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java @@ -0,0 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.parameter; + +import de.chojo.sadu.queries.query.TokenizedQuery; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface BaseParameter { + void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException; +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java new file mode 100644 index 00000000..cc507e9c --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for a parameter + */ +package de.chojo.sadu.queries.api.parameter; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java new file mode 100644 index 00000000..986eb75b --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.query; + +import org.intellij.lang.annotations.Language; + +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface AppendedQuery { + /** + * Execute another query with the same chain. + * + * @param sql the query you want to execute + * @param format will work like calling {@link String#formatted(Object...)}. + * DO NOT USE THAT FOR PARAMETER OR WITH USER INPUT + * @return a parsed query + */ + ParsedQuery query(@Language("sql") String sql, Object... format); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java new file mode 100644 index 00000000..01d6e284 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java @@ -0,0 +1,113 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.query; + +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.call.calls.Calls; +import de.chojo.sadu.queries.api.execution.writing.CalledBatchQuery; +import de.chojo.sadu.queries.api.execution.writing.CalledSingletonQuery; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.calls.CallSupplier; +import de.chojo.sadu.queries.calls.SingletonCall; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +/** + * A Parsed query that is ready for execution + */ +public interface ParsedQuery { + /** + * Define a batch call for your query. + * This will execute the query with every argument combination that are passed here. + * + * @param calls the batch call to be executed + * @return A called batch query + */ + CalledBatchQuery batch(BatchCall calls); + + /** + * Define a batch call for your query. + * This will execute the query with every argument combination that are passed here. + * + * @param calls a call supplier that allows access to the query storage + * @return A called batch query + */ + CalledBatchQuery batch(CallSupplier calls); + + /** + * Define a batch call for your query. + * This will execute the query with every argument combination that are passed here. + * + * @param calls a list of calls + * @return A called batch query + */ + default CalledBatchQuery batch(List calls) { + return batch(new BatchCall(calls)); + } + + /** + * Define a batch call for your query. + * This will execute the query with every argument combination that are passed here. + * + * @param calls a stream of calls + * @return A called batch query + */ + default CalledBatchQuery batch(Stream calls) { + return batch(calls.collect(Calls.collect())); + } + + /** + * Define a batch call for your query. + * This will execute the query with every argument combination that are passed here. + * + * @param calls any number of calls + * @return A called batch query + */ + default CalledBatchQuery batch(Call... calls) { + return batch(Arrays.stream(calls).toList()); + } + + /** + * Define a call for your query. + * This will execute the query with your arguments. + * + * @param call a singleton call + * @return A called batch query + */ + CalledSingletonQuery single(SingletonCall call); + + /** + * Define a call without any parameter set. + * + * @return A called batch query + */ + default CalledSingletonQuery single() { + return single(Calls.empty()); + } + + /** + * Define a call for your query. + * This will execute the query with your arguments. + * + * @param call a call + * @return A called singleton query + */ + default CalledSingletonQuery single(Call call) { + return single(call.asSingleCall()); + } + + /** + * Define a call for your query. + * This will execute the query with your arguments. + * + * @param call a call supplier that allows access to the query storage + * @return A called singleton query + */ + CalledSingletonQuery single(CallSupplier call); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java new file mode 100644 index 00000000..c3920d1d --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.query; + +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.query.ParsedQueryImpl; +import de.chojo.sadu.queries.query.QueryImpl; +import org.intellij.lang.annotations.Language; + +/** + * Starting point for executing one or more queries. + */ +public interface Query { + /** + * Create a new query. + * + * @param configuration query configuration + * @param sql the query you want to execute + * @param format will work like calling {@link String#formatted(Object...)}. + * DO NOT USE THAT FOR PARAMETER OR WITH USER INPUT + * @return a parsed query + */ + static ParsedQuery query(QueryConfiguration configuration, @Language("sql") String sql, Object... format) { + return ParsedQueryImpl.create(new QueryImpl(configuration), sql, format); + } + + /** + * Create a new query using the default query configuration. + *

+ * {@link QueryConfiguration#setDefault(QueryConfiguration)} has to be used before to configure it. + * + * @param sql the query you want to execute + * @param format will work like calling {@link String#formatted(Object...)}. + * DO NOT USE THAT FOR PARAMETER OR WITH USER INPUT + * @return a parsed query + */ + static ParsedQuery query(@Language("sql") String sql, Object... format) { + return ParsedQueryImpl.create(new QueryImpl(QueryConfiguration.getDefault()), sql, format); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java new file mode 100644 index 00000000..28ff2364 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for creating a query + */ +package de.chojo.sadu.queries.api.query; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java new file mode 100644 index 00000000..8e6ce4d4 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java @@ -0,0 +1,4 @@ +/** + * Defined the api for result handling + */ +package de.chojo.sadu.queries.api.results; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java new file mode 100644 index 00000000..d9212b02 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.results.reading; + +import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; + +/** + * Base of a result returned by a {@link MappedQuery} + * + * @param type of returned object + */ +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface Result { + /** + * Get the result of the query + * + * @return result + */ + T result(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java new file mode 100644 index 00000000..023bfcaa --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for result reading + */ +package de.chojo.sadu.queries.api.results.reading; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java new file mode 100644 index 00000000..e3d5b446 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.results.writing; + +import java.util.List; + +public interface ManipulationBatchResult extends ManipulationResult { + /** + * Returns a list of ManipulationResult representing the results of each indivudual manipulation operation. + * + * @return The list of ManipulationResults. + */ + List results(); + + /** + * Retrieves the number of rows affected by the all executions of the query. + * + * @return The number of rows affected by the batch execution. + */ + @Override + int rows(); + + /** + * Determines whether there were any changes made by the query execution. + * + * @return {@code true} if changes were made, {@code false} otherwise. + */ + @Override + boolean changed(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java new file mode 100644 index 00000000..d5e7c921 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.api.results.writing; + +/** + * The ManipulationResult interface represents the result of a manipulation operation, + * such as an insert, update, or delete operation. + */ +public interface ManipulationResult { + /** + * Returns the total number of changed rows resulting from a manipulation operation. + * + * @return the total number of changed rows + */ + int rows(); + + /** + * Checks whether at least one row was changed. + * + * @return true if one row or more were changed + */ + boolean changed(); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java new file mode 100644 index 00000000..01331c59 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines the api for reading of writing results + */ +package de.chojo.sadu.queries.api.results.writing; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java new file mode 100644 index 00000000..bc773a4c --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java @@ -0,0 +1,13 @@ +package de.chojo.sadu.queries.api.storage; + +import java.util.List; +import java.util.Optional; + +public interface ResultStorage { + @SuppressWarnings("unchecked") + T get(String key); + + Optional getAs(String key, Class clazz); + + List getList(String key, Class clazz); +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java new file mode 100644 index 00000000..b5eb42ca --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java @@ -0,0 +1,4 @@ +/** + * Defines api for query storage + */ +package de.chojo.sadu.queries.api.storage; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java new file mode 100644 index 00000000..624f693c --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java @@ -0,0 +1,405 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.call; + +import de.chojo.sadu.exceptions.ThrowingBiConsumer; +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.call.adapter.Adapter; +import de.chojo.sadu.queries.api.call.calls.Calls; +import de.chojo.sadu.queries.api.parameter.BaseParameter; +import de.chojo.sadu.queries.call.adapter.StandardAdapter; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.calls.SingletonCall; +import de.chojo.sadu.queries.parameter.IndexParameter; +import de.chojo.sadu.queries.parameter.TokenParameter; +import de.chojo.sadu.queries.query.TokenizedQuery; +import de.chojo.sadu.types.SqlType; + +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BIG_DECIMAL; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BLOB; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BOOLEAN; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BYTE; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BYTE_ARRAY; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.CLOB; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.DATE; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.DOUBLE; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ENUM; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.FLOAT; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.INTEGER; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_DATE; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_DATE_TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LONG; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.OFFSET_DATE_TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.OFFSET_TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.REF; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ROW_ID; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.SHORT; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.STRING; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.TIMESTAMP; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ZONED_DATE_TIME; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.forArray; +import static de.chojo.sadu.queries.call.adapter.StandardAdapter.forCollection; + +/** + * A call is a subelement of a {@link Calls}. It represents a single query call of any kind. + */ +public final class CallImpl implements Call { + private final List tokens = new ArrayList<>(); + private int index = 1; + + public CallImpl() { + } + + private int nextIndex() { + return index++; + } + + private Call addToken(String token, ThrowingBiConsumer apply) { + tokens.add(new TokenParameter(token, apply)); + return this; + } + + private Call addToken(ThrowingBiConsumer apply) { + tokens.add(new IndexParameter(nextIndex(), apply)); + return this; + } + + private ThrowingBiConsumer nullSave(Object value, ThrowingBiConsumer apply, int type) { + if (value == null) return (stmt, index) -> stmt.setNull(index, type); + return apply; + } + + @Override + public Call bind(String value) { + return bind(value, STRING); + } + + @Override + public Call bind(String token, String value) { + return bind(token, value, STRING); + } + + @Override + public Call bind(Enum value) { + return bind(value, ENUM); + } + + @Override + public Call bind(String token, Enum value) { + return bind(token, value, ENUM); + } + + @Override + public Call bind(short value) { + return bind(value, SHORT); + } + + @Override + public Call bind(String token, short value) { + return bind(token, value, SHORT); + } + + @Override + public Call bind(int value) { + return bind(value, INTEGER); + } + + @Override + public Call bind(String token, int value) { + return bind(token, value, INTEGER); + } + + @Override + public Call bind(boolean value) { + return bind(value, BOOLEAN); + } + + @Override + public Call bind(String token, boolean value) { + return bind(token, value, BOOLEAN); + } + + @Override + public Call bind(byte value) { + return bind(value, BYTE); + } + + @Override + public Call bind(String token, byte value) { + return bind(token, value, BYTE); + } + + @Override + public Call bind(byte[] value) { + return bind(value, BYTE_ARRAY); + } + + @Override + public Call bind(String token, byte[] value) { + return bind(token, value, BYTE_ARRAY); + } + + @Override + public Call bind(Date value) { + return bind(value, DATE); + } + + @Override + public Call bind(String token, Date value) { + return bind(token, value, DATE); + } + + @Override + public Call bind(long value) { + return bind(value, LONG); + } + + @Override + public Call bind(String token, long value) { + return bind(token, value, LONG); + } + + @Override + public Call bind(double value) { + return bind(value, DOUBLE); + } + + @Override + public Call bind(String token, double value) { + return bind(token, value, DOUBLE); + } + + @Override + public Call bind(BigDecimal value) { + return bind(value, BIG_DECIMAL); + } + + @Override + public Call bind(String token, BigDecimal value) { + return bind(token, value, BIG_DECIMAL); + } + + @Override + public Call bind(float value) { + return bind(value, FLOAT); + } + + @Override + public Call bind(String token, float value) { + return bind(token, value, FLOAT); + } + + @Override + public Call bind(LocalDate value) { + return bind(value, LOCAL_DATE); + } + + @Override + public Call bind(String token, LocalDate value) { + return bind(token, value, LOCAL_DATE); + } + + @Override + public Call bind(Time value) { + return bind(value, TIME); + } + + @Override + public Call bind(String token, Time value) { + return bind(token, value, TIME); + } + + @Override + public Call bind(LocalTime value) { + return bind(value, LOCAL_TIME); + } + + @Override + public Call bind(String token, LocalTime value) { + return bind(token, value, LOCAL_TIME); + } + + @Override + public Call bind(Timestamp value) { + return bind(value, TIMESTAMP); + } + + @Override + public Call bind(String token, Timestamp value) { + return bind(token, value, TIMESTAMP); + } + + @Override + public Call bind(LocalDateTime value) { + return bind(value, LOCAL_DATE_TIME); + } + + @Override + public Call bind(String token, LocalDateTime value) { + return bind(token, value, LOCAL_DATE_TIME); + } + + @Override + public Call bind(ZonedDateTime value) { + return bind(value, ZONED_DATE_TIME); + } + + @Override + public Call bind(String token, ZonedDateTime value) { + return bind(token, value, ZONED_DATE_TIME); + } + + @Override + public Call bind(OffsetDateTime value) { + return bind(value, OFFSET_DATE_TIME); + } + + @Override + public Call bind(String token, OffsetDateTime value) { + return bind(token, value, OFFSET_DATE_TIME); + } + + @Override + public Call bind(OffsetTime value) { + return bind(value, OFFSET_TIME); + } + + @Override + public Call bind(String token, OffsetTime value) { + return bind(token, value, OFFSET_TIME); + } + + @Override + public Call bind(Ref value) { + return bind(value, REF); + } + + @Override + public Call bind(String token, Ref value) { + return bind(token, value, REF); + } + + @Override + public Call bind(Blob value) { + return bind(value, BLOB); + } + + @Override + public Call bind(String token, Blob value) { + return bind(token, value, BLOB); + } + + @Override + public Call bind(Clob value) { + return bind(value, CLOB); + } + + @Override + public Call bind(String token, Clob value) { + return bind(token, value, CLOB); + } + + @Override + public Call bind(URL value) { + return bind(value, StandardAdapter.URL); + } + + @Override + public Call bind(String token, URL value) { + return bind(token, value, StandardAdapter.URL); + } + + @Override + public Call bind(RowId value) { + return bind(value, ROW_ID); + } + + @Override + public Call bind(String token, RowId value) { + return bind(token, value, ROW_ID); + } + + @Override + public Call bind(Collection value, SqlType type) { + return bind(value, forCollection(value, type)); + } + + @Override + public Call bind(String token, Collection value, SqlType type) { + return bind(token, value, forCollection(value, type)); + } + + @Override + public Call bind(Object[] value, SqlType type) { + return bind(value, forArray(value, type)); + } + + @Override + public Call bind(String token, Object[] value, SqlType type) { + return bind(token, value, forArray(value, type)); + } + + @Override + public Call bind(String token, T value, Adapter adapter) { + return addToken(token, nullSave(value, (stmt, index) -> adapter.apply(stmt, index, value), adapter.type())); + } + + @Override + public Call bind(T value, Adapter adapter) { + return addToken(nullSave(value, (stmt, index) -> adapter.apply(stmt, index, value), adapter.type())); + } + + public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException { + for (var token : tokens) { + token.apply(query, stmt); + } + } + + /** + * Returns a SingletonCall object for the current Call instance. + * This allows executing the query with a single set of arguments. + * + * @return A SingletonCall object + */ + @Override + public SingletonCall asSingleCall() { + return new SingletonCall(this); + } + + /** + * Converts the current Call object into a BatchCall object. + * + * @return a new instance of the BatchCall class with the current Call object added to it. + */ + @Override + public BatchCall asBatchCall() { + return new BatchCall(List.of(this)); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java new file mode 100644 index 00000000..6c5fe17e --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java @@ -0,0 +1,76 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.call.adapter; + +import de.chojo.sadu.queries.api.call.adapter.Adapter; +import de.chojo.sadu.types.SqlType; + +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.Types; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.util.Collection; + +import static de.chojo.sadu.conversion.ArrayConverter.toSqlArray; +import static de.chojo.sadu.queries.api.call.adapter.Adapter.create; + +/** + * The StandardAdapter class provides a set of static instances of Adapter, which map Java objects to specific SQL data types and provide the necessary conversions when binding the + * objects to a PreparedStatement. + */ +public final class StandardAdapter { + public static final Adapter STRING = create(PreparedStatement::setString, Types.VARCHAR); + public static final Adapter> ENUM = create(PreparedStatement::setString, Types.VARCHAR, Enum::name); + public static final Adapter SHORT = create(PreparedStatement::setShort, Types.TINYINT); + public static final Adapter INTEGER = create(PreparedStatement::setInt, Types.INTEGER); + public static final Adapter BIG_DECIMAL = create(PreparedStatement::setBigDecimal, Types.DECIMAL); + public static final Adapter FLOAT = create(PreparedStatement::setFloat, Types.FLOAT); + public static final Adapter DOUBLE = create(PreparedStatement::setDouble, Types.DOUBLE); + public static final Adapter LONG = create(PreparedStatement::setLong, Types.BIGINT); + public static final Adapter BOOLEAN = create(PreparedStatement::setBoolean, Types.BOOLEAN); + public static final Adapter BYTE = create(PreparedStatement::setByte, Types.BIT); + public static final Adapter BYTE_ARRAY = create(PreparedStatement::setBytes, Types.BINARY); + public static final Adapter DATE = create(PreparedStatement::setDate, Types.DATE); + public static final Adapter LOCAL_DATE = create(PreparedStatement::setDate, Types.DATE, Date::valueOf); + public static final Adapter

+ * An empty call is a SingletonCall that contains a single query call, but with no arguments. + * It is often used when executing a query that does not require any parameters. + */ + public static final SingletonCall EMPTY = new SingletonCall(Call.of()); + + @Override + public List calls() { + return Collections.singletonList(call); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/package-info.java new file mode 100644 index 00000000..ac46bb1f --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/calls/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds the implementation of {@link de.chojo.sadu.queries.api.call.calls.Calls} + */ +package de.chojo.sadu.queries.calls; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java new file mode 100644 index 00000000..142d7a85 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.configuration; + +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.queries.exception.WrappedQueryExecutionException; +import de.chojo.sadu.queries.query.QueryImpl; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.function.Consumer; + +public class ConnectedQueryConfiguration extends QueryConfiguration implements AutoCloseable { + private Connection connection = null; + + ConnectedQueryConfiguration(QueryImpl query, DataSource dataSource, boolean atomic, boolean throwExceptions, Consumer exceptionHandler, RowMapperRegistry rowMapperRegistry) { + super(query, dataSource, atomic, throwExceptions, exceptionHandler, rowMapperRegistry); + } + + public ConnectedQueryConfiguration forQuery(QueryImpl query) { + return new ConnectedQueryConfiguration(query, dataSource, atomic, throwExceptions, exceptionHandler, rowMapperRegistry); + } + + @Override + public void close() { + try { + if (connection != null && !connection.isClosed()) { + if (query.exceptions().isEmpty()) { + if (atomic()) { + connection.commit(); + } + } + connection.close(); + } + } catch (SQLException e) { + handleException(e); + } + } + + public Connection connection() { + if (connection == null) { + try { + connection = dataSource.getConnection(); + connection.setAutoCommit(!atomic); + } catch (SQLException e) { + handleException(e); + throw (WrappedQueryExecutionException) new WrappedQueryExecutionException(e.getMessage()).initCause(e); + } + } + return connection; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java new file mode 100644 index 00000000..705f1440 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java @@ -0,0 +1,158 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.configuration; + +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.queries.api.query.ParsedQuery; +import de.chojo.sadu.queries.api.query.Query; +import de.chojo.sadu.queries.exception.WrappedQueryExecutionException; +import de.chojo.sadu.queries.query.QueryImpl; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + +public class QueryConfiguration { + static final AtomicReference DEFAULT = new AtomicReference<>(null); + protected final QueryImpl query; + protected final @NotNull DataSource dataSource; + protected final boolean atomic; + protected final boolean throwExceptions; + protected final Consumer exceptionHandler; + protected final RowMapperRegistry rowMapperRegistry; + + QueryConfiguration(@NotNull DataSource dataSource, boolean atomic, boolean throwExceptions, Consumer exceptionHandler, RowMapperRegistry rowMapperRegistry) { + query = null; + this.dataSource = dataSource; + this.atomic = atomic; + this.throwExceptions = throwExceptions; + this.exceptionHandler = exceptionHandler; + this.rowMapperRegistry = rowMapperRegistry; + } + + QueryConfiguration(QueryImpl query, @NotNull DataSource dataSource, boolean atomic, boolean throwExceptions, Consumer exceptionHandler, RowMapperRegistry rowMapperRegistry) { + this.query = query; + this.dataSource = dataSource; + this.atomic = atomic; + this.throwExceptions = throwExceptions; + this.exceptionHandler = exceptionHandler; + this.rowMapperRegistry = rowMapperRegistry; + } + + /** + * Retrieves the default QueryConfiguration. + * + * @return the default QueryConfiguration + */ + public static QueryConfiguration getDefault() { + return Objects.requireNonNull(DEFAULT.get(), "You need to configure the configuration first by calling QueryConfiguration.setDefault()"); + } + + /** + * Sets the default query configuration. + * + * @param configuration the query configuration to set as default + */ + public static void setDefault(QueryConfiguration configuration) { + DEFAULT.set(configuration); + } + + /** + * Creates a new QueryConfigurationBuilder instance with the given DataSource. + * + * @param source the DataSource to use for QueryConfiguration + * @return a QueryConfigurationBuilder instance + */ + public static QueryConfigurationBuilder builder(DataSource source) { + return new QueryConfigurationBuilder(source); + } + + /** + * Returns a new QueryConfiguration object with the provided query and other configuration settings. + * + * @param query the query to be associated with the configuration + * @return the new QueryConfiguration object + */ + public QueryConfiguration forQuery(QueryImpl query) { + return new QueryConfiguration(query, dataSource, atomic, throwExceptions, exceptionHandler, rowMapperRegistry); + } + + /** + * Handles a SQLException by invoking the exceptionHandler consumer, logging the exception, + * and potentially throwing a WrappedQueryExecutionException. + * + * @param e the SQLException to handle + */ + public void handleException(SQLException e) { + exceptionHandler.accept(e); + query.logException(e); + if (throwExceptions) { + throw (WrappedQueryExecutionException) new WrappedQueryExecutionException(e.getMessage()).initCause(e); + } + } + + /** + * Retrieves the value of the atomic flag. + * + * @return {@code true} if atomic flag is set; {@code false} otherwise. + */ + public boolean atomic() { + return atomic; + } + + /** + * Retrieves the value of the throwExceptions field. + * + * @return the value of the throwExceptions field + */ + public boolean throwExceptions() { + return throwExceptions; + } + + /** + * Retrieves the {@link RowMapperRegistry} object from the {@link QueryConfiguration}. + * + * @return The {@link RowMapperRegistry} object from the {@link QueryConfiguration}. + */ + public RowMapperRegistry rowMapperRegistry() { + return rowMapperRegistry; + } + + /** + * Returns the DataSource object associated with this QueryConfiguration. + * + * @return the DataSource object + */ + public DataSource dataSource() { + return dataSource; + } + + /** + * Executes a SQL query with the given SQL statement and format arguments. + * + * @param sql the SQL statement to be executed + * @param format the format arguments to be applied to the SQL statement + * @return a parsed query ready for execution + */ + public ParsedQuery query(@Language("sql") String sql, Object... format) { + return Query.query(this, sql, format); + } + + /** + * Returns a new instance of the ConnectedQueryConfiguration class with the "single transaction" configuration applied. + * This means that a single transaction will be used for the queries executed using this configuration. + * + * @return A new instance of the ConnectedQueryConfiguration class with the "single transaction" configuration applied. + */ + public ConnectedQueryConfiguration withSingleTransaction() { + return new ConnectedQueryConfiguration(query, dataSource, true, throwExceptions, exceptionHandler, rowMapperRegistry); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfigurationBuilder.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfigurationBuilder.java new file mode 100644 index 00000000..7ee9a2f7 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/QueryConfigurationBuilder.java @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.configuration; + +import de.chojo.sadu.exceptions.ExceptionTransformer; +import de.chojo.sadu.mapper.RowMapperRegistry; +import org.jetbrains.annotations.NotNull; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.util.function.Consumer; + +public class QueryConfigurationBuilder { + private final DataSource dataSource; + private boolean atomic = true; + private boolean throwExceptions; + @SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) + private Consumer exceptionHandler = throwable -> { + System.err.println(ExceptionTransformer.prettyException(throwable)); + throwable.printStackTrace(); + }; + private RowMapperRegistry rowMapperRegistry = new RowMapperRegistry(); + + /** + * QueryConfigurationBuilder is a builder class used to create an instance of QueryConfiguration. + * It provides methods to configure various properties of the QueryConfiguration. + */ + public QueryConfigurationBuilder(@NotNull DataSource dataSource) { + this.dataSource = dataSource; + } + + /** + * Sets the atomic flag for the QueryConfigurationBuilder. + *

+ * Default: true + * + * @param atomic the value to set the atomic flag to + * @return the QueryConfigurationBuilder instance + */ + public QueryConfigurationBuilder setAtomic(boolean atomic) { + this.atomic = atomic; + return this; + } + + /** + * Sets the flag indicating whether exceptions thrown during database queries should be thrown or logged. + * + * @param throwExceptions flag indicating whether exceptions should be thrown (true) or logged (false) + * @return the QueryConfigurationBuilder instance + */ + public QueryConfigurationBuilder setThrowExceptions(boolean throwExceptions) { + this.throwExceptions = throwExceptions; + return this; + } + + /** + * Sets the exception handler for handling SQLExceptions that may occur during database operations. + *

+ * Default: stdout + * + * @param exceptionHandler the consumer function that handles SQLExceptions + * @return the QueryConfigurationBuilder instance + */ + public QueryConfigurationBuilder setExceptionHandler(Consumer exceptionHandler) { + this.exceptionHandler = exceptionHandler; + return this; + } + + /** + * Sets the {@link RowMapperRegistry} for the {@link QueryConfiguration}. + * + * @param rowMapperRegistry the RowMapperRegistry to set + * @return the QueryConfigurationBuilder instance + */ + public QueryConfigurationBuilder setRowMapperRegistry(RowMapperRegistry rowMapperRegistry) { + this.rowMapperRegistry = rowMapperRegistry; + return this; + } + + /** + * Returns a new {@link QueryConfiguration} object based on the current configuration settings. + * + * @return a new {@link QueryConfiguration} object + */ + public QueryConfiguration build() { + return new QueryConfiguration(dataSource, atomic, throwExceptions, exceptionHandler, rowMapperRegistry); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/package-info.java new file mode 100644 index 00000000..c7472ba7 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/configuration/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation for query configuration. + */ +package de.chojo.sadu.queries.configuration; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java new file mode 100644 index 00000000..11261483 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java @@ -0,0 +1,54 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.exception; + +import de.chojo.sadu.queries.query.QueryImpl; + +import java.sql.SQLException; + +/** + * Exception to wrap {@link Exception} as {@link Exception} thrown during queries executed by {@link QueryImpl} + */ +public class QueryExecutionException extends SQLException { + /** + * Cause of the exception + */ + private SQLException cause; + + /** + * Creates a new exception + * + * @param message message + */ + public QueryExecutionException(String message) { + super(message); + } + + /** + * @throws ClassCastException If the throwable is not a {@link SQLException} + */ + @Override + public synchronized Throwable initCause(Throwable cause) { + this.cause = (SQLException) cause; + return super.initCause(cause); + } + + @Override + public String getSQLState() { + return cause.getSQLState(); + } + + @Override + public int getErrorCode() { + return cause.getErrorCode(); + } + + @Override + public String getMessage() { + return cause.getMessage(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java new file mode 100644 index 00000000..f39e52d2 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.exception; + +import de.chojo.sadu.queries.query.QueryImpl; + +import java.sql.SQLException; + +/** + * Exception to wrap {@link Exception} as {@link RuntimeException} thrown during queries executed by {@link QueryImpl} + */ +public class WrappedQueryExecutionException extends RuntimeException { + /** + * Cause of the exception + */ + private SQLException cause; + + /** + * Creates a new exception. + * + * @param message message + */ + public WrappedQueryExecutionException(String message) { + super(message); + } + + /** + * @throws ClassCastException If the throwable is not a {@link SQLException} + */ + @Override + public synchronized Throwable initCause(Throwable cause) { + this.cause = (SQLException) cause; + return super.initCause(cause); + } + + + /** + * SQL state of the exception + * + * @return sql state + */ + public String getSQLState() { + return cause.getSQLState(); + } + + /** + * Error code of the exception + * + * @return error code + */ + public int getErrorCode() { + return cause.getErrorCode(); + } + + @Override + public String getMessage() { + return cause.getMessage(); + } + +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/package-info.java new file mode 100644 index 00000000..0b055e1d --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/exception/package-info.java @@ -0,0 +1,4 @@ +/** + * General exception definitions + */ +package de.chojo.sadu.queries.exception; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/IndexParameter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/IndexParameter.java new file mode 100644 index 00000000..d4af248b --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/IndexParameter.java @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.parameter; + +import de.chojo.sadu.exceptions.ThrowingBiConsumer; +import de.chojo.sadu.queries.api.parameter.BaseParameter; +import de.chojo.sadu.queries.query.TokenizedQuery; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class IndexParameter implements BaseParameter { + private final int index; + private final ThrowingBiConsumer apply; + + public IndexParameter(int index, ThrowingBiConsumer apply) { + this.index = index; + this.apply = apply; + } + + @Override + public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException { + apply.accept(stmt, query.getIndexTokenIndex(index)); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/TokenParameter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/TokenParameter.java new file mode 100644 index 00000000..87525875 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/TokenParameter.java @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.parameter; + +import de.chojo.sadu.exceptions.ThrowingBiConsumer; +import de.chojo.sadu.queries.api.parameter.BaseParameter; +import de.chojo.sadu.queries.query.TokenizedQuery; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class TokenParameter implements BaseParameter { + private final String token; + private final ThrowingBiConsumer apply; + + public TokenParameter(String token, ThrowingBiConsumer apply) { + if (!token.startsWith(":")) { + this.token = ":" + token; + } else { + this.token = token; + } + this.apply = apply; + } + + public void apply(TokenizedQuery query, PreparedStatement stmt) throws SQLException { + for (var index : query.getNamedTokenIndex(token)) { + apply.accept(stmt, index); + } + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/package-info.java new file mode 100644 index 00000000..f672d7b7 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/parameter/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementatino for parameter + */ +package de.chojo.sadu.queries.parameter; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/AppendedQueryImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/AppendedQueryImpl.java new file mode 100644 index 00000000..6b24fad9 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/AppendedQueryImpl.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.query; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.query.AppendedQuery; +import org.intellij.lang.annotations.Language; + +public class AppendedQueryImpl implements QueryProvider, AppendedQuery { + private final QueryProvider query; + + public AppendedQueryImpl(QueryProvider query) { + this.query = query; + } + + + @Override + public ParsedQueryImpl query(@Language("sql") String sql, Object... format) { + return ParsedQueryImpl.create(query, sql.formatted(format)); + } + + @Override + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java new file mode 100644 index 00000000..7cca71e1 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.query; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.execution.writing.CalledBatchQuery; +import de.chojo.sadu.queries.api.execution.writing.CalledSingletonQuery; +import de.chojo.sadu.queries.api.query.ParsedQuery; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.calls.CallSupplier; +import de.chojo.sadu.queries.calls.SingletonCall; +import de.chojo.sadu.queries.stages.execution.writing.CalledBatchQueryImpl; +import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; + +public class ParsedQueryImpl implements QueryProvider, ParsedQuery { + private final QueryProvider query; + private final TokenizedQuery sql; + + private ParsedQueryImpl(QueryProvider query, TokenizedQuery sql) { + this.query = query; + this.sql = sql; + } + + public static ParsedQueryImpl create(QueryProvider query, String sql, Object... format) { + return new ParsedQueryImpl(query, TokenizedQuery.create(sql.formatted(format))); + } + + @Override + public CalledSingletonQuery single(SingletonCall param) { + return new CalledSingletonQueryImpl(this, param); + } + + @Override + public CalledSingletonQuery single(CallSupplier call) { + return new CalledSingletonQueryImpl(this, call.supply(query().storage())); + } + + @Override + public CalledBatchQuery batch(BatchCall calls) { + return new CalledBatchQueryImpl(this, calls); + } + + @Override + public CalledBatchQuery batch(CallSupplier calls) { + return new CalledBatchQueryImpl(this, calls.supply(query().storage())); + } + + public TokenizedQuery sql() { + return sql; + } + + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/QueryImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/QueryImpl.java new file mode 100644 index 00000000..56fe2902 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/QueryImpl.java @@ -0,0 +1,86 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.query; + +import de.chojo.sadu.base.DataSourceProvider; +import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.queries.api.base.ConnectionProvider; +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.query.Query; +import de.chojo.sadu.queries.configuration.ConnectedQueryConfiguration; +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.storage.ResultStorageImpl; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +public class QueryImpl implements DataSourceProvider, ConnectionProvider, QueryProvider, Query { + + private final QueryConfiguration conf; + private final ResultStorageImpl storage = new ResultStorageImpl(); + private final List exceptions = new ArrayList<>(); + + public QueryImpl(QueryConfiguration conf) { + this.conf = conf.forQuery(this); + } + + @Override + public DataSource source() { + return conf.dataSource(); + } + + + @Override + public QueryImpl query() { + return this; + } + + public ResultStorageImpl storage() { + return storage; + } + + public void logException(Exception ex) { + exceptions.add(ex); + } + + @Override + public T callConnection(Supplier defaultResult, ThrowingFunction connectionConsumer) { + if (!(conf instanceof ConnectedQueryConfiguration conn)) { + try (var conn = conf.dataSource().getConnection()) { + conn.setAutoCommit(false); + var result = connectionConsumer.apply(conn); + conn.commit(); + return result; + } catch (SQLException e) { + conf.handleException(e); + } + } else { + try { + return connectionConsumer.apply(conn.connection()); + } catch (SQLException e) { + conf.handleException(e); + } + } + return defaultResult.get(); + } + + public List exceptions() { + return exceptions; + } + + public void handleException(SQLException e) { + conf.handleException(e); + } + + public QueryConfiguration configuration() { + return conf; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/TokenizedQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/TokenizedQuery.java new file mode 100644 index 00000000..4881172c --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/TokenizedQuery.java @@ -0,0 +1,62 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.query; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +public class TokenizedQuery { + private static final Pattern PARAM_TOKEN = Pattern.compile("\\?|(?:([ \t,=(])(?:[a-zA-Z_]+))"); + private final Map indexToken; + private final Map> namedToken; + private final String sql; + private final String tokenizedSql; + + public TokenizedQuery(String sql, Map indexToken, Map> namedToken) { + this.sql = sql; + tokenizedSql = PARAM_TOKEN.matcher(sql).replaceAll("$1?"); + this.indexToken = indexToken; + this.namedToken = namedToken; + } + + public static TokenizedQuery create(String sql) { + var matcher = PARAM_TOKEN.matcher(sql); + var index = 1; + var currIndexToken = 1; + Map indexToken = new HashMap<>(); + Map> namedToken = new HashMap<>(); + + + while (matcher.find()) { + if ("?".equals(matcher.group())) { + indexToken.put(currIndexToken++, index++); + } else { + namedToken.computeIfAbsent(matcher.group("token"), key -> new ArrayList<>()).add(index++); + } + } + return new TokenizedQuery(sql, indexToken, namedToken); + } + + public List getNamedTokenIndex(String token) { + return namedToken.get(token); + } + + public int getIndexTokenIndex(int index) { + return indexToken.get(index); + } + + public String sql() { + return sql; + } + + public String tokenizedSql() { + return tokenizedSql; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/package-info.java new file mode 100644 index 00000000..56d42f03 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/query/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementations for queries + */ +package de.chojo.sadu.queries.query; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java new file mode 100644 index 00000000..55c51454 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation for executing queries. + */ +package de.chojo.sadu.queries.stages.execution; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java new file mode 100644 index 00000000..f70c0bcc --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java @@ -0,0 +1,41 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.execution.reading; + +import de.chojo.sadu.mapper.MapperConfig; +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; + +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * Class that represents a query that will be mapped via a {@link RowMapperRegistry} + * + * @param Type of result object + */ +public class AutoMappedQuery extends ReaderImpl { + private final Class clazz; + private final MapperConfig config; + + public AutoMappedQuery(CalledSingletonQueryImpl query, Class clazz, MapperConfig config) { + super(query); + this.clazz = clazz; + this.config = config; + } + + @Override + protected RowMapping mapper(ResultSet set) throws SQLException { + return query().configuration().rowMapperRegistry().findOrWildcard(clazz, set, config); + } + + @Override + protected MapperConfig mapperConfig() { + return config; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java new file mode 100644 index 00000000..d07cc11e --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.execution.reading; + +import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; + +import java.sql.ResultSet; + +public class MappedQuery extends ReaderImpl { + private final RowMapping mapper; + + public MappedQuery(CalledSingletonQueryImpl query, RowMapping mapper) { + super(query); + this.mapper = mapper; + } + + @Override + protected RowMapping mapper(ResultSet set) { + return mapper; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java new file mode 100644 index 00000000..6f3ac6ad --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java @@ -0,0 +1,123 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.execution.reading; + +import de.chojo.sadu.mapper.MapperConfig; +import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.execution.reading.Reader; +import de.chojo.sadu.queries.api.query.AppendedQuery; +import de.chojo.sadu.queries.api.results.reading.Result; +import de.chojo.sadu.queries.call.CallImpl; +import de.chojo.sadu.queries.query.AppendedQueryImpl; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.query.TokenizedQuery; +import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; +import de.chojo.sadu.queries.stages.results.reading.MultiResult; +import de.chojo.sadu.queries.stages.results.reading.SingleResult; +import de.chojo.sadu.wrapper.util.Row; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public abstract class ReaderImpl implements QueryProvider, Reader { + private final CalledSingletonQueryImpl query; + + public ReaderImpl(CalledSingletonQueryImpl query) { + this.query = query; + } + + @Override + public Result first() { + return mapOne(); + } + + @Override + public Result> all() { + return mapAll(); + } + + @Override + public AppendedQuery storeOneAndAppend(String key) { + store(key, mapOne()); + return new AppendedQueryImpl(this); + } + + @Override + public AppendedQuery storeAllAndAppend(String key) { + store(key, mapAll()); + return new AppendedQueryImpl(this); + } + + private > void store(String key, T result) { + query.query().storage().store(key, result); + } + + @SuppressWarnings("JDBCPrepareStatementWithNonConstantString") + private SingleResult mapOne() { + return query().callConnection(() -> new SingleResult<>(this, null), conn -> { + try (var stmt = conn.prepareStatement(sql().tokenizedSql())) { + ((CallImpl) call()).apply(sql(), stmt); + var resultSet = stmt.executeQuery(); + var row = new Row(resultSet, mapperConfig()); + if (resultSet.next()) { + return new SingleResult<>(this, mapper(resultSet).map(row)); + } + } + return new SingleResult<>(this, null); + }); + } + + @SuppressWarnings("JDBCPrepareStatementWithNonConstantString") + private MultiResult> mapAll() { + return query().callConnection(() -> new MultiResult<>(this, Collections.emptyList()), conn -> { + var result = new ArrayList(); + try (var stmt = conn.prepareStatement(sql().tokenizedSql())) { + ((CallImpl) call()).apply(sql(), stmt); + var resultSet = stmt.executeQuery(); + var row = new Row(resultSet, mapperConfig()); + while (resultSet.next()) result.add(mapper(resultSet).map(row)); + } + return new MultiResult<>(this, result); + }); + } + + protected abstract RowMapping mapper(ResultSet set) throws SQLException; + + protected MapperConfig mapperConfig() { + return MapperConfig.DEFAULT; + } + + @Override + public Optional oneAndGet() { + return Optional.ofNullable(first().result()); + } + + @Override + public List allAndGet() { + return Objects.requireNonNullElse(all().result(), Collections.emptyList()); + } + + public TokenizedQuery sql() { + return query.sql(); + } + + public Call call() { + return query.call(); + } + + @Override + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java new file mode 100644 index 00000000..7cbbdf28 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation for executing reading queries. + */ +package de.chojo.sadu.queries.stages.execution.reading; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java new file mode 100644 index 00000000..33f10aa0 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java @@ -0,0 +1,65 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.execution.writing; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.execution.writing.CalledBatchQuery; +import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.call.CallImpl; +import de.chojo.sadu.queries.calls.BatchCall; +import de.chojo.sadu.queries.query.ParsedQueryImpl; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.stages.results.writing.ManipulationBatchQuery; +import de.chojo.sadu.queries.stages.results.writing.ManipulationResultImpl; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; + +public class CalledBatchQueryImpl implements QueryProvider, CalledBatchQuery { + private final ParsedQueryImpl parsedQuery; + private final BatchCall calls; + + public CalledBatchQueryImpl(ParsedQueryImpl parsedQuery, BatchCall calls) { + this.parsedQuery = parsedQuery; + this.calls = calls; + } + + @Override + public ManipulationBatchResult insert() { + return update(); + } + + @SuppressWarnings("JDBCPrepareStatementWithNonConstantString") + @Override + public ManipulationBatchResult update() { + return query().callConnection(() -> new ManipulationBatchQuery(this, Collections.emptyList()), conn -> { + var changed = new ArrayList(); + for (var call : calls.calls()) { + try (var stmt = conn.prepareStatement(parsedQuery.sql().tokenizedSql())) { + //TODO find way to return generated keys + ((CallImpl) call).apply(parsedQuery.sql(), stmt); + changed.add(new ManipulationResultImpl(this, stmt.executeUpdate())); + } catch (SQLException ex) { + query().handleException(ex); + } + } + return new ManipulationBatchQuery(this, changed); + }); + } + + @Override + public ManipulationBatchResult delete() { + return update(); + } + + @Override + public QueryImpl query() { + return parsedQuery.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java new file mode 100644 index 00000000..00dd3bbd --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java @@ -0,0 +1,97 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.execution.writing; + +import de.chojo.sadu.mapper.MapperConfig; +import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.execution.reading.Reader; +import de.chojo.sadu.queries.api.execution.writing.CalledSingletonQuery; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.call.CallImpl; +import de.chojo.sadu.queries.calls.SingletonCall; +import de.chojo.sadu.queries.query.ParsedQueryImpl; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.query.TokenizedQuery; +import de.chojo.sadu.queries.stages.execution.reading.AutoMappedQuery; +import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; +import de.chojo.sadu.queries.stages.results.writing.ManipulationResultImpl; + +import java.sql.SQLException; + +public class CalledSingletonQueryImpl implements QueryProvider, CalledSingletonQuery { + private final ParsedQueryImpl query; + private final SingletonCall call; + + public CalledSingletonQueryImpl(ParsedQueryImpl query, SingletonCall call) { + this.query = query; + this.call = call; + } + + @Override + public Reader map(RowMapping row) { + return new MappedQuery<>(this, row); + } + + @Override + public Reader mapAs(Class clazz) { + return new AutoMappedQuery<>(this, clazz, MapperConfig.DEFAULT); + } + + @Override + public Reader mapAs(Class clazz, MapperConfig config) { + return new AutoMappedQuery<>(this, clazz, config); + } + + @Override + public ManipulationResult insert() { + return query.callConnection(() -> new ManipulationResultImpl(this, 0), conn -> { + var changed = 0; + try (var stmt = conn.prepareStatement(query.sql().tokenizedSql())) { + //TODO find way to return generated keys + ((CallImpl) call.call()).apply(query.sql(), stmt); + changed = stmt.executeUpdate(); + } catch (SQLException ex) { + query().handleException(ex); + } + return new ManipulationResultImpl(this, changed); + }); + } + + @Override + public ManipulationResult update() { + return query().callConnection(() -> new ManipulationResultImpl(this, 0), conn -> { + var changed = 0; + try (var stmt = conn.prepareStatement(query.sql().tokenizedSql())) { + ((CallImpl) call.call()).apply(query.sql(), stmt); + changed = stmt.executeUpdate(); + } catch (SQLException ex) { + query().handleException(ex); + } + return new ManipulationResultImpl(this, changed); + }); + } + + @Override + public ManipulationResult delete() { + return update(); + } + + @Override + public QueryImpl query() { + return query.query(); + } + + public TokenizedQuery sql() { + return query.sql(); + } + + public Call call() { + return call.call(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java new file mode 100644 index 00000000..4e4ed143 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementatino for executing writing queries. + */ +package de.chojo.sadu.queries.stages.execution.writing; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/package-info.java new file mode 100644 index 00000000..face8c79 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of the different stages of a query lifecycle. + */ +package de.chojo.sadu.queries.stages; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java new file mode 100644 index 00000000..9924abf4 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of stages for result retrieval + */ +package de.chojo.sadu.queries.stages.results; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java new file mode 100644 index 00000000..50b2a48e --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.results.reading; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.results.reading.Result; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; + +/** + * Result of a {@link MappedQuery#all()} call + * + * @param Type of returned object + */ + +public class MultiResult implements QueryProvider, Result { + private final QueryProvider query; + private final T results; + + public MultiResult(QueryProvider query, T results) { + this.query = query; + this.results = results; + } + + @Override + public QueryImpl query() { + return query.query(); + } + + @Override + public T result() { + return results; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java new file mode 100644 index 00000000..6ae8edfc --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.results.reading; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.results.reading.Result; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; + +/** + * Result of a {@link MappedQuery#first()} call + * + * @param Type of returned object + */ +public class SingleResult implements Result, QueryProvider { + private final QueryProvider query; + private final T result; + + public SingleResult(QueryProvider query, T result) { + this.query = query; + this.result = result; + } + + @Override + public T result() { + return result; + } + + @Override + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java new file mode 100644 index 00000000..32a17940 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation for retrieving results of a reading query. + */ +package de.chojo.sadu.queries.stages.results.reading; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java new file mode 100644 index 00000000..295f188f --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java @@ -0,0 +1,63 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.results.writing; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.stages.execution.writing.CalledBatchQueryImpl; + +import java.util.List; + +/** + * Result of a {@link CalledBatchQueryImpl} + */ +public class ManipulationBatchQuery implements QueryProvider, ManipulationBatchResult { + private final QueryProvider query; + private final List results; + + public ManipulationBatchQuery(QueryProvider query, List results) { + this.query = query; + this.results = results; + } + + /** + * List of results of all calls in the batch + * + * @return list of results + */ + @Override + public List results() { + return results; + } + + /** + * total amount of changed rows + * + * @return total count + */ + @Override + public int rows() { + return results.stream().mapToInt(ManipulationResult::rows).sum(); + } + + /** + * Checks whether at least one row was changed. + * + * @return true if one row or more were changed + */ + @Override + public boolean changed() { + return results.stream().anyMatch(ManipulationResult::changed); + } + + @Override + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java new file mode 100644 index 00000000..e42e1c16 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.stages.results.writing; + +import de.chojo.sadu.queries.api.base.QueryProvider; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.query.QueryImpl; +import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; + +/** + * Result of a {@link CalledSingletonQueryImpl}. + */ +public class ManipulationResultImpl implements QueryProvider, ManipulationResult { + private final QueryProvider query; + private final int rows; + + public ManipulationResultImpl(QueryProvider query, int rows) { + this.query = query; + this.rows = rows; + } + + /** + * Amount of changed rows + * + * @return rows + */ + @Override + public int rows() { + return rows; + } + + /** + * Checks whether at least one row was changed + * + * @return true if at least one row was changed + */ + @Override + public boolean changed() { + return rows != 0; + } + + @Override + public QueryImpl query() { + return query.query(); + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java new file mode 100644 index 00000000..c7258e88 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation for results of a writing query. + */ +package de.chojo.sadu.queries.stages.results.writing; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/ResultStorageImpl.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/ResultStorageImpl.java new file mode 100644 index 00000000..e2acbf1b --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/ResultStorageImpl.java @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.storage; + +import de.chojo.sadu.queries.api.results.reading.Result; +import de.chojo.sadu.queries.api.storage.ResultStorage; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@SuppressWarnings("unchecked") +public class ResultStorageImpl implements ResultStorage { + private final Map> storage = new HashMap<>(); + + public ResultStorageImpl() { + } + + public void store(String key, Result value) { + storage.put(key, value); + } + + @Override + @SuppressWarnings("unchecked") + public T get(String key) { + return (T) retrieve(key).result(); + } + + @Override + public Optional getAs(String key, Class clazz) { + return Optional.ofNullable((T) retrieve(key).result()); + } + + @Override + public List getList(String key, Class clazz) { + return Objects.requireNonNullElse((List) retrieve(key).result(), Collections.emptyList()); + } + + private Result retrieve(String key) { + var result = storage.get(key); + if (result == null) throw new IllegalArgumentException("Key %s is not set.".formatted(key)); + return result; + } +} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/package-info.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/package-info.java new file mode 100644 index 00000000..d1019a40 --- /dev/null +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/storage/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of the query storage. + */ +package de.chojo.sadu.queries.storage; diff --git a/sadu-queries2/src/main/java/module-info.java b/sadu-queries2/src/main/java/module-info.java new file mode 100644 index 00000000..9a268781 --- /dev/null +++ b/sadu-queries2/src/main/java/module-info.java @@ -0,0 +1,37 @@ +module sadu.sadu.queries2.main { + requires java.sql; + requires transitive sadu.sadu.core.main; + requires transitive sadu.sadu.mapper.main; + + exports de.chojo.sadu.queries.api.base; + exports de.chojo.sadu.queries.api.call; + exports de.chojo.sadu.queries.api.call.adapter; + exports de.chojo.sadu.queries.api.call.calls; + exports de.chojo.sadu.queries.api.execution.reading; + exports de.chojo.sadu.queries.api.execution.writing; + exports de.chojo.sadu.queries.api.parameter; + exports de.chojo.sadu.queries.api.query; + exports de.chojo.sadu.queries.api.results.reading; + exports de.chojo.sadu.queries.api.results.writing; + exports de.chojo.sadu.queries.api.storage; + + exports de.chojo.sadu.queries.call; + exports de.chojo.sadu.queries.call.adapter; + + exports de.chojo.sadu.queries.calls; + + exports de.chojo.sadu.queries.configuration; + + exports de.chojo.sadu.queries.exception; + + exports de.chojo.sadu.queries.parameter; + + exports de.chojo.sadu.queries.query; + + exports de.chojo.sadu.queries.stages.execution.reading; + exports de.chojo.sadu.queries.stages.execution.writing; + exports de.chojo.sadu.queries.stages.results.reading; + exports de.chojo.sadu.queries.stages.results.writing; + + exports de.chojo.sadu.queries.storage; +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java b/sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java new file mode 100644 index 00000000..95b7fc24 --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu; + +import de.chojo.sadu.databases.PostgreSql; +import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.updater.SqlUpdater; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +import javax.sql.DataSource; +import java.io.IOException; +import java.sql.SQLException; + +public class PostgresDatabase { + public static Database createContainer(String user, String pw) throws IOException, SQLException { + GenericContainer self = new GenericContainer<>(DockerImageName.parse("postgres:latest")) + .withExposedPorts(5432) + .withEnv("POSTGRES_USER", user) + .withEnv("POSTGRES_PASSWORD", pw) + .waitingFor(Wait.forLogMessage(".*database system is ready to accept connections.*", 2)); + self.start(); + + DataSource dc = DataSourceCreator.create(PostgreSql.get()) + .configure(c -> c.host(self.getHost()).port(self.getFirstMappedPort())).create() + .usingPassword("postgres") + .usingUsername("postgres") + .build(); + + SqlUpdater.builder(dc, PostgreSql.get()) + .execute(); + + return new Database(self, dc); + } + + public static record Database(GenericContainer container, DataSource dataSource) { + public void close() { + container.close(); + } + } +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java new file mode 100644 index 00000000..35df34e5 --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java @@ -0,0 +1,49 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries; + +import de.chojo.sadu.queries.query.TokenizedQuery; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TokenizedQueryTest { + private final String sql = "INSERT INTO persons VALUES(:name, ?,:age::integer, ?, ?,:gender,:gender);"; + private final TokenizedQuery tokenizedQuery = TokenizedQuery.create(sql); + + @Test + void create() { + TokenizedQuery.create(sql); + } + + @Test + void getNamedTokenIndex() { + assertEquals(Collections.singletonList(1), tokenizedQuery.getNamedTokenIndex(":name")); + assertEquals(Collections.singletonList(3), tokenizedQuery.getNamedTokenIndex(":age")); + assertEquals(List.of(6, 7), tokenizedQuery.getNamedTokenIndex(":gender")); + } + + @Test + void getIndexTokenIndex() { + assertEquals(2, tokenizedQuery.getIndexTokenIndex(1)); + assertEquals(4, tokenizedQuery.getIndexTokenIndex(2)); + assertEquals(5, tokenizedQuery.getIndexTokenIndex(3)); + } + + @Test + void sql() { + assertEquals(sql, tokenizedQuery.sql()); + } + + @Test + void tokenizedSql() { + assertEquals("INSERT INTO persons VALUES(?, ?,?::integer, ?, ?,?,?);", tokenizedQuery.tokenizedSql()); + } +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java new file mode 100644 index 00000000..4180e71e --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java @@ -0,0 +1,115 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.examples; + +import de.chojo.sadu.PostgresDatabase; +import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.call.calls.Calls; +import de.chojo.sadu.queries.api.results.reading.Result; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.configuration.QueryConfigurationBuilder; +import de.chojo.sadu.queries.examples.dao.User; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.sql.SQLException; +import java.time.LocalDate; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static de.chojo.sadu.PostgresDatabase.createContainer; +import static de.chojo.sadu.queries.api.call.Call.call; +import static de.chojo.sadu.queries.call.adapter.UUIDAdapter.AS_STRING; + +@SuppressWarnings({"unused", "ResultOfMethodCallIgnored", "OptionalGetWithoutIsPresent", "RedundantExplicitVariableType"}) +public class ReadTest { + + private QueryConfiguration query; + private PostgresDatabase.Database db; + + + @BeforeEach + void before() throws IOException, SQLException { + db = createContainer("postgres", "postgres"); + query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())).build(); + query.query("INSERT INTO users(uuid, name) VALUES (?::uuid,?)") + .batch(Call.of().bind(UUID.randomUUID(), AS_STRING).bind("Lilly"), + Call.of().bind(UUID.randomUUID(), AS_STRING).bind("Chojo")) + .insert(); + } + + @AfterEach + void after() { + db.close(); + } + + // Retrieve all matching users directly + @Test + public void retrieveAllDirectly() { + List users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") + .single(Call.of().bind(1).bind("name", "lilly")) + .map(User.map()) + .allAndGet(); + Assertions.assertEquals(1, users.size()); + } + + @Test + public void retrieveAllDirectlyNoFilter() { + List users = query.query("SELECT * FROM users") + .single(Calls.empty()) + .map(User.map()) + .allAndGet(); + Assertions.assertEquals(2, users.size()); + } + + // Retrieve all matching users directly + + @Test + public void retrieveFirstDirectly() { + // Retrieve the first user object directly + Optional user = query.query("SELECT * FROM users where id = :id") + .single(Call.of().bind("id", 1)) + .map(User.map()) + .oneAndGet(); + } + + @Test + public void retrieveAllMatching() { + // Retrieve all matching users and store them to use them again later + // From here on another query could be issued that uses the results of this query + Result> usersResult = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") + .single(Call.of().bind(1).bind("name", "lilly")) + .map(User.map()) + .storeOneAndAppend("user") + .query("SELECT * FROM users WHERE uuid = :uuid::uuid") + .single(storage -> call().bind("uuid", storage.getAs("user", User.class).get().uuid(), AS_STRING).asSingleCall()) + .map(User.map()) + .all(); + Assertions.assertEquals(1, usersResult.result().size()); + } + + @Test + public void storeAndUse() { + // Retrieve the first user and store them it to use it again later + // From here on another query could be issued that uses the results of this query + ManipulationResult manipulation = query.query("INSERT INTO users(uuid, name) VALUES (:uuid::uuid, :name) RETURNING id, uuid, name") + .single(call().bind("uuid", UUID.randomUUID(), AS_STRING).bind("name", "lilly")) + .map(User.map()) + .storeOneAndAppend("user") + .query("INSERT INTO birthdays(user_id, birth_date) VALUES (:id, :date)") + .single(storage -> call().bind("id", storage.getAs("user", User.class).get().id()).bind("date", LocalDate.of(1990, 1, 1)).asSingleCall()) + .insert(); + Assertions.assertEquals(1, manipulation.rows()); + } +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java new file mode 100644 index 00000000..bad68736 --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java @@ -0,0 +1,73 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.examples; + +import de.chojo.sadu.PostgresDatabase; +import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.queries.api.call.calls.Calls; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.configuration.QueryConfigurationBuilder; +import de.chojo.sadu.queries.examples.dao.User; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +import static de.chojo.sadu.PostgresDatabase.createContainer; +import static de.chojo.sadu.queries.api.call.Call.call; +import static de.chojo.sadu.queries.call.adapter.UUIDAdapter.AS_STRING; + +@SuppressWarnings({"unused", "ResultOfMethodCallIgnored", "OptionalGetWithoutIsPresent", "RedundantExplicitVariableType"}) +public class TransactionTest { + private static QueryConfiguration query; + private static PostgresDatabase.Database db; + + @BeforeAll + static void beforeAll() throws IOException, SQLException { + db = createContainer("postgres", "postgres"); + query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())).build(); + } + + @AfterAll + static void afterAll() { + db.close(); + } + + @Test + public void example() { + // atomic transaction + try (var conn = query.withSingleTransaction()) { + // Retrieve the first user and store them it to use it again later + // From here on another query could be issued that uses the results of this query + ManipulationResult manipulation = conn.query("INSERT INTO users(uuid, name) VALUES (:uuid::uuid, :name) RETURNING id, uuid, name") + .single(call().bind("uuid", UUID.randomUUID(), AS_STRING).bind("name", "lilly")) + .map(User.map()) + .storeOneAndAppend("user") + .query("INSERT INTO birthdays(user_id, birth_date) VALUES (:id, :date)") + // produce error + .single(storage -> call().bind("id", storage.getAs("user", User.class).get().id()).bind("date", "").asSingleCall()) + .insert(); + } + + List users = query.query("SELECT * FROM users") + .single(Calls.empty()) + .map(User.map()) + .allAndGet(); + + // Make sure that the first insert was not commited + Assertions.assertEquals(0, users.size()); + } + + +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java new file mode 100644 index 00000000..632686bb --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java @@ -0,0 +1,137 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.examples; + +import de.chojo.sadu.PostgresDatabase; +import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.queries.api.call.Call; +import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; +import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.call.adapter.UUIDAdapter; +import de.chojo.sadu.queries.configuration.QueryConfiguration; +import de.chojo.sadu.queries.configuration.QueryConfigurationBuilder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.UUID; +import java.util.stream.Stream; + +import static de.chojo.sadu.PostgresDatabase.createContainer; +import static de.chojo.sadu.queries.call.adapter.UUIDAdapter.AS_STRING; + +@SuppressWarnings({"unused", "RedundantExplicitVariableType"}) +public class WriteTest { + private PostgresDatabase.Database db; + private QueryConfiguration query; + + @BeforeEach + void beforeEach() throws IOException, SQLException { + db = createContainer("postgres", "postgres"); + query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())).build(); + } + + @AfterEach + void afterAll() { + db.close(); + } + + @Test + public void exampleIndex() { + // Insert multiple entries at the same time + ManipulationBatchResult change = query + // Define the query + .query("INSERT INTO users(uuid, name) VALUES(?::uuid,?)") + // Create a new batch call + .batch( + // Define the first call + Call.of().bind(UUID.randomUUID(), AS_STRING).bind((String) null), + // Define the second call + Call.of().bind(UUID.randomUUID(), AS_STRING).bind((String) null)) + // Insert the data + .insert(); + + // Check that something changed + Assertions.assertTrue(change.changed()); + // Check that two rows were added + Assertions.assertEquals(2, change.rows()); + + // Check how many rows for each batch execution were changed + for (ManipulationResult result : change.results()) { + Assertions.assertEquals(1, result.rows()); + } + } + + @Test + public void exampleTokenized() { + // Insert multiple entries at the same time + ManipulationBatchResult change = query + // Define the query + .query("INSERT INTO users(uuid, name) VALUES(:uuid::uuid,?)") + // Create a new batch call + .batch( + // Define the first call + Call.of().bind("uuid", UUID.randomUUID(), AS_STRING).bind((String) null), + // Define the second call + Call.of().bind("uuid", UUID.randomUUID(), AS_STRING).bind((String) null)) + // Insert the data + .insert(); + + // Check that something changed + Assertions.assertTrue(change.changed()); + // Check that two rows were added + Assertions.assertEquals(2, change.rows()); + + // Check how many rows for each batch execution were changed + for (ManipulationResult result : change.results()) { + Assertions.assertEquals(1, result.rows()); + } + } + + @Test + public void exampleStream() { + // Insert multiple entries at the same time + ManipulationBatchResult change = query + // Define the query + .query("INSERT INTO users(uuid, name) VALUES(:uuid::uuid,?)") + // Create a new batch call + .batch(Stream.generate(UUID::randomUUID).limit(2).map(id -> Call.of().bind("uuid", id, AS_STRING).bind((String) null))) + // Insert the data + .insert(); + + // Check that something changed + Assertions.assertTrue(change.changed()); + // Check that two rows were added + Assertions.assertEquals(change.rows(), 2); + + // Check how many rows for each batch execution were changed + for (ManipulationResult result : change.results()) { + Assertions.assertEquals(result.rows(), 1); + } + } + + @Test + public void exampleSingle() { + // Insert multiple entries at the same time + ManipulationResult change = query + // Define the query + .query("INSERT INTO users(uuid, name) VALUES(:uuid::uuid,?)") + // Create a new call + .single(Call.of().bind("uuid", UUID.randomUUID(), UUIDAdapter.AS_STRING).bind("someone")) + // Insert the data + .insert(); + + // Check that something changed + Assertions.assertTrue(change.changed()); + // Check that two rows were added + Assertions.assertEquals(change.rows(), 1); + } +} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java new file mode 100644 index 00000000..3241b1a1 --- /dev/null +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java @@ -0,0 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.examples.dao; + +import de.chojo.sadu.mapper.rowmapper.RowMapping; + +import java.util.UUID; + +public record User(int id, UUID uuid, String name) { + public static RowMapping map() { + return row -> new User(row.getInt("id"), row.getUuidFromString("uuid"), row.getString("name")); + } +} diff --git a/sadu-queries2/src/test/resources/database/postgresql/1/setup.sql b/sadu-queries2/src/test/resources/database/postgresql/1/setup.sql new file mode 100644 index 00000000..46858074 --- /dev/null +++ b/sadu-queries2/src/test/resources/database/postgresql/1/setup.sql @@ -0,0 +1,16 @@ +create table users +( + id serial + constraint users_pk + primary key, + uuid uuid not null, + name text +); + +create table birthdays +( + user_id integer not null + constraint birthdays_pk + primary key, + birth_date date not null +); diff --git a/sadu-queries2/src/test/resources/database/version b/sadu-queries2/src/test/resources/database/version new file mode 100644 index 00000000..d3827e75 --- /dev/null +++ b/sadu-queries2/src/test/resources/database/version @@ -0,0 +1 @@ +1.0 diff --git a/sadu-sqlite/build.gradle.kts b/sadu-sqlite/build.gradle.kts index 336c1c91..863c4c68 100644 --- a/sadu-sqlite/build.gradle.kts +++ b/sadu-sqlite/build.gradle.kts @@ -2,4 +2,5 @@ description = "SADU module for interaction with a SqLite database" dependencies { api(project(":sadu-updater")) + api(project(":sadu-mapper")) } diff --git a/sadu-updater/build.gradle.kts b/sadu-updater/build.gradle.kts index 1af0dda1..bc8cee00 100644 --- a/sadu-updater/build.gradle.kts +++ b/sadu-updater/build.gradle.kts @@ -1,7 +1,7 @@ description = "SADU updater to setup and update your database using patch files." dependencies { - api(project(":sadu-queries")) + api(project(":sadu-core")) testImplementation(project(":sadu-postgresql")) } diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java index 74f284c9..104e67ad 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java @@ -6,10 +6,8 @@ package de.chojo.sadu.updater; -import de.chojo.sadu.base.QueryFactory; import de.chojo.sadu.databases.Database; import de.chojo.sadu.jdbc.JdbcConfig; -import de.chojo.sadu.wrapper.QueryBuilderConfig; import javax.annotation.CheckReturnValue; import javax.sql.DataSource; @@ -33,7 +31,6 @@ public class BaseSqlUpdaterBuilder, S extends BaseSqlUpd protected final Database type; protected String versionTable = "version"; protected QueryReplacement[] replacements = new QueryReplacement[0]; - protected QueryBuilderConfig config = QueryBuilderConfig.builder().throwExceptions().build(); protected ClassLoader classLoader = getClass().getClassLoader(); public BaseSqlUpdaterBuilder(Database type) { @@ -77,18 +74,6 @@ public S setReplacements(QueryReplacement... replacements) { return self(); } - /** - * Set the {@link QueryBuilderConfig} for the underlying {@link QueryFactory} - * - * @param config config so apply - * @return builder instance - */ - @CheckReturnValue - public S withConfig(QueryBuilderConfig config) { - this.config = config; - return self(); - } - public S preUpdateHook(SqlVersion version, Consumer consumer) { preUpdateHook.put(version, consumer); return self(); @@ -114,7 +99,7 @@ public S withClassLoader(ClassLoader classLoader) { */ public void execute() throws SQLException, IOException { if (version == null) version = SqlVersion.load(classLoader); - var sqlUpdater = new SqlUpdater<>(source, config, versionTable, replacements, version, type, preUpdateHook, postUpdateHook, classLoader); + var sqlUpdater = new SqlUpdater<>(source, versionTable, replacements, version, type, preUpdateHook, postUpdateHook, classLoader); sqlUpdater.init(); } diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java index afb55dfa..2a2a319f 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java @@ -6,10 +6,8 @@ package de.chojo.sadu.updater; -import de.chojo.sadu.base.QueryFactory; import de.chojo.sadu.databases.Database; import de.chojo.sadu.jdbc.JdbcConfig; -import de.chojo.sadu.wrapper.QueryBuilderConfig; import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +99,7 @@ * - 2/patch_1.sql * */ -public class SqlUpdater, U extends BaseSqlUpdaterBuilder> extends QueryFactory { +public class SqlUpdater, U extends BaseSqlUpdaterBuilder> { private static final Logger log = LoggerFactory.getLogger(SqlUpdater.class); private final SqlVersion version; private final Map> preUpdateHook; @@ -112,8 +110,7 @@ public class SqlUpdater, U extends BaseSqlUpdaterBuilder private final Database type; private final ClassLoader classLoader; - protected SqlUpdater(DataSource source, QueryBuilderConfig config, String versionTable, QueryReplacement[] replacements, SqlVersion version, Database type, Map> preUpdateHook, Map> postUpdateHook, ClassLoader classLoader) { - super(source, config); + protected SqlUpdater(DataSource source, String versionTable, QueryReplacement[] replacements, SqlVersion version, Database type, Map> preUpdateHook, Map> postUpdateHook, ClassLoader classLoader) { this.source = Objects.requireNonNull(source); this.versionTable = versionTable; this.replacements = replacements; @@ -348,6 +345,10 @@ private String adjust(String query) { return result; } + public DataSource source() { + return source; + } + protected Database type() { return type; } diff --git a/settings.gradle.kts b/settings.gradle.kts index e2592df2..fe2be8a4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ include("sadu-updater") include("sadu-mapper") include("sadu-examples") include("sadu-testing") +include("sadu-queries2") pluginManagement { repositories { From ca1061949789e6ec59bc99cb44de5df3b21d3979 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:10:03 +0100 Subject: [PATCH 08/29] Bump version to 1.5.0 --- build.gradle.kts | 2 +- .../java/de/chojo/sadu/mapper/DefaultMapper.java | 1 + .../sadu/mapper/rowmapper/PartialRowMapper.java | 2 +- .../de/chojo/sadu/mapper/rowmapper/RowMapper.java | 6 +++--- .../sadu/mapper/rowmapper/RowMapperBuilder.java | 4 ++-- .../de/chojo/sadu/queries/examples/ReadTest.java | 15 +++++++++++++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e84bbec9..b915bb6d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ plugins { publishData { useEldoNexusRepos(false) - publishingVersion = "1.4.1" + publishingVersion = "1.5.0" } group = "de.chojo.sadu" diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java index 7d50097a..57e47bc5 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java @@ -8,6 +8,7 @@ import de.chojo.sadu.exceptions.ThrowingBiFunction; import de.chojo.sadu.mapper.rowmapper.RowMapper; +import de.chojo.sadu.mapper.rowmapper.RowMapping; import de.chojo.sadu.mapper.util.Results; import de.chojo.sadu.types.SqlType; import de.chojo.sadu.wrapper.util.Row; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java index ca63972a..c63796ff 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java @@ -22,5 +22,5 @@ public interface PartialRowMapper { * @param mapper mapper * @return builder instance */ - RowMapperBuilder mapper(ThrowingFunction mapper); + RowMapperBuilder mapper(RowMapping mapper); } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java index 42811b84..014a0684 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java @@ -28,10 +28,10 @@ public class RowMapper implements RowMapping { private static final Logger log = getLogger(RowMapper.class); private final Class clazz; - private final ThrowingFunction mapper; + private final RowMapping mapper; private final Set columns; - RowMapper(Class clazz, ThrowingFunction mapper, Set columns) { + RowMapper(Class clazz, RowMapping mapper, Set columns) { this.clazz = clazz; this.mapper = mapper; this.columns = columns; @@ -51,7 +51,7 @@ public Set columns() { @Override public T map(Row row) throws SQLException { - return mapper.apply(row); + return mapper.map(row); } public boolean isWildcard() { diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java index 47c735d1..bd0c7ded 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java @@ -21,14 +21,14 @@ public class RowMapperBuilder implements PartialRowMapper { private final Class clazz; private final Set columns = new HashSet<>(); - private ThrowingFunction mapper; + private RowMapping mapper; RowMapperBuilder(Class clazz) { this.clazz = clazz; } @Override - public RowMapperBuilder mapper(ThrowingFunction mapper) { + public RowMapperBuilder mapper(RowMapping mapper) { this.mapper = mapper; return this; } diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java index 4180e71e..c19e6993 100644 --- a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java +++ b/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java @@ -9,6 +9,7 @@ import de.chojo.sadu.PostgresDatabase; import de.chojo.sadu.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.mapper.rowmapper.RowMapper; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.call.calls.Calls; import de.chojo.sadu.queries.api.results.reading.Result; @@ -42,7 +43,8 @@ public class ReadTest { @BeforeEach void before() throws IOException, SQLException { db = createContainer("postgres", "postgres"); - query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())).build(); + query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper()) + .register(RowMapper.forClass(User.class).mapper(User.map()).build())).build(); query.query("INSERT INTO users(uuid, name) VALUES (?::uuid,?)") .batch(Call.of().bind(UUID.randomUUID(), AS_STRING).bind("Lilly"), Call.of().bind(UUID.randomUUID(), AS_STRING).bind("Chojo")) @@ -58,12 +60,21 @@ void after() { @Test public void retrieveAllDirectly() { List users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") - .single(Call.of().bind(1).bind("name", "lilly")) + .single(call().bind(1).bind("name", "lilly")) .map(User.map()) .allAndGet(); Assertions.assertEquals(1, users.size()); } + @Test + public void mapViaRegistry() { + List users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") + .single(call().bind(1).bind("name", "lilly")) + .mapAs(User.class) + .allAndGet(); + Assertions.assertEquals(1, users.size()); + } + @Test public void retrieveAllDirectlyNoFilter() { List users = query.query("SELECT * FROM users") From 16a68fdcee999439a88618fbf344e9a363960ade Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:20:28 +0100 Subject: [PATCH 09/29] Fix compile error --- .../src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java | 2 +- .../de/chojo/sadu/queries/api/storage/ResultStorage.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java index 3f02e51b..0723e9f8 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java @@ -158,7 +158,7 @@ public ResultStage parameter(ThrowingConsumer par @Override public RetrievalStage readRow(ThrowingFunction mapper) { Objects.requireNonNull(clazz); - currRowMapper = RowMapper.forClass(clazz).mapper(mapper).build(); + currRowMapper = RowMapper.forClass(clazz).mapper(mapper::apply).build(); queueTask(); return this; } diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java index bc773a4c..e7143980 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java +++ b/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java @@ -1,3 +1,9 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + package de.chojo.sadu.queries.api.storage; import java.util.List; From 9825e6c04557a95313a0264717a82171abdb7f7f Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:39:46 +0100 Subject: [PATCH 10/29] Migrate to 2.0.0 (#162) --- README.md | 17 +- build.gradle.kts | 3 +- sadu-core/build.gradle.kts | 1 - .../{ => core}/base/DataSourceProvider.java | 2 +- .../{ => core}/conversion/ArrayConverter.java | 4 +- .../{ => core}/conversion/UUIDConverter.java | 2 +- .../sadu/{ => core}/databases/Database.java | 10 +- .../{ => core}/databases/DefaultDatabase.java | 6 +- .../exceptions/NotImplementedException.java | 2 +- .../exceptions/NotSupportedException.java | 2 +- .../exceptions/ExceptionTransformer.java | 2 +- .../exceptions/ThrowingBiConsumer.java | 2 +- .../exceptions/ThrowingBiFunction.java | 2 +- .../exceptions/ThrowingConsumer.java | 2 +- .../exceptions/ThrowingFunction.java | 2 +- .../sadu/{ => core}/jdbc/JdbProperty.java | 2 +- .../sadu/{ => core}/jdbc/JdbcConfig.java | 2 +- .../{ => core}/jdbc/RemoteJdbcConfig.java | 2 +- .../chojo/sadu/{ => core}/types/SqlType.java | 2 +- .../sadu/{ => core}/updater/SqlVersion.java | 2 +- .../{ => core}/updater/StatementSplitter.java | 2 +- .../{ => core}/updater/UpdaterBuilder.java | 4 +- sadu-core/src/main/java/module-info.java | 21 +- .../sadu/conversion/UUIDConverterTest.java | 1 + .../chojo/sadu/jdbc/RemoteJdbcConfigTest.java | 1 + .../de/chojo/sadu/updater/SqlVersionTest.java | 1 + .../sadu/updater/StatementSplitterTest.java | 1 + .../sadu/datasource/DataSourceCreator.java | 12 +- .../datasource/stage/ConfigurationStage.java | 2 +- .../sadu/datasource/stage/JdbcStage.java | 3 +- .../src/main/java/module-info.java | 7 + .../datasource/DataSourceCreatorTest.java | 4 +- .../sadu/examples/datasource/Create.java | 2 +- .../sadu/examples/querybuilder/MyQueries.java | 135 -- .../querybuilder/QueryBuilderExample.java | 51 - .../de/chojo/sadu/mapper/DefaultMapper.java | 5 +- .../mapper/rowmapper/PartialRowMapper.java | 5 - .../sadu/mapper/rowmapper/RowMapper.java | 1 - .../mapper/rowmapper/RowMapperBuilder.java | 4 - .../sadu/mapper/rowmapper/RowMapping.java | 2 +- .../de/chojo/sadu/mapper/util/Results.java | 2 +- .../java/de/chojo/sadu/wrapper/util/Row.java | 4 +- sadu-mapper/src/main/java/module-info.java | 3 - .../sadu/{ => mariadb}/databases/MariaDb.java | 9 +- .../sadu/{ => mariadb}/jdbc/MariaDbJdbc.java | 6 +- .../{ => mariadb}/mapper/MariaDbMapper.java | 45 +- .../{ => mariadb}/types/MariaDbTypes.java | 6 +- sadu-mariadb/src/main/java/module-info.java | 9 + .../de/chojo/sadu/jdbc/MariaDbJdbcTest.java | 3 +- .../chojo/sadu/mapper/MariaDbMapperTest.java | 28 +- .../sadu/{ => mysql}/databases/MySql.java | 9 +- .../sadu/{ => mysql}/jdbc/MySQLJdbc.java | 4 +- .../sadu/{ => mysql}/mapper/MySqlMapper.java | 40 +- .../sadu/{ => mysql}/types/MySqlTypes.java | 6 +- sadu-mysql/src/main/java/module-info.java | 9 + .../de/chojo/sadu/jdbc/MySQLJdbcTest.java | 3 +- .../databases/PostgreSql.java | 7 +- .../{ => postgresql}/jdbc/PostgreSqlJdbc.java | 4 +- .../mapper/PostgresqlMapper.java | 37 +- .../types/PostgreSqlTypes.java | 6 +- .../update/PostgreSqlUpdater.java | 8 +- .../update/PostgreSqlUpdaterBuilder.java | 10 +- .../src/main/java/module-info.java | 10 + .../chojo/sadu/jdbc/PostgreSqlJdbcTest.java | 2 +- .../sadu/mapper/PostgresqlMapperTest.java | 24 +- sadu-queries/build.gradle.kts | 12 +- .../sadu/adapter/StaticQueryAdapter.java | 94 -- .../java/de/chojo/sadu/base/DataHolder.java | 86 -- .../java/de/chojo/sadu/base/QueryFactory.java | 107 -- .../queries/api/base/ConnectionProvider.java | 4 +- .../sadu/queries/api/base/QueryProvider.java | 4 +- .../sadu/queries/api/base/package-info.java | 0 .../de/chojo/sadu/queries/api/call/Call.java | 2 +- .../queries/api/call/adapter/Adapter.java | 0 .../api/call/adapter/AdapterMapping.java | 0 .../api/call/adapter/package-info.java | 0 .../sadu/queries/api/call/calls/Calls.java | 0 .../queries/api/call/calls/package-info.java | 0 .../sadu/queries/api/call/package-info.java | 0 .../queries/api/execution/package-info.java | 0 .../queries/api/execution/reading/Reader.java | 12 +- .../api/execution/reading/package-info.java | 0 .../execution/writing/CalledBatchQuery.java | 0 .../writing/CalledSingletonQuery.java | 0 .../api/execution/writing/package-info.java | 0 .../queries/api/parameter/BaseParameter.java | 0 .../queries/api/parameter/package-info.java | 0 .../sadu/queries/api/query/AppendedQuery.java | 0 .../sadu/queries/api/query/ParsedQuery.java | 0 .../chojo/sadu/queries/api/query/Query.java | 0 .../sadu/queries/api/query/package-info.java | 0 .../queries/api/results/package-info.java | 0 .../queries/api/results/reading/Result.java | 6 + .../api/results/reading/package-info.java | 0 .../writing/ManipulationBatchResult.java | 0 .../results/writing/ManipulationResult.java | 0 .../api/results/writing/package-info.java | 0 .../queries/api/storage/ResultStorage.java | 0 .../queries/api/storage/package-info.java | 0 .../de/chojo/sadu/queries/call/CallImpl.java | 135 +- .../queries/call/adapter/StandardAdapter.java | 76 + .../queries/call/adapter/UUIDAdapter.java | 2 +- .../queries/call/adapter/package-info.java | 0 .../chojo/sadu/queries/call/package-info.java | 0 .../chojo/sadu/queries/calls/BatchCall.java | 0 .../sadu/queries/calls/CallSupplier.java | 0 .../sadu/queries/calls/SingletonCall.java | 0 .../sadu/queries/calls/package-info.java | 0 .../ConnectedQueryConfiguration.java | 0 .../configuration/QueryConfiguration.java | 0 .../QueryConfigurationBuilder.java | 2 +- .../queries/configuration/package-info.java | 0 .../exception/QueryExecutionException.java | 0 .../WrappedQueryExecutionException.java | 0 .../sadu/queries/exception/package-info.java | 0 .../queries/parameter/IndexParameter.java | 2 +- .../queries/parameter/TokenParameter.java | 2 +- .../sadu/queries/parameter/package-info.java | 0 .../sadu/queries/query/AppendedQueryImpl.java | 0 .../sadu/queries/query/ParsedQueryImpl.java | 0 .../chojo/sadu/queries/query/QueryImpl.java | 4 +- .../sadu/queries/query/TokenizedQuery.java | 0 .../sadu/queries/query/package-info.java | 0 .../stages/execution/package-info.java | 0 .../execution/reading/AutoMappedQuery.java | 0 .../stages/execution/reading/MappedQuery.java | 0 .../stages/execution/reading/ReaderImpl.java | 12 +- .../execution/reading/package-info.java | 0 .../writing/CalledBatchQueryImpl.java | 0 .../writing/CalledSingletonQueryImpl.java | 0 .../execution/writing/package-info.java | 0 .../sadu/queries/stages/package-info.java | 0 .../queries/stages/results/package-info.java | 0 .../stages/results/reading/MultiResult.java | 2 +- .../stages/results/reading/SingleResult.java | 2 +- .../stages/results/reading/package-info.java | 0 .../writing/ManipulationBatchQuery.java | 0 .../writing/ManipulationResultImpl.java | 0 .../stages/results/writing/package-info.java | 0 .../queries/storage/ResultStorageImpl.java | 0 .../sadu/queries/storage/package-info.java | 0 .../de/chojo/sadu/wrapper/QueryBuilder.java | 481 ------ .../sadu/wrapper/QueryBuilderConfig.java | 240 --- .../exception/QueryExecutionException.java | 54 - .../WrappedQueryExecutionException.java | 64 - .../wrapper/stage/ConfigurationStage.java | 70 - .../chojo/sadu/wrapper/stage/InsertStage.java | 80 - .../chojo/sadu/wrapper/stage/QueryStage.java | 68 - .../chojo/sadu/wrapper/stage/ResultStage.java | 116 -- .../sadu/wrapper/stage/RetrievalStage.java | 85 -- .../sadu/wrapper/stage/StatementStage.java | 77 - .../chojo/sadu/wrapper/stage/UpdateStage.java | 75 - .../chojo/sadu/wrapper/util/ParamBuilder.java | 1303 ----------------- .../chojo/sadu/wrapper/util/UpdateResult.java | 44 - .../src/main/java/module-info.java | 3 +- .../java/de/chojo/sadu/MariaDbDatabase.java | 22 - .../java/de/chojo/sadu/PostgresDatabase.java | 2 +- .../sadu/queries/TokenizedQueryTest.java | 0 .../chojo/sadu/queries/examples/ReadTest.java | 12 +- .../queries/examples/TransactionTest.java | 4 +- .../sadu/queries/examples/WriteTest.java | 2 +- .../chojo/sadu/queries/examples/dao/User.java | 0 .../chojo/sadu/wrapper/QueryBuilderTest.java | 97 -- .../de/chojo/sadu/wrapper/mapper/Mapper.java | 31 - .../chojo/sadu/wrapper/mapper/MetaResult.java | 93 -- .../de/chojo/sadu/wrapper/mapper/Result.java | 41 - .../wrapper/mapper/RowMapperRegistryTest.java | 55 - .../sadu/wrapper/mapper/RowMapperTest.java | 122 -- .../resources/database/postgresql/1/setup.sql | 0 .../src/test/resources/database/version | 0 sadu-queries2/build.gradle.kts | 11 - .../queries/call/adapter/StandardAdapter.java | 76 - .../sadu/{ => sqlite}/databases/SqLite.java | 9 +- .../sadu/{ => sqlite}/jdbc/SqLiteJdbc.java | 4 +- .../{ => sqlite}/mapper/SqLiteMapper.java | 4 +- .../sadu/{ => sqlite}/types/SqLiteTypes.java | 6 +- sadu-sqlite/src/main/java/module-info.java | 9 + .../{tests => testing}/DatabaseChecks.java | 4 +- .../DatabaseVersionChecks.java | 4 +- .../sadu/{tests => testing}/PatchChecks.java | 8 +- .../{tests => testing}/ResourceChecks.java | 4 +- .../sadu/{tests => testing}/SaduTests.java | 4 +- .../sadu/{tests => testing}/TestUtil.java | 2 +- .../de/chojo/sadu/testing/package-info.java | 8 + .../de/chojo/sadu/tests/package-info.java | 6 - sadu-testing/src/main/java/module-info.java | 6 + .../DatabaseChecksTest.java | 2 +- .../DatabaseVersionChecksTest.java | 2 +- .../{tests => testing}/PatchChecksTest.java | 4 +- .../sadu/updater/BaseSqlUpdaterBuilder.java | 8 +- .../java/de/chojo/sadu/updater/Patch.java | 2 + .../de/chojo/sadu/updater/SqlUpdater.java | 9 +- sadu-updater/src/main/java/module-info.java | 5 + .../de/chojo/sadu/updater/SqlUpdaterTest.java | 2 +- settings.gradle.kts | 1 - 195 files changed, 460 insertions(+), 4174 deletions(-) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/base/DataSourceProvider.java (91%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/conversion/ArrayConverter.java (99%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/conversion/UUIDConverter.java (96%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/databases/Database.java (94%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/databases/DefaultDatabase.java (87%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/databases/exceptions/NotImplementedException.java (87%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/databases/exceptions/NotSupportedException.java (87%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/exceptions/ExceptionTransformer.java (96%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/exceptions/ThrowingBiConsumer.java (95%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/exceptions/ThrowingBiFunction.java (94%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/exceptions/ThrowingConsumer.java (95%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/exceptions/ThrowingFunction.java (94%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/jdbc/JdbProperty.java (97%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/jdbc/JdbcConfig.java (99%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/jdbc/RemoteJdbcConfig.java (99%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/types/SqlType.java (96%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/updater/SqlVersion.java (98%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/updater/StatementSplitter.java (99%) rename sadu-core/src/main/java/de/chojo/sadu/{ => core}/updater/UpdaterBuilder.java (90%) create mode 100644 sadu-datasource/src/main/java/module-info.java delete mode 100644 sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/MyQueries.java delete mode 100644 sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/QueryBuilderExample.java rename sadu-mariadb/src/main/java/de/chojo/sadu/{ => mariadb}/databases/MariaDb.java (82%) rename sadu-mariadb/src/main/java/de/chojo/sadu/{ => mariadb}/jdbc/MariaDbJdbc.java (98%) rename sadu-mariadb/src/main/java/de/chojo/sadu/{ => mariadb}/mapper/MariaDbMapper.java (53%) rename sadu-mariadb/src/main/java/de/chojo/sadu/{ => mariadb}/types/MariaDbTypes.java (94%) create mode 100644 sadu-mariadb/src/main/java/module-info.java rename sadu-mysql/src/main/java/de/chojo/sadu/{ => mysql}/databases/MySql.java (82%) rename sadu-mysql/src/main/java/de/chojo/sadu/{ => mysql}/jdbc/MySQLJdbc.java (92%) rename sadu-mysql/src/main/java/de/chojo/sadu/{ => mysql}/mapper/MySqlMapper.java (50%) rename sadu-mysql/src/main/java/de/chojo/sadu/{ => mysql}/types/MySqlTypes.java (94%) create mode 100644 sadu-mysql/src/main/java/module-info.java rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/databases/PostgreSql.java (88%) rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/jdbc/PostgreSqlJdbc.java (98%) rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/mapper/PostgresqlMapper.java (61%) rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/types/PostgreSqlTypes.java (92%) rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/update/PostgreSqlUpdater.java (92%) rename sadu-postgresql/src/main/java/de/chojo/sadu/{ => postgresql}/update/PostgreSqlUpdaterBuilder.java (84%) create mode 100644 sadu-postgresql/src/main/java/module-info.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/adapter/StaticQueryAdapter.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/base/DataHolder.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/base/QueryFactory.java rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java (80%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java (89%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/base/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/Call.java (98%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/call/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java (89%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/query/Query.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/query/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java (81%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/call/CallImpl.java (62%) create mode 100644 sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/call/adapter/UUIDAdapter.java (96%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/call/adapter/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/call/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/calls/CallSupplier.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/calls/SingletonCall.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/calls/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/configuration/QueryConfigurationBuilder.java (98%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/configuration/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/exception/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/parameter/IndexParameter.java (93%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/parameter/TokenParameter.java (94%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/parameter/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/query/AppendedQueryImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/query/QueryImpl.java (95%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/query/TokenizedQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/query/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java (92%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java (94%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java (94%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/storage/ResultStorageImpl.java (100%) rename {sadu-queries2 => sadu-queries}/src/main/java/de/chojo/sadu/queries/storage/package-info.java (100%) delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilder.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilderConfig.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/QueryExecutionException.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/WrappedQueryExecutionException.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ConfigurationStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/InsertStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/QueryStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ResultStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/RetrievalStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/StatementStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/UpdateStage.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/ParamBuilder.java delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/UpdateResult.java rename {sadu-queries2 => sadu-queries}/src/main/java/module-info.java (95%) delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/MariaDbDatabase.java rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/PostgresDatabase.java (96%) rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java (100%) rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java (96%) rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java (97%) rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java (98%) rename {sadu-queries2 => sadu-queries}/src/test/java/de/chojo/sadu/queries/examples/dao/User.java (100%) delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/QueryBuilderTest.java delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Mapper.java delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/MetaResult.java delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Result.java delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperRegistryTest.java delete mode 100644 sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperTest.java rename {sadu-queries2 => sadu-queries}/src/test/resources/database/postgresql/1/setup.sql (100%) rename {sadu-queries2 => sadu-queries}/src/test/resources/database/version (100%) delete mode 100644 sadu-queries2/build.gradle.kts delete mode 100644 sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java rename sadu-sqlite/src/main/java/de/chojo/sadu/{ => sqlite}/databases/SqLite.java (84%) rename sadu-sqlite/src/main/java/de/chojo/sadu/{ => sqlite}/jdbc/SqLiteJdbc.java (95%) rename sadu-sqlite/src/main/java/de/chojo/sadu/{ => sqlite}/mapper/SqLiteMapper.java (95%) rename sadu-sqlite/src/main/java/de/chojo/sadu/{ => sqlite}/types/SqLiteTypes.java (83%) create mode 100644 sadu-sqlite/src/main/java/module-info.java rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/DatabaseChecks.java (94%) rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/DatabaseVersionChecks.java (95%) rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/PatchChecks.java (96%) rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/ResourceChecks.java (92%) rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/SaduTests.java (89%) rename sadu-testing/src/main/java/de/chojo/sadu/{tests => testing}/TestUtil.java (98%) create mode 100644 sadu-testing/src/main/java/de/chojo/sadu/testing/package-info.java delete mode 100644 sadu-testing/src/main/java/de/chojo/sadu/tests/package-info.java create mode 100644 sadu-testing/src/main/java/module-info.java rename sadu-testing/src/test/java/de/chojo/sadu/{tests => testing}/DatabaseChecksTest.java (94%) rename sadu-testing/src/test/java/de/chojo/sadu/{tests => testing}/DatabaseVersionChecksTest.java (96%) rename sadu-testing/src/test/java/de/chojo/sadu/{tests => testing}/PatchChecksTest.java (87%) create mode 100644 sadu-updater/src/main/java/module-info.java diff --git a/README.md b/README.md index b31e8dca..549b44d5 100644 --- a/README.md +++ b/README.md @@ -72,16 +72,11 @@ class MyQueries { But using the query builder your code becomes this: ```java -class MyQueries extends QueryFactory { - MyQueries(DataSource dataSource){ - super(dataSource); - } - - public CompletableFuture> getResultNew(int id) { - return builder(Result.class) - .query("SELECT result FROM results WHERE id = ?") - .parameters(stmt -> stmt.setInt(id)) - .readRow(rs -> new Result(rs.getString("result"))) +class MyQueries { + public Optional getResultNew(int id) { + return Query.query("SELECT result FROM results WHERE id = ?") + .single(Call.of().setInt(id)) + .map(row -> new Result(rs.getString("result"))) .first(); } } @@ -107,7 +102,7 @@ SADU offers a simple sql updater which deploys upgrade and migration scripts to to use it import: `sadu-updater` -Learn how to use it [here](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Updater) +Learn how to use it [here](https://sadu.docs.chojo.dev/queries/) [nexus_releases]: https://search.maven.org/search?q=de.chojo.sadu diff --git a/build.gradle.kts b/build.gradle.kts index b915bb6d..0a79c89f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ plugins { publishData { useEldoNexusRepos(false) - publishingVersion = "1.5.0" + publishingVersion = "2.0.0" } group = "de.chojo.sadu" @@ -157,7 +157,6 @@ allprojects { fun applyJavaDocOptions(options: MinimalJavadocOptions) { val javaDocOptions = options as StandardJavadocDocletOptions javaDocOptions.links( - "https://javadoc.io/doc/com.google.code.findbugs/jsr305/latest/", "https://javadoc.io/doc/org.jetbrains/annotations/latest/", "https://docs.oracle.com/en/java/javase/${java.toolchain.languageVersion.get().asInt()}/docs/api/" ) diff --git a/sadu-core/build.gradle.kts b/sadu-core/build.gradle.kts index 5ba4d246..9c6221bb 100644 --- a/sadu-core/build.gradle.kts +++ b/sadu-core/build.gradle.kts @@ -3,5 +3,4 @@ description = "SADU core module, containing common logic between modules." dependencies { api(libs.slf4j.api) api("org.jetbrains", "annotations", "24.1.0") - api("com.google.code.findbugs", "jsr305", "3.0.2") } diff --git a/sadu-core/src/main/java/de/chojo/sadu/base/DataSourceProvider.java b/sadu-core/src/main/java/de/chojo/sadu/core/base/DataSourceProvider.java similarity index 91% rename from sadu-core/src/main/java/de/chojo/sadu/base/DataSourceProvider.java rename to sadu-core/src/main/java/de/chojo/sadu/core/base/DataSourceProvider.java index fcbea015..a7a6f6f9 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/base/DataSourceProvider.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/base/DataSourceProvider.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.base; +package de.chojo.sadu.core.base; import javax.sql.DataSource; diff --git a/sadu-core/src/main/java/de/chojo/sadu/conversion/ArrayConverter.java b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/ArrayConverter.java similarity index 99% rename from sadu-core/src/main/java/de/chojo/sadu/conversion/ArrayConverter.java rename to sadu-core/src/main/java/de/chojo/sadu/core/conversion/ArrayConverter.java index b0dac35f..d52efa55 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/conversion/ArrayConverter.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/ArrayConverter.java @@ -4,9 +4,9 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.conversion; +package de.chojo.sadu.core.conversion; -import de.chojo.sadu.types.SqlType; +import de.chojo.sadu.core.types.SqlType; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/sadu-core/src/main/java/de/chojo/sadu/conversion/UUIDConverter.java b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/UUIDConverter.java similarity index 96% rename from sadu-core/src/main/java/de/chojo/sadu/conversion/UUIDConverter.java rename to sadu-core/src/main/java/de/chojo/sadu/core/conversion/UUIDConverter.java index 473325e2..2180b8de 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/conversion/UUIDConverter.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/UUIDConverter.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.conversion; +package de.chojo.sadu.core.conversion; import java.nio.ByteBuffer; import java.util.UUID; diff --git a/sadu-core/src/main/java/de/chojo/sadu/databases/Database.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java similarity index 94% rename from sadu-core/src/main/java/de/chojo/sadu/databases/Database.java rename to sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java index 528fcb34..7026248e 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/databases/Database.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java @@ -4,12 +4,12 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases; +package de.chojo.sadu.core.databases; -import de.chojo.sadu.updater.UpdaterBuilder; -import de.chojo.sadu.databases.exceptions.NotImplementedException; -import de.chojo.sadu.databases.exceptions.NotSupportedException; -import de.chojo.sadu.jdbc.JdbcConfig; +import de.chojo.sadu.core.databases.exceptions.NotImplementedException; +import de.chojo.sadu.core.databases.exceptions.NotSupportedException; +import de.chojo.sadu.core.jdbc.JdbcConfig; +import de.chojo.sadu.core.updater.UpdaterBuilder; import org.jetbrains.annotations.ApiStatus; import java.util.Arrays; diff --git a/sadu-core/src/main/java/de/chojo/sadu/databases/DefaultDatabase.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java similarity index 87% rename from sadu-core/src/main/java/de/chojo/sadu/databases/DefaultDatabase.java rename to sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java index d889a979..44f4a755 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/databases/DefaultDatabase.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java @@ -4,10 +4,10 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases; +package de.chojo.sadu.core.databases; -import de.chojo.sadu.updater.UpdaterBuilder; -import de.chojo.sadu.jdbc.JdbcConfig; +import de.chojo.sadu.core.jdbc.JdbcConfig; +import de.chojo.sadu.core.updater.UpdaterBuilder; /** * Represents a default database diff --git a/sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotImplementedException.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java similarity index 87% rename from sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotImplementedException.java rename to sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java index 28fcc7cf..48edea51 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotImplementedException.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases.exceptions; +package de.chojo.sadu.core.databases.exceptions; /** * Thrown when a method is called which is not implemented but supported by this type. diff --git a/sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotSupportedException.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java similarity index 87% rename from sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotSupportedException.java rename to sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java index 38662433..9761b450 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/databases/exceptions/NotSupportedException.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases.exceptions; +package de.chojo.sadu.core.databases.exceptions; /** * Thrown when a method is called which is not supported by this type. diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ExceptionTransformer.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ExceptionTransformer.java similarity index 96% rename from sadu-core/src/main/java/de/chojo/sadu/exceptions/ExceptionTransformer.java rename to sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ExceptionTransformer.java index a075cb48..041ec356 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ExceptionTransformer.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ExceptionTransformer.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.exceptions; +package de.chojo.sadu.core.exceptions; import java.sql.SQLException; diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiConsumer.java similarity index 95% rename from sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java rename to sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiConsumer.java index c8541b38..c8d014b7 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiConsumer.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiConsumer.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.exceptions; +package de.chojo.sadu.core.exceptions; /** * Represents an operation that accepts a single input argument and returns no diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiFunction.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiFunction.java similarity index 94% rename from sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiFunction.java rename to sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiFunction.java index 4f021175..1525ce4d 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingBiFunction.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingBiFunction.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.exceptions; +package de.chojo.sadu.core.exceptions; /** * Represents a function which can throw an exception. diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingConsumer.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingConsumer.java similarity index 95% rename from sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingConsumer.java rename to sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingConsumer.java index 542828b1..b2e29bde 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingConsumer.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingConsumer.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.exceptions; +package de.chojo.sadu.core.exceptions; /** * Represents an operation that accepts a single input argument and returns no diff --git a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingFunction.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingFunction.java similarity index 94% rename from sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingFunction.java rename to sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingFunction.java index f35ada70..5bcb51c2 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/exceptions/ThrowingFunction.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/ThrowingFunction.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.exceptions; +package de.chojo.sadu.core.exceptions; /** * Represents a function which can throw an exception. diff --git a/sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbProperty.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java similarity index 97% rename from sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbProperty.java rename to sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java index 4f3e19ba..8aa5b010 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbProperty.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.core.jdbc; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; diff --git a/sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbcConfig.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java similarity index 99% rename from sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbcConfig.java rename to sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java index 9858d776..0ccb0644 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/jdbc/JdbcConfig.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.core.jdbc; import org.jetbrains.annotations.NotNull; diff --git a/sadu-core/src/main/java/de/chojo/sadu/jdbc/RemoteJdbcConfig.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java similarity index 99% rename from sadu-core/src/main/java/de/chojo/sadu/jdbc/RemoteJdbcConfig.java rename to sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java index 0a6d927f..98939544 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/jdbc/RemoteJdbcConfig.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.core.jdbc; import org.jetbrains.annotations.ApiStatus; diff --git a/sadu-core/src/main/java/de/chojo/sadu/types/SqlType.java b/sadu-core/src/main/java/de/chojo/sadu/core/types/SqlType.java similarity index 96% rename from sadu-core/src/main/java/de/chojo/sadu/types/SqlType.java rename to sadu-core/src/main/java/de/chojo/sadu/core/types/SqlType.java index 47956dd9..25409249 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/types/SqlType.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/types/SqlType.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.types; +package de.chojo.sadu.core.types; /** * Represents a named data type in a database. diff --git a/sadu-core/src/main/java/de/chojo/sadu/updater/SqlVersion.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java similarity index 98% rename from sadu-core/src/main/java/de/chojo/sadu/updater/SqlVersion.java rename to sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java index a3e2ccf4..cb77e322 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/updater/SqlVersion.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.updater; +package de.chojo.sadu.core.updater; import org.jetbrains.annotations.NotNull; diff --git a/sadu-core/src/main/java/de/chojo/sadu/updater/StatementSplitter.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java similarity index 99% rename from sadu-core/src/main/java/de/chojo/sadu/updater/StatementSplitter.java rename to sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java index 5bb42d7a..f0fecc67 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/updater/StatementSplitter.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.updater; +package de.chojo.sadu.core.updater; import org.intellij.lang.annotations.RegExp; diff --git a/sadu-core/src/main/java/de/chojo/sadu/updater/UpdaterBuilder.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java similarity index 90% rename from sadu-core/src/main/java/de/chojo/sadu/updater/UpdaterBuilder.java rename to sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java index 73652d29..ea59dd28 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/updater/UpdaterBuilder.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java @@ -4,9 +4,9 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.updater; +package de.chojo.sadu.core.updater; -import de.chojo.sadu.jdbc.JdbcConfig; +import de.chojo.sadu.core.jdbc.JdbcConfig; import org.jetbrains.annotations.ApiStatus; import javax.sql.DataSource; diff --git a/sadu-core/src/main/java/module-info.java b/sadu-core/src/main/java/module-info.java index 12e12d60..18903d67 100644 --- a/sadu-core/src/main/java/module-info.java +++ b/sadu-core/src/main/java/module-info.java @@ -1,13 +1,14 @@ module sadu.sadu.core.main { - requires java.sql; - requires org.jetbrains.annotations; + requires transitive java.sql; + requires transitive org.jetbrains.annotations; + requires transitive org.slf4j; - exports de.chojo.sadu.base; - exports de.chojo.sadu.conversion; - exports de.chojo.sadu.databases; - exports de.chojo.sadu.databases.exceptions; - exports de.chojo.sadu.exceptions; - exports de.chojo.sadu.jdbc; - exports de.chojo.sadu.types; - exports de.chojo.sadu.updater; + exports de.chojo.sadu.core.base; + exports de.chojo.sadu.core.conversion; + exports de.chojo.sadu.core.databases; + exports de.chojo.sadu.core.databases.exceptions; + exports de.chojo.sadu.core.exceptions; + exports de.chojo.sadu.core.jdbc; + exports de.chojo.sadu.core.types; + exports de.chojo.sadu.core.updater; } diff --git a/sadu-core/src/test/java/de/chojo/sadu/conversion/UUIDConverterTest.java b/sadu-core/src/test/java/de/chojo/sadu/conversion/UUIDConverterTest.java index a7a81a72..4187a018 100644 --- a/sadu-core/src/test/java/de/chojo/sadu/conversion/UUIDConverterTest.java +++ b/sadu-core/src/test/java/de/chojo/sadu/conversion/UUIDConverterTest.java @@ -6,6 +6,7 @@ package de.chojo.sadu.conversion; +import de.chojo.sadu.core.conversion.UUIDConverter; import org.junit.jupiter.api.Test; import java.util.UUID; diff --git a/sadu-core/src/test/java/de/chojo/sadu/jdbc/RemoteJdbcConfigTest.java b/sadu-core/src/test/java/de/chojo/sadu/jdbc/RemoteJdbcConfigTest.java index a53a2f77..bc8ecd00 100644 --- a/sadu-core/src/test/java/de/chojo/sadu/jdbc/RemoteJdbcConfigTest.java +++ b/sadu-core/src/test/java/de/chojo/sadu/jdbc/RemoteJdbcConfigTest.java @@ -6,6 +6,7 @@ package de.chojo.sadu.jdbc; +import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/sadu-core/src/test/java/de/chojo/sadu/updater/SqlVersionTest.java b/sadu-core/src/test/java/de/chojo/sadu/updater/SqlVersionTest.java index 356ddf60..40659d2a 100644 --- a/sadu-core/src/test/java/de/chojo/sadu/updater/SqlVersionTest.java +++ b/sadu-core/src/test/java/de/chojo/sadu/updater/SqlVersionTest.java @@ -6,6 +6,7 @@ package de.chojo.sadu.updater; +import de.chojo.sadu.core.updater.SqlVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/sadu-core/src/test/java/de/chojo/sadu/updater/StatementSplitterTest.java b/sadu-core/src/test/java/de/chojo/sadu/updater/StatementSplitterTest.java index 8f268fd5..741e5de8 100644 --- a/sadu-core/src/test/java/de/chojo/sadu/updater/StatementSplitterTest.java +++ b/sadu-core/src/test/java/de/chojo/sadu/updater/StatementSplitterTest.java @@ -6,6 +6,7 @@ package de.chojo.sadu.updater; +import de.chojo.sadu.core.updater.StatementSplitter; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java index 357793d1..f14a453e 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java @@ -8,18 +8,16 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import de.chojo.sadu.databases.Database; +import de.chojo.sadu.core.databases.Database; import de.chojo.sadu.datasource.stage.ConfigurationStage; import de.chojo.sadu.datasource.stage.JdbcStage; -import de.chojo.sadu.jdbc.JdbProperty; -import de.chojo.sadu.jdbc.JdbcConfig; -import de.chojo.sadu.jdbc.RemoteJdbcConfig; +import de.chojo.sadu.core.jdbc.JdbcConfig; +import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; +import org.jetbrains.annotations.CheckReturnValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.CheckReturnValue; import javax.sql.DataSource; -import java.util.Optional; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.function.Consumer; @@ -45,7 +43,7 @@ private DataSourceCreator(Database type) { * @param database type defined by the {@link Database} * @return a DataSourceCreator in {@link JdbcStage}. */ - @CheckReturnValue + @org.jetbrains.annotations.CheckReturnValue public static > JdbcStage create(Database type) { return new DataSourceCreator<>(type); } diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java index c2febb04..6398c0d8 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java @@ -8,8 +8,8 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import org.jetbrains.annotations.CheckReturnValue; -import javax.annotation.CheckReturnValue; import javax.sql.DataSource; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/JdbcStage.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/JdbcStage.java index 63c707a4..a61a0649 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/JdbcStage.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/JdbcStage.java @@ -6,7 +6,8 @@ package de.chojo.sadu.datasource.stage; -import javax.annotation.CheckReturnValue; +import org.jetbrains.annotations.CheckReturnValue; + import java.util.function.Consumer; /** diff --git a/sadu-datasource/src/main/java/module-info.java b/sadu-datasource/src/main/java/module-info.java new file mode 100644 index 00000000..9b599f3f --- /dev/null +++ b/sadu-datasource/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module sadu.sadu.datasource.main { + requires transitive sadu.sadu.core.main; + requires transitive com.zaxxer.hikari; + + exports de.chojo.sadu.datasource.stage; + exports de.chojo.sadu.datasource; +} diff --git a/sadu-datasource/src/test/java/de/chojo/sadu/datasource/DataSourceCreatorTest.java b/sadu-datasource/src/test/java/de/chojo/sadu/datasource/DataSourceCreatorTest.java index bd2b718a..c0f5c29b 100644 --- a/sadu-datasource/src/test/java/de/chojo/sadu/datasource/DataSourceCreatorTest.java +++ b/sadu-datasource/src/test/java/de/chojo/sadu/datasource/DataSourceCreatorTest.java @@ -7,8 +7,8 @@ package de.chojo.sadu.datasource; import com.zaxxer.hikari.HikariDataSource; -import de.chojo.sadu.databases.SqLite; -import de.chojo.sadu.jdbc.SqLiteJdbc; +import de.chojo.sadu.sqlite.databases.SqLite; +import de.chojo.sadu.sqlite.jdbc.SqLiteJdbc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java b/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java index 4da20b4d..1d326c43 100644 --- a/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java +++ b/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java @@ -7,7 +7,7 @@ package de.chojo.sadu.examples.datasource; import com.zaxxer.hikari.HikariDataSource; -import de.chojo.sadu.databases.PostgreSql; +import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; import org.postgresql.Driver; diff --git a/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/MyQueries.java b/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/MyQueries.java deleted file mode 100644 index b18e9973..00000000 --- a/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/MyQueries.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.examples.querybuilder; - -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.wrapper.util.UpdateResult; - -import javax.sql.DataSource; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; - -// Our class will extend the QueryFactory. -// This allows us to simply create preconfigured builder. -public class MyQueries extends QueryFactory { - - /** - * Create a new queries object. - * - * @param dataSource data source used to query data from a database - */ - public MyQueries(DataSource dataSource) { - super(dataSource); - } - - /** - * Retrieve a result by id. - * - * @param id id to retrieve - * @return An optional holding a result if found. - */ - public CompletableFuture> getResult(int id) { - // We want to have a class of type Result. - return builder(Result.class) - // We define our query - .query("SELECT result FROM results WHERE id = ?") - // We set the first parameter. No need to define the index. - .parameter(stmt -> stmt.setInt(id)) - // We map our current row to a result. - .readRow(rs -> new Result(rs.getString("result"))) - // We retrieve only the first result we get. - .first(); - } - - /** - * Retrieve a list of all results in the result table. - * - * @return list of results - */ - public CompletableFuture> getResults() { - // We want to have a class of type Result. - return builder(Result.class) - // We define our query - .query("SELECT result FROM results") - // We skip the parameter assignment - .emptyParams() - // We map our current row to a result. - .readRow(rs -> new Result(rs.getString("result"))) - // We retrieve only the first result we get. - .all(); - } - - /** - * Delete a result. - * - * @param id the id to delete - * @return true if result was present and got deleted - */ - public CompletableFuture deleteResult(int id) { - // We want to delete. We leave the expected class empty. - return builder() - // We define our query - .query("DELETE FROM results WHERE id = ?") - // We set the first parameter. No need to define the index. - .parameter(stmt -> stmt.setInt(id)) - // We say that we want to execute a deletion - .delete() - // We execute the query asynchronously - .send() - // We check if a row was changed - .thenApply(UpdateResult::changed); - } - - /** - * Delete a result. - * - * @param id the id to delete - * @return true if result was present and got updated - */ - public CompletableFuture updateResult(int id, String newValue) { - // We want to update. We leave the expected class empty. - return builder() - // We define our query - .query("UPDATE results SET result = ? WHERE id = ?") - // The param builder will set the parameters in the order you define them - .parameter(stmt -> stmt.setString(newValue).setInt(id)) - // We say that we want to execute a deletion - .update() - // We execute the query asynchronously - .send() - // We check if a row was changed - .thenApply(UpdateResult::changed); - } - - /** - * Delete a result. - * - * @param result the result to add - * @return returns the id of the new result - */ - public CompletableFuture> addResult(String result) { - // We want to insert. We leave the expected class empty. - return builder() - // We define our query - .query("INSERT INTO results(result) VALUES(?)") - // We set the first parameter. No need to define the index. - .parameter(stmt -> stmt.setString(result)) - // We say that we want to execute an insert - .insert() - // We execute the query asynchronously and get the created key. - .key(); - } - - private class Result { - private final String result; - - private Result(String result) { - this.result = result; - } - } -} diff --git a/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/QueryBuilderExample.java b/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/QueryBuilderExample.java deleted file mode 100644 index fb2fed99..00000000 --- a/sadu-examples/src/main/java/de/chojo/sadu/examples/querybuilder/QueryBuilderExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.examples.querybuilder; - -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.QueryBuilderConfig; - -import javax.sql.DataSource; - -public class QueryBuilderExample extends QueryFactory { - public QueryBuilderExample(DataSource dataSource) { - super(dataSource); - } - - public static void main(String[] args) { - QueryBuilder.builder(null) - .configure(QueryBuilderConfig.builder().build()) - .query("INSERT INTO") - .emptyParams() - .readRow(null) - .all(); - - QueryBuilder.builder(null) - .configure(QueryBuilderConfig.builder().build()) - .query("INSERT INTO") - .emptyParams() - .delete() - .sendSync() - .rows(); - - QueryBuilder.builder(null) - .configure(QueryBuilderConfig.builder().build()) - .query("INSERT INTO") - .emptyParams() - .insert() - - .key(); - } - - public void createUser(String name, int age) { - builder().query("INSERT INTO user(name, age) VALUES(?,?)") - .parameter(p -> p.setString(name).setInt(age)) - .insert() - .send(); - } -} diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java index 57e47bc5..8934cd8c 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java @@ -6,11 +6,10 @@ package de.chojo.sadu.mapper; -import de.chojo.sadu.exceptions.ThrowingBiFunction; +import de.chojo.sadu.core.exceptions.ThrowingBiFunction; import de.chojo.sadu.mapper.rowmapper.RowMapper; -import de.chojo.sadu.mapper.rowmapper.RowMapping; import de.chojo.sadu.mapper.util.Results; -import de.chojo.sadu.types.SqlType; +import de.chojo.sadu.core.types.SqlType; import de.chojo.sadu.wrapper.util.Row; import java.math.BigDecimal; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java index c63796ff..c37833eb 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java @@ -6,11 +6,6 @@ package de.chojo.sadu.mapper.rowmapper; -import de.chojo.sadu.exceptions.ThrowingFunction; -import de.chojo.sadu.wrapper.util.Row; - -import java.sql.SQLException; - /** * Represents a partially configured {@link RowMapper} * @param type of the mapper result. diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java index 014a0684..83d46a50 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java @@ -6,7 +6,6 @@ package de.chojo.sadu.mapper.rowmapper; -import de.chojo.sadu.exceptions.ThrowingFunction; import de.chojo.sadu.mapper.MapperConfig; import de.chojo.sadu.wrapper.util.Row; import org.slf4j.Logger; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java index bd0c7ded..8e4cdfc1 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java @@ -6,10 +6,6 @@ package de.chojo.sadu.mapper.rowmapper; -import de.chojo.sadu.exceptions.ThrowingFunction; -import de.chojo.sadu.wrapper.util.Row; - -import java.sql.SQLException; import java.util.HashSet; import java.util.List; import java.util.Set; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java index 4d04139e..996b9b75 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java @@ -6,7 +6,7 @@ package de.chojo.sadu.mapper.rowmapper; -import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.core.exceptions.ThrowingFunction; import de.chojo.sadu.wrapper.util.Row; import java.sql.SQLException; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/Results.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/Results.java index f82bf5b2..ea0504e3 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/Results.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/Results.java @@ -6,7 +6,7 @@ package de.chojo.sadu.mapper.util; -import de.chojo.sadu.types.SqlType; +import de.chojo.sadu.core.types.SqlType; import java.sql.ResultSet; import java.sql.ResultSetMetaData; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java b/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java index e512f0da..dcd40ae7 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java @@ -6,8 +6,8 @@ package de.chojo.sadu.wrapper.util; -import de.chojo.sadu.conversion.ArrayConverter; -import de.chojo.sadu.conversion.UUIDConverter; +import de.chojo.sadu.core.conversion.ArrayConverter; +import de.chojo.sadu.core.conversion.UUIDConverter; import de.chojo.sadu.mapper.MapperConfig; import org.jetbrains.annotations.ApiStatus; import java.io.InputStream; diff --git a/sadu-mapper/src/main/java/module-info.java b/sadu-mapper/src/main/java/module-info.java index 6a9f21ad..87de377c 100644 --- a/sadu-mapper/src/main/java/module-info.java +++ b/sadu-mapper/src/main/java/module-info.java @@ -1,8 +1,5 @@ module sadu.sadu.mapper.main { - requires transitive java.sql; - requires org.slf4j; requires transitive sadu.sadu.core.main; - requires transitive org.jetbrains.annotations; exports de.chojo.sadu.mapper; exports de.chojo.sadu.mapper.exceptions; diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/databases/MariaDb.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java similarity index 82% rename from sadu-mariadb/src/main/java/de/chojo/sadu/databases/MariaDb.java rename to sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java index 53a158ba..d14527b2 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/databases/MariaDb.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java @@ -4,11 +4,12 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases; +package de.chojo.sadu.mariadb.databases; -import de.chojo.sadu.updater.StatementSplitter; -import de.chojo.sadu.updater.UpdaterBuilder; -import de.chojo.sadu.jdbc.MariaDbJdbc; +import de.chojo.sadu.core.databases.DefaultDatabase; +import de.chojo.sadu.core.updater.StatementSplitter; +import de.chojo.sadu.core.updater.UpdaterBuilder; +import de.chojo.sadu.mariadb.jdbc.MariaDbJdbc; import de.chojo.sadu.updater.BaseSqlUpdaterBuilder; /** diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/jdbc/MariaDbJdbc.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java similarity index 98% rename from sadu-mariadb/src/main/java/de/chojo/sadu/jdbc/MariaDbJdbc.java rename to sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java index 054d8692..4c5db3f0 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/jdbc/MariaDbJdbc.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java @@ -4,11 +4,9 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.mariadb.jdbc; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Optional; +import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; /** * A builder to create a MariaDB jdbc url. diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mapper/MariaDbMapper.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java similarity index 53% rename from sadu-mariadb/src/main/java/de/chojo/sadu/mapper/MariaDbMapper.java rename to sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java index 3f875f3e..8b941940 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/mapper/MariaDbMapper.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java @@ -4,9 +4,10 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.mapper; +package de.chojo.sadu.mariadb.mapper; import de.chojo.sadu.mapper.rowmapper.RowMapper; +import de.chojo.sadu.mariadb.types.MariaDbTypes; import java.math.BigDecimal; import java.util.List; @@ -22,43 +23,23 @@ import static de.chojo.sadu.mapper.DefaultMapper.createShort; import static de.chojo.sadu.mapper.DefaultMapper.createString; import static de.chojo.sadu.mapper.DefaultMapper.createUuid; -import static de.chojo.sadu.types.MariaDbTypes.BIGINT; -import static de.chojo.sadu.types.MariaDbTypes.BLOB; -import static de.chojo.sadu.types.MariaDbTypes.BOOLEAN; -import static de.chojo.sadu.types.MariaDbTypes.CHAR; -import static de.chojo.sadu.types.MariaDbTypes.DECIMAL; -import static de.chojo.sadu.types.MariaDbTypes.DOUBLE; -import static de.chojo.sadu.types.MariaDbTypes.FLOAT; -import static de.chojo.sadu.types.MariaDbTypes.INT; -import static de.chojo.sadu.types.MariaDbTypes.LONGBLOB; -import static de.chojo.sadu.types.MariaDbTypes.LONGTEXT; -import static de.chojo.sadu.types.MariaDbTypes.MEDIUMBLOB; -import static de.chojo.sadu.types.MariaDbTypes.MEDIUMINT; -import static de.chojo.sadu.types.MariaDbTypes.MEDIUMTEXT; -import static de.chojo.sadu.types.MariaDbTypes.SMALLINT; -import static de.chojo.sadu.types.MariaDbTypes.TEXT; -import static de.chojo.sadu.types.MariaDbTypes.TINYBLOB; -import static de.chojo.sadu.types.MariaDbTypes.TINYINT; -import static de.chojo.sadu.types.MariaDbTypes.TINYTEXT; -import static de.chojo.sadu.types.MariaDbTypes.VARBINARY; -import static de.chojo.sadu.types.MariaDbTypes.VARCHAR; public final class MariaDbMapper { private MariaDbMapper() { throw new UnsupportedOperationException("This is a utility class."); } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(BOOLEAN)); - public static final RowMapper SHORT_MAPPER = createShort(List.of(TINYINT, SMALLINT)); - public static final RowMapper INTEGER_MAPPER = createInteger(List.of(TINYINT, SMALLINT, MEDIUMINT, INT)); - public static final RowMapper LONG_MAPPER = createLong(List.of(BIGINT, TINYINT, SMALLINT, MEDIUMINT, INT)); - public static final RowMapper FLOAT_MAPPER = createFloat(List.of(FLOAT)); - public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(DOUBLE)); - public static final RowMapper BIG_DECIMAL_MAPPER = createBigDecimal(List.of(DECIMAL)); - public static final RowMapper STRING_MAPPER = createString(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR, CHAR)); - public static final RowMapper BYTES_MAPPER = createBytes(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR)); - public static final RowMapper UUID_MAPPER = createUuid(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR), - List.of(TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, VARBINARY)); + public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(MariaDbTypes.BOOLEAN)); + public static final RowMapper SHORT_MAPPER = createShort(List.of(MariaDbTypes.TINYINT, MariaDbTypes.SMALLINT)); + public static final RowMapper INTEGER_MAPPER = createInteger(List.of(MariaDbTypes.TINYINT, MariaDbTypes.SMALLINT, MariaDbTypes.MEDIUMINT, MariaDbTypes.INT)); + public static final RowMapper LONG_MAPPER = createLong(List.of(MariaDbTypes.BIGINT, MariaDbTypes.TINYINT, MariaDbTypes.SMALLINT, MariaDbTypes.MEDIUMINT, MariaDbTypes.INT)); + public static final RowMapper FLOAT_MAPPER = createFloat(List.of(MariaDbTypes.FLOAT)); + public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(MariaDbTypes.DOUBLE)); + public static final RowMapper BIG_DECIMAL_MAPPER = createBigDecimal(List.of(MariaDbTypes.DECIMAL)); + public static final RowMapper STRING_MAPPER = createString(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR, MariaDbTypes.CHAR)); + public static final RowMapper BYTES_MAPPER = createBytes(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR)); + public static final RowMapper UUID_MAPPER = createUuid(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR), + List.of(MariaDbTypes.TINYBLOB, MariaDbTypes.BLOB, MariaDbTypes.MEDIUMBLOB, MariaDbTypes.LONGBLOB, MariaDbTypes.VARBINARY)); public static List> getDefaultMapper(){ return List.of(BOOLEAN_MAPPER, SHORT_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, BIG_DECIMAL_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/types/MariaDbTypes.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/types/MariaDbTypes.java similarity index 94% rename from sadu-mariadb/src/main/java/de/chojo/sadu/types/MariaDbTypes.java rename to sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/types/MariaDbTypes.java index ff394bb3..5373d590 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/types/MariaDbTypes.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/types/MariaDbTypes.java @@ -4,9 +4,11 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.types; +package de.chojo.sadu.mariadb.types; -import static de.chojo.sadu.types.SqlType.ofName; +import de.chojo.sadu.core.types.SqlType; + +import static de.chojo.sadu.core.types.SqlType.ofName; /** * Types present in a MariaDB database. diff --git a/sadu-mariadb/src/main/java/module-info.java b/sadu-mariadb/src/main/java/module-info.java new file mode 100644 index 00000000..f8985a48 --- /dev/null +++ b/sadu-mariadb/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module sadu.sadu.mariadb.main { + requires transitive sadu.sadu.updater.main; + requires transitive sadu.sadu.mapper.main; + + exports de.chojo.sadu.mariadb.databases; + exports de.chojo.sadu.mariadb.jdbc; + exports de.chojo.sadu.mariadb.mapper; + exports de.chojo.sadu.mariadb.types; +} diff --git a/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java b/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java index 1bbb66a0..9eceb763 100644 --- a/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java +++ b/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java @@ -6,8 +6,9 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.databases.MariaDb; +import de.chojo.sadu.mariadb.databases.MariaDb; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.mariadb.jdbc.MariaDbJdbc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/sadu-mariadb/src/test/java/de/chojo/sadu/mapper/MariaDbMapperTest.java b/sadu-mariadb/src/test/java/de/chojo/sadu/mapper/MariaDbMapperTest.java index 53aef3e0..c020c696 100644 --- a/sadu-mariadb/src/test/java/de/chojo/sadu/mapper/MariaDbMapperTest.java +++ b/sadu-mariadb/src/test/java/de/chojo/sadu/mapper/MariaDbMapperTest.java @@ -6,10 +6,11 @@ package de.chojo.sadu.mapper; -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.databases.MariaDb; import de.chojo.sadu.datasource.DataSourceCreator; -import de.chojo.sadu.wrapper.QueryBuilderConfig; +import de.chojo.sadu.mariadb.databases.MariaDb; +import de.chojo.sadu.mariadb.mapper.MariaDbMapper; +import de.chojo.sadu.queries.api.query.Query; +import de.chojo.sadu.queries.configuration.QueryConfiguration; import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -94,7 +95,6 @@ INSERT INTO test(_bigint, _integer, _mediumint, _smallint, _tinyint, _char, _tin static final BigDecimal bigDecimal = BigDecimal.valueOf(327674568765487845L, 5); static final String text = "text"; private static GenericContainer db; - private static QueryFactory factory; @BeforeAll static void beforeAll() throws IOException { @@ -104,12 +104,11 @@ static void beforeAll() throws IOException { .usingPassword("root") .usingUsername("root") .build(); - var config = QueryBuilderConfig.builder() - .rowMappers(new RowMapperRegistry().register(MariaDbMapper.getDefaultMapper())) - .build(); - factory = new QueryFactory(dc, config); - factory.builder().query(TEST_TABLE).emptyParams().insert().sendSync(); - assert factory.builder().query(INSERTS).emptyParams().insert().sendSync().rows() > 0 : "Could not insert data."; + QueryConfiguration.setDefault(QueryConfiguration.builder(dc) + .setRowMapperRegistry(new RowMapperRegistry().register(MariaDbMapper.getDefaultMapper())) + .build()); + Query.query(TEST_TABLE).single().insert(); + assert Query.query(INSERTS).single().insert().rows() > 0 : "Could not insert data."; } static Stream shortTestInput() { @@ -157,11 +156,10 @@ static void afterAll() throws IOException { @ParameterizedTest @MethodSource("shortTestInput") void testAutoParsing(Class clazz, String _col, T expected) { - var val = factory.builder(clazz) - .query("SELECT %s FROM test", _col) - .emptyParams() - .map() - .firstSync(); + var val = Query.query("SELECT %s FROM test", _col) + .single() + .mapAs(clazz) + .first(); Assertions.assertTrue(val.isPresent()); Assertions.assertEquals(expected, val.get()); } diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/databases/MySql.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java similarity index 82% rename from sadu-mysql/src/main/java/de/chojo/sadu/databases/MySql.java rename to sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java index be7553bd..748c3571 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/databases/MySql.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java @@ -4,11 +4,12 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases; +package de.chojo.sadu.mysql.databases; -import de.chojo.sadu.updater.StatementSplitter; -import de.chojo.sadu.updater.UpdaterBuilder; -import de.chojo.sadu.jdbc.MySQLJdbc; +import de.chojo.sadu.core.databases.DefaultDatabase; +import de.chojo.sadu.core.updater.StatementSplitter; +import de.chojo.sadu.core.updater.UpdaterBuilder; +import de.chojo.sadu.mysql.jdbc.MySQLJdbc; import de.chojo.sadu.updater.BaseSqlUpdaterBuilder; /** diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/jdbc/MySQLJdbc.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java similarity index 92% rename from sadu-mysql/src/main/java/de/chojo/sadu/jdbc/MySQLJdbc.java rename to sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java index 66cb3043..1e5ce314 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/jdbc/MySQLJdbc.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java @@ -4,7 +4,9 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.mysql.jdbc; + +import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; /** * A builder to create a MySQL jdbc url. diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mapper/MySqlMapper.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java similarity index 50% rename from sadu-mysql/src/main/java/de/chojo/sadu/mapper/MySqlMapper.java rename to sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java index 27c0beb7..34a6ca61 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/mapper/MySqlMapper.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java @@ -4,9 +4,10 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.mapper; +package de.chojo.sadu.mysql.mapper; import de.chojo.sadu.mapper.rowmapper.RowMapper; +import de.chojo.sadu.mysql.types.MySqlTypes; import java.util.List; import java.util.UUID; @@ -19,40 +20,21 @@ import static de.chojo.sadu.mapper.DefaultMapper.createLong; import static de.chojo.sadu.mapper.DefaultMapper.createString; import static de.chojo.sadu.mapper.DefaultMapper.createUuid; -import static de.chojo.sadu.types.MySqlTypes.BIGINT; -import static de.chojo.sadu.types.MySqlTypes.BLOB; -import static de.chojo.sadu.types.MySqlTypes.BOOLEAN; -import static de.chojo.sadu.types.MySqlTypes.DECIMAL; -import static de.chojo.sadu.types.MySqlTypes.DOUBLE; -import static de.chojo.sadu.types.MySqlTypes.FLOAT; -import static de.chojo.sadu.types.MySqlTypes.INT; -import static de.chojo.sadu.types.MySqlTypes.LONGBLOB; -import static de.chojo.sadu.types.MySqlTypes.LONGTEXT; -import static de.chojo.sadu.types.MySqlTypes.MEDIUMBLOB; -import static de.chojo.sadu.types.MySqlTypes.MEDIUMINT; -import static de.chojo.sadu.types.MySqlTypes.MEDIUMTEXT; -import static de.chojo.sadu.types.MySqlTypes.SMALLINT; -import static de.chojo.sadu.types.MySqlTypes.TEXT; -import static de.chojo.sadu.types.MySqlTypes.TINYBLOB; -import static de.chojo.sadu.types.MySqlTypes.TINYINT; -import static de.chojo.sadu.types.MySqlTypes.TINYTEXT; -import static de.chojo.sadu.types.MySqlTypes.VARBINARY; -import static de.chojo.sadu.types.MySqlTypes.VARCHAR; public final class MySqlMapper { private MySqlMapper() { throw new UnsupportedOperationException("This is a utility class."); } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(BOOLEAN)); - public static final RowMapper INTEGER_MAPPER = createInteger(List.of(TINYINT, SMALLINT, MEDIUMINT, INT)); - public static final RowMapper LONG_MAPPER = createLong(List.of(BIGINT, TINYINT, SMALLINT, MEDIUMINT, INT)); - public static final RowMapper FLOAT_MAPPER = createFloat(List.of(DOUBLE, DECIMAL, FLOAT)); - public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(DOUBLE, DECIMAL, FLOAT)); - public static final RowMapper STRING_MAPPER = createString(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR)); - public static final RowMapper BYTES_MAPPER = createBytes(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR)); - public static final RowMapper UUID_MAPPER = createUuid(List.of(TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, VARCHAR), - List.of(TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, VARBINARY)); + public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(MySqlTypes.BOOLEAN)); + public static final RowMapper INTEGER_MAPPER = createInteger(List.of(MySqlTypes.TINYINT, MySqlTypes.SMALLINT, MySqlTypes.MEDIUMINT, MySqlTypes.INT)); + public static final RowMapper LONG_MAPPER = createLong(List.of(MySqlTypes.BIGINT, MySqlTypes.TINYINT, MySqlTypes.SMALLINT, MySqlTypes.MEDIUMINT, MySqlTypes.INT)); + public static final RowMapper FLOAT_MAPPER = createFloat(List.of(MySqlTypes.DOUBLE, MySqlTypes.DECIMAL, MySqlTypes.FLOAT)); + public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(MySqlTypes.DOUBLE, MySqlTypes.DECIMAL, MySqlTypes.FLOAT)); + public static final RowMapper STRING_MAPPER = createString(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR)); + public static final RowMapper BYTES_MAPPER = createBytes(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR)); + public static final RowMapper UUID_MAPPER = createUuid(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR), + List.of(MySqlTypes.TINYBLOB, MySqlTypes.BLOB, MySqlTypes.MEDIUMBLOB, MySqlTypes.LONGBLOB, MySqlTypes.VARBINARY)); public static List> getDefaultMapper(){ return List.of(BOOLEAN_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/types/MySqlTypes.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/types/MySqlTypes.java similarity index 94% rename from sadu-mysql/src/main/java/de/chojo/sadu/types/MySqlTypes.java rename to sadu-mysql/src/main/java/de/chojo/sadu/mysql/types/MySqlTypes.java index 743a10f3..d3604741 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/types/MySqlTypes.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/types/MySqlTypes.java @@ -4,9 +4,11 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.types; +package de.chojo.sadu.mysql.types; -import static de.chojo.sadu.types.SqlType.ofName; +import de.chojo.sadu.core.types.SqlType; + +import static de.chojo.sadu.core.types.SqlType.ofName; /** * Types present in a MySQL database. diff --git a/sadu-mysql/src/main/java/module-info.java b/sadu-mysql/src/main/java/module-info.java new file mode 100644 index 00000000..c63cab31 --- /dev/null +++ b/sadu-mysql/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module sadu.sadu.mysql.main { + requires transitive sadu.sadu.mapper.main; + requires transitive sadu.sadu.updater.main; + + exports de.chojo.sadu.mysql.databases; + exports de.chojo.sadu.mysql.jdbc; + exports de.chojo.sadu.mysql.mapper; + exports de.chojo.sadu.mysql.types; +} diff --git a/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java b/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java index d0d9c549..d2620046 100644 --- a/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java +++ b/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java @@ -6,8 +6,9 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.databases.MySql; +import de.chojo.sadu.mysql.databases.MySql; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.mysql.jdbc.MySQLJdbc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/databases/PostgreSql.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java similarity index 88% rename from sadu-postgresql/src/main/java/de/chojo/sadu/databases/PostgreSql.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java index f411273c..99b0600f 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/databases/PostgreSql.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java @@ -4,10 +4,11 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.databases; +package de.chojo.sadu.postgresql.databases; -import de.chojo.sadu.jdbc.PostgreSqlJdbc; -import de.chojo.sadu.update.PostgreSqlUpdaterBuilder; +import de.chojo.sadu.core.databases.DefaultDatabase; +import de.chojo.sadu.postgresql.jdbc.PostgreSqlJdbc; +import de.chojo.sadu.postgresql.update.PostgreSqlUpdaterBuilder; import de.chojo.sadu.updater.BaseSqlUpdaterBuilder; /** diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/jdbc/PostgreSqlJdbc.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java similarity index 98% rename from sadu-postgresql/src/main/java/de/chojo/sadu/jdbc/PostgreSqlJdbc.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java index 44ffce25..b684ed29 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/jdbc/PostgreSqlJdbc.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java @@ -4,7 +4,9 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.jdbc; +package de.chojo.sadu.postgresql.jdbc; + +import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; /** * A builder to create a PostgreSQL jdbc url. diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/mapper/PostgresqlMapper.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java similarity index 61% rename from sadu-postgresql/src/main/java/de/chojo/sadu/mapper/PostgresqlMapper.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java index b4fd43e2..e0b67f75 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/mapper/PostgresqlMapper.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java @@ -4,9 +4,10 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.mapper; +package de.chojo.sadu.postgresql.mapper; import de.chojo.sadu.mapper.rowmapper.RowMapper; +import de.chojo.sadu.postgresql.types.PostgreSqlTypes; import java.math.BigDecimal; import java.util.List; @@ -22,36 +23,22 @@ import static de.chojo.sadu.mapper.DefaultMapper.createShort; import static de.chojo.sadu.mapper.DefaultMapper.createString; import static de.chojo.sadu.mapper.DefaultMapper.createUuid; -import static de.chojo.sadu.types.PostgreSqlTypes.BIGINT; -import static de.chojo.sadu.types.PostgreSqlTypes.BOOLEAN; -import static de.chojo.sadu.types.PostgreSqlTypes.BYTEA; -import static de.chojo.sadu.types.PostgreSqlTypes.CHAR; -import static de.chojo.sadu.types.PostgreSqlTypes.DECIMAL; -import static de.chojo.sadu.types.PostgreSqlTypes.DOUBLE; -import static de.chojo.sadu.types.PostgreSqlTypes.INTEGER; -import static de.chojo.sadu.types.PostgreSqlTypes.JSON; -import static de.chojo.sadu.types.PostgreSqlTypes.JSONB; -import static de.chojo.sadu.types.PostgreSqlTypes.NUMERIC; -import static de.chojo.sadu.types.PostgreSqlTypes.REAL; -import static de.chojo.sadu.types.PostgreSqlTypes.SMALLINT; -import static de.chojo.sadu.types.PostgreSqlTypes.TEXT; -import static de.chojo.sadu.types.PostgreSqlTypes.VARCHAR; public final class PostgresqlMapper { private PostgresqlMapper() { throw new UnsupportedOperationException("This is a utility class."); } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(BOOLEAN)); - public static final RowMapper SHORT_MAPPER = createShort(List.of(SMALLINT, INTEGER)); - public static final RowMapper INTEGER_MAPPER = createInteger(List.of(SMALLINT, INTEGER)); - public static final RowMapper LONG_MAPPER = createLong(List.of(SMALLINT, INTEGER, BIGINT)); - public static final RowMapper FLOAT_MAPPER = createFloat(List.of(REAL)); - public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(DECIMAL, NUMERIC, DOUBLE, REAL)); - public static final RowMapper BIG_DECIMAL_MAPPER = createBigDecimal(List.of(DECIMAL, NUMERIC, DOUBLE, REAL)); - public static final RowMapper STRING_MAPPER = createString(List.of(TEXT, VARCHAR, CHAR, JSON, JSONB)); - public static final RowMapper BYTES_MAPPER = createBytes(List.of(BYTEA)); - public static final RowMapper UUID_MAPPER = createUuid(List.of(TEXT), List.of(BYTEA)); + public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(PostgreSqlTypes.BOOLEAN)); + public static final RowMapper SHORT_MAPPER = createShort(List.of(PostgreSqlTypes.SMALLINT, PostgreSqlTypes.INTEGER)); + public static final RowMapper INTEGER_MAPPER = createInteger(List.of(PostgreSqlTypes.SMALLINT, PostgreSqlTypes.INTEGER)); + public static final RowMapper LONG_MAPPER = createLong(List.of(PostgreSqlTypes.SMALLINT, PostgreSqlTypes.INTEGER, PostgreSqlTypes.BIGINT)); + public static final RowMapper FLOAT_MAPPER = createFloat(List.of(PostgreSqlTypes.REAL)); + public static final RowMapper DOUBLE_MAPPER = createDouble(List.of(PostgreSqlTypes.DECIMAL, PostgreSqlTypes.NUMERIC, PostgreSqlTypes.DOUBLE, PostgreSqlTypes.REAL)); + public static final RowMapper BIG_DECIMAL_MAPPER = createBigDecimal(List.of(PostgreSqlTypes.DECIMAL, PostgreSqlTypes.NUMERIC, PostgreSqlTypes.DOUBLE, PostgreSqlTypes.REAL)); + public static final RowMapper STRING_MAPPER = createString(List.of(PostgreSqlTypes.TEXT, PostgreSqlTypes.VARCHAR, PostgreSqlTypes.CHAR, PostgreSqlTypes.JSON, PostgreSqlTypes.JSONB)); + public static final RowMapper BYTES_MAPPER = createBytes(List.of(PostgreSqlTypes.BYTEA)); + public static final RowMapper UUID_MAPPER = createUuid(List.of(PostgreSqlTypes.TEXT), List.of(PostgreSqlTypes.BYTEA)); public static List> getDefaultMapper() { return List.of(BOOLEAN_MAPPER, SHORT_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, BIG_DECIMAL_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/types/PostgreSqlTypes.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/types/PostgreSqlTypes.java similarity index 92% rename from sadu-postgresql/src/main/java/de/chojo/sadu/types/PostgreSqlTypes.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/types/PostgreSqlTypes.java index 31f9ce3f..2da3dbbe 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/types/PostgreSqlTypes.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/types/PostgreSqlTypes.java @@ -4,9 +4,11 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.types; +package de.chojo.sadu.postgresql.types; -import static de.chojo.sadu.types.SqlType.ofName; +import de.chojo.sadu.core.types.SqlType; + +import static de.chojo.sadu.core.types.SqlType.ofName; /** * Types present in a PostgreSQL database. diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java similarity index 92% rename from sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java index 9444da74..a3b1ef32 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdater.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java @@ -4,13 +4,13 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.update; +package de.chojo.sadu.postgresql.update; -import de.chojo.sadu.databases.Database; -import de.chojo.sadu.jdbc.PostgreSqlJdbc; +import de.chojo.sadu.core.databases.Database; +import de.chojo.sadu.postgresql.jdbc.PostgreSqlJdbc; import de.chojo.sadu.updater.QueryReplacement; import de.chojo.sadu.updater.SqlUpdater; -import de.chojo.sadu.updater.SqlVersion; +import de.chojo.sadu.core.updater.SqlVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java similarity index 84% rename from sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java index cfcaa1c0..db50653b 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/update/PostgreSqlUpdaterBuilder.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java @@ -4,14 +4,14 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.update; +package de.chojo.sadu.postgresql.update; -import de.chojo.sadu.databases.Database; -import de.chojo.sadu.jdbc.PostgreSqlJdbc; +import de.chojo.sadu.core.databases.Database; +import de.chojo.sadu.core.updater.SqlVersion; +import de.chojo.sadu.postgresql.jdbc.PostgreSqlJdbc; import de.chojo.sadu.updater.BaseSqlUpdaterBuilder; -import de.chojo.sadu.updater.SqlVersion; +import org.jetbrains.annotations.CheckReturnValue; -import javax.annotation.CheckReturnValue; import java.io.IOException; import java.sql.SQLException; diff --git a/sadu-postgresql/src/main/java/module-info.java b/sadu-postgresql/src/main/java/module-info.java new file mode 100644 index 00000000..9daa1680 --- /dev/null +++ b/sadu-postgresql/src/main/java/module-info.java @@ -0,0 +1,10 @@ +module sadu.sadu.postgresql.main { + requires transitive sadu.sadu.updater.main; + requires transitive sadu.sadu.mapper.main; + + exports de.chojo.sadu.postgresql.databases; + exports de.chojo.sadu.postgresql.jdbc; + exports de.chojo.sadu.postgresql.mapper; + exports de.chojo.sadu.postgresql.types; + exports de.chojo.sadu.postgresql.update; +} diff --git a/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java b/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java index d7b8d1c8..08bfc983 100644 --- a/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java +++ b/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java @@ -6,7 +6,7 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.databases.PostgreSql; +import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/sadu-postgresql/src/test/java/de/chojo/sadu/mapper/PostgresqlMapperTest.java b/sadu-postgresql/src/test/java/de/chojo/sadu/mapper/PostgresqlMapperTest.java index aa2cb3d2..1214b0bd 100644 --- a/sadu-postgresql/src/test/java/de/chojo/sadu/mapper/PostgresqlMapperTest.java +++ b/sadu-postgresql/src/test/java/de/chojo/sadu/mapper/PostgresqlMapperTest.java @@ -6,10 +6,11 @@ package de.chojo.sadu.mapper; -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; -import de.chojo.sadu.wrapper.QueryBuilderConfig; +import de.chojo.sadu.postgresql.databases.PostgreSql; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; +import de.chojo.sadu.queries.api.query.Query; +import de.chojo.sadu.queries.configuration.QueryConfiguration; import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -60,7 +61,6 @@ class PostgresqlMapperTest { static final String text = "text"; static final String json = "{\"a\": \"b\"}"; private static GenericContainer pg; - private static QueryFactory factory; @BeforeAll static void beforeAll() throws IOException { @@ -70,10 +70,9 @@ static void beforeAll() throws IOException { .usingPassword("postgres") .usingUsername("postgres") .build(); - var config = QueryBuilderConfig.builder() - .rowMappers(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())) - .build(); - factory = new QueryFactory(dc, config); + QueryConfiguration.setDefault(QueryConfiguration.builder(dc) + .setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper())) + .build()); } static Stream shortTestInput() { @@ -118,11 +117,10 @@ static void afterAll() throws IOException { @ParameterizedTest @MethodSource("shortTestInput") void testAutoParsing(Class clazz, String query, T expected) { - var val = factory.builder(clazz) - .query(query) - .emptyParams() - .map() - .firstSync(); + var val = Query.query(query) + .single() + .mapAs(clazz) + .first(); Assertions.assertTrue(val.isPresent()); Assertions.assertEquals(expected, val.get()); } diff --git a/sadu-queries/build.gradle.kts b/sadu-queries/build.gradle.kts index 067f1f50..5e59d3e4 100644 --- a/sadu-queries/build.gradle.kts +++ b/sadu-queries/build.gradle.kts @@ -1,13 +1,11 @@ -description = "SADU module to send queries to a database." - dependencies { api(project(":sadu-core")) api(project(":sadu-mapper")) - + testImplementation("org.postgresql", "postgresql", "42.7.1") + testImplementation(testlibs.bundles.junit) testImplementation(project(":sadu-datasource")) - testImplementation(project(":sadu-mariadb")) - testImplementation(project(":sadu-mapper")) - testImplementation(testlibs.bundles.database.mariadb) + testImplementation(project(":sadu-postgresql")) + + testImplementation(testlibs.bundles.database.postgres) testImplementation(testlibs.slf4j.noop) - testImplementation(testlibs.bundles.junit) } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/adapter/StaticQueryAdapter.java b/sadu-queries/src/main/java/de/chojo/sadu/adapter/StaticQueryAdapter.java deleted file mode 100644 index 81ebda89..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/adapter/StaticQueryAdapter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.adapter; - -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.wrapper.QueryBuilderConfig; -import de.chojo.sadu.wrapper.stage.QueryStage; -import org.slf4j.Logger; - -import javax.sql.DataSource; - -import static org.slf4j.LoggerFactory.getLogger; - -/** - * The StaticQueryAdapter class provides a static interface for executing queries using a query builder. - * It allows for initializing the adapter with a data source and configuration, and provides methods for - * building query stages. - */ - -public class StaticQueryAdapter { - private static final Logger log = getLogger(StaticQueryAdapter.class); - private static QueryFactory factory = null; - - private StaticQueryAdapter() { - throw new UnsupportedOperationException("This is a utility class."); - } - - /** - * Creates a new query builder instance without specifying the model class. - * This version of the builder is typically used for non-model specific queries. - * - * @return a query builder instance for non-model specific queries - * @throws NotInitializedException if the adapter has not been initialized - */ - public static QueryStage builder() { - assertInit(); - return factory.builder(); - } - - /** - * Creates a new query builder instance. - * - * @param clazz the class of the model for which the queries will be built - * @param the type of the model - * @return a query builder instance for the specified model class - * @throws NotInitializedException if the adapter has not been initialized - */ - public static QueryStage builder(Class clazz) { - assertInit(); - return factory.builder(clazz); - } - - /** - * Initializes the static SADU query adapter. - * - * @param dataSource the data source used for executing queries - * @param config the configuration for the query builder - * @throws AlreadyInitializedException if the adapter has already been initialized - */ - public static void init(DataSource dataSource, QueryBuilderConfig config) { - if (factory != null) throw new AlreadyInitializedException(); - factory = new QueryFactory(dataSource, config); - log.info("Static SADU query adapter started"); - } - - - /** - * Initializes the static SADU query adapter. - * - * @param dataSource the data source used for executing queries - * @throws AlreadyInitializedException if the adapter has already been initialized - */ - public static void init(DataSource dataSource) { - if (factory != null) throw new AlreadyInitializedException(); - factory = new QueryFactory(dataSource); - log.info("Static SADU query adapter started"); - } - - private static void assertInit() { - if (factory == null) throw new NotInitializedException(); - } - - private static class NotInitializedException extends RuntimeException { - - } - - private static class AlreadyInitializedException extends RuntimeException { - - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/base/DataHolder.java b/sadu-queries/src/main/java/de/chojo/sadu/base/DataHolder.java deleted file mode 100644 index e9276f3a..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/base/DataHolder.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.base; - -import de.chojo.sadu.exceptions.ExceptionTransformer; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.stage.ConfigurationStage; -import org.slf4j.Logger; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLTimeoutException; - -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Base class which can be used for classes which call the database. - *

- * Provides convenience methods for connection retrieval, logging and a querybuilder. - *

- * You may use a {@link QueryFactory} for builder creation or extend {@link QueryFactory} - */ -public class DataHolder implements DataSourceProvider { - private static final Logger log = getLogger(DataHolder.class); - private final DataSource dataSource; - - /** - * Create a new DataHolder - * - * @param dataSource data source - */ - public DataHolder(DataSource dataSource) { - this.dataSource = dataSource; - } - - /** - * Get a query builder for easy sql execution. - * - * @param clazz clazz which should be retrieved. Doesn't matter if you want a list and multiple results or not. - * @param type of result - * @return query builder in a query stage - */ - protected ConfigurationStage queryBuilder(Class clazz) { - return QueryBuilder.builder(dataSource, clazz); - } - - /** - * Logs the exception with a message - * - * @param message message - * @param e exception - */ - public void logDbError(String message, SQLException e) { - log.error(ExceptionTransformer.prettyException(message, e), e); - } - - /** - * Logs the exception with a default message. - * - * @param e exception - */ - public void logDbError(SQLException e) { - logDbError("An error occurred while executing a query", e); - } - - /** - * Attempts to establish a connection with the data source that this DataSource object represents. - * - * @return a connection to the data source - * @throws SQLException if a database access error occurs - * @throws SQLTimeoutException when the driver has determined that the timeout value specified by the setLoginTimeout method has been exceeded and has at least tried to cancel the current database connection attempt - */ - public Connection getConnection() throws SQLException { - return dataSource.getConnection(); - } - - @Override - public DataSource source() { - return dataSource; - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/base/QueryFactory.java b/sadu-queries/src/main/java/de/chojo/sadu/base/QueryFactory.java deleted file mode 100644 index d84cbb23..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/base/QueryFactory.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.base; - -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.QueryBuilderConfig; -import de.chojo.sadu.wrapper.stage.QueryStage; - -import javax.sql.DataSource; -import java.util.concurrent.atomic.AtomicReference; - -/** - * Base class which provides a factory for easy usage. - *

- * Can be used instead of a {@link DataHolder} - */ -public class QueryFactory extends DataHolder { - private final AtomicReference config; - - /** - * Create a new QueryFactory - * - * @param dataSource datasource - * @param config factory config - */ - public QueryFactory(DataSource dataSource, QueryBuilderConfig config) { - this(dataSource, new AtomicReference<>(config)); - } - - private QueryFactory(DataSource dataSource, AtomicReference config) { - super(dataSource); - this.config = config; - } - - /** - * Create a new QueryFactory - * - * @param dataSource datasource - */ - public QueryFactory(DataSource dataSource) { - this(dataSource, QueryBuilderConfig.defaultConfig()); - } - - /** - * Creates a QueryFactory and uses the {@link DataSource} contained in the {@link DataSourceProvider}. - * - * @param provider provider - * @param config factory config - */ - public QueryFactory(DataSourceProvider provider, QueryBuilderConfig config) { - this(provider.source(), config); - } - - /** - * Creates a QueryFactory and uses the {@link DataSource} contained in the {@link DataSourceProvider}. - * - * @param provider provider - */ - public QueryFactory(DataSourceProvider provider) { - this(provider.source()); - } - - /** - * Creates a QueryFactory based on the passed QueryFactory. - *

- * Configuration will be copied. - * - * @param factoryHolder parent factory holder - */ - public QueryFactory(QueryFactory factoryHolder) { - this(factoryHolder.source(), factoryHolder.config()); - } - - /** - * Create a new query builder with a defined return type. Use it for selects. - * - * @param clazz class of required return type. Doesn't matter if you want a list or single result. - * @param type if result as class - * @return a new query builder in a {@link QueryStage} - */ - public QueryStage builder(Class clazz) { - return QueryBuilder.builder(source(), clazz).configure(config); - } - - /** - * Create a new Query builder without a defined return type. Use it for updates. - * - * @return a new query builder in a {@link QueryStage} - */ - public QueryStage builder() { - return QueryBuilder.builder(source(), Void.class).configure(config); - } - - /** - * Gets the underlying config. - * - * @return config reference - */ - public AtomicReference config() { - return config; - } - -} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java similarity index 80% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java index 25edca1e..46e0909c 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/ConnectionProvider.java @@ -6,8 +6,8 @@ package de.chojo.sadu.queries.api.base; -import de.chojo.sadu.base.DataSourceProvider; -import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.core.base.DataSourceProvider; +import de.chojo.sadu.core.exceptions.ThrowingFunction; import java.sql.Connection; import java.sql.SQLException; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java similarity index 89% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java index 5ecd919a..7c8e6116 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/QueryProvider.java @@ -6,8 +6,8 @@ package de.chojo.sadu.queries.api.base; -import de.chojo.sadu.base.DataSourceProvider; -import de.chojo.sadu.exceptions.ThrowingFunction; +import de.chojo.sadu.core.base.DataSourceProvider; +import de.chojo.sadu.core.exceptions.ThrowingFunction; import de.chojo.sadu.queries.configuration.QueryConfiguration; import de.chojo.sadu.queries.query.QueryImpl; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/base/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/base/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java similarity index 98% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java index 4bebe571..49750c54 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/Call.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java @@ -10,7 +10,7 @@ import de.chojo.sadu.queries.call.CallImpl; import de.chojo.sadu.queries.calls.BatchCall; import de.chojo.sadu.queries.calls.SingletonCall; -import de.chojo.sadu.types.SqlType; +import de.chojo.sadu.core.types.SqlType; import java.math.BigDecimal; import java.net.URL; diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/Adapter.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/AdapterMapping.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/adapter/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/calls/Calls.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/calls/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/call/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java similarity index 89% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java index 78c7c7fd..6db34981 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/reading/Reader.java @@ -20,17 +20,21 @@ public interface Reader { /** * Retrieves a single result from the query. + *

+ * See {@link #first()} for direct access * * @return the result of the query */ - Result first(); + Result firstResult(); /** * Retrieves all the results of the query. + *

+ * See {@link #all()} for direct access * * @return a Result object containing a List of results */ - Result> all(); + Result> allResults(); /** * Stores a query result and allows to create a new query. @@ -56,12 +60,12 @@ public interface Reader { * @return an {@link Optional} containing the first value from the query result, * or an empty {@link Optional} if the query returns no results */ - Optional oneAndGet(); + Optional first(); /** * Retrieves all elements from the Reader. * * @return a List of all elements */ - List allAndGet(); + List all(); } diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/reading/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledBatchQuery.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/CalledSingletonQuery.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/execution/writing/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/parameter/BaseParameter.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/parameter/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/AppendedQuery.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/ParsedQuery.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/Query.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/Query.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/Query.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/query/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/query/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java similarity index 81% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java index d9212b02..56ec0df4 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java @@ -8,6 +8,8 @@ import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; +import java.util.Optional; + /** * Base of a result returned by a {@link MappedQuery} * @@ -21,4 +23,8 @@ public interface Result { * @return result */ T result(); + + default Optional ifPresent() { + return Optional.ofNullable(result()); + } } diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationBatchResult.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java similarity index 100% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/package-info.java diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java similarity index 62% rename from sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java index 624f693c..175aea59 100644 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/CallImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java @@ -6,7 +6,7 @@ package de.chojo.sadu.queries.call; -import de.chojo.sadu.exceptions.ThrowingBiConsumer; +import de.chojo.sadu.core.exceptions.ThrowingBiConsumer; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.call.adapter.Adapter; import de.chojo.sadu.queries.api.call.calls.Calls; @@ -17,7 +17,7 @@ import de.chojo.sadu.queries.parameter.IndexParameter; import de.chojo.sadu.queries.parameter.TokenParameter; import de.chojo.sadu.queries.query.TokenizedQuery; -import de.chojo.sadu.types.SqlType; +import de.chojo.sadu.core.types.SqlType; import java.math.BigDecimal; import java.net.URL; @@ -40,33 +40,6 @@ import java.util.Collection; import java.util.List; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BIG_DECIMAL; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BLOB; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BOOLEAN; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BYTE; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.BYTE_ARRAY; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.CLOB; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.DATE; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.DOUBLE; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ENUM; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.FLOAT; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.INTEGER; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_DATE; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_DATE_TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LOCAL_TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.LONG; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.OFFSET_DATE_TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.OFFSET_TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.REF; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ROW_ID; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.SHORT; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.STRING; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.TIMESTAMP; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.ZONED_DATE_TIME; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.forArray; -import static de.chojo.sadu.queries.call.adapter.StandardAdapter.forCollection; - /** * A call is a subelement of a {@link Calls}. It represents a single query call of any kind. */ @@ -98,232 +71,232 @@ private ThrowingBiConsumer nullSave(Ob @Override public Call bind(String value) { - return bind(value, STRING); + return bind(value, StandardAdapter.STRING); } @Override public Call bind(String token, String value) { - return bind(token, value, STRING); + return bind(token, value, StandardAdapter.STRING); } @Override public Call bind(Enum value) { - return bind(value, ENUM); + return bind(value, StandardAdapter.ENUM); } @Override public Call bind(String token, Enum value) { - return bind(token, value, ENUM); + return bind(token, value, StandardAdapter.ENUM); } @Override public Call bind(short value) { - return bind(value, SHORT); + return bind(value, StandardAdapter.SHORT); } @Override public Call bind(String token, short value) { - return bind(token, value, SHORT); + return bind(token, value, StandardAdapter.SHORT); } @Override public Call bind(int value) { - return bind(value, INTEGER); + return bind(value, StandardAdapter.INTEGER); } @Override public Call bind(String token, int value) { - return bind(token, value, INTEGER); + return bind(token, value, StandardAdapter.INTEGER); } @Override public Call bind(boolean value) { - return bind(value, BOOLEAN); + return bind(value, StandardAdapter.BOOLEAN); } @Override public Call bind(String token, boolean value) { - return bind(token, value, BOOLEAN); + return bind(token, value, StandardAdapter.BOOLEAN); } @Override public Call bind(byte value) { - return bind(value, BYTE); + return bind(value, StandardAdapter.BYTE); } @Override public Call bind(String token, byte value) { - return bind(token, value, BYTE); + return bind(token, value, StandardAdapter.BYTE); } @Override public Call bind(byte[] value) { - return bind(value, BYTE_ARRAY); + return bind(value, StandardAdapter.BYTE_ARRAY); } @Override public Call bind(String token, byte[] value) { - return bind(token, value, BYTE_ARRAY); + return bind(token, value, StandardAdapter.BYTE_ARRAY); } @Override public Call bind(Date value) { - return bind(value, DATE); + return bind(value, StandardAdapter.DATE); } @Override public Call bind(String token, Date value) { - return bind(token, value, DATE); + return bind(token, value, StandardAdapter.DATE); } @Override public Call bind(long value) { - return bind(value, LONG); + return bind(value, StandardAdapter.LONG); } @Override public Call bind(String token, long value) { - return bind(token, value, LONG); + return bind(token, value, StandardAdapter.LONG); } @Override public Call bind(double value) { - return bind(value, DOUBLE); + return bind(value, StandardAdapter.DOUBLE); } @Override public Call bind(String token, double value) { - return bind(token, value, DOUBLE); + return bind(token, value, StandardAdapter.DOUBLE); } @Override public Call bind(BigDecimal value) { - return bind(value, BIG_DECIMAL); + return bind(value, StandardAdapter.BIG_DECIMAL); } @Override public Call bind(String token, BigDecimal value) { - return bind(token, value, BIG_DECIMAL); + return bind(token, value, StandardAdapter.BIG_DECIMAL); } @Override public Call bind(float value) { - return bind(value, FLOAT); + return bind(value, StandardAdapter.FLOAT); } @Override public Call bind(String token, float value) { - return bind(token, value, FLOAT); + return bind(token, value, StandardAdapter.FLOAT); } @Override public Call bind(LocalDate value) { - return bind(value, LOCAL_DATE); + return bind(value, StandardAdapter.LOCAL_DATE); } @Override public Call bind(String token, LocalDate value) { - return bind(token, value, LOCAL_DATE); + return bind(token, value, StandardAdapter.LOCAL_DATE); } @Override public Call bind(Time value) { - return bind(value, TIME); + return bind(value, StandardAdapter.TIME); } @Override public Call bind(String token, Time value) { - return bind(token, value, TIME); + return bind(token, value, StandardAdapter.TIME); } @Override public Call bind(LocalTime value) { - return bind(value, LOCAL_TIME); + return bind(value, StandardAdapter.LOCAL_TIME); } @Override public Call bind(String token, LocalTime value) { - return bind(token, value, LOCAL_TIME); + return bind(token, value, StandardAdapter.LOCAL_TIME); } @Override public Call bind(Timestamp value) { - return bind(value, TIMESTAMP); + return bind(value, StandardAdapter.TIMESTAMP); } @Override public Call bind(String token, Timestamp value) { - return bind(token, value, TIMESTAMP); + return bind(token, value, StandardAdapter.TIMESTAMP); } @Override public Call bind(LocalDateTime value) { - return bind(value, LOCAL_DATE_TIME); + return bind(value, StandardAdapter.LOCAL_DATE_TIME); } @Override public Call bind(String token, LocalDateTime value) { - return bind(token, value, LOCAL_DATE_TIME); + return bind(token, value, StandardAdapter.LOCAL_DATE_TIME); } @Override public Call bind(ZonedDateTime value) { - return bind(value, ZONED_DATE_TIME); + return bind(value, StandardAdapter.ZONED_DATE_TIME); } @Override public Call bind(String token, ZonedDateTime value) { - return bind(token, value, ZONED_DATE_TIME); + return bind(token, value, StandardAdapter.ZONED_DATE_TIME); } @Override public Call bind(OffsetDateTime value) { - return bind(value, OFFSET_DATE_TIME); + return bind(value, StandardAdapter.OFFSET_DATE_TIME); } @Override public Call bind(String token, OffsetDateTime value) { - return bind(token, value, OFFSET_DATE_TIME); + return bind(token, value, StandardAdapter.OFFSET_DATE_TIME); } @Override public Call bind(OffsetTime value) { - return bind(value, OFFSET_TIME); + return bind(value, StandardAdapter.OFFSET_TIME); } @Override public Call bind(String token, OffsetTime value) { - return bind(token, value, OFFSET_TIME); + return bind(token, value, StandardAdapter.OFFSET_TIME); } @Override public Call bind(Ref value) { - return bind(value, REF); + return bind(value, StandardAdapter.REF); } @Override public Call bind(String token, Ref value) { - return bind(token, value, REF); + return bind(token, value, StandardAdapter.REF); } @Override public Call bind(Blob value) { - return bind(value, BLOB); + return bind(value, StandardAdapter.BLOB); } @Override public Call bind(String token, Blob value) { - return bind(token, value, BLOB); + return bind(token, value, StandardAdapter.BLOB); } @Override public Call bind(Clob value) { - return bind(value, CLOB); + return bind(value, StandardAdapter.CLOB); } @Override public Call bind(String token, Clob value) { - return bind(token, value, CLOB); + return bind(token, value, StandardAdapter.CLOB); } @Override @@ -338,32 +311,32 @@ public Call bind(String token, URL value) { @Override public Call bind(RowId value) { - return bind(value, ROW_ID); + return bind(value, StandardAdapter.ROW_ID); } @Override public Call bind(String token, RowId value) { - return bind(token, value, ROW_ID); + return bind(token, value, StandardAdapter.ROW_ID); } @Override public Call bind(Collection value, SqlType type) { - return bind(value, forCollection(value, type)); + return bind(value, StandardAdapter.forCollection(value, type)); } @Override public Call bind(String token, Collection value, SqlType type) { - return bind(token, value, forCollection(value, type)); + return bind(token, value, StandardAdapter.forCollection(value, type)); } @Override public Call bind(Object[] value, SqlType type) { - return bind(value, forArray(value, type)); + return bind(value, StandardAdapter.forArray(value, type)); } @Override public Call bind(String token, Object[] value, SqlType type) { - return bind(token, value, forArray(value, type)); + return bind(token, value, StandardAdapter.forArray(value, type)); } @Override diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java new file mode 100644 index 00000000..fcfb2e53 --- /dev/null +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java @@ -0,0 +1,76 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + +package de.chojo.sadu.queries.call.adapter; + +import de.chojo.sadu.queries.api.call.adapter.Adapter; +import de.chojo.sadu.core.types.SqlType; + +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.Types; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.util.Collection; + +import static de.chojo.sadu.core.conversion.ArrayConverter.toSqlArray; +import static de.chojo.sadu.queries.api.call.adapter.Adapter.create; + +/** + * The StandardAdapter class provides a set of static instances of Adapter, which map Java objects to specific SQL data types and provide the necessary conversions when binding the + * objects to a PreparedStatement. + */ +public final class StandardAdapter { + public static final Adapter STRING = Adapter.create(PreparedStatement::setString, Types.VARCHAR); + public static final Adapter> ENUM = Adapter.create(PreparedStatement::setString, Types.VARCHAR, Enum::name); + public static final Adapter SHORT = Adapter.create(PreparedStatement::setShort, Types.TINYINT); + public static final Adapter INTEGER = Adapter.create(PreparedStatement::setInt, Types.INTEGER); + public static final Adapter BIG_DECIMAL = Adapter.create(PreparedStatement::setBigDecimal, Types.DECIMAL); + public static final Adapter FLOAT = Adapter.create(PreparedStatement::setFloat, Types.FLOAT); + public static final Adapter DOUBLE = Adapter.create(PreparedStatement::setDouble, Types.DOUBLE); + public static final Adapter LONG = Adapter.create(PreparedStatement::setLong, Types.BIGINT); + public static final Adapter BOOLEAN = Adapter.create(PreparedStatement::setBoolean, Types.BOOLEAN); + public static final Adapter BYTE = Adapter.create(PreparedStatement::setByte, Types.BIT); + public static final Adapter BYTE_ARRAY = Adapter.create(PreparedStatement::setBytes, Types.BINARY); + public static final Adapter DATE = Adapter.create(PreparedStatement::setDate, Types.DATE); + public static final Adapter LOCAL_DATE = Adapter.create(PreparedStatement::setDate, Types.DATE, Date::valueOf); + public static final Adapter

- * The query builder is a stage organized object. Every call will be invoked on a stage of the same query builder. - *

- * You may execute as many updates as you want. You may only get the returned results of one query, which must be the last. - *

- * All methods which are not labeled with a {@code Sync} suffix will be executed in an async context. Async method will - * provide a callback via a {@link CompletableFuture}. - *

- * All queries will be executed in an atomic transaction. This means that data will be only written if all queries are executed successfully. - * This behaviour can be changed by calling {@link QueryBuilderConfig.Builder#notAtomic()} ()} on config creation. - *

- * Any exception thrown while executing queries will be wrapped into an {@link QueryExecutionException}. This exception - * was created on query submission to the query builder. Note that this is not the execution, which may be called on - * another thread. This exception will help you to trace back async calls. - *

- * Any {@link SQLException} thrown inside the query builder will not be thrown but logged by default. - * - * @param type of query return type - */ -public class QueryBuilder extends DataHolder implements ConfigurationStage, QueryStage, StatementStage, ResultStage, RetrievalStage, InsertStage { - private final Queue tasks = new ArrayDeque<>(); - private final QueryExecutionException executionException; - private final WrappedQueryExecutionException wrappedExecutionException; - private final Class clazz; - private String currQuery; - private ThrowingConsumer currStatementConsumer; - private RowMapper currRowMapper; - private AtomicReference config; - private MapperConfig mapperConfig = new MapperConfig(); - - private QueryBuilder(DataSource dataSource, Class clazz) { - super(dataSource); - this.clazz = clazz; - executionException = new QueryExecutionException("An error occurred while executing a query."); - wrappedExecutionException = new WrappedQueryExecutionException("An error occurred while executing a query."); - } - - /** - * Create a new query builder with a defined return type. Use it for selects. - * - * @param source datasource for connection - * @param clazz class of required return type. Doesn't matter if you want a list or single result. - * @param type of return type - * @return a new query builder in a {@link QueryStage} - */ - public static ConfigurationStage builder(DataSource source, Class clazz) { - return new QueryBuilder<>(source, clazz); - } - - /** - * Create a new Query builder without a defined return type. Use it for updates. - * - * @param source datasource for connection - * @return a new query builder in a {@link QueryStage} - */ - public static ConfigurationStage builder(DataSource source) { - return new QueryBuilder<>(source, null); - } - - // CONFIGURATION STAGE - - @Override - public QueryStage configure(AtomicReference config) { - this.config = config; - return this; - } - - @Override - public QueryStage defaultConfig() { - config = QueryBuilderConfig.defaultConfig(); - return this; - } - - @Override - public QueryStage defaultConfig(Consumer builderModifier) { - var builder = config.get().toBuilder(); - builderModifier.accept(builder); - config = new AtomicReference<>(builder.build()); - return this; - } - - // QUERY STAGE - - @Override - public StatementStage query(String query) { - currQuery = query; - return this; - } - - @Override - public ResultStage queryWithoutParams(String query) { - currQuery = query; - return emptyParams(); - } - - // STATEMENT STAGE - - @Override - public ResultStage params(ThrowingConsumer stmt) { - currStatementConsumer = stmt; - return this; - } - - @Override - public ResultStage parameter(ThrowingConsumer params) { - currStatementConsumer = stmt -> params.accept(new ParamBuilder(stmt)); - return this; - } - - // RESULT STAGE - - @Override - public RetrievalStage readRow(ThrowingFunction mapper) { - Objects.requireNonNull(clazz); - currRowMapper = RowMapper.forClass(clazz).mapper(mapper::apply).build(); - queueTask(); - return this; - } - - @Override - public RetrievalStage map(MapperConfig mapperConfig) { - Objects.requireNonNull(clazz); - this.mapperConfig = mapperConfig.copy(); - queueTask(); - return this; - } - - @Override - public UpdateStage update() { - currRowMapper = null; - queueTask(); - return this; - } - - @Override - public InsertStage insert() { - update(); - return this; - } - - @Override - public QueryStage append() { - currRowMapper = null; - queueTask(); - return this; - } - - private void queueTask() { - tasks.add(new QueryTask(clazz, currQuery, currStatementConsumer, currRowMapper, mapperConfig)); - } - - // RETRIEVAL STAGE - - // LISTS RETRIEVAL - - @Override - public CompletableFuture> all() { - return CompletableFuture.supplyAsync(this::allSync); - } - - @Override - public CompletableFuture> all(Executor executor) { - return CompletableFuture.supplyAsync(this::allSync, executor); - } - - @Override - public List allSync() { - try (var conn = getConnection()) { - autoCommit(conn); - var results = executeAndGetLast(conn).retrieveResults(conn); - commit(conn); - return results; - } catch (QueryExecutionException e) { - logDbError(e); - } catch (SQLException e) { - handleException(e); - } - return Collections.emptyList(); - } - - @Override - public CompletableFuture> keys() { - return CompletableFuture.supplyAsync(this::keysSync); - } - - @Override - public CompletableFuture> keys(Executor executor) { - return CompletableFuture.supplyAsync(this::keysSync, executor); - } - - @Override - public List keysSync() { - try (var conn = getConnection()) { - autoCommit(conn); - var results = executeAndGetLast(conn).retrieveKeys(conn); - commit(conn); - return results; - } catch (QueryExecutionException e) { - logDbError(e); - } catch (SQLException e) { - handleException(e); - } - return Collections.emptyList(); - } - - @Override - public void logDbError(SQLException e) { - config.get().exceptionHandler().ifPresentOrElse(consumer -> consumer.accept(e), () -> super.logDbError(e)); - } - - // SINGLE RETRIEVAL - - @Override - public CompletableFuture> first() { - return CompletableFuture.supplyAsync(this::firstSync); - } - - @Override - public CompletableFuture> first(Executor executor) { - return CompletableFuture.supplyAsync(this::firstSync, executor); - } - - @Override - public Optional firstSync() { - try (var conn = getConnection()) { - autoCommit(conn); - var result = executeAndGetLast(conn).retrieveResult(conn); - commit(conn); - return result; - } catch (SQLException e) { - handleException(e); - } - return Optional.empty(); - } - - @Override - public CompletableFuture> key() { - return CompletableFuture.supplyAsync(this::keySync); - } - - @Override - public CompletableFuture> key(Executor executor) { - return CompletableFuture.supplyAsync(this::keySync, executor); - } - - @SuppressWarnings("OverlyBroadCatchBlock") - @Override - public Optional keySync() { - try (var conn = getConnection()) { - autoCommit(conn); - var result = executeAndGetLast(conn).retrieveKey(conn); - commit(conn); - return result; - } catch (SQLException e) { - handleException(e); - } - return Optional.empty(); - } - - // UPDATE STAGE - - @Override - public UpdateResult sendSync() { - return new UpdateResult(executeSync()); - } - - @Override - public CompletableFuture send() { - return CompletableFuture.supplyAsync(() -> new UpdateResult(executeSync())); - } - - @Override - public CompletableFuture send(Executor executor) { - return CompletableFuture.supplyAsync(() -> new UpdateResult(executeSync()), executor); - } - - @Override - public CompletableFuture execute() { - return CompletableFuture.supplyAsync(this::executeSync, config.get().executor()); - } - - @Override - public CompletableFuture execute(Executor executor) { - return CompletableFuture.supplyAsync(this::executeSync, executor); - } - - @SuppressWarnings("OverlyBroadCatchBlock") - @Override - public int executeSync() { - try (var conn = getConnection()) { - autoCommit(conn); - var update = executeAndGetLast(conn).update(conn); - commit(conn); - return update; - } catch (SQLException e) { - handleException(e); - } - return 0; - } - - - /* - Execute all queries, since we are only interested in the result of the last of our queries. - That's why we will execute all queries inside this method regardless of the method which calls this method - We will use a single connection for this, since the user may be interested in the last inserted id or something. - */ - private QueryTask executeAndGetLast(Connection conn) throws QueryExecutionException { - while (tasks.size() > 1) { - tasks.poll().execute(conn); - } - return tasks.poll(); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - private void handleException(SQLException e) { - if (config.get().isThrowing()) { - wrappedExecutionException.initCause(e); - throw wrappedExecutionException; - } - executionException.initCause(e); - config.get().exceptionHandler() - .ifPresentOrElse(consumer -> consumer.accept(executionException), () -> logDbError(executionException)); - } - - private void autoCommit(Connection conn) throws SQLException { - conn.setAutoCommit(!config.get().isAtomic()); - } - - private void commit(Connection conn) throws SQLException { - if (config.get().isAtomic()) conn.commit(); - } - - @SuppressWarnings("JDBCPrepareStatementWithNonConstantString") - private class QueryTask { - private final Class clazz; - private final String query; - private final ThrowingConsumer statementConsumer; - private final MapperConfig mapperConfig; - private final QueryExecutionException executionException; - private RowMapper rowMapper; - - private QueryTask(Class clazz, String currQuery, ThrowingConsumer statementConsumer, - RowMapper rowMapper, MapperConfig mapperConfig) { - this.clazz = clazz; - query = currQuery; - this.statementConsumer = statementConsumer; - this.rowMapper = rowMapper; - this.mapperConfig = mapperConfig; - executionException = new QueryExecutionException("An error occurred while executing a query."); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - private void initAndThrow(SQLException e) throws QueryExecutionException { - executionException.initCause(e); - throw executionException; - } - - public List retrieveResults(Connection conn) throws QueryExecutionException { - List results = new ArrayList<>(); - try (var stmt = conn.prepareStatement(query)) { - statementConsumer.accept(stmt); - var resultSet = stmt.executeQuery(); - var row = new Row(resultSet, mapperConfig); - while (resultSet.next()) results.add(mapper(resultSet).map(row)); - } catch (SQLException e) { - initAndThrow(e); - } - return results; - } - - public Optional retrieveResult(Connection conn) throws QueryExecutionException { - try (var stmt = conn.prepareStatement(query)) { - statementConsumer.accept(stmt); - var resultSet = stmt.executeQuery(); - var row = new Row(resultSet, mapperConfig); - if (resultSet.next()) return Optional.ofNullable(mapper(resultSet).map(row)); - } catch (SQLException e) { - initAndThrow(e); - } - return Optional.empty(); - } - - public void execute(Connection conn) throws QueryExecutionException { - try (var stmt = conn.prepareStatement(query)) { - statementConsumer.accept(stmt); - stmt.execute(); - } catch (SQLException e) { - initAndThrow(e); - } - } - - public List retrieveKeys(Connection conn) throws QueryExecutionException { - List results = new ArrayList<>(); - try (var stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)) { - statementConsumer.accept(stmt); - stmt.execute(); - var generatedKeys = stmt.getGeneratedKeys(); - while (generatedKeys.next()) results.add(generatedKeys.getLong(1)); - } catch (SQLException e) { - initAndThrow(e); - } - return results; - } - - public Optional retrieveKey(Connection conn) throws QueryExecutionException { - try (var stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)) { - statementConsumer.accept(stmt); - stmt.execute(); - var generatedKeys = stmt.getGeneratedKeys(); - if (generatedKeys.next()) return Optional.of(generatedKeys.getLong(1)); - } catch (SQLException e) { - initAndThrow(e); - } - return Optional.empty(); - } - - public int update(Connection conn) throws QueryExecutionException { - try (var stmt = conn.prepareStatement(query)) { - statementConsumer.accept(stmt); - return stmt.executeUpdate(); - } catch (SQLException e) { - initAndThrow(e); - } - return 0; - } - - private RowMapper mapper(ResultSet resultSet) throws SQLException { - if (rowMapper != null) { - return rowMapper; - } - rowMapper = config.get().rowMappers().findOrWildcard(clazz, resultSet, mapperConfig); - return rowMapper; - } - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilderConfig.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilderConfig.java deleted file mode 100644 index 184bafb0..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/QueryBuilderConfig.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper; - -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.exceptions.ExceptionTransformer; -import de.chojo.sadu.mapper.RowMapperRegistry; -import de.chojo.sadu.mapper.rowmapper.RowMapper; -import de.chojo.sadu.wrapper.exception.QueryExecutionException; -import org.jetbrains.annotations.NotNull; - -import java.sql.SQLException; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; - -/** - * Configuration for a {@link QueryBuilder} - */ -public class QueryBuilderConfig { - /** - * Contains the default configuration. - */ - private static final AtomicReference DEFAULT = new AtomicReference<>(new Builder().build()); - private final boolean throwing; - private final boolean atomic; - private final Consumer exceptionHandler; - private final ExecutorService executor; - private final RowMapperRegistry rowMapperRegistry; - - private QueryBuilderConfig(boolean throwing, boolean atomic, Consumer exceptionHandler, ExecutorService executorService, RowMapperRegistry rowMapperRegistry) { - this.throwing = throwing; - this.atomic = atomic; - this.exceptionHandler = exceptionHandler; - executor = executorService; - this.rowMapperRegistry = rowMapperRegistry; - } - - /** - * Get a builder for a QueryBuilderConfig. - * The builder is pre-populated by the values set via {@link QueryBuilderConfig#setDefault(QueryBuilderConfig)} - * - * @return new builder instance - */ - public static Builder builder() { - return DEFAULT.get().toBuilder(); - } - - /** - * Sets the default config. This config will be used by all {@link QueryBuilder} and {@link QueryFactory} which do not have their own configuration. - * - * @param config config to set - */ - public static void setDefault(QueryBuilderConfig config) { - Objects.requireNonNull(config); - DEFAULT.set(config); - } - - /** - * Gets a reference on the configuration. The underlying configuration may change at any time. - * - * @return config reference - */ - public static AtomicReference defaultConfig() { - return DEFAULT; - } - - /** - * Check if the config is throwing - * - * @return true if throwing - */ - public boolean isThrowing() { - return throwing; - } - - /** - * Checks if atomic transactions should be used. - * - * @return true if atomic - */ - public boolean isAtomic() { - return atomic; - } - - /** - * Get the row mappers of the config. - * - * @return row mappers instance - */ - public RowMapperRegistry rowMappers() { - return rowMapperRegistry; - } - - /** - * Exception handler for thrown exceptions - * - * @return error handler - */ - public Optional> exceptionHandler() { - return Optional.ofNullable(exceptionHandler); - } - - /** - * Executor to submit the completable futures. - * - * @return executor - */ - public ExecutorService executor() { - return executor; - } - - public Builder toBuilder() { - return new Builder(throwing, atomic, exceptionHandler, executor, rowMapperRegistry); - } - - /** - * Builder for a {@link QueryBuilderConfig} - */ - public static class Builder { - private boolean throwing; - private boolean atomic = true; - @SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) - private Consumer exceptionHandler = throwable -> { - System.err.println(ExceptionTransformer.prettyException(throwable)); - throwable.printStackTrace(); - }; - - private RowMapperRegistry rowMapperRegistry = new RowMapperRegistry(); - - - private ExecutorService executorService = ForkJoinPool.commonPool(); - - private Builder(boolean throwing, boolean atomic, Consumer exceptionHandler, ExecutorService executor, RowMapperRegistry rowMapperRegistry) { - this.throwing = throwing; - this.atomic = atomic; - this.exceptionHandler = exceptionHandler; - executorService = executor; - this.rowMapperRegistry = rowMapperRegistry; - } - - public Builder() { - } - - /** - * Sets the query builder as throwing. This will cause any occurring exception to be wrapped into an {@link QueryExecutionException} and be thrown instead of logged. - * - * @return builder instance - */ - public Builder throwExceptions() { - throwing = true; - return this; - } - - /** - * Sets the query builder exception handler. This will only have an effect if {@link #throwExceptions()} is not called. - * - * @param exceptionHandler handler for exception - * @return builder instance - */ - public Builder withExceptionHandler(Consumer exceptionHandler) { - this.exceptionHandler = exceptionHandler; - return this; - } - - /** - * Disable the default logger. - * - * @return builder instance - */ - public Builder disableDefaultLogger() { - exceptionHandler = null; - return this; - } - - /** - * Set that the queries are not executed atomic. - *

- * When the queries are atomic they will be executed in one transaction. This will cause that no data will be changed if any query fails to execute. - *

- * On default queries will be also executed atomic. This method just exists for convenience. No queries will be executed after one query fails in any way. - * - * @return builder instance - */ - public Builder notAtomic() { - atomic = false; - return this; - } - - /** - * Sets the executor service used for the completable futures. - * - * @param executorService executor service - * @return builder instance - */ - public Builder withExecutor(ExecutorService executorService) { - this.executorService = executorService; - return this; - } - - /** - * Adds a new row mapper to the row mappers. - * - * @param rowMapper row mapper to add - * @return builder instance - */ - public Builder addRowMapper(RowMapper rowMapper) { - rowMapperRegistry.register(rowMapper); - return this; - } - - /** - * Adds a row mappers instance, overriding the previously registered one - * - * @param rowMapperRegistry row mappers instance to add - * @return builder instance - */ - public Builder rowMappers(@NotNull RowMapperRegistry rowMapperRegistry) { - Objects.requireNonNull(rowMapperRegistry); - this.rowMapperRegistry = rowMapperRegistry; - return this; - } - - /** - * Retrieve a new {@link QueryBuilderConfig} instance. - * - * @return config with defined values - */ - public QueryBuilderConfig build() { - return new QueryBuilderConfig(throwing, atomic, exceptionHandler, executorService, rowMapperRegistry); - } - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/QueryExecutionException.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/QueryExecutionException.java deleted file mode 100644 index c6f34de4..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/QueryExecutionException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.exception; - -import de.chojo.sadu.wrapper.QueryBuilder; - -import java.sql.SQLException; - -/** - * Exception to wrap {@link Exception} as {@link Exception} thrown during queries executed by {@link QueryBuilder} - */ -public class QueryExecutionException extends SQLException { - /** - * Cause of the exception - */ - private SQLException cause; - - /** - * Creates a new exception - * - * @param message message - */ - public QueryExecutionException(String message) { - super(message); - } - - /** - * @throws ClassCastException If the throwable is not a {@link SQLException} - */ - @Override - public synchronized Throwable initCause(Throwable cause) { - this.cause = (SQLException) cause; - return super.initCause(cause); - } - - @Override - public String getSQLState() { - return cause.getSQLState(); - } - - @Override - public int getErrorCode() { - return cause.getErrorCode(); - } - - @Override - public String getMessage() { - return cause.getMessage(); - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/WrappedQueryExecutionException.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/WrappedQueryExecutionException.java deleted file mode 100644 index 44e86d4d..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/exception/WrappedQueryExecutionException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.exception; - -import de.chojo.sadu.wrapper.QueryBuilder; - -import java.sql.SQLException; - -/** - * Exception to wrap {@link Exception} as {@link RuntimeException} thrown during queries executed by {@link QueryBuilder} - */ -public class WrappedQueryExecutionException extends RuntimeException { - /** - * Cause of the exception - */ - private SQLException cause; - - /** - * Creates a new exception. - * - * @param message message - */ - public WrappedQueryExecutionException(String message) { - super(message); - } - - /** - * @throws ClassCastException If the throwable is not a {@link SQLException} - */ - @Override - public synchronized Throwable initCause(Throwable cause) { - this.cause = (SQLException) cause; - return super.initCause(cause); - } - - - /** - * SQL state of the exception - * - * @return sql state - */ - public String getSQLState() { - return cause.getSQLState(); - } - - /** - * Error code of the exception - * - * @return error code - */ - public int getErrorCode() { - return cause.getErrorCode(); - } - - @Override - public String getMessage() { - return cause.getMessage(); - } - -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ConfigurationStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ConfigurationStage.java deleted file mode 100644 index f6d8c940..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ConfigurationStage.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.base.QueryFactory; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.QueryBuilderConfig; - -import javax.annotation.CheckReturnValue; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; - -/** - * Represents a ConfigurationStage of a {@link QueryBuilder}. - *

- * Allows to configure the {@link QueryBuilderConfig}. This stage can be skipped when using a {@link QueryFactory}. - * - * @param result type - */ -public interface ConfigurationStage { - /** - * Configure the query builder. - *

- * A configured {@link QueryFactory} can be used to skip this step. - * - * @param config The config of the {@link QueryBuilder} - * @return The {@link QueryBuilder} in {@link QueryStage} with the config set. - */ - @CheckReturnValue - default QueryStage configure(QueryBuilderConfig config) { - return configure(new AtomicReference<>(config)); - } - - /** - * Configure the query builder. - *

- * A configured {@link QueryFactory} can be used to skip this step. - * - * @param config The config of the {@link QueryBuilder} - * @return The {@link QueryBuilder} in {@link QueryStage} with the config set. - */ - @CheckReturnValue - QueryStage configure(AtomicReference config); - - /** - * Set the settings to default values. - *

- * Default will be atomic transactions and not throwing any exception. - *

- * A configured {@link QueryFactory} can be used to skip this step. - * - * @return The {@link QueryBuilder} in {@link QueryStage} with the config set. - */ - @CheckReturnValue - QueryStage defaultConfig(); - - /** - * Allows to modify a config, pre-populated with the default values defined via {@link QueryBuilderConfig#setDefault(QueryBuilderConfig)} - *

- * A configured {@link QueryFactory} can be used to skip this step. - * - * @return The {@link QueryBuilder} in {@link QueryStage} with the config set. - */ - @CheckReturnValue - QueryStage defaultConfig(Consumer builderModifier); -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/InsertStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/InsertStage.java deleted file mode 100644 index f571dc0c..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/InsertStage.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.wrapper.QueryBuilderConfig; -import de.chojo.sadu.wrapper.exception.WrappedQueryExecutionException; -import de.chojo.sadu.wrapper.util.UpdateResult; - -import javax.annotation.CheckReturnValue; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/** - * Represents a InsertStage providing the result of an insert statement. - *

- * Can either provide the created keys or a {@link UpdateResult} via the underlying {@link UpdateStage} - */ -public interface InsertStage extends UpdateStage { - /** - * Retrieve the first created key async - * - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> key(); - - /** - * Retrieve the first created key async - * - * @param executor the executor used for async call - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> key(Executor executor); - - /** - * Retrieve the first created key synced - * - * @return result wrapped into an optional - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - Optional keySync(); - - /** - * Retrieve all created keys as a list - * - * @return A list of created key. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - List keysSync(); - - /** - * Retrieve all created keys async as a list - * - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> keys(); - - /** - * Retrieve all created keys async as a list - * - * @param executor the executor used for async call - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> keys(Executor executor); -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/QueryStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/QueryStage.java deleted file mode 100644 index 736f699c..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/QueryStage.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.wrapper.QueryBuilder; - -import javax.annotation.CheckReturnValue; - -/** - * Represents a QueryStage of a {@link QueryBuilder}. Allows to set the sql query. - *

- * Can either redirect to a {@link StatementStage} or directly to a {@link ResultStage} - * - * @param return type - */ -public interface QueryStage { - /** - * Set the query to execute. - * - * @param sql query to set. - * @return The {@link QueryBuilder} in a {@link StatementStage} with the query defined. - */ - @CheckReturnValue - StatementStage query(String sql); - - /** - * Set the query to execute. - * - * @param sql query to set. - * @param objects objects to replace in a {@link String#format(String, Object...)} - * Do not use this with user input! This should be only used to insert column or table names at runtime - * @return The {@link QueryBuilder} in a {@link StatementStage} with the query defined. - */ - @CheckReturnValue - default StatementStage query(String sql, Object... objects) { - return query(String.format(sql, objects)); - } - - /** - * Set the query to execute. - *

- * This will also skip the statement stage. - * - * @param sql query to set. - * @return The {@link QueryBuilder} in a {@link ResultStage} with the query defined and no parameter set. - */ - @CheckReturnValue - ResultStage queryWithoutParams(String sql); - - /** - * Set the query to execute. - *

- * This will also skip the statement stage. - * - * @param sql query to set. - * @param objects objects to replace in a {@link String#format(String, Object...)} - * Do not use this with user input! This should be only used to insert column or table names at runtime - * @return The {@link QueryBuilder} in a {@link ResultStage} with the query defined and no parameter set. - */ - @CheckReturnValue - default ResultStage queryWithoutParams(String sql, Object... objects) { - return queryWithoutParams(String.format(sql, objects)); - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ResultStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ResultStage.java deleted file mode 100644 index 5bfb3321..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/ResultStage.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.exceptions.ThrowingFunction; -import de.chojo.sadu.mapper.MapperConfig; -import de.chojo.sadu.mapper.rowmapper.RowMapper; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.util.Row; - -import javax.annotation.CheckReturnValue; -import java.sql.SQLException; -import java.util.function.Consumer; - -/** - * Represents a ResultStage of a {@link QueryBuilder}. - *

- * A ResultStage is used to read the result set, perform updates or append another query. - *

- * Can forward to a {@link RetrievalStage} when data needs to be read, a {@link UpdateStage} when data is updated or deleted or a {@link InsertStage} when data gets inserted. - *

- * Additionally, it allows to go back to a {@link QueryStage} to add another query into the transaction. - * - * @param return type - */ -public interface ResultStage { - - /** - * Extract results from the current row and only the current row. It doesn't matter if you will get 0, 1 or more results. - *

- * This is not the place to define how many results you want. - *

- * Do not try to read multiple rows here. - *

- * Do not modify the underlying result set. - * - * @param mapper mapper to map the current row. - * @return The {@link QueryBuilder} in a {@link RetrievalStage} to retrieve the row/s. - */ - @CheckReturnValue - RetrievalStage readRow(ThrowingFunction mapper); - - /** - * Maps the rows of the result with a previously registered {@link RowMapper}. - *

- * The best matching mapper will be used for the result set. - * - * @return The {@link QueryBuilder} in a {@link RetrievalStage} to retrieve the row/s. - */ - default RetrievalStage map() { - return map(MapperConfig.DEFAULT); - } - - /** - * Maps the rows of the result with a previously registered {@link RowMapper}. - *

- * Maps the row and applies a mapper config to the query builder. - * - * @param mapperConfig mapper config - * @return The {@link QueryBuilder} in a {@link RetrievalStage} to retrieve the row/s. - */ - RetrievalStage map(MapperConfig mapperConfig); - - /** - * Maps the rows of the result with a previously registered {@link RowMapper}. - *

- * Maps the row and applies a mapper config to the query builder. - * - * @param mapperConfig modify the mapper config - * @return The {@link QueryBuilder} in a {@link RetrievalStage} to retrieve the row/s. - */ - default RetrievalStage map(Consumer mapperConfig) { - var config = new MapperConfig(); - mapperConfig.accept(config); - return map(config); - } - - /** - * Mark this query as update query. - * - * @return The {@link QueryBuilder} in a {@link UpdateStage} to update the data. - */ - @CheckReturnValue - UpdateStage update(); - - /** - * Mark this query as deletion query. Alias for {@link #update()} - * - * @return The {@link QueryBuilder} in a {@link UpdateStage} to update the data. - */ - @CheckReturnValue - default UpdateStage delete() { - return update(); - } - - /** - * Insert data into a table. Alias for {@link #update()} - * - * @return The {@link QueryBuilder} in a {@link InsertStage} to update the data. - */ - @CheckReturnValue - InsertStage insert(); - - - /** - * Append another query to the query builder. - * - * @return The {@link QueryBuilder} in a {@link QueryStage} - */ - @CheckReturnValue - QueryStage append(); -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/RetrievalStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/RetrievalStage.java deleted file mode 100644 index 5269efbc..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/RetrievalStage.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.QueryBuilderConfig; -import de.chojo.sadu.wrapper.exception.WrappedQueryExecutionException; - -import javax.annotation.CheckReturnValue; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/** - * Represents a RetrievalStage of a {@link QueryBuilder}. - *

- * A RetrievalStage is used to retrieve the actual data from the database. - *

- * The RetrievalStage defines in which way the results should be retrieved and how many. - * - * @param type of RetrievalStage - */ -public interface RetrievalStage { - - /** - * Retrieve all results async as a list - * - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> all(); - - /** - * Retrieve all results async as a list - * - * @param executor the executor used for async call - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> all(Executor executor); - - /** - * Retrieve all results synced as a list - * - * @return results as list - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - List allSync(); - - /** - * Retrieve the first result from the results set async - * - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> first(); - - /** - * Retrieve the first result from the results set async - * - * @param executor the executor used for async call - * @return A {@link CompletableFuture} to retrieve the data. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - CompletableFuture> first(Executor executor); - - /** - * Retrieve the first result from the results set synced - * - * @return result wrapped into an optional - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and a exceptions occurs during query building or execution - */ - @CheckReturnValue - Optional firstSync(); -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/StatementStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/StatementStage.java deleted file mode 100644 index 4d6b4456..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/StatementStage.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.exceptions.ThrowingConsumer; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.util.ParamBuilder; - -import javax.annotation.CheckReturnValue; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -/** - * Represents a StatementStage of a {@link QueryBuilder}. - *

- * Allows to set query parameter. - * - * @param return type - */ -public interface StatementStage { - /** - * Set the parameter of the {@link PreparedStatement} of the query. - * - * @param stmt statement to change - * @return The {@link QueryBuilder} in a {@link ResultStage} with the parameters applied to the query. - * @deprecated This method exists for the sole purpose of backwards compatibility. Usage of {@link #parameter(ThrowingConsumer)} is preferred. - */ - @Deprecated - @CheckReturnValue - ResultStage params(ThrowingConsumer stmt); - - /** - * Set the parameter of the {@link PreparedStatement} of the query. - *

- * Use the query builder so set the parameters in the defined order. - *

- * {@code stmt -> stmt.setString("value").setInt(1)} - * - * @param params a consumer of a param builder used for simple setting of params. - * @return The {@link QueryBuilder} in a {@link ResultStage} with the parameters applied to the query. - * @deprecated use {@link #parameter(ThrowingConsumer)} instead - */ - @Deprecated(forRemoval = true) - @CheckReturnValue - default ResultStage paramsBuilder(ThrowingConsumer params) { - return parameter(params); - } - - /** - * Set the parameter of the {@link PreparedStatement} of the query. - *

- * Use the query builder so set the parameters in the defined order. - *

- * {@code stmt -> stmt.setString("value").setInt(1)} - * - * @param stmt a consumer of a param builder used for simple setting of params. - * @return The {@link QueryBuilder} in a {@link ResultStage} with the parameters applied to the query. - */ - @CheckReturnValue - ResultStage parameter(ThrowingConsumer stmt); - - /** - * Skip this stage and set no parameters in the query. - *

- * You can also call {@link QueryStage#queryWithoutParams(String)} on the previous {@link QueryStage} instead to avoid this step completely. - * - * @return The {@link QueryBuilder} in a {@link ResultStage} with no parameters set. - */ - @CheckReturnValue - default ResultStage emptyParams() { - return params(stmt -> {}); - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/UpdateStage.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/UpdateStage.java deleted file mode 100644 index 4879f3be..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/stage/UpdateStage.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.stage; - -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.QueryBuilderConfig; -import de.chojo.sadu.wrapper.exception.WrappedQueryExecutionException; -import de.chojo.sadu.wrapper.util.UpdateResult; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/** - * Represents a UpdateStage of a {@link QueryBuilder}. - *

- * Allows to check the changed rows of an update statement. - */ -public interface UpdateStage { - /** - * Executes the update. - * - * @return A {@link CompletableFuture} which returns the number of changed rows. - */ - UpdateResult sendSync(); - - /** - * Executes the update async. - * - * @return A {@link CompletableFuture} which returns the number of changed rows. - */ - CompletableFuture send(); - - /** - * Executes the update async. - * - * @param executor executor used for async call - * @return A {@link CompletableFuture} which returns the number of changed rows. - */ - CompletableFuture send(Executor executor); - - /** - * Execute the update async. - * - * @return A {@link CompletableFuture} which returns the number of changed rows. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - * @deprecated Deprecated in favor of {@link #send()} - */ - @Deprecated - CompletableFuture execute(); - - /** - * Execute the update async. - * - * @param executor executor used for async call - * @return A {@link CompletableFuture} which returns the number of changed rows. - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - * @deprecated Deprecated in favor of {@link #send(Executor)} - */ - @Deprecated - CompletableFuture execute(Executor executor); - - /** - * Execute the update synced. - * - * @return Number of changed rows - * @throws WrappedQueryExecutionException if {@link QueryBuilderConfig#isThrowing()} is set to {@code true} and an exceptions occurs during query building or execution - * @deprecated Deprecated in favor of {@link #sendSync()} - */ - @Deprecated - int executeSync(); -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/ParamBuilder.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/ParamBuilder.java deleted file mode 100644 index 532f55e8..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/ParamBuilder.java +++ /dev/null @@ -1,1303 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.util; - -import de.chojo.sadu.conversion.ArrayConverter; -import de.chojo.sadu.conversion.UUIDConverter; -import de.chojo.sadu.types.SqlType; -import org.jetbrains.annotations.NotNull; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.JDBCType; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLType; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.sql.Types; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.ZonedDateTime; -import java.util.Collection; -import java.util.UUID; - -/** - * A class wrapping a {@link PreparedStatement} and allows to set the values with a builder pattern. - *

- * The index of the argument will be moved automatically - */ -@SuppressWarnings("unused") -public class ParamBuilder { - private final PreparedStatement stmt; - private int index = 1; - - /** - * Create a new ParamBuilder - * - * @param stmt statement to wrap - */ - public ParamBuilder(PreparedStatement stmt) { - this.stmt = stmt; - } - - private int index() { - return index++; - } - - /** - * Sets the designated parameter to SQL {@code NULL}. - * - *

Note: You must specify the parameter's SQL type. - * - * @param sqlType the SQL type code defined in {@code java.sql.Types} - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if {@code sqlType} is - * a {@code ARRAY}, {@code BLOB}, {@code CLOB}, - * {@code DATALINK}, {@code JAVA_OBJECT}, {@code NCHAR}, - * {@code NCLOB}, {@code NVARCHAR}, {@code LONGNVARCHAR}, - * {@code REF}, {@code ROWID}, {@code SQLXML} - * or {@code STRUCT} data type and the JDBC driver does not support - * this data type - */ - public ParamBuilder setNull(int sqlType) throws SQLException { - stmt.setNull(index(), sqlType); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Array} object. - * The driver converts this to an SQL {@code ARRAY} value when it - * sends it to the database. - * - * @param list A {@code Collection} that maps an SQL {@code ARRAY} value - * @param type The type of the sql column. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setArray(@NotNull Collection list, SqlType type) throws SQLException { - stmt.setArray(index(), ArrayConverter.toSqlArray(stmt.getConnection(), type, list)); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Array} object. - * The driver converts this to an SQL {@code ARRAY} value when it - * sends it to the database. - * - * @param array An {@code Array} object that maps an SQL {@code ARRAY} value - * @param type An - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setArray(@NotNull Object[] array, SqlType type) throws SQLException { - stmt.setArray(index(), ArrayConverter.toSqlArray(stmt.getConnection(), type, array)); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code boolean} value. - * The driver converts this - * to an SQL {@code BIT} or {@code BOOLEAN} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; - * if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setBoolean(Boolean x) throws SQLException { - if (x == null) return setNull(Types.BOOLEAN); - stmt.setBoolean(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code byte} value. - * The driver converts this - * to an SQL {@code TINYINT} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setByte(Byte x) throws SQLException { - if (x == null) return setNull(Types.BIT); - stmt.setByte(index(), x); - return this; - } - - /** - * Sets the uuid as a byte value. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setUuidAsBytes(UUID x) throws SQLException { - if (x == null) return setNull(Types.BIT); - stmt.setBytes(index(), UUIDConverter.convert(x)); - return this; - } - - /** - * Sets the uuid as a string value. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setUuidAsString(UUID x) throws SQLException { - if (x == null) return setNull(Types.BIT); - stmt.setString(index(), x.toString()); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code short} value. - * The driver converts this - * to an SQL {@code SMALLINT} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setShort(Short x) throws SQLException { - if (x == null) return setNull(Types.INTEGER); - stmt.setShort(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code int} value. - * The driver converts this - * to an SQL {@code INTEGER} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setInt(Integer x) throws SQLException { - if (x == null) return setNull(Types.INTEGER); - stmt.setInt(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code long} value. - * The driver converts this - * to an SQL {@code BIGINT} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setLong(Long x) throws SQLException { - if (x == null) return setNull(Types.BIGINT); - stmt.setLong(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code float} value. - * The driver converts this - * to an SQL {@code REAL} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setFloat(Float x) throws SQLException { - if (x == null) return setNull(Types.FLOAT); - stmt.setFloat(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code double} value. - * The driver converts this - * to an SQL {@code DOUBLE} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setDouble(Double x) throws SQLException { - if (x == null) return setNull(Types.DOUBLE); - stmt.setDouble(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.math.BigDecimal} value. - * The driver converts this to an SQL {@code NUMERIC} value when - * it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setBigDecimal(BigDecimal x) throws SQLException { - if (x == null) return setNull(Types.DECIMAL); - stmt.setBigDecimal(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code String} value. - * The driver converts this - * to an SQL {@code VARCHAR} or {@code LONGVARCHAR} value - * (depending on the argument's - * size relative to the driver's limits on {@code VARCHAR} values) - * when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setString(String x) throws SQLException { - if (x == null) return setNull(Types.VARCHAR); - stmt.setString(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given Java {@code Enum} name value. - * The driver converts this - * to an SQL {@code VARCHAR} or {@code LONGVARCHAR} value - * (depending on the argument's - * size relative to the driver's limits on {@code VARCHAR} values) - * when it sends it to the database. - * - * @param x the parameter value - * @param Type of enum - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public > ParamBuilder setEnum(T x) throws SQLException { - if (x == null) return setNull(Types.VARCHAR); - stmt.setString(index(), x.name()); - return this; - } - - /** - * Sets the designated parameter to the given Java array of bytes. The driver converts - * this to an SQL {@code VARBINARY} or {@code LONGVARBINARY} - * (depending on the argument's size relative to the driver's limits on - * {@code VARBINARY} values) when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setBytes(byte[] x) throws SQLException { - if (x == null) return setNull(Types.BINARY); - stmt.setBytes(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Date} value - * using the default time zone of the virtual machine that is running - * the application. - * The driver converts this - * to an SQL {@code DATE} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setDate(Date x) throws SQLException { - if (x == null) return setNull(Types.DATE); - stmt.setDate(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.LocalDate} value - * using the default time zone of the virtual machine that is running - * the application. - * The driver converts this - * to an SQL {@code DATE} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setLocalDate(LocalDate x) throws SQLException { - if (x == null ) return setNull(Types.DATE); - stmt.setDate(index(), Date.valueOf(x)); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Time} value. - * The driver converts this - * to an SQL {@code TIME} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setTime(Time x) throws SQLException { - if (x == null) return setNull(Types.TIME); - stmt.setTime(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.LocalTime} value. - * The driver converts this - * to an SQL {@code TIME} value when it sends it to the database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setLocalTime(LocalTime x) throws SQLException { - if (x == null) return setNull(Types.TIME); - stmt.setTime(index(), Time.valueOf(x)); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Timestamp} value. - * The driver - * converts this to an SQL {@code TIMESTAMP} value when it sends it to the - * database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setTimestamp(Timestamp x) throws SQLException { - if (x == null) return setNull(Types.TIMESTAMP); - stmt.setTimestamp(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.LocalDateTime} value. - * The driver - * converts this to an SQL {@code TIMESTAMP} value when it sends it to the - * database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setLocalDateTime(LocalDateTime x) throws SQLException { - if (x == null) return setNull(Types.TIMESTAMP); - stmt.setTimestamp(index(), Timestamp.valueOf(x)); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.ZonedDateTime} value. - * The driver - * converts this to an SQL {@code TIMESTAMP} value when it sends it to the - * database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setZonedDateTime(ZonedDateTime x) throws SQLException { - if (x == null) return setNull(Types.TIMESTAMP); - stmt.setTimestamp(index(), Timestamp.valueOf(x.toLocalDateTime())); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.OffsetDateTime} value. - * The driver - * converts this to an SQL {@code TIMESTAMP} value when it sends it to the - * database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setOffsetDateTime(OffsetDateTime x) throws SQLException { - if (x == null) return setNull(Types.TIMESTAMP); - stmt.setTimestamp(index(), Timestamp.valueOf(x.toLocalDateTime())); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.time.OffsetTime} value. - * The driver - * converts this to an SQL {@code TIMESTAMP} value when it sends it to the - * database. - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setOffsetTime(OffsetTime x) throws SQLException { - if (x == null) return setNull(Types.TIME); - stmt.setTime(index(), Time.valueOf(x.toLocalTime())); - return this; - } - - /** - * Sets the designated parameter to the given input stream, which will have - * the specified number of bytes. - * When a very large ASCII value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream}. Data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from ASCII to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param x the Java input stream that contains the ASCII parameter value - * @param length the number of bytes in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setAsciiStream(InputStream x, int length) throws SQLException { - if (x == null) return setNull(Types.VARCHAR); - stmt.setAsciiStream(index(), x, length); - return this; - } - - /** - * Sets the designated parameter to the given input stream, which will have - * the specified number of bytes. - * When a very large binary value is input to a {@code LONGVARBINARY} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream} object. The data will be read from the - * stream as needed until end-of-file is reached. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param x the java input stream which contains the binary parameter value - * @param length the number of bytes in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - */ - public ParamBuilder setBinaryStream(InputStream x, int length) throws SQLException { - if (x == null) return setNull(Types.VARCHAR); - stmt.setBinaryStream(index(), x, length); - return this; - } - - /** - * Sets the value of the designated parameter with the given object. - *

- * This method is similar to {@link #setObject(Object x, int targetSqlType, int scaleOrLength)}, - * except that it assumes a scale of zero. - * - * @param x the object containing the input parameter value - * @param targetSqlType the SQL type (as defined in java.sql.Types) to be - * sent to the database - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or this - * method is called on a closed PreparedStatement - * @throws SQLFeatureNotSupportedException if - * the JDBC driver does not support the specified targetSqlType - * @see Types - */ - public ParamBuilder setObject(Object x, int targetSqlType) throws SQLException { - if (x == null) return setNull(targetSqlType); - stmt.setObject(index(), x, targetSqlType); - return this; - } - - /** - *

Sets the value of the designated parameter using the given object. - * - *

The JDBC specification specifies a standard mapping from - * Java {@code Object} types to SQL types. The given argument - * will be converted to the corresponding SQL type before being - * sent to the database. - * - *

Note that this method may be used to pass database-specific - * abstract data types, by using a driver-specific Java type. - *

- * If the object is of a class implementing the interface {@code SQLData}, - * the JDBC driver should call the method {@code SQLData.writeSQL} - * to write it to the SQL data stream. - * If, on the other hand, the object is of a class implementing - * {@code Ref}, {@code Blob}, {@code Clob}, {@code NClob}, - * {@code Struct}, {@code java.net.URL}, {@code RowId}, {@code SQLXML} - * or {@code Array}, the driver should pass it to the database as a - * value of the corresponding SQL type. - *

- * Note: Not all databases allow for a non-typed Null to be sent to - * the backend. For maximum portability, the {@code setNull} or the - * {@code setObject(Object x, int sqlType)} - * method should be used - * instead of {@code setObject(Object x)}. - *

- * Note: This method throws an exception if there is an ambiguity, for example, if the - * object is of a class implementing more than one of the interfaces named above. - * - * @param x the object containing the input parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; - * this method is called on a closed {@code PreparedStatement} - * or the type of the given object is ambiguous - */ - public ParamBuilder setObject(Object x) throws SQLException { - stmt.setObject(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code Reader} - * object, which is the given number of characters long. - * When a very large UNICODE value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.Reader} object. The data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from UNICODE to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param reader the {@code java.io.Reader} object that contains the - * Unicode data - * @param length the number of characters in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @since 1.2 - */ - public ParamBuilder setCharacterStream(Reader reader, int length) throws SQLException { - if (reader == null) return setNull(Types.VARCHAR); - stmt.setCharacterStream(index(), reader, length); - return this; - } - - /** - * Sets the designated parameter to the given - * {@code REF(<structured-type>)} value. - * The driver converts this to an SQL {@code REF} value when it - * sends it to the database. - * - * @param x an SQL {@code REF} value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setRef(Ref x) throws SQLException { - if (x == null) return setNull(Types.REF); - stmt.setRef(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Blob} object. - * The driver converts this to an SQL {@code BLOB} value when it - * sends it to the database. - * - * @param x a {@code Blob} object that maps an SQL {@code BLOB} value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setBlob(Blob x) throws SQLException { - if (x == null) return setNull(Types.BLOB); - stmt.setBlob(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Clob} object. - * The driver converts this to an SQL {@code CLOB} value when it - * sends it to the database. - * - * @param x a {@code Clob} object that maps an SQL {@code CLOB} value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setClob(Clob x) throws SQLException { - if (x == null) return setNull(Types.CLOB); - stmt.setClob(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.Array} object. - * The driver converts this to an SQL {@code ARRAY} value when it - * sends it to the database. - * - * @param x an {@code Array} object that maps an SQL {@code ARRAY} value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.2 - */ - public ParamBuilder setArray(Array x) throws SQLException { - if (x == null) return setNull(Types.ARRAY); - stmt.setArray(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.net.URL} value. - * The driver converts this to an SQL {@code DATALINK} value - * when it sends it to the database. - * - * @param x the {@code java.net.URL} object to be set - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.4 - */ - public ParamBuilder setURL(URL x) throws SQLException { - if (x == null) return setNull(Types.DATALINK); - stmt.setURL(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.RowId} object. The - * driver converts this to a SQL {@code ROWID} value when it sends it - * to the database - * - * @param x the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setRowId(RowId x) throws SQLException { - if (x == null) return setNull(Types.ROWID); - stmt.setRowId(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code String} object. - * The driver converts this to a SQL {@code NCHAR} or - * {@code NVARCHAR} or {@code LONGNVARCHAR} value - * (depending on the argument's - * size relative to the driver's limits on {@code NVARCHAR} values) - * when it sends it to the database. - * - * @param value the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if the driver does not support national - * character sets; if the driver can detect that a data conversion - * error could occur; if a database access error occurs; or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNString(String value) throws SQLException { - if (value == null) return setNull(Types.NVARCHAR); - stmt.setNString(index(), value); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. The - * {@code Reader} reads the data till end-of-file is reached. The - * driver does the necessary conversion from Java character format to - * the national character set in the database. - * - * @param value the parameter value - * @param length the number of characters in the parameter data. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if the driver does not support national - * character sets; if the driver can detect that a data conversion - * error could occur; if a database access error occurs; or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNCharacterStream(Reader value, long length) throws SQLException { - if (value == null) return setNull(Types.VARCHAR); - stmt.setNCharacterStream(index(), value, length); - return this; - } - - /** - * Sets the designated parameter to a {@code java.sql.NClob} object. The driver converts this to a - * SQL {@code NCLOB} value when it sends it to the database. - * - * @param value the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if the driver does not support national - * character sets; if the driver can detect that a data conversion - * error could occur; if a database access error occurs; or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNClob(NClob value) throws SQLException { - if (value == null) return setNull(Types.NCLOB); - stmt.setNClob(index(), value); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. The reader must contain the number - * of characters specified by length otherwise a {@code SQLException} will be - * generated when the {@code PreparedStatement} is executed. - * This method differs from the {@code setCharacterStream (int, Reader, int)} method - * because it informs the driver that the parameter value should be sent to - * the server as a {@code CLOB}. When the {@code setCharacterStream} method is used, the - * driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGVARCHAR} or a {@code CLOB} - * - * @param reader An object that contains the data to set the parameter value to. - * @param length the number of characters in the parameter data. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; this method is called on - * a closed {@code PreparedStatement} or if the length specified is less than zero. - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setClob(Reader reader, long length) throws SQLException { - if (reader == null) return setNull(Types.VARCHAR); - stmt.setClob(index(), reader, length); - return this; - } - - /** - * Sets the designated parameter to a {@code InputStream} object. - * The {@code Inputstream} must contain the number - * of characters specified by length otherwise a {@code SQLException} will be - * generated when the {@code PreparedStatement} is executed. - * This method differs from the {@code setBinaryStream (int, InputStream, int)} - * method because it informs the driver that the parameter value should be - * sent to the server as a {@code BLOB}. When the {@code setBinaryStream} method is used, - * the driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGVARBINARY} or a {@code BLOB} - * - * @param inputStream An object that contains the data to set the parameter - * value to. - * @param length the number of bytes in the parameter data. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; - * this method is called on a closed {@code PreparedStatement}; - * if the length specified - * is less than zero or if the number of bytes in the {@code InputStream} does not match - * the specified length. - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setBlob(InputStream inputStream, long length) throws SQLException { - if (inputStream == null) return setNull(Types.VARCHAR); - stmt.setBlob(index(), inputStream, length); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. The reader must contain the number - * of characters specified by length otherwise a {@code SQLException} will be - * generated when the {@code PreparedStatement} is executed. - * This method differs from the {@code setCharacterStream (int, Reader, int)} method - * because it informs the driver that the parameter value should be sent to - * the server as a {@code NCLOB}. When the {@code setCharacterStream} method is used, the - * driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGNVARCHAR} or a {@code NCLOB} - * - * @param reader An object that contains the data to set the parameter value to. - * @param length the number of characters in the parameter data. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if the length specified is less than zero; - * if the driver does not support national character sets; - * if the driver can detect that a data conversion - * error could occur; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNClob(Reader reader, long length) throws SQLException { - if (reader == null) return setNull(Types.VARCHAR); - stmt.setNClob(index(), reader, length); - return this; - } - - /** - * Sets the designated parameter to the given {@code java.sql.SQLXML} object. - * The driver converts this to an - * SQL {@code XML} value when it sends it to the database. - * - * @param xmlObject a {@code SQLXML} object that maps an SQL {@code XML} value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; - * this method is called on a closed {@code PreparedStatement} - * or the {@code java.xml.transform.Result}, - * {@code Writer} or {@code OutputStream} has not been closed for - * the {@code SQLXML} object - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setSQLXML(SQLXML xmlObject) throws SQLException { - if (xmlObject == null) return setNull(Types.SQLXML); - stmt.setSQLXML(index(), xmlObject); - return this; - } - - /** - *

Sets the value of the designated parameter with the given object. - *

- * If the second argument is an {@code InputStream} then the stream must contain - * the number of bytes specified by scaleOrLength. If the second argument is a - * {@code Reader} then the reader must contain the number of characters specified - * by scaleOrLength. If these conditions are not true the driver will generate a - * {@code SQLException} when the prepared statement is executed. - * - *

The given Java object will be converted to the given targetSqlType - * before being sent to the database. - *

- * If the object has a custom mapping (is of a class implementing the - * interface {@code SQLData}), - * the JDBC driver should call the method {@code SQLData.writeSQL} to - * write it to the SQL data stream. - * If, on the other hand, the object is of a class implementing - * {@code Ref}, {@code Blob}, {@code Clob}, {@code NClob}, - * {@code Struct}, {@code java.net.URL}, - * or {@code Array}, the driver should pass it to the database as a - * value of the corresponding SQL type. - * - *

Note that this method may be used to pass database-specific - * abstract data types. - * - * @param x the object containing the input parameter value - * @param targetSqlType the SQL type (as defined in java.sql.Types) to be - * sent to the database. The scale argument may further qualify this type. - * @param scaleOrLength for {@code java.sql.Types.DECIMAL} - * or {@code java.sql.Types.NUMERIC types}, - * this is the number of digits after the decimal point. For - * Java Object types {@code InputStream} and {@code Reader}, - * this is the length - * of the data in the stream or reader. For all other types, - * this value will be ignored. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; - * this method is called on a closed {@code PreparedStatement} or - * if the Java Object specified by x is an InputStream - * or Reader object and the value of the scale parameter is less - * than zero - * @throws SQLFeatureNotSupportedException if - * the JDBC driver does not support the specified targetSqlType - * @see Types - */ - public ParamBuilder setObject(Object x, int targetSqlType, int scaleOrLength) throws SQLException { - if (x == null) return setNull(targetSqlType); - stmt.setObject(index(), x, targetSqlType, scaleOrLength); - return this; - } - - /** - * Sets the designated parameter to the given input stream, which will have - * the specified number of bytes. - * When a very large ASCII value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream}. Data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from ASCII to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param x the Java input stream that contains the ASCII parameter value - * @param length the number of bytes in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @since 1.6 - */ - public ParamBuilder setAsciiStream(InputStream x, long length) throws SQLException { - if (x == null) return setNull(Types.VARCHAR); - stmt.setAsciiStream(index(), x, length); - return this; - } - - /** - * Sets the designated parameter to the given input stream, which will have - * the specified number of bytes. - * When a very large binary value is input to a {@code LONGVARBINARY} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream} object. The data will be read from the - * stream as needed until end-of-file is reached. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param x the java input stream which contains the binary parameter value - * @param length the number of bytes in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @since 1.6 - */ - public ParamBuilder setBinaryStream(InputStream x, long length) throws SQLException { - if (x == null) return setNull(Types.LONGVARBINARY); - stmt.setBinaryStream(index(), x, length); - return this; - } - - /** - * Sets the designated parameter to the given {@code Reader} - * object, which is the given number of characters long. - * When a very large UNICODE value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.Reader} object. The data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from UNICODE to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - * - * @param reader the {@code java.io.Reader} object that contains the - * Unicode data - * @param length the number of characters in the stream - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @since 1.6 - */ - public ParamBuilder setCharacterStream(Reader reader, long length) throws SQLException { - if (reader == null) return setNull(Types.LONGVARCHAR); - stmt.setCharacterStream(index(), reader, length); - return this; - } - - /** - * Sets the designated parameter to the given input stream. - * When a very large ASCII value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream}. Data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from ASCII to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setAsciiStream} which takes a length parameter. - * - * @param x the Java input stream that contains the ASCII parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setAsciiStream(InputStream x) throws SQLException { - if (x == null) return setNull(Types.LONGVARCHAR); - stmt.setAsciiStream(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given input stream. - * When a very large binary value is input to a {@code LONGVARBINARY} - * parameter, it may be more practical to send it via a - * {@code java.io.InputStream} object. The data will be read from the - * stream as needed until end-of-file is reached. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setBinaryStream} which takes a length parameter. - * - * @param x the java input stream which contains the binary parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setBinaryStream(InputStream x) throws SQLException { - if (x == null) return setNull(Types.LONGVARBINARY); - stmt.setBinaryStream(index(), x); - return this; - } - - /** - * Sets the designated parameter to the given {@code Reader} - * object. - * When a very large UNICODE value is input to a {@code LONGVARCHAR} - * parameter, it may be more practical to send it via a - * {@code java.io.Reader} object. The data will be read from the stream - * as needed until end-of-file is reached. The JDBC driver will - * do any necessary conversion from UNICODE to the database char format. - * - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setCharacterStream} which takes a length parameter. - * - * @param reader the {@code java.io.Reader} object that contains the - * Unicode data - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setCharacterStream(Reader reader) throws SQLException { - if (reader == null) return setNull(Types.LONGVARCHAR); - stmt.setCharacterStream(index(), reader); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. The - * {@code Reader} reads the data till end-of-file is reached. The - * driver does the necessary conversion from Java character format to - * the national character set in the database. - *

Note: This stream object can either be a standard - * Java stream object or your own subclass that implements the - * standard interface. - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setNCharacterStream} which takes a length parameter. - * - * @param value the parameter value - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if the driver does not support national - * character sets; if the driver can detect that a data conversion - * error could occur; if a database access error occurs; or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNCharacterStream(Reader value) throws SQLException { - if (value == null) return setNull(Types.VARCHAR); - stmt.setNCharacterStream(index(), value); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. - * This method differs from the {@code setCharacterStream (int, Reader)} method - * because it informs the driver that the parameter value should be sent to - * the server as a {@code CLOB}. When the {@code setCharacterStream} method is used, the - * driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGVARCHAR} or a {@code CLOB} - * - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setClob} which takes a length parameter. - * - * @param reader An object that contains the data to set the parameter value to. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; this method is called on - * a closed {@code PreparedStatement}or if parameterIndex does not correspond to a parameter - * marker in the SQL statement - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setClob(Reader reader) throws SQLException { - if (reader == null) return setNull(Types.CLOB); - stmt.setClob(index(), reader); - return this; - } - - /** - * Sets the designated parameter to a {@code InputStream} object. - * This method differs from the {@code setBinaryStream (int, InputStream)} - * method because it informs the driver that the parameter value should be - * sent to the server as a {@code BLOB}. When the {@code setBinaryStream} method is used, - * the driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGVARBINARY} or a {@code BLOB} - * - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setBlob} which takes a length parameter. - * - * @param inputStream An object that contains the data to set the parameter - * value to. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; if a database access error occurs; - * this method is called on a closed {@code PreparedStatement} or - * if parameterIndex does not correspond - * to a parameter marker in the SQL statement, - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setBlob(InputStream inputStream) throws SQLException { - if (inputStream == null) return setNull(Types.VARCHAR); - stmt.setBlob(index(), inputStream); - return this; - } - - /** - * Sets the designated parameter to a {@code Reader} object. - * This method differs from the {@code setCharacterStream (int, Reader)} method - * because it informs the driver that the parameter value should be sent to - * the server as a {@code NCLOB}. When the {@code setCharacterStream} method is used, the - * driver may have to do extra work to determine whether the parameter - * data should be sent to the server as a {@code LONGNVARCHAR} or a {@code NCLOB} - *

Note: Consult your JDBC driver documentation to determine if - * it might be more efficient to use a version of - * {@code setNClob} which takes a length parameter. - * - * @param reader An object that contains the data to set the parameter value to. - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a parameter - * marker in the SQL statement; - * if the driver does not support national character sets; - * if the driver can detect that a data conversion - * error could occur; if a database access error occurs or - * this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method - * @since 1.6 - */ - public ParamBuilder setNClob(Reader reader) throws SQLException { - if (reader == null) return setNull(Types.VARCHAR); - stmt.setNClob(index(), reader); - return this; - } - - /** - * Sets the value of the designated parameter with the given object. - *

- * This method is similar to {@link #setObject(Object, int, int)}, - * except that it assumes a scale of zero. - *

- * The default implementation will throw {@code SQLFeatureNotSupportedException} - * - * @param x the object containing the input parameter value - * @param targetSqlType the SQL type to be sent to the database - * @return ParamBuilder with values set. - * @throws SQLException if parameterIndex does not correspond to a - * parameter marker in the SQL statement; if a database access error occurs - * or this method is called on a closed {@code PreparedStatement} - * @throws SQLFeatureNotSupportedException if - * the JDBC driver does not support the specified targetSqlType - * @see JDBCType - * @see SQLType - * @since 1.8 - */ - public ParamBuilder setObject(Object x, SQLType targetSqlType) throws SQLException { - if (x == null) return setNull(targetSqlType.getVendorTypeNumber()); - stmt.setObject(index(), x, targetSqlType); - return this; - } -} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/UpdateResult.java b/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/UpdateResult.java deleted file mode 100644 index fc95a79d..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/wrapper/util/UpdateResult.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.util; - -import de.chojo.sadu.wrapper.stage.InsertStage; -import de.chojo.sadu.wrapper.stage.UpdateStage; - -/** - * Represent the result of an {@link UpdateStage} or {@link InsertStage} - */ -public class UpdateResult { - private final int rows; - - /** - * Creates a new update result - * - * @param rows changed rows - */ - public UpdateResult(int rows) { - this.rows = rows; - } - - /** - * The amount of affected rows. - * - * @return changed rows - */ - public int rows() { - return rows; - } - - /** - * Checks if something has changed. - * - * @return true if something has changed - */ - public boolean changed() { - return rows > 0; - } -} diff --git a/sadu-queries2/src/main/java/module-info.java b/sadu-queries/src/main/java/module-info.java similarity index 95% rename from sadu-queries2/src/main/java/module-info.java rename to sadu-queries/src/main/java/module-info.java index 9a268781..c927a7bd 100644 --- a/sadu-queries2/src/main/java/module-info.java +++ b/sadu-queries/src/main/java/module-info.java @@ -1,5 +1,4 @@ -module sadu.sadu.queries2.main { - requires java.sql; +module sadu.sadu.queries.main { requires transitive sadu.sadu.core.main; requires transitive sadu.sadu.mapper.main; diff --git a/sadu-queries/src/test/java/de/chojo/sadu/MariaDbDatabase.java b/sadu-queries/src/test/java/de/chojo/sadu/MariaDbDatabase.java deleted file mode 100644 index 9e59d482..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/MariaDbDatabase.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu; - -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.DockerImageName; - -public class MariaDbDatabase { - public static GenericContainer createContainer(String user/*ignored*/, String pw) { - GenericContainer self = new GenericContainer<>(DockerImageName.parse("mariadb:latest")) - .withExposedPorts(3306) - .withEnv("MARIADB_ROOT_PASSWORD", pw) - .waitingFor(Wait.forLogMessage(".*mariadbd: ready for connections\\..*", 2)); - self.start(); - return self; - } -} diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java b/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java similarity index 96% rename from sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java rename to sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java index 95b7fc24..24c41331 100644 --- a/sadu-queries2/src/test/java/de/chojo/sadu/PostgresDatabase.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java @@ -6,7 +6,7 @@ package de.chojo.sadu; -import de.chojo.sadu.databases.PostgreSql; +import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; import de.chojo.sadu.updater.SqlUpdater; import org.testcontainers.containers.GenericContainer; diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java similarity index 100% rename from sadu-queries2/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java rename to sadu-queries/src/test/java/de/chojo/sadu/queries/TokenizedQueryTest.java diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java similarity index 96% rename from sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java rename to sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java index c19e6993..834c53c6 100644 --- a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java @@ -7,7 +7,7 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; import de.chojo.sadu.mapper.rowmapper.RowMapper; import de.chojo.sadu.queries.api.call.Call; @@ -62,7 +62,7 @@ public void retrieveAllDirectly() { List users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") .single(call().bind(1).bind("name", "lilly")) .map(User.map()) - .allAndGet(); + .all(); Assertions.assertEquals(1, users.size()); } @@ -71,7 +71,7 @@ public void mapViaRegistry() { List users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name") .single(call().bind(1).bind("name", "lilly")) .mapAs(User.class) - .allAndGet(); + .all(); Assertions.assertEquals(1, users.size()); } @@ -80,7 +80,7 @@ public void retrieveAllDirectlyNoFilter() { List users = query.query("SELECT * FROM users") .single(Calls.empty()) .map(User.map()) - .allAndGet(); + .all(); Assertions.assertEquals(2, users.size()); } @@ -92,7 +92,7 @@ public void retrieveFirstDirectly() { Optional user = query.query("SELECT * FROM users where id = :id") .single(Call.of().bind("id", 1)) .map(User.map()) - .oneAndGet(); + .first(); } @Test @@ -106,7 +106,7 @@ public void retrieveAllMatching() { .query("SELECT * FROM users WHERE uuid = :uuid::uuid") .single(storage -> call().bind("uuid", storage.getAs("user", User.class).get().uuid(), AS_STRING).asSingleCall()) .map(User.map()) - .all(); + .allResults(); Assertions.assertEquals(1, usersResult.result().size()); } diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java similarity index 97% rename from sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java rename to sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java index bad68736..ef084759 100644 --- a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java @@ -7,7 +7,7 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; import de.chojo.sadu.queries.api.call.calls.Calls; import de.chojo.sadu.queries.api.results.writing.ManipulationResult; @@ -63,7 +63,7 @@ public void example() { List users = query.query("SELECT * FROM users") .single(Calls.empty()) .map(User.map()) - .allAndGet(); + .all(); // Make sure that the first insert was not commited Assertions.assertEquals(0, users.size()); diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java similarity index 98% rename from sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java rename to sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java index 632686bb..49e57d7e 100644 --- a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java @@ -7,7 +7,7 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.mapper.PostgresqlMapper; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; diff --git a/sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/dao/User.java similarity index 100% rename from sadu-queries2/src/test/java/de/chojo/sadu/queries/examples/dao/User.java rename to sadu-queries/src/test/java/de/chojo/sadu/queries/examples/dao/User.java diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/QueryBuilderTest.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/QueryBuilderTest.java deleted file mode 100644 index 1cae8316..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/QueryBuilderTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper; - -import com.zaxxer.hikari.HikariDataSource; -import de.chojo.sadu.databases.MariaDb; -import de.chojo.sadu.datasource.DataSourceCreator; -import org.intellij.lang.annotations.Language; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; - -import java.io.IOException; -import java.util.List; - -import static de.chojo.sadu.MariaDbDatabase.createContainer; - -class QueryBuilderTest { - private static GenericContainer db; - private HikariDataSource source; - @Language("mariadb") - private static final String CREATE_TABLE = """ - CREATE TABLE IF NOT EXISTS test( - id INTEGER PRIMARY KEY AUTO_INCREMENT, - user_name TEXT NOT NULL - ) - """; - @Language("mariadb") - private static final String INSERT_SINGLE = "INSERT INTO test(user_name) VALUES(?)"; - @Language("mariadb") - private static final String INSERT_MULTI = "INSERT INTO test(user_name) VALUES(?),(?),(?)"; - - @BeforeAll - public static void setup() { - db = createContainer("root", "root"); - QueryBuilderConfig.setDefault(QueryBuilderConfig.builder().throwExceptions().build()); - } - - @BeforeEach - public void setupDB() { - source = DataSourceCreator.create(MariaDb.get()) - .configure(config -> config.host(db.getHost()).port(db.getFirstMappedPort()).database("mysql")) - .create() - .usingUsername("root") - .usingPassword("root") - .build(); - } - - @AfterEach - public void after() throws IOException { - source.close(); - } - - @Test - public void getKey() { - QueryBuilder.builder(source).defaultConfig() - .queryWithoutParams(CREATE_TABLE) - .update() - .send() - .join(); - - long l = QueryBuilder.builder(source).defaultConfig() - .query(INSERT_SINGLE) - .parameter(stmt -> stmt.setString("test")) - .insert() - .keySync() - .orElse(-1L); - - Assertions.assertNotEquals(-1, l); - } - - @Test - public void getKeys() { - QueryBuilder.builder(source).defaultConfig() - .queryWithoutParams(CREATE_TABLE) - .update() - .send() - .join(); - - List l = QueryBuilder.builder(source).defaultConfig() - .query(INSERT_MULTI) - .parameter(stmt -> stmt.setString("test").setString("test").setString("test")) - .insert() - .keysSync(); - - // Only the last key is returned. Multiple keys would be returned if there would be multiple keys in a single row. - Assertions.assertEquals(1, l.size()); - } - -} diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Mapper.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Mapper.java deleted file mode 100644 index 147f1229..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Mapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.mapper; - -import de.chojo.sadu.mapper.rowmapper.RowMapper; - -public class Mapper { - public static final RowMapper wildcard = RowMapper.forClass(Result.class) - .mapper(row -> new Result(row.getInt("id"), - row.getString("result"))) - .build(); - - public static final RowMapper sparse = RowMapper.forClass(Result.class) - .mapper(row -> new Result(row.getInt("id"), - row.getString("result"))) - .addColumn("id") - .addColumn("result") - .build(); - public static final RowMapper full = RowMapper.forClass(Result.class) - .mapper(row -> new MetaResult(row.getInt("id"), - row.getString("result"), - row.getString("meta"))) - .addColumn("id") - .addColumn("result") - .addColumn("meta") - .build(); -} diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/MetaResult.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/MetaResult.java deleted file mode 100644 index 79d08595..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/MetaResult.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.mapper; - -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.Objects; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class MetaResult extends Result { - String meta; - - public MetaResult(int id, String result, String meta) { - super(id, result); - this.meta = meta; - } - - public static ResultSet fullResultSet() throws SQLException { - ResultSet resultSet = mock(ResultSet.class); - when(resultSet.getInt("id")).thenReturn(1); - when(resultSet.getString("result")).thenReturn("result"); - when(resultSet.getString("meta")).thenReturn("meta"); - - ResultSetMetaData meta = mock(ResultSetMetaData.class); - when(meta.getColumnCount()).thenReturn(3); - when(meta.getColumnLabel(1)).thenReturn("id"); - when(meta.getColumnLabel(2)).thenReturn("result"); - when(meta.getColumnLabel(3)).thenReturn("meta"); - - when(resultSet.getMetaData()).thenReturn(meta); - return resultSet; - } - - public static ResultSet sparseResultSet() throws SQLException { - ResultSet resultSet = mock(ResultSet.class); - when(resultSet.getInt("id")).thenReturn(1); - when(resultSet.getString("result")).thenReturn("result"); - - ResultSetMetaData meta = mock(ResultSetMetaData.class); - when(meta.getColumnCount()).thenReturn(2); - when(meta.getColumnLabel(1)).thenReturn("id"); - when(meta.getColumnLabel(2)).thenReturn("result"); - - when(resultSet.getMetaData()).thenReturn(meta); - return resultSet; - } - - public static ResultSet aliasedResultSet() throws SQLException { - ResultSet resultSet = mock(ResultSet.class); - when(resultSet.getInt("id")).thenReturn(1); - when(resultSet.getString("r_result")).thenReturn("result"); - - ResultSetMetaData meta = mock(ResultSetMetaData.class); - when(meta.getColumnCount()).thenReturn(2); - when(meta.getColumnLabel(1)).thenReturn("id"); - when(meta.getColumnLabel(2)).thenReturn("r_result"); - - when(resultSet.getMetaData()).thenReturn(meta); - return resultSet; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MetaResult)) return false; - - MetaResult metaResult1 = (MetaResult) o; - - if (id != metaResult1.id) return false; - if (!result.equals(metaResult1.result)) return false; - return Objects.equals(meta, metaResult1.meta); - } - - @Override - public int hashCode() { - int result1 = id; - result1 = 31 * result1 + result.hashCode(); - result1 = 31 * result1 + (meta != null ? meta.hashCode() : 0); - return result1; - } - - @Override - public String toString() { - return "Result{id=%d, result='%s', meta='%s'}".formatted(id, result, meta); - } -} diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Result.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Result.java deleted file mode 100644 index fa8df474..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/Result.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.mapper; - -class Result { - int id; - String result; - - public Result(int id, String result) { - this.id = id; - this.result = result; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Result)) return false; - - Result result1 = (Result) o; - - if (id != result1.id) return false; - return result.equals(result1.result); - } - - @Override - public int hashCode() { - int result1 = id; - result1 = 31 * result1 + result.hashCode(); - return result1; - } - - @Override - public String toString() { - return "Result{id=%d, result='%s'}".formatted(id, result); - } -} diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperRegistryTest.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperRegistryTest.java deleted file mode 100644 index 2a0a2be9..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperRegistryTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.mapper; - -import de.chojo.sadu.mapper.MapperConfig; -import de.chojo.sadu.mapper.RowMapperRegistry; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class RowMapperRegistryTest { - static RowMapperRegistry rowMapperRegistry = new RowMapperRegistry(); - - @BeforeAll - static void setUp() { - rowMapperRegistry.register(Mapper.full, Mapper.sparse, Mapper.wildcard); - } - - @AfterEach - void tearDown() { - } - - @Test - void wildcard() throws SQLException { - var rowMapper = rowMapperRegistry.wildcard(Result.class); - assertTrue(rowMapper.isPresent()); - } - - @Test - void find() throws SQLException { - var rowMapper = rowMapperRegistry.find(Result.class, MetaResult.fullResultSet(), MapperConfig.DEFAULT); - assertTrue(rowMapper.isPresent()); - assertEquals(Mapper.full, rowMapper.get()); - - rowMapper = rowMapperRegistry.find(Result.class, MetaResult.sparseResultSet(), MapperConfig.DEFAULT); - assertTrue(rowMapper.isPresent()); - assertEquals(Mapper.sparse, rowMapper.get()); - - rowMapper = rowMapperRegistry.find(Result.class, MetaResult.aliasedResultSet(), - new MapperConfig() - .addAlias("result", "r_result") - .strict()); - assertTrue(rowMapper.isPresent()); - assertEquals(Mapper.sparse, rowMapper.get()); - } -} diff --git a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperTest.java b/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperTest.java deleted file mode 100644 index b85416e7..00000000 --- a/sadu-queries/src/test/java/de/chojo/sadu/wrapper/mapper/RowMapperTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.wrapper.mapper; - -import de.chojo.sadu.mapper.MapperConfig; -import de.chojo.sadu.mapper.RowMapperRegistry; -import de.chojo.sadu.mapper.rowmapper.RowMapper; -import de.chojo.sadu.wrapper.QueryBuilder; -import de.chojo.sadu.wrapper.util.Row; -import org.junit.jupiter.api.Test; - -import javax.sql.DataSource; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class RowMapperTest { - - @Test - void map() throws SQLException { - var map = Mapper.sparse.map(new Row(MetaResult.sparseResultSet(), MapperConfig.DEFAULT)); - assertEquals(Result.class, map.getClass(), "Polimorphism check failed."); - assertEquals(new Result(1, "result"), map); - - map = Mapper.full.map(new Row(MetaResult.fullResultSet(), MapperConfig.DEFAULT)); - assertEquals(MetaResult.class, map.getClass(), "Polimorphism check failed."); - assertEquals(new MetaResult(1, "result", "meta"), map); - - map = Mapper.full.map(new Row(MetaResult.aliasedResultSet(), new MapperConfig().addAlias("result", "r_result").strict())); - assertEquals(MetaResult.class, map.getClass(), "Polimorphism check failed."); - assertEquals(new Result(1, "result"), map); - } - - @Test - void isWildcard() { - assertTrue(Mapper.wildcard.isWildcard()); - assertFalse(Mapper.sparse.isWildcard()); - } - - @Test - void applicable() throws SQLException { - ResultSet resultSet = mock(ResultSet.class); - ResultSetMetaData meta = mock(ResultSetMetaData.class); - when(meta.getColumnCount()).thenReturn(3); - when(meta.getColumnLabel(1)).thenReturn("id"); - when(meta.getColumnLabel(2)).thenReturn("result"); - when(meta.getColumnLabel(3)).thenReturn("meta"); - when(resultSet.getMetaData()).thenReturn(meta); - - // Check strict mode. - // Mapper is not applicable since we would loose the meta column - assertEquals(0, Mapper.sparse.applicable(resultSet, new MapperConfig().strict())); - // Mapper is applicable - assertEquals(3, Mapper.full.applicable(resultSet, new MapperConfig().strict())); - // Check non strict mode. Mapper can apply two fields - assertEquals(2, Mapper.sparse.applicable(resultSet)); - assertEquals(3, Mapper.full.applicable(resultSet)); - } - - void syntaxExample() { - DataSource source = null; - -// Create a row mapper for the Result class with three different colums - RowMapper fullMapper = RowMapper.forClass(Result.class) - // Define how the row should be mapped - .mapper(row -> new MetaResult(row.getInt("id"), - row.getString("result"), - row.getString("meta"))) - // define the column names - .addColumns("id", "result", "meta") - .build(); - -// Allows polymorphism - RowMapper sparseMapper = RowMapper.forClass(Result.class) - // Define how the row should be mapped - .mapper(row -> new Result(row.getInt("id"), - row.getString("result"))) - // define the column names - .addColumns("id", "result") - .build(); - -// Register the mapper - RowMapperRegistry rowMapperRegistry = new RowMapperRegistry().register(fullMapper, sparseMapper); - -// Retrieves a list of MetaResults - List metaResults = QueryBuilder.builder(source, Result.class) - .defaultConfig(config -> config.rowMappers(rowMapperRegistry)) - .query("SELECT id, result, meta FROM results") - .emptyParams() - // Call map instead of read rows. This will let the query builder determine the type by itself. - .map() - .allSync(); - - -// Retrieves a list of Results - List results = QueryBuilder.builder(source, Result.class) - .defaultConfig(config -> config.rowMappers(rowMapperRegistry)) - .query("SELECT id, result FROM results") - .emptyParams() - // Call map instead of read rows. This will let the query builder determine the type by itself. - .map() - .allSync(); - -// Allows setting of an alias for a column without the need of creating a new mapper - results = QueryBuilder.builder(source, Result.class) - .defaultConfig(config -> config.rowMappers(rowMapperRegistry)) - .query("SELECT id, result as r_result FROM results") - .emptyParams() - // Call map instead of read rows. We map the column result to r_result when it gets requested. - .map(new MapperConfig().addAlias("result", "r_result").strict()) - .allSync(); - } -} diff --git a/sadu-queries2/src/test/resources/database/postgresql/1/setup.sql b/sadu-queries/src/test/resources/database/postgresql/1/setup.sql similarity index 100% rename from sadu-queries2/src/test/resources/database/postgresql/1/setup.sql rename to sadu-queries/src/test/resources/database/postgresql/1/setup.sql diff --git a/sadu-queries2/src/test/resources/database/version b/sadu-queries/src/test/resources/database/version similarity index 100% rename from sadu-queries2/src/test/resources/database/version rename to sadu-queries/src/test/resources/database/version diff --git a/sadu-queries2/build.gradle.kts b/sadu-queries2/build.gradle.kts deleted file mode 100644 index 5e59d3e4..00000000 --- a/sadu-queries2/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -dependencies { - api(project(":sadu-core")) - api(project(":sadu-mapper")) - testImplementation("org.postgresql", "postgresql", "42.7.1") - testImplementation(testlibs.bundles.junit) - testImplementation(project(":sadu-datasource")) - testImplementation(project(":sadu-postgresql")) - - testImplementation(testlibs.bundles.database.postgres) - testImplementation(testlibs.slf4j.noop) -} diff --git a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java b/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java deleted file mode 100644 index 6c5fe17e..00000000 --- a/sadu-queries2/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * - * Copyright (C) RainbowDashLabs and Contributor - */ - -package de.chojo.sadu.queries.call.adapter; - -import de.chojo.sadu.queries.api.call.adapter.Adapter; -import de.chojo.sadu.types.SqlType; - -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.RowId; -import java.sql.Time; -import java.sql.Timestamp; -import java.sql.Types; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.ZonedDateTime; -import java.util.Collection; - -import static de.chojo.sadu.conversion.ArrayConverter.toSqlArray; -import static de.chojo.sadu.queries.api.call.adapter.Adapter.create; - -/** - * The StandardAdapter class provides a set of static instances of Adapter, which map Java objects to specific SQL data types and provide the necessary conversions when binding the - * objects to a PreparedStatement. - */ -public final class StandardAdapter { - public static final Adapter STRING = create(PreparedStatement::setString, Types.VARCHAR); - public static final Adapter> ENUM = create(PreparedStatement::setString, Types.VARCHAR, Enum::name); - public static final Adapter SHORT = create(PreparedStatement::setShort, Types.TINYINT); - public static final Adapter INTEGER = create(PreparedStatement::setInt, Types.INTEGER); - public static final Adapter BIG_DECIMAL = create(PreparedStatement::setBigDecimal, Types.DECIMAL); - public static final Adapter FLOAT = create(PreparedStatement::setFloat, Types.FLOAT); - public static final Adapter DOUBLE = create(PreparedStatement::setDouble, Types.DOUBLE); - public static final Adapter LONG = create(PreparedStatement::setLong, Types.BIGINT); - public static final Adapter BOOLEAN = create(PreparedStatement::setBoolean, Types.BOOLEAN); - public static final Adapter BYTE = create(PreparedStatement::setByte, Types.BIT); - public static final Adapter BYTE_ARRAY = create(PreparedStatement::setBytes, Types.BINARY); - public static final Adapter DATE = create(PreparedStatement::setDate, Types.DATE); - public static final Adapter LOCAL_DATE = create(PreparedStatement::setDate, Types.DATE, Date::valueOf); - public static final Adapter

+ * Use {@link de.chojo.sadu.testing.SaduTests#execute(int, Database[])} to execute all required tests + */ +package de.chojo.sadu.testing; + +import de.chojo.sadu.core.databases.Database; diff --git a/sadu-testing/src/main/java/de/chojo/sadu/tests/package-info.java b/sadu-testing/src/main/java/de/chojo/sadu/tests/package-info.java deleted file mode 100644 index 48425fa8..00000000 --- a/sadu-testing/src/main/java/de/chojo/sadu/tests/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * The tests package contains utils to simply validate the integrity of sadus updater files using junit. - *

- * Use {@link de.chojo.sadu.tests.SaduTests#execute(int, de.chojo.sadu.databases.Database[])} to execute all required tests - */ -package de.chojo.sadu.tests; diff --git a/sadu-testing/src/main/java/module-info.java b/sadu-testing/src/main/java/module-info.java new file mode 100644 index 00000000..26778229 --- /dev/null +++ b/sadu-testing/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module sadu.sadu.testing.main { + requires transitive sadu.sadu.core.main; + requires transitive org.junit.jupiter.api; + + exports de.chojo.sadu.testing; +} diff --git a/sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseChecksTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseChecksTest.java similarity index 94% rename from sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseChecksTest.java rename to sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseChecksTest.java index 22c4ad4a..43097d3f 100644 --- a/sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseChecksTest.java +++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseChecksTest.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.tests; +package de.chojo.sadu.testing; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseVersionChecksTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseVersionChecksTest.java similarity index 96% rename from sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseVersionChecksTest.java rename to sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseVersionChecksTest.java index cb5e9b26..355fbf8c 100644 --- a/sadu-testing/src/test/java/de/chojo/sadu/tests/DatabaseVersionChecksTest.java +++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/DatabaseVersionChecksTest.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.tests; +package de.chojo.sadu.testing; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/sadu-testing/src/test/java/de/chojo/sadu/tests/PatchChecksTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java similarity index 87% rename from sadu-testing/src/test/java/de/chojo/sadu/tests/PatchChecksTest.java rename to sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java index 3334cd8c..7137bf00 100644 --- a/sadu-testing/src/test/java/de/chojo/sadu/tests/PatchChecksTest.java +++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.tests; +package de.chojo.sadu.testing; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -12,8 +12,6 @@ import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; - class PatchChecksTest { @Test diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java index 104e67ad..55eba896 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java @@ -6,10 +6,12 @@ package de.chojo.sadu.updater; -import de.chojo.sadu.databases.Database; -import de.chojo.sadu.jdbc.JdbcConfig; +import de.chojo.sadu.core.databases.Database; +import de.chojo.sadu.core.jdbc.JdbcConfig; +import de.chojo.sadu.core.updater.SqlVersion; +import de.chojo.sadu.core.updater.UpdaterBuilder; +import org.jetbrains.annotations.CheckReturnValue; -import javax.annotation.CheckReturnValue; import javax.sql.DataSource; import java.io.IOException; import java.sql.Connection; diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java index 76da07a3..12171c13 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java @@ -6,6 +6,8 @@ package de.chojo.sadu.updater; +import de.chojo.sadu.core.updater.SqlVersion; + class Patch { private final int major; private final int patch; diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java index 2a2a319f..22ddbf56 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java @@ -6,13 +6,15 @@ package de.chojo.sadu.updater; -import de.chojo.sadu.databases.Database; -import de.chojo.sadu.jdbc.JdbcConfig; +import de.chojo.sadu.core.databases.Database; +import de.chojo.sadu.core.jdbc.JdbcConfig; +import de.chojo.sadu.core.updater.SqlVersion; +import de.chojo.sadu.core.updater.UpdaterBuilder; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.CheckReturnValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.CheckReturnValue; import javax.sql.DataSource; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -53,7 +55,6 @@ * Every Major version which has a following major version requires a {@code migrate.sql} script. *

* This script should update the database to the same state as a clean installation via the new {@code setup.sql} would do. - *

* *

{@code
  * database
diff --git a/sadu-updater/src/main/java/module-info.java b/sadu-updater/src/main/java/module-info.java
new file mode 100644
index 00000000..beee8b47
--- /dev/null
+++ b/sadu-updater/src/main/java/module-info.java
@@ -0,0 +1,5 @@
+module sadu.sadu.updater.main {
+    requires transitive sadu.sadu.core.main;
+
+    exports de.chojo.sadu.updater;
+}
diff --git a/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java b/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java
index 96b3a674..24245c04 100644
--- a/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java
+++ b/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java
@@ -6,7 +6,7 @@
 
 package de.chojo.sadu.updater;
 
-import de.chojo.sadu.databases.PostgreSql;
+import de.chojo.sadu.postgresql.databases.PostgreSql;
 
 import javax.sql.DataSource;
 
diff --git a/settings.gradle.kts b/settings.gradle.kts
index fe2be8a4..e2592df2 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -11,7 +11,6 @@ include("sadu-updater")
 include("sadu-mapper")
 include("sadu-examples")
 include("sadu-testing")
-include("sadu-queries2")
 
 pluginManagement {
     repositories {

From a3d78bc57d89954728363b4e1116fb4cfbb5e764 Mon Sep 17 00:00:00 2001
From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com>
Date: Fri, 9 Feb 2024 13:04:28 +0100
Subject: [PATCH 11/29] Update testing module

---
 README.md                                           |  2 +-
 sadu-testing/build.gradle.kts                       |  3 ++-
 .../test/java/de/chojo/sadu/testing/SaduTest.java   | 13 +++++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java

diff --git a/README.md b/README.md
index 549b44d5..befeb3a6 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ But using the query builder your code becomes this:
 class MyQueries {
     public Optional getResultNew(int id) {
         return Query.query("SELECT result FROM results WHERE id = ?")
-                .single(Call.of().setInt(id))
+                .single(Call.of().bind(id))
                 .map(row -> new Result(rs.getString("result")))
                 .first();
     }
diff --git a/sadu-testing/build.gradle.kts b/sadu-testing/build.gradle.kts
index 504f1fa7..9ef7ab31 100644
--- a/sadu-testing/build.gradle.kts
+++ b/sadu-testing/build.gradle.kts
@@ -2,9 +2,10 @@ description = "SADU module for checking validity of updater files"
 
 dependencies {
 
-    api(platform("org.junit:junit-bom:5.10.2"))
+    api(platform("org.junit:junit-bom:5+"))
     api("org.junit.jupiter:junit-jupiter")
     api(project(":sadu-core"))
     testImplementation(platform("org.junit:junit-bom:5.10.2"))
     testImplementation("org.junit.jupiter:junit-jupiter")
+    testImplementation(project(":sadu-postgresql"))
 }
diff --git a/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java
new file mode 100644
index 00000000..7e350cd6
--- /dev/null
+++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java
@@ -0,0 +1,13 @@
+package de.chojo.sadu.testing;
+
+import de.chojo.sadu.postgresql.databases.PostgreSql;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+public class SaduTest {
+    @Test
+    public void checkDatabase() throws IOException {
+        SaduTests.execute(1, PostgreSql.get());
+    }
+}

From 4f1c885ef19989ea07f675512be94b25f1c4e73c Mon Sep 17 00:00:00 2001
From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com>
Date: Fri, 9 Feb 2024 13:13:49 +0100
Subject: [PATCH 12/29] Disable wrong test!

---
 .../src/test/java/de/chojo/sadu/testing/SaduTest.java     | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java
index 7e350cd6..a2d9bd3f 100644
--- a/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java
+++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/SaduTest.java
@@ -1,12 +1,20 @@
+/*
+ *     SPDX-License-Identifier: LGPL-3.0-or-later
+ *
+ *     Copyright (C) RainbowDashLabs and Contributor
+ */
+
 package de.chojo.sadu.testing;
 
 import de.chojo.sadu.postgresql.databases.PostgreSql;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
 public class SaduTest {
     @Test
+    @Disabled
     public void checkDatabase() throws IOException {
         SaduTests.execute(1, PostgreSql.get());
     }

From cede1a919d1e9241e5d268e607b2da5f9ce2907d Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Fri, 9 Feb 2024 13:43:42 +0100
Subject: [PATCH 13/29] fix(deps): update slf4j monorepo to v2.0.12 (#159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
---
 settings.gradle.kts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/settings.gradle.kts b/settings.gradle.kts
index e2592df2..d8578034 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -41,7 +41,7 @@ dependencyResolutionManagement {
             plugin("indra-publishing", "net.kyori.indra.publishing").versionRef("indra")
             plugin("indra-sonatype", "net.kyori.indra.publishing.sonatype").versionRef("indra")
 
-            version("slf4j", "2.0.11")
+            version("slf4j", "2.0.12")
             library("slf4j-api", "org.slf4j", "slf4j-api").versionRef("slf4j")
         }
 
@@ -58,7 +58,7 @@ dependencyResolutionManagement {
             library("testcontainers-core", "org.testcontainers", "testcontainers").versionRef("testcontainers")
             library("testcontainers-junit", "org.testcontainers", "junit-jupiter").versionRef("testcontainers")
 
-            version("slf4j", "2.0.11")
+            version("slf4j", "2.0.12")
             library("slf4j-noop", "org.slf4j", "slf4j-nop").versionRef("slf4j")
 
             library("driver-postgres", "org.postgresql:postgresql:42.7.1")

From 1a1ed82dc68f1bfe18335c0291fd3ca4bed6107b Mon Sep 17 00:00:00 2001
From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com>
Date: Fri, 9 Feb 2024 14:30:36 +0100
Subject: [PATCH 14/29] Apply formatting

---
 .github/renovate.json                         |  8 +--
 .github/workflows/verify.yml                  |  2 +-
 CONTRIBUTING.md                               |  2 +
 README.md                                     | 11 +++--
 .../chojo/sadu/core/databases/Database.java   |  1 +
 .../de/chojo/sadu/core/jdbc/JdbProperty.java  |  1 +
 .../sadu/core/jdbc/RemoteJdbcConfig.java      |  2 +-
 .../chojo/sadu/core/updater/SqlVersion.java   | 30 ++++++------
 .../sadu/core/updater/UpdaterBuilder.java     |  3 ++
 .../sadu/datasource/DataSourceCreator.java    |  6 +--
 .../datasource/stage/ConfigurationStage.java  |  1 +
 .../sadu/examples/datasource/Create.java      |  2 +-
 .../de/chojo/sadu/mapper/DefaultMapper.java   |  2 +-
 .../de/chojo/sadu/mapper/MapperConfig.java    |  1 +
 .../chojo/sadu/mapper/RowMapperRegistry.java  |  7 +--
 .../mapper/rowmapper/PartialRowMapper.java    |  1 +
 .../mapper/rowmapper/RowMapperBuilder.java    |  1 +
 .../sadu/mapper/rowmapper/RowMapping.java     |  6 +--
 .../java/de/chojo/sadu/wrapper/util/Row.java  | 49 +------------------
 .../sadu/mariadb/mapper/MariaDbMapper.java    |  9 ++--
 .../java/de/chojo/sadu/MariaDbDatabase.java   |  2 +-
 .../de/chojo/sadu/jdbc/MariaDbJdbcTest.java   |  2 +-
 .../chojo/sadu/mysql/mapper/MySqlMapper.java  |  9 ++--
 .../de/chojo/sadu/jdbc/MySQLJdbcTest.java     | 26 +++++-----
 .../postgresql/mapper/PostgresqlMapper.java   |  7 ++-
 .../postgresql/update/PostgreSqlUpdater.java  |  2 +-
 .../chojo/sadu/jdbc/PostgreSqlJdbcTest.java   |  2 +-
 .../de/chojo/sadu/queries/api/call/Call.java  |  2 +-
 .../de/chojo/sadu/queries/call/CallImpl.java  |  2 +-
 .../queries/call/adapter/StandardAdapter.java |  3 +-
 .../java/de/chojo/sadu/PostgresDatabase.java  |  2 +-
 .../chojo/sadu/queries/examples/ReadTest.java |  2 +-
 .../queries/examples/TransactionTest.java     |  2 +-
 .../sadu/queries/examples/WriteTest.java      |  2 +-
 .../sadu/sqlite/mapper/SqLiteMapper.java      | 13 +++--
 .../de/chojo/sadu/testing/PatchChecks.java    |  1 -
 .../chojo/sadu/testing/PatchChecksTest.java   |  2 +-
 .../sadu/updater/BaseSqlUpdaterBuilder.java   |  2 +-
 .../java/de/chojo/sadu/updater/Patch.java     |  2 +-
 .../de/chojo/sadu/updater/SqlUpdaterTest.java |  2 +-
 40 files changed, 101 insertions(+), 131 deletions(-)

diff --git a/.github/renovate.json b/.github/renovate.json
index e940c308..1b7c3aa3 100644
--- a/.github/renovate.json
+++ b/.github/renovate.json
@@ -1,6 +1,6 @@
 {
-    "$schema": "https://docs.renovatebot.com/renovate-schema.json",
-    "extends": [
-        "github>rainbowdashlabs/rainbowdashlabs"
-    ]
+  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
+  "extends": [
+    "github>rainbowdashlabs/rainbowdashlabs"
+  ]
 }
diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml
index cb04d97e..aeb2969c 100644
--- a/.github/workflows/verify.yml
+++ b/.github/workflows/verify.yml
@@ -1,6 +1,6 @@
 name: Verify state
 
-on: [push, pull_request]
+on: [ push, pull_request ]
 
 jobs:
   build:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e2b8c4bb..b67437e3 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,9 +1,11 @@
 Hello and welcome new contributor.
 
 # Issues
+
 Please make sure to describe your issue as precisely as possible.
 
 # Pull Requests
+
 When you create a new pull request you have to take care of a few things.
 
 - Create a feature branch based on the development branch
diff --git a/README.md b/README.md
index befeb3a6..64d337ab 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ SADU offers support for four different databases at the moment. To use them simp
 - `sadu-sqlite`
 
 ## Querybuilder
+
 SADU offers a query builder to manage resources, error handling, result set reading and dispatching of queries.
 
 to use it import: `sadu-queries`
@@ -44,12 +45,13 @@ Learn how to use the query builder [here](https://github.com/RainbowDashLabs/sad
 Before I give you a long talk about how much nicer the syntax and code is let me simple show you a comparison.
 
 Without the query builder your code would ideally look like this:
+
 ```java
 class MyQueries {
-    
+
     DataSource dataSource;
-    
-    MyQueries(DataSource dataSource){
+
+    MyQueries(DataSource dataSource) {
         this.dataSource = dataSource;
     }
 
@@ -71,6 +73,7 @@ class MyQueries {
 ```
 
 But using the query builder your code becomes this:
+
 ```java
 class MyQueries {
     public Optional getResultNew(int id) {
@@ -88,6 +91,7 @@ read the result set and additionally handle the exceptions for you.
 [How does it work?](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Queries#how-does-it-work)
 
 ## Datasource Builder
+
 SADU offsers a data source builder to create data sources for the databases listed above.
 
 to use it import: `sadu-datasource`
@@ -106,4 +110,5 @@ Learn how to use it [here](https://sadu.docs.chojo.dev/queries/)
 
 
 [nexus_releases]: https://search.maven.org/search?q=de.chojo.sadu
+
 [nexus_snapshots]: https://s01.oss.sonatype.org/#nexus-search;quick~de.chojo.sadu
diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java
index 7026248e..d8a46e46 100644
--- a/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java
+++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/Database.java
@@ -177,6 +177,7 @@ default boolean hasSchemas() {
 
     /**
      * Instantiates an implementation of {@link UpdaterBuilder}
+     *
      * @return the instance
      */
     @ApiStatus.Internal
diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java
index 8aa5b010..78a9aa47 100644
--- a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java
+++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java
@@ -46,6 +46,7 @@ public String key() {
     public String value() {
         return URLEncoder.encode(String.valueOf(value), StandardCharsets.UTF_8);
     }
+
     public String valueRaw() {
         return String.valueOf(value);
     }
diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java
index 98939544..c996735a 100644
--- a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java
+++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java
@@ -200,7 +200,7 @@ public Credentials userCredentials() {
     }
 
     public static class Credentials {
-        public static final Credentials EMPTY = new Credentials(null,null);
+        public static final Credentials EMPTY = new Credentials(null, null);
         private final JdbProperty user;
         private final JdbProperty password;
 
diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java
index cb77e322..36260be8 100644
--- a/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java
+++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java
@@ -31,6 +31,21 @@ public SqlVersion(int major, int patch) {
         this.patch = patch;
     }
 
+    public static SqlVersion load() throws IOException {
+        return load(SqlVersion.class.getClassLoader());
+    }
+
+    public static SqlVersion load(ClassLoader classLoader) throws IOException {
+        var version = "";
+        try (var versionFile = classLoader.getResourceAsStream("database/version")) {
+            version = new String(versionFile.readAllBytes(), StandardCharsets.UTF_8).trim();
+        }
+
+        var ver = version.split("\\.");
+        return new SqlVersion(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]));
+
+    }
+
     /**
      * Major version
      *
@@ -88,19 +103,4 @@ public int compareTo(@NotNull SqlVersion o) {
         }
         return Integer.compare(patch, o.patch);
     }
-
-    public static SqlVersion load() throws IOException {
-        return load(SqlVersion.class.getClassLoader());
-    }
-
-    public static SqlVersion load(ClassLoader classLoader) throws IOException {
-        var version = "";
-        try (var versionFile = classLoader.getResourceAsStream("database/version")) {
-            version = new String(versionFile.readAllBytes(), StandardCharsets.UTF_8).trim();
-        }
-
-        var ver = version.split("\\.");
-        return new SqlVersion(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]));
-
-    }
 }
diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java
index ea59dd28..82a718b9 100644
--- a/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java
+++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/UpdaterBuilder.java
@@ -15,18 +15,21 @@
 public interface UpdaterBuilder, S extends UpdaterBuilder> {
     /**
      * Set the datasource that should be used
+     *
      * @param source source
      */
     S setSource(DataSource source);
 
     /**
      * Set the current db version that is expected
+     *
      * @param version version
      */
     S setVersion(SqlVersion version);
 
     /**
      * Set the Classloader that should be used to load resourced.
+     *
      * @param classLoader classloader
      */
     S withClassLoader(ClassLoader classLoader);
diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java
index f14a453e..2f8c39c4 100644
--- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java
+++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java
@@ -9,10 +9,10 @@
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
 import de.chojo.sadu.core.databases.Database;
-import de.chojo.sadu.datasource.stage.ConfigurationStage;
-import de.chojo.sadu.datasource.stage.JdbcStage;
 import de.chojo.sadu.core.jdbc.JdbcConfig;
 import de.chojo.sadu.core.jdbc.RemoteJdbcConfig;
+import de.chojo.sadu.datasource.stage.ConfigurationStage;
+import de.chojo.sadu.datasource.stage.JdbcStage;
 import org.jetbrains.annotations.CheckReturnValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,7 +61,7 @@ public ConfigurationStage create() {
         loadDriverClass();
         RemoteJdbcConfig.Credentials credentials = RemoteJdbcConfig.Credentials.EMPTY;
         if (builder instanceof RemoteJdbcConfig) {
-            credentials = ((RemoteJdbcConfig)builder).userCredentials();
+            credentials = ((RemoteJdbcConfig) builder).userCredentials();
         }
         var jdbcUrl = builder.jdbcUrl();
         log.info("Creating Hikari config using jdbc url: {}", jdbcUrl.replaceAll("password=.+?(&|$)", "password=******"));
diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java
index 6398c0d8..fa6db3a5 100644
--- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java
+++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/ConfigurationStage.java
@@ -161,6 +161,7 @@ public interface ConfigurationStage {
 
     /**
      * Allows the direct mutation of the HikariConfig, should be used for config options, that are not represented by a delegate.
+     *
      * @param configConsumer the config consumer
      * @return Configuration Stage with value set
      */
diff --git a/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java b/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java
index 1d326c43..c4eae97a 100644
--- a/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java
+++ b/sadu-examples/src/main/java/de/chojo/sadu/examples/datasource/Create.java
@@ -7,8 +7,8 @@
 package de.chojo.sadu.examples.datasource;
 
 import com.zaxxer.hikari.HikariDataSource;
-import de.chojo.sadu.postgresql.databases.PostgreSql;
 import de.chojo.sadu.datasource.DataSourceCreator;
+import de.chojo.sadu.postgresql.databases.PostgreSql;
 import org.postgresql.Driver;
 
 public class Create {
diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java
index 8934cd8c..4953e432 100644
--- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java
+++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java
@@ -7,9 +7,9 @@
 package de.chojo.sadu.mapper;
 
 import de.chojo.sadu.core.exceptions.ThrowingBiFunction;
+import de.chojo.sadu.core.types.SqlType;
 import de.chojo.sadu.mapper.rowmapper.RowMapper;
 import de.chojo.sadu.mapper.util.Results;
-import de.chojo.sadu.core.types.SqlType;
 import de.chojo.sadu.wrapper.util.Row;
 
 import java.math.BigDecimal;
diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java
index 9d139a4b..b59f9aa9 100644
--- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java
+++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java
@@ -53,6 +53,7 @@ public MapperConfig addAlias(String original, String alias) {
 
     /**
      * When true only mappers will be used, which have a mapping value for all columns or the wild card mapper if present and no matching mapper was found.
+     *
      * @return true when strict
      */
     public boolean isStrict() {
diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java
index 531bdaf7..0cb29bec 100644
--- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java
+++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java
@@ -64,6 +64,7 @@ public RowMapperRegistry register(RowMapper... rowMapper) {
         }
         return this;
     }
+
     /**
      * Registers new mapper.
      * 

@@ -93,9 +94,9 @@ private List> mapper(Class clazz) { @SuppressWarnings("unchecked") public Optional> wildcard(Class clazz) { return mapper(clazz).stream() - .filter(RowMapper::isWildcard) - .findAny() - .map(rowMapper -> (RowMapper) rowMapper); + .filter(RowMapper::isWildcard) + .findAny() + .map(rowMapper -> (RowMapper) rowMapper); } /** diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java index c37833eb..4e48064e 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/PartialRowMapper.java @@ -8,6 +8,7 @@ /** * Represents a partially configured {@link RowMapper} + * * @param type of the mapper result. */ public interface PartialRowMapper { diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java index 8e4cdfc1..7ba7e48d 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapperBuilder.java @@ -12,6 +12,7 @@ /** * A builder to build a {@link RowMapper}. + * * @param type of the mapper result. */ public class RowMapperBuilder implements PartialRowMapper { diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java index 996b9b75..7056ce93 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java @@ -12,9 +12,9 @@ import java.sql.SQLException; public interface RowMapping { - T map(Row row) throws SQLException; - - static RowMapping create(ThrowingFunction mapper){ + static RowMapping create(ThrowingFunction mapper) { return mapper::apply; } + + T map(Row row) throws SQLException; } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java b/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java index dcd40ae7..935649be 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java @@ -10,6 +10,7 @@ import de.chojo.sadu.core.conversion.UUIDConverter; import de.chojo.sadu.mapper.MapperConfig; import org.jetbrains.annotations.ApiStatus; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -101,7 +102,6 @@ public String getString(int columnIndex) throws SQLException { * called on a closed result set * @throws IllegalArgumentException when the value could not be mapped * @throws NullPointerException when the class is null - * * @since 1.2 */ public > T getEnum(int columnIndex, Class clazz) throws SQLException { @@ -1035,7 +1035,6 @@ public Object getObject(String columnLabel) throws SQLException { * @throws SQLException if the columnIndex is not valid; * if a database access error occurs or this method is * called on a closed result set - */ public Reader getCharacterStream(int columnIndex) throws SQLException { return resultSet.getCharacterStream(columnIndex); @@ -1053,7 +1052,6 @@ public Reader getCharacterStream(int columnIndex) throws SQLException { * @throws SQLException if the columnLabel is not valid; * if a database access error occurs or this method is * called on a closed result set - */ public Reader getCharacterStream(String columnLabel) throws SQLException { return resultSet.getCharacterStream(columnAlias(columnLabel)); @@ -1071,7 +1069,6 @@ public Reader getCharacterStream(String columnLabel) throws SQLException { * @throws SQLException if the columnIndex is not valid; * if a database access error occurs or this method is * called on a closed result set - */ public BigDecimal getBigDecimal(int columnIndex) throws SQLException { return resultSet.getBigDecimal(columnIndex); @@ -1089,7 +1086,6 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException { * @throws SQLException if the columnLabel is not valid; * if a database access error occurs or this method is * called on a closed result set - */ public BigDecimal getBigDecimal(String columnLabel) throws SQLException { return resultSet.getBigDecimal(columnAlias(columnLabel)); @@ -1115,7 +1111,6 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Object getObject(int columnIndex, Map> map) throws SQLException { return resultSet.getObject(columnIndex, map); @@ -1134,7 +1129,6 @@ public Object getObject(int columnIndex, Map> map) throws SQLEx * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Ref getRef(int columnIndex) throws SQLException { return resultSet.getRef(columnIndex); @@ -1153,7 +1147,6 @@ public Ref getRef(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Blob getBlob(int columnIndex) throws SQLException { return resultSet.getBlob(columnIndex); @@ -1172,7 +1165,6 @@ public Blob getBlob(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Clob getClob(int columnIndex) throws SQLException { return resultSet.getClob(columnIndex); @@ -1191,7 +1183,6 @@ public Clob getClob(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Array getArray(int columnIndex) throws SQLException { return resultSet.getArray(columnIndex); @@ -1216,7 +1207,6 @@ public Array getArray(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Object getObject(String columnLabel, Map> map) throws SQLException { return resultSet.getObject(columnAlias(columnLabel), map); @@ -1235,7 +1225,6 @@ public Object getObject(String columnLabel, Map> map) throws SQ * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Ref getRef(String columnLabel) throws SQLException { return resultSet.getRef(columnAlias(columnLabel)); @@ -1254,7 +1243,6 @@ public Ref getRef(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Blob getBlob(String columnLabel) throws SQLException { return resultSet.getBlob(columnAlias(columnLabel)); @@ -1273,7 +1261,6 @@ public Blob getBlob(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Clob getClob(String columnLabel) throws SQLException { return resultSet.getClob(columnAlias(columnLabel)); @@ -1292,7 +1279,6 @@ public Clob getClob(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Array getArray(String columnLabel) throws SQLException { return resultSet.getArray(columnAlias(columnLabel)); @@ -1315,7 +1301,6 @@ public Array getArray(String columnLabel) throws SQLException { * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public Date getDate(int columnIndex, Calendar cal) throws SQLException { return resultSet.getDate(columnIndex, cal); @@ -1338,12 +1323,12 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException { * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public LocalDate getLocalDate(int columnIndex, Calendar cal) throws SQLException { var date = getDate(columnIndex, cal); return date == null ? null : date.toLocalDate(); } + /** * Retrieves the value of the designated column in the current row * of this {@code Row} object as a {@code java.sql.Date} object @@ -1361,7 +1346,6 @@ public LocalDate getLocalDate(int columnIndex, Calendar cal) throws SQLException * @throws SQLException if the columnLabel is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public Date getDate(String columnLabel, Calendar cal) throws SQLException { return resultSet.getDate(columnAlias(columnLabel), cal); @@ -1384,7 +1368,6 @@ public Date getDate(String columnLabel, Calendar cal) throws SQLException { * @throws SQLException if the columnLabel is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public LocalDate getLocalDate(String columnLabel, Calendar cal) throws SQLException { var date = getDate(columnLabel, cal); @@ -1408,7 +1391,6 @@ public LocalDate getLocalDate(String columnLabel, Calendar cal) throws SQLExcept * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public Time getTime(int columnIndex, Calendar cal) throws SQLException { return resultSet.getTime(columnIndex, cal); @@ -1431,7 +1413,6 @@ public Time getTime(int columnIndex, Calendar cal) throws SQLException { * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public LocalTime getLocalTime(int columnIndex, Calendar cal) throws SQLException { var time = getTime(columnIndex, cal); @@ -1456,7 +1437,6 @@ public LocalTime getLocalTime(int columnIndex, Calendar cal) throws SQLException * @throws SQLException if the columnLabel is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public Time getTime(String columnLabel, Calendar cal) throws SQLException { return resultSet.getTime(columnAlias(columnLabel), cal); @@ -1479,7 +1459,6 @@ public Time getTime(String columnLabel, Calendar cal) throws SQLException { * @throws SQLException if the columnLabel is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public LocalTime getLocalTime(String columnLabel, Calendar cal) throws SQLException { var time = getTime(columnLabel, cal); @@ -1503,7 +1482,6 @@ public LocalTime getLocalTime(String columnLabel, Calendar cal) throws SQLExcept * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { return resultSet.getTimestamp(columnIndex, cal); @@ -1526,7 +1504,6 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException * @throws SQLException if the columnLabel is not valid or * if a database access error occurs * or this method is called on a closed result set - */ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { return resultSet.getTimestamp(columnAlias(columnLabel), cal); @@ -1550,7 +1527,6 @@ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLExcept * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public LocalDateTime getLocalDateTime(int columnIndex, Calendar cal) throws SQLException { Timestamp timestamp = getTimestamp(columnIndex, cal); @@ -1575,7 +1551,6 @@ public LocalDateTime getLocalDateTime(int columnIndex, Calendar cal) throws SQLE * @throws SQLException if the columnLabel is not valid or * if a database access error occurs * or this method is called on a closed result set - */ public LocalDateTime getLocalDateTime(String columnLabel, Calendar cal) throws SQLException { Timestamp timestamp = getTimestamp(columnLabel, cal); @@ -1599,7 +1574,6 @@ public LocalDateTime getLocalDateTime(String columnLabel, Calendar cal) throws S * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public ZonedDateTime getZonedDateTime(int columnIndex, Calendar cal) throws SQLException { LocalDateTime localDateTime = getLocalDateTime(columnIndex, cal); @@ -1623,7 +1597,6 @@ public ZonedDateTime getZonedDateTime(int columnIndex, Calendar cal) throws SQLE * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public ZonedDateTime getZonedDateTime(String columnLabel, Calendar cal) throws SQLException { LocalDateTime localDateTime = getLocalDateTime(columnLabel, cal); @@ -1647,7 +1620,6 @@ public ZonedDateTime getZonedDateTime(String columnLabel, Calendar cal) throws S * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public OffsetDateTime getOffsetDateTime(int columnIndex, Calendar cal) throws SQLException { LocalDateTime localDateTime = getLocalDateTime(columnIndex, cal); @@ -1671,7 +1643,6 @@ public OffsetDateTime getOffsetDateTime(int columnIndex, Calendar cal) throws SQ * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public OffsetDateTime getOffsetDateTime(String columnLabel, Calendar cal) throws SQLException { LocalDateTime localDateTime = getLocalDateTime(columnLabel, cal); @@ -1695,7 +1666,6 @@ public OffsetDateTime getOffsetDateTime(String columnLabel, Calendar cal) throws * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public OffsetTime getOffsetTime(int columnIndex, Calendar cal) throws SQLException { LocalTime localDateTime = getLocalTime(columnIndex, cal); @@ -1719,7 +1689,6 @@ public OffsetTime getOffsetTime(int columnIndex, Calendar cal) throws SQLExcepti * @throws SQLException if the columnIndex is not valid; * if a database access error occurs * or this method is called on a closed result set - */ public OffsetTime getOffsetTime(String columnLabel, Calendar cal) throws SQLException { LocalTime localDateTime = getLocalTime(columnLabel, cal); @@ -1740,7 +1709,6 @@ public OffsetTime getOffsetTime(String columnLabel, Calendar cal) throws SQLExce * is called on a closed result set or if a URL is malformed * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public URL getURL(int columnIndex) throws SQLException { return resultSet.getURL(columnIndex); @@ -1760,7 +1728,6 @@ public URL getURL(int columnIndex) throws SQLException { * is called on a closed result set or if a URL is malformed * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public URL getURL(String columnLabel) throws SQLException { return resultSet.getURL(columnAlias(columnLabel)); @@ -1779,7 +1746,6 @@ public URL getURL(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public RowId getRowId(int columnIndex) throws SQLException { return resultSet.getRowId(columnIndex); @@ -1798,7 +1764,6 @@ public RowId getRowId(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public RowId getRowId(String columnLabel) throws SQLException { return resultSet.getRowId(columnAlias(columnLabel)); @@ -1819,7 +1784,6 @@ public RowId getRowId(String columnLabel) throws SQLException { * or if a database access error occurs * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public NClob getNClob(int columnIndex) throws SQLException { return resultSet.getNClob(columnIndex); @@ -1840,7 +1804,6 @@ public NClob getNClob(int columnIndex) throws SQLException { * or if a database access error occurs * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public NClob getNClob(String columnLabel) throws SQLException { return resultSet.getNClob(columnAlias(columnLabel)); @@ -1858,7 +1821,6 @@ public NClob getNClob(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public SQLXML getSQLXML(int columnIndex) throws SQLException { return resultSet.getSQLXML(columnIndex); @@ -1876,7 +1838,6 @@ public SQLXML getSQLXML(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public SQLXML getSQLXML(String columnLabel) throws SQLException { return resultSet.getSQLXML(columnAlias(columnLabel)); @@ -1898,7 +1859,6 @@ public SQLXML getSQLXML(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public String getNString(int columnIndex) throws SQLException { return resultSet.getNString(columnIndex); @@ -1920,7 +1880,6 @@ public String getNString(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public String getNString(String columnLabel) throws SQLException { return resultSet.getNString(columnAlias(columnLabel)); @@ -1943,7 +1902,6 @@ public String getNString(String columnLabel) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Reader getNCharacterStream(int columnIndex) throws SQLException { return resultSet.getNCharacterStream(columnIndex); @@ -1966,7 +1924,6 @@ public Reader getNCharacterStream(int columnIndex) throws SQLException { * or this method is called on a closed result set * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public Reader getNCharacterStream(String columnLabel) throws SQLException { return resultSet.getNCharacterStream(columnAlias(columnLabel)); @@ -1996,7 +1953,6 @@ public Reader getNCharacterStream(String columnLabel) throws SQLException { * a conversion error occurs * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public T getObject(int columnIndex, Class type) throws SQLException { return resultSet.getObject(columnIndex, type); @@ -2028,7 +1984,6 @@ public T getObject(int columnIndex, Class type) throws SQLException { * a conversion error occurs * @throws SQLFeatureNotSupportedException if the JDBC driver does not support * this method - */ public T getObject(String columnLabel, Class type) throws SQLException { return resultSet.getObject(columnAlias(columnLabel), type); diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java index 8b941940..0a2ebb9b 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java @@ -25,10 +25,6 @@ import static de.chojo.sadu.mapper.DefaultMapper.createUuid; public final class MariaDbMapper { - private MariaDbMapper() { - throw new UnsupportedOperationException("This is a utility class."); - } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(MariaDbTypes.BOOLEAN)); public static final RowMapper SHORT_MAPPER = createShort(List.of(MariaDbTypes.TINYINT, MariaDbTypes.SMALLINT)); public static final RowMapper INTEGER_MAPPER = createInteger(List.of(MariaDbTypes.TINYINT, MariaDbTypes.SMALLINT, MariaDbTypes.MEDIUMINT, MariaDbTypes.INT)); @@ -40,8 +36,11 @@ private MariaDbMapper() { public static final RowMapper BYTES_MAPPER = createBytes(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR)); public static final RowMapper UUID_MAPPER = createUuid(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR), List.of(MariaDbTypes.TINYBLOB, MariaDbTypes.BLOB, MariaDbTypes.MEDIUMBLOB, MariaDbTypes.LONGBLOB, MariaDbTypes.VARBINARY)); + private MariaDbMapper() { + throw new UnsupportedOperationException("This is a utility class."); + } - public static List> getDefaultMapper(){ + public static List> getDefaultMapper() { return List.of(BOOLEAN_MAPPER, SHORT_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, BIG_DECIMAL_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); } } diff --git a/sadu-mariadb/src/test/java/de/chojo/sadu/MariaDbDatabase.java b/sadu-mariadb/src/test/java/de/chojo/sadu/MariaDbDatabase.java index 9e59d482..e9df5254 100644 --- a/sadu-mariadb/src/test/java/de/chojo/sadu/MariaDbDatabase.java +++ b/sadu-mariadb/src/test/java/de/chojo/sadu/MariaDbDatabase.java @@ -11,7 +11,7 @@ import org.testcontainers.utility.DockerImageName; public class MariaDbDatabase { - public static GenericContainer createContainer(String user/*ignored*/, String pw) { + public static GenericContainer createContainer(String user/*ignored*/, String pw) { GenericContainer self = new GenericContainer<>(DockerImageName.parse("mariadb:latest")) .withExposedPorts(3306) .withEnv("MARIADB_ROOT_PASSWORD", pw) diff --git a/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java b/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java index 9eceb763..122fbca9 100644 --- a/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java +++ b/sadu-mariadb/src/test/java/de/chojo/sadu/jdbc/MariaDbJdbcTest.java @@ -6,8 +6,8 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.mariadb.databases.MariaDb; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.mariadb.databases.MariaDb; import de.chojo.sadu.mariadb.jdbc.MariaDbJdbc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java index 34a6ca61..53862952 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java @@ -22,10 +22,6 @@ import static de.chojo.sadu.mapper.DefaultMapper.createUuid; public final class MySqlMapper { - private MySqlMapper() { - throw new UnsupportedOperationException("This is a utility class."); - } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(MySqlTypes.BOOLEAN)); public static final RowMapper INTEGER_MAPPER = createInteger(List.of(MySqlTypes.TINYINT, MySqlTypes.SMALLINT, MySqlTypes.MEDIUMINT, MySqlTypes.INT)); public static final RowMapper LONG_MAPPER = createLong(List.of(MySqlTypes.BIGINT, MySqlTypes.TINYINT, MySqlTypes.SMALLINT, MySqlTypes.MEDIUMINT, MySqlTypes.INT)); @@ -35,8 +31,11 @@ private MySqlMapper() { public static final RowMapper BYTES_MAPPER = createBytes(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR)); public static final RowMapper UUID_MAPPER = createUuid(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR), List.of(MySqlTypes.TINYBLOB, MySqlTypes.BLOB, MySqlTypes.MEDIUMBLOB, MySqlTypes.LONGBLOB, MySqlTypes.VARBINARY)); + private MySqlMapper() { + throw new UnsupportedOperationException("This is a utility class."); + } - public static List> getDefaultMapper(){ + public static List> getDefaultMapper() { return List.of(BOOLEAN_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); } } diff --git a/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java b/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java index d2620046..6f3e6885 100644 --- a/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java +++ b/sadu-mysql/src/test/java/de/chojo/sadu/jdbc/MySQLJdbcTest.java @@ -6,8 +6,8 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.mysql.databases.MySql; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.mysql.databases.MySql; import de.chojo.sadu.mysql.jdbc.MySQLJdbc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; @@ -32,6 +32,18 @@ private static List createCredentials() { ); } + private static List escapeTest() { + return List.of( + Arguments.arguments("root", "abc", "jdbc:mysql://localhost/?user=root&password=abc"), // letters + Arguments.arguments("root", "54871", "jdbc:mysql://localhost/?user=root&password=54871"), // numbers + Arguments.arguments("root", "x89jwWpE", "jdbc:mysql://localhost/?user=root&password=x89jwWpE"), //alphanumeric + Arguments.arguments("root", "x89j&wW&pE", "jdbc:mysql://localhost/?user=root&password=x89j%26wW%26pE"), // everything that could break + Arguments.arguments("root", "x89j!wW!pE", "jdbc:mysql://localhost/?user=root&password=x89j%21wW%21pE"), + Arguments.arguments("root", "x89j=wW=pE", "jdbc:mysql://localhost/?user=root&password=x89j%3DwW%3DpE"), + Arguments.arguments("root", "x89j$wW$pE", "jdbc:mysql://localhost/?user=root&password=x89j%24wW%24pE") + ); + } + @ParameterizedTest @MethodSource("createCredentials") public void connectionTestWithDatasource(String user, String pw) { @@ -67,18 +79,6 @@ private GenericContainer createContainer(String user/*ignored*/, String pw) { return self; } - private static List escapeTest() { - return List.of( - Arguments.arguments("root", "abc", "jdbc:mysql://localhost/?user=root&password=abc"), // letters - Arguments.arguments("root", "54871", "jdbc:mysql://localhost/?user=root&password=54871"), // numbers - Arguments.arguments("root", "x89jwWpE", "jdbc:mysql://localhost/?user=root&password=x89jwWpE"), //alphanumeric - Arguments.arguments("root", "x89j&wW&pE", "jdbc:mysql://localhost/?user=root&password=x89j%26wW%26pE"), // everything that could break - Arguments.arguments("root", "x89j!wW!pE", "jdbc:mysql://localhost/?user=root&password=x89j%21wW%21pE"), - Arguments.arguments("root", "x89j=wW=pE", "jdbc:mysql://localhost/?user=root&password=x89j%3DwW%3DpE"), - Arguments.arguments("root", "x89j$wW$pE", "jdbc:mysql://localhost/?user=root&password=x89j%24wW%24pE") - ); - } - @ParameterizedTest @MethodSource("escapeTest") public void escape(String user, String password, String result) { diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java index e0b67f75..52a591cb 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java @@ -25,10 +25,6 @@ import static de.chojo.sadu.mapper.DefaultMapper.createUuid; public final class PostgresqlMapper { - private PostgresqlMapper() { - throw new UnsupportedOperationException("This is a utility class."); - } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(PostgreSqlTypes.BOOLEAN)); public static final RowMapper SHORT_MAPPER = createShort(List.of(PostgreSqlTypes.SMALLINT, PostgreSqlTypes.INTEGER)); public static final RowMapper INTEGER_MAPPER = createInteger(List.of(PostgreSqlTypes.SMALLINT, PostgreSqlTypes.INTEGER)); @@ -39,6 +35,9 @@ private PostgresqlMapper() { public static final RowMapper STRING_MAPPER = createString(List.of(PostgreSqlTypes.TEXT, PostgreSqlTypes.VARCHAR, PostgreSqlTypes.CHAR, PostgreSqlTypes.JSON, PostgreSqlTypes.JSONB)); public static final RowMapper BYTES_MAPPER = createBytes(List.of(PostgreSqlTypes.BYTEA)); public static final RowMapper UUID_MAPPER = createUuid(List.of(PostgreSqlTypes.TEXT), List.of(PostgreSqlTypes.BYTEA)); + private PostgresqlMapper() { + throw new UnsupportedOperationException("This is a utility class."); + } public static List> getDefaultMapper() { return List.of(BOOLEAN_MAPPER, SHORT_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, BIG_DECIMAL_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java index a3b1ef32..d7faa240 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java @@ -7,10 +7,10 @@ package de.chojo.sadu.postgresql.update; import de.chojo.sadu.core.databases.Database; +import de.chojo.sadu.core.updater.SqlVersion; import de.chojo.sadu.postgresql.jdbc.PostgreSqlJdbc; import de.chojo.sadu.updater.QueryReplacement; import de.chojo.sadu.updater.SqlUpdater; -import de.chojo.sadu.core.updater.SqlVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java b/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java index 08bfc983..6bd899fe 100644 --- a/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java +++ b/sadu-postgresql/src/test/java/de/chojo/sadu/jdbc/PostgreSqlJdbcTest.java @@ -6,8 +6,8 @@ package de.chojo.sadu.jdbc; -import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.postgresql.databases.PostgreSql; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java index 49750c54..be7db150 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java @@ -6,11 +6,11 @@ package de.chojo.sadu.queries.api.call; +import de.chojo.sadu.core.types.SqlType; import de.chojo.sadu.queries.api.call.adapter.Adapter; import de.chojo.sadu.queries.call.CallImpl; import de.chojo.sadu.queries.calls.BatchCall; import de.chojo.sadu.queries.calls.SingletonCall; -import de.chojo.sadu.core.types.SqlType; import java.math.BigDecimal; import java.net.URL; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java index 175aea59..7f376850 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java @@ -7,6 +7,7 @@ package de.chojo.sadu.queries.call; import de.chojo.sadu.core.exceptions.ThrowingBiConsumer; +import de.chojo.sadu.core.types.SqlType; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.call.adapter.Adapter; import de.chojo.sadu.queries.api.call.calls.Calls; @@ -17,7 +18,6 @@ import de.chojo.sadu.queries.parameter.IndexParameter; import de.chojo.sadu.queries.parameter.TokenParameter; import de.chojo.sadu.queries.query.TokenizedQuery; -import de.chojo.sadu.core.types.SqlType; import java.math.BigDecimal; import java.net.URL; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java index fcfb2e53..99572659 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java @@ -6,8 +6,8 @@ package de.chojo.sadu.queries.call.adapter; -import de.chojo.sadu.queries.api.call.adapter.Adapter; import de.chojo.sadu.core.types.SqlType; +import de.chojo.sadu.queries.api.call.adapter.Adapter; import java.math.BigDecimal; import java.net.URL; @@ -29,7 +29,6 @@ import java.util.Collection; import static de.chojo.sadu.core.conversion.ArrayConverter.toSqlArray; -import static de.chojo.sadu.queries.api.call.adapter.Adapter.create; /** * The StandardAdapter class provides a set of static instances of Adapter, which map Java objects to specific SQL data types and provide the necessary conversions when binding the diff --git a/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java b/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java index 24c41331..2c51f767 100644 --- a/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/PostgresDatabase.java @@ -6,8 +6,8 @@ package de.chojo.sadu; -import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.datasource.DataSourceCreator; +import de.chojo.sadu.postgresql.databases.PostgreSql; import de.chojo.sadu.updater.SqlUpdater; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; diff --git a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java index 834c53c6..c85e760c 100644 --- a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/ReadTest.java @@ -7,9 +7,9 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; import de.chojo.sadu.mapper.rowmapper.RowMapper; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.call.calls.Calls; import de.chojo.sadu.queries.api.results.reading.Result; diff --git a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java index ef084759..747d557b 100644 --- a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/TransactionTest.java @@ -7,8 +7,8 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.queries.api.call.calls.Calls; import de.chojo.sadu.queries.api.results.writing.ManipulationResult; import de.chojo.sadu.queries.configuration.QueryConfiguration; diff --git a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java index 49e57d7e..ffe459e2 100644 --- a/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java +++ b/sadu-queries/src/test/java/de/chojo/sadu/queries/examples/WriteTest.java @@ -7,8 +7,8 @@ package de.chojo.sadu.queries.examples; import de.chojo.sadu.PostgresDatabase; -import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.mapper.RowMapperRegistry; +import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; import de.chojo.sadu.queries.api.results.writing.ManipulationResult; diff --git a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java index 9b315ef3..a00ae381 100644 --- a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java +++ b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java @@ -19,13 +19,13 @@ import static de.chojo.sadu.mapper.DefaultMapper.createLong; import static de.chojo.sadu.mapper.DefaultMapper.createString; import static de.chojo.sadu.mapper.DefaultMapper.createUuid; -import static de.chojo.sadu.sqlite.types.SqLiteTypes.*; +import static de.chojo.sadu.sqlite.types.SqLiteTypes.BLOB; +import static de.chojo.sadu.sqlite.types.SqLiteTypes.BOOLEAN; +import static de.chojo.sadu.sqlite.types.SqLiteTypes.INTEGER; +import static de.chojo.sadu.sqlite.types.SqLiteTypes.REAL; +import static de.chojo.sadu.sqlite.types.SqLiteTypes.TEXT; public final class SqLiteMapper { - private SqLiteMapper() { - throw new UnsupportedOperationException("This is a utility class."); - } - public static final RowMapper BOOLEAN_MAPPER = createBoolean(List.of(BOOLEAN)); public static final RowMapper INTEGER_MAPPER = createInteger(List.of(INTEGER)); public static final RowMapper LONG_MAPPER = createLong(List.of(INTEGER)); @@ -34,6 +34,9 @@ private SqLiteMapper() { public static final RowMapper STRING_MAPPER = createString(List.of(TEXT)); public static final RowMapper BYTES_MAPPER = createBytes(List.of(BLOB)); public static final RowMapper UUID_MAPPER = createUuid(List.of(TEXT), List.of(BLOB)); + private SqLiteMapper() { + throw new UnsupportedOperationException("This is a utility class."); + } public static List> getDefaultMapper() { return List.of(BOOLEAN_MAPPER, INTEGER_MAPPER, LONG_MAPPER, FLOAT_MAPPER, DOUBLE_MAPPER, STRING_MAPPER, BYTES_MAPPER, UUID_MAPPER); diff --git a/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java b/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java index 8a2b838e..9fd6cbab 100644 --- a/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java +++ b/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java @@ -23,7 +23,6 @@ import java.util.stream.Collectors; import static de.chojo.sadu.testing.TestUtil.resourceContent; -import static de.chojo.sadu.testing.TestUtil.resourceContent; /** diff --git a/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java b/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java index 7137bf00..95ccf896 100644 --- a/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java +++ b/sadu-testing/src/test/java/de/chojo/sadu/testing/PatchChecksTest.java @@ -17,6 +17,6 @@ class PatchChecksTest { @Test void checkFiles() throws IOException { Assertions.assertDoesNotThrow(() -> PatchChecks.checkFiles(1, "2.1", "postgresql")); - Assertions.assertThrows(AssertionFailedError.class,() -> PatchChecks.checkFiles(1, "2.2", "postgresql")); + Assertions.assertThrows(AssertionFailedError.class, () -> PatchChecks.checkFiles(1, "2.2", "postgresql")); } } diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java index 55eba896..e0b4a4b7 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java @@ -26,11 +26,11 @@ * @param The type of the jdbc link defined by the {@link Database} */ public class BaseSqlUpdaterBuilder, S extends BaseSqlUpdaterBuilder> implements UpdaterBuilder { + protected final Database type; protected DataSource source; protected SqlVersion version; protected Map> preUpdateHook = new HashMap<>(); protected Map> postUpdateHook = new HashMap<>(); - protected final Database type; protected String versionTable = "version"; protected QueryReplacement[] replacements = new QueryReplacement[0]; protected ClassLoader classLoader = getClass().getClassLoader(); diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java index 12171c13..ba7708c0 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java @@ -31,7 +31,7 @@ public String query() { return query; } - public SqlVersion version(){ + public SqlVersion version() { return new SqlVersion(major, patch); } } diff --git a/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java b/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java index 24245c04..b1e30538 100644 --- a/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java +++ b/sadu-updater/src/test/java/de/chojo/sadu/updater/SqlUpdaterTest.java @@ -9,12 +9,12 @@ import de.chojo.sadu.postgresql.databases.PostgreSql; import javax.sql.DataSource; - import java.io.IOException; import java.sql.SQLException; class SqlUpdaterTest { DataSource dataSource; + public void update() throws IOException, SQLException { SqlUpdater.builder(dataSource, PostgreSql.get()) .setReplacements(new QueryReplacement("dev_schema", "live_schema")) From aa18010ccd4aae7e6a0ca5139faa4e5c148a2aa0 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 14:32:20 +0100 Subject: [PATCH 15/29] Move wrapper into mapper package --- .../src/main/java/de/chojo/sadu/mapper/DefaultMapper.java | 2 +- .../src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java | 2 +- .../main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java | 2 +- .../de/chojo/sadu/{wrapper/util => mapper/wrapper}/Row.java | 2 +- sadu-mapper/src/main/java/module-info.java | 2 +- .../chojo/sadu/queries/stages/execution/reading/ReaderImpl.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename sadu-mapper/src/main/java/de/chojo/sadu/{wrapper/util => mapper/wrapper}/Row.java (99%) diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java index 4953e432..817e85f4 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/DefaultMapper.java @@ -10,7 +10,7 @@ import de.chojo.sadu.core.types.SqlType; import de.chojo.sadu.mapper.rowmapper.RowMapper; import de.chojo.sadu.mapper.util.Results; -import de.chojo.sadu.wrapper.util.Row; +import de.chojo.sadu.mapper.wrapper.Row; import java.math.BigDecimal; import java.sql.ResultSetMetaData; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java index 83d46a50..19d783b4 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapper.java @@ -7,7 +7,7 @@ package de.chojo.sadu.mapper.rowmapper; import de.chojo.sadu.mapper.MapperConfig; -import de.chojo.sadu.wrapper.util.Row; +import de.chojo.sadu.mapper.wrapper.Row; import org.slf4j.Logger; import java.sql.ResultSet; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java index 7056ce93..58e2096d 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java @@ -7,7 +7,7 @@ package de.chojo.sadu.mapper.rowmapper; import de.chojo.sadu.core.exceptions.ThrowingFunction; -import de.chojo.sadu.wrapper.util.Row; +import de.chojo.sadu.mapper.wrapper.Row; import java.sql.SQLException; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java similarity index 99% rename from sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java rename to sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java index 935649be..5cb59df9 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/wrapper/util/Row.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.wrapper.util; +package de.chojo.sadu.mapper.wrapper; import de.chojo.sadu.core.conversion.ArrayConverter; import de.chojo.sadu.core.conversion.UUIDConverter; diff --git a/sadu-mapper/src/main/java/module-info.java b/sadu-mapper/src/main/java/module-info.java index 87de377c..6b5cceca 100644 --- a/sadu-mapper/src/main/java/module-info.java +++ b/sadu-mapper/src/main/java/module-info.java @@ -5,5 +5,5 @@ exports de.chojo.sadu.mapper.exceptions; exports de.chojo.sadu.mapper.rowmapper; exports de.chojo.sadu.mapper.util; - exports de.chojo.sadu.wrapper.util; + exports de.chojo.sadu.mapper.wrapper; } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java index 19637b32..9fef53b8 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java @@ -20,7 +20,7 @@ import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; import de.chojo.sadu.queries.stages.results.reading.MultiResult; import de.chojo.sadu.queries.stages.results.reading.SingleResult; -import de.chojo.sadu.wrapper.util.Row; +import de.chojo.sadu.mapper.wrapper.Row; import java.sql.ResultSet; import java.sql.SQLException; From 0c052afd75c7d3dc8d818b3e06e51c70eb6a0354 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 14:56:53 +0100 Subject: [PATCH 16/29] Update readme with wiki links --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 64d337ab..e18a8fda 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ SADU offers a query builder to manage resources, error handling, result set read to use it import: `sadu-queries` -Learn how to use the query builder [here](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Queries) +Learn how to use the query builder [here](https://sadu.docs.chojo.dev/queries/) ### But why should I use it? @@ -88,7 +88,7 @@ class MyQueries { Beautiful isnt it? The query builder will enforce try with resources, set parameters in the order defined by you, read the result set and additionally handle the exceptions for you. -[How does it work?](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Queries#how-does-it-work) +[How does it work?](https://sadu.docs.chojo.dev/queries/) ## Datasource Builder @@ -98,7 +98,7 @@ to use it import: `sadu-datasource` Note that in order to use this, you need at least one of the listed databases from above. -Learn how to use the datasource builder [here](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Datasource) +Learn how to use the datasource builder [here](https://sadu.docs.chojo.dev/data_source/) ## Updater @@ -106,7 +106,7 @@ SADU offers a simple sql updater which deploys upgrade and migration scripts to to use it import: `sadu-updater` -Learn how to use it [here](https://sadu.docs.chojo.dev/queries/) +Learn how to use it [here](https://sadu.docs.chojo.dev/updater/) [nexus_releases]: https://search.maven.org/search?q=de.chojo.sadu From 8df315907bdb067f5f83e65f170f3ff4af43b036 Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:07:47 +0100 Subject: [PATCH 17/29] Feature/cleanup (#163) --- .../sadu/core/databases/DefaultDatabase.java | 10 +++---- .../exceptions/NotImplementedException.java | 5 ++++ .../exceptions/NotSupportedException.java | 5 ++++ .../de/chojo/sadu/core/jdbc/JdbProperty.java | 4 +-- .../de/chojo/sadu/core/jdbc/JdbcConfig.java | 5 +++- .../sadu/core/jdbc/RemoteJdbcConfig.java | 3 +++ .../chojo/sadu/core/updater/SqlVersion.java | 18 +++---------- .../sadu/core/updater/StatementSplitter.java | 8 +++--- .../sadu/datasource/DataSourceCreator.java | 4 +-- .../DriverClassNotFoundException.java | 5 ++++ .../de/chojo/sadu/mapper/MapperConfig.java | 8 +----- .../chojo/sadu/mapper/RowMapperRegistry.java | 2 ++ .../MappingAlreadyRegisteredException.java | 5 ++++ .../mapper/exceptions/MappingException.java | 3 +++ .../sadu/mapper/rowmapper/RowMapping.java | 1 + .../de/chojo/sadu/mapper/wrapper/Row.java | 2 +- .../chojo/sadu/mariadb/databases/MariaDb.java | 2 +- .../chojo/sadu/mariadb/jdbc/MariaDbJdbc.java | 4 +++ .../sadu/mariadb/mapper/MariaDbMapper.java | 1 + .../de/chojo/sadu/mysql/databases/MySql.java | 2 +- .../de/chojo/sadu/mysql/jdbc/MySQLJdbc.java | 3 +++ .../chojo/sadu/mysql/mapper/MySqlMapper.java | 1 + .../sadu/postgresql/databases/PostgreSql.java | 2 +- .../sadu/postgresql/jdbc/PostgreSqlJdbc.java | 5 ++++ .../postgresql/mapper/PostgresqlMapper.java | 1 + .../postgresql/update/PostgreSqlUpdater.java | 2 ++ .../queries/api/storage/ResultStorage.java | 1 - .../chojo/sadu/queries/calls/BatchCall.java | 2 +- .../ConnectedQueryConfiguration.java | 1 + .../configuration/QueryConfiguration.java | 5 ++-- .../exception/QueryExecutionException.java | 3 +++ .../WrappedQueryExecutionException.java | 4 +++ .../stages/execution/reading/ReaderImpl.java | 2 +- .../writing/CalledSingletonQueryImpl.java | 2 ++ .../chojo/sadu/sqlite/databases/SqLite.java | 2 +- .../sadu/sqlite/mapper/SqLiteMapper.java | 1 + .../sadu/testing/DatabaseVersionChecks.java | 6 ++++- .../de/chojo/sadu/testing/PatchChecks.java | 14 +++------- .../java/de/chojo/sadu/testing/SaduTests.java | 7 ++++- .../java/de/chojo/sadu/testing/TestUtil.java | 2 +- .../sadu/updater/BaseSqlUpdaterBuilder.java | 4 +-- .../java/de/chojo/sadu/updater/Patch.java | 23 +--------------- .../de/chojo/sadu/updater/SqlUpdater.java | 27 ++++--------------- .../chojo/sadu/updater/UpdateException.java | 5 ++++ 44 files changed, 117 insertions(+), 105 deletions(-) diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java index 44f4a755..b802b274 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/DefaultDatabase.java @@ -14,25 +14,25 @@ * * @param database type defined by the {@link Database} */ -public abstract class DefaultDatabase, U extends UpdaterBuilder> implements Database { +public interface DefaultDatabase, U extends UpdaterBuilder> extends Database { @Override - public String versionQuery(String table) { + default String versionQuery(String table) { return String.format("SELECT major, patch FROM %s LIMIT 1", table); } @Override - public String insertVersion(String table) { + default String insertVersion(String table) { return String.format("INSERT INTO %s VALUES (?, ?)", table); } @Override - public String deleteVersion(String table) { + default String deleteVersion(String table) { return String.format("DELETE FROM %s;", table); } @Override - public String createVersionTableQuery(String table) { + default String createVersionTableQuery(String table) { return String.format("CREATE TABLE IF NOT EXISTS %s(major INTEGER, patch INTEGER);", table); } } diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java index 48edea51..dd046e6d 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotImplementedException.java @@ -6,10 +6,15 @@ package de.chojo.sadu.core.databases.exceptions; +import java.io.Serial; + /** * Thrown when a method is called which is not implemented but supported by this type. */ public class NotImplementedException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + public NotImplementedException(String message) { super(message); } diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java index 9761b450..77751511 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/NotSupportedException.java @@ -6,10 +6,15 @@ package de.chojo.sadu.core.databases.exceptions; +import java.io.Serial; + /** * Thrown when a method is called which is not supported by this type. */ public class NotSupportedException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + public NotSupportedException(String message) { super(message); } diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java index 78a9aa47..407caa20 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbProperty.java @@ -54,9 +54,7 @@ public String valueRaw() { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof JdbProperty)) return false; - - var prop = (JdbProperty) o; + if (!(o instanceof JdbProperty prop)) return false; return key.equals(prop.key); } diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java index 0ccb0644..5ea24f52 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/JdbcConfig.java @@ -25,6 +25,9 @@ public abstract class JdbcConfig> { private String driverClass; + public JdbcConfig() { + } + /** * Set the driver class which should be used. *

@@ -96,7 +99,7 @@ protected T self() { */ public T addParameter(String key, V value) { if (!parameter.add(new JdbProperty<>(key, value))) { - var property = parameter.stream().filter(e -> e.key().equals(key)).findFirst().get(); + var property = parameter.stream().filter(e -> e.key().equals(key)).findFirst().orElseThrow(); throw new IllegalArgumentException(String.format("Parameter '%s' is already set to '%s' and can not be set to '%s'.", key, property.value(), value)); } return self(); diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java index c996735a..0581dc8f 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/RemoteJdbcConfig.java @@ -24,6 +24,9 @@ public abstract class RemoteJdbcConfig> extends Jd private String port; private String database; + public RemoteJdbcConfig() { + } + /** * Sets the host explicit to local host. *

diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java index 36260be8..24f34050 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java @@ -16,19 +16,14 @@ *

* A version id defined by a major and a patch version. */ -public class SqlVersion implements Comparable { - private final int major; - private final int patch; - +public record SqlVersion(int major, int patch) implements Comparable { /** * A new SqlVersion with a major and patch version * * @param major major * @param patch patch */ - public SqlVersion(int major, int patch) { - this.major = major; - this.patch = patch; + public SqlVersion { } public static SqlVersion load() throws IOException { @@ -51,6 +46,7 @@ public static SqlVersion load(ClassLoader classLoader) throws IOException { * * @return major */ + @Override public int major() { return major; } @@ -60,6 +56,7 @@ public int major() { * * @return patch */ + @Override public int patch() { return patch; } @@ -75,13 +72,6 @@ public boolean equals(Object o) { return patch == that.patch; } - @Override - public int hashCode() { - int result = major; - result = 31 * result + patch; - return result; - } - @Override public String toString() { return "%s.%s".formatted(major, patch); diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java b/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java index f0fecc67..58be0b0e 100644 --- a/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java +++ b/sadu-core/src/main/java/de/chojo/sadu/core/updater/StatementSplitter.java @@ -20,8 +20,7 @@ * The delimiter is not case sensitive. *

*/ -public class StatementSplitter { - +public final class StatementSplitter { /** * The default marker, which is regularly used to split statements. *

@@ -32,7 +31,6 @@ public class StatementSplitter { *

*/ public static final String DEFAULT_SPLIT_MARKER = ";"; - /** * This is the default delimiter keyword, which is regularly used to change the delimiter. *

@@ -43,10 +41,12 @@ public class StatementSplitter { *

*/ public static final String DEFAULT_DELIMITER_KEYWORD = "DELIMITER"; - private static final Pattern CLEANER = Pattern.compile("^([ \n\r]+)"); @RegExp private static final String DELIMITER_FORMAT = "^%s (?[^ \n\r]+)"; + private StatementSplitter() { + throw new UnsupportedOperationException("This is a utility class."); + } /** * Splits a string of SQL statements into an array of statements. diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java index 2f8c39c4..a65ae38c 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java @@ -43,7 +43,7 @@ private DataSourceCreator(Database type) { * @param database type defined by the {@link Database} * @return a DataSourceCreator in {@link JdbcStage}. */ - @org.jetbrains.annotations.CheckReturnValue + @CheckReturnValue public static > JdbcStage create(Database type) { return new DataSourceCreator<>(type); } @@ -61,7 +61,7 @@ public ConfigurationStage create() { loadDriverClass(); RemoteJdbcConfig.Credentials credentials = RemoteJdbcConfig.Credentials.EMPTY; if (builder instanceof RemoteJdbcConfig) { - credentials = ((RemoteJdbcConfig) builder).userCredentials(); + credentials = ((RemoteJdbcConfig) builder).userCredentials(); } var jdbcUrl = builder.jdbcUrl(); log.info("Creating Hikari config using jdbc url: {}", jdbcUrl.replaceAll("password=.+?(&|$)", "password=******")); diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java index 487d144e..f53443c7 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java @@ -6,12 +6,17 @@ package de.chojo.sadu.datasource; +import java.io.Serial; + /** * Thrown when a driver class is not found. */ public class DriverClassNotFoundException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + public DriverClassNotFoundException(String message, ClassNotFoundException e) { super(message, e); } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java index b59f9aa9..dbe6a9bc 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/MapperConfig.java @@ -14,7 +14,7 @@ /** * The config of a {@link RowMapper}. */ -public class MapperConfig implements Cloneable { +public class MapperConfig { public static final MapperConfig DEFAULT = new MapperConfig(); private Map aliases = new HashMap<>(); private boolean strict = false; @@ -68,12 +68,6 @@ public MapperConfig strict() { return this; } - @Override - @Deprecated(forRemoval = true) - public MapperConfig clone() { - return copy(); - } - public MapperConfig copy() { var mapperConfig = new MapperConfig(); mapperConfig.aliases = new HashMap<>(aliases); diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java index 0cb29bec..23518c13 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/RowMapperRegistry.java @@ -60,6 +60,7 @@ public RowMapperRegistry register(RowMapper rowMapper) { */ public RowMapperRegistry register(RowMapper... rowMapper) { for (var mapper : rowMapper) { + //noinspection ResultOfMethodCallIgnored register(mapper); } return this; @@ -75,6 +76,7 @@ public RowMapperRegistry register(RowMapper... rowMapper) { */ public RowMapperRegistry register(List> rowMapper) { for (var mapper : rowMapper) { + //noinspection ResultOfMethodCallIgnored register(mapper); } return this; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingAlreadyRegisteredException.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingAlreadyRegisteredException.java index 8a43a37d..ae00e674 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingAlreadyRegisteredException.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingAlreadyRegisteredException.java @@ -6,7 +6,12 @@ package de.chojo.sadu.mapper.exceptions; +import java.io.Serial; + public class MappingAlreadyRegisteredException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + public MappingAlreadyRegisteredException(String message) { super(message); } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingException.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingException.java index 133d750d..85fe3803 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingException.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/MappingException.java @@ -8,10 +8,13 @@ import de.chojo.sadu.mapper.util.Results; +import java.io.Serial; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class MappingException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; public MappingException(String message) { super(message); diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java index 58e2096d..0088ae5e 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/RowMapping.java @@ -11,6 +11,7 @@ import java.sql.SQLException; +@FunctionalInterface public interface RowMapping { static RowMapping create(ThrowingFunction mapper) { return mapper::apply; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java index 5cb59df9..ef538c0f 100644 --- a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/Row.java @@ -43,7 +43,7 @@ /** * Represents the row of a result set. Made to restrict actions on valid calls. */ -@SuppressWarnings("unused") +@SuppressWarnings({"unused", "UseOfObsoleteDateTimeApi"}) public class Row { private final ResultSet resultSet; diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java index d14527b2..7bbfe9d6 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/databases/MariaDb.java @@ -15,7 +15,7 @@ /** * Represents a MariaDb database. */ -public class MariaDb extends DefaultDatabase> { +public class MariaDb implements DefaultDatabase> { private static final MariaDb type = new MariaDb(); diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java index 4c5db3f0..6c4a9abf 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/jdbc/MariaDbJdbc.java @@ -12,6 +12,9 @@ * A builder to create a MariaDB jdbc url. */ public class MariaDbJdbc extends RemoteJdbcConfig { + public MariaDbJdbc() { + } + @Override public String driver() { return "mariadb"; @@ -183,6 +186,7 @@ public Credentials userCredentials() { /** * Represents different SSL modes. */ + @SuppressWarnings("NewClassNamingConvention") public enum SslMode { /** * Do not use SSL/TLS diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java index 0a2ebb9b..a8dafc45 100644 --- a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/mapper/MariaDbMapper.java @@ -36,6 +36,7 @@ public final class MariaDbMapper { public static final RowMapper BYTES_MAPPER = createBytes(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR)); public static final RowMapper UUID_MAPPER = createUuid(List.of(MariaDbTypes.TINYTEXT, MariaDbTypes.TEXT, MariaDbTypes.MEDIUMTEXT, MariaDbTypes.LONGTEXT, MariaDbTypes.VARCHAR), List.of(MariaDbTypes.TINYBLOB, MariaDbTypes.BLOB, MariaDbTypes.MEDIUMBLOB, MariaDbTypes.LONGBLOB, MariaDbTypes.VARBINARY)); + private MariaDbMapper() { throw new UnsupportedOperationException("This is a utility class."); } diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java index 748c3571..51bfdb8c 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/databases/MySql.java @@ -15,7 +15,7 @@ /** * Represents a SqLite database. */ -public class MySql extends DefaultDatabase> { +public class MySql implements DefaultDatabase> { private static final MySql type = new MySql(); diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java index 1e5ce314..2f0e0f5c 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/jdbc/MySQLJdbc.java @@ -12,6 +12,9 @@ * A builder to create a MySQL jdbc url. */ public class MySQLJdbc extends RemoteJdbcConfig { + public MySQLJdbc() { + } + @Override public String driver() { return "mysql"; diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java index 53862952..bd3681af 100644 --- a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/mapper/MySqlMapper.java @@ -31,6 +31,7 @@ public final class MySqlMapper { public static final RowMapper BYTES_MAPPER = createBytes(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR)); public static final RowMapper UUID_MAPPER = createUuid(List.of(MySqlTypes.TINYTEXT, MySqlTypes.TEXT, MySqlTypes.MEDIUMTEXT, MySqlTypes.LONGTEXT, MySqlTypes.VARCHAR), List.of(MySqlTypes.TINYBLOB, MySqlTypes.BLOB, MySqlTypes.MEDIUMBLOB, MySqlTypes.LONGBLOB, MySqlTypes.VARBINARY)); + private MySqlMapper() { throw new UnsupportedOperationException("This is a utility class."); } diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java index 99b0600f..ed2d8242 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java @@ -14,7 +14,7 @@ /** * Represents a PostgreSQL database. */ -public class PostgreSql extends DefaultDatabase { +public class PostgreSql implements DefaultDatabase { private static final PostgreSql type = new PostgreSql(); diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java index b684ed29..9b7b01e3 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/jdbc/PostgreSqlJdbc.java @@ -12,6 +12,10 @@ * A builder to create a PostgreSQL jdbc url. */ public class PostgreSqlJdbc extends RemoteJdbcConfig { + + public PostgreSqlJdbc() { + } + @Override public String driver() { return "postgresql"; @@ -201,6 +205,7 @@ protected String defaultDriverClass() { /** * Represents different SSL modes. */ + @SuppressWarnings("NewClassNamingConvention") public enum SslMode { /** * No validation diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java index 52a591cb..7e238090 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/mapper/PostgresqlMapper.java @@ -35,6 +35,7 @@ public final class PostgresqlMapper { public static final RowMapper STRING_MAPPER = createString(List.of(PostgreSqlTypes.TEXT, PostgreSqlTypes.VARCHAR, PostgreSqlTypes.CHAR, PostgreSqlTypes.JSON, PostgreSqlTypes.JSONB)); public static final RowMapper BYTES_MAPPER = createBytes(List.of(PostgreSqlTypes.BYTEA)); public static final RowMapper UUID_MAPPER = createUuid(List.of(PostgreSqlTypes.TEXT), List.of(PostgreSqlTypes.BYTEA)); + private PostgresqlMapper() { throw new UnsupportedOperationException("This is a utility class."); } diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java index d7faa240..554daa33 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java @@ -38,6 +38,7 @@ protected void forceDatabaseConsistency() throws IOException, SQLException { if (type().hasSchemas()) { for (var schema : schemas) { if (!schemaExists(schema)) { + //noinspection JDBCPrepareStatementWithNonConstantString try (var stmt = conn.prepareStatement(type().createSchema(schema))) { stmt.execute(); log.info("Schema {} did not exist. Created.", schema); @@ -53,6 +54,7 @@ protected void forceDatabaseConsistency() throws IOException, SQLException { } private boolean schemaExists(String schema) { + //noinspection JDBCPrepareStatementWithNonConstantString try (var conn = source().getConnection(); var stmt = conn.prepareStatement(type().schemaExists())) { stmt.setString(1, schema); var row = stmt.executeQuery(); diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java index e7143980..8d51c24f 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/storage/ResultStorage.java @@ -10,7 +10,6 @@ import java.util.Optional; public interface ResultStorage { - @SuppressWarnings("unchecked") T get(String key); Optional getAs(String key, Class clazz); diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java index 6224c984..c79c48d4 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/calls/BatchCall.java @@ -50,7 +50,7 @@ public BatchCall(List calls) { * Adds a {@link CallImpl} object to the list of calls. * * @param call The call to be added to the list. - * @return The updated {@link BatchCall} object. + * @return The updated object. */ public BatchCall add(Call call) { calls.add(call); diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java index 142d7a85..bf8f4653 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/ConnectedQueryConfiguration.java @@ -30,6 +30,7 @@ public ConnectedQueryConfiguration forQuery(QueryImpl query) { public void close() { try { if (connection != null && !connection.isClosed()) { + //noinspection DataFlowIssue if (query.exceptions().isEmpty()) { if (atomic()) { connection.commit(); diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java index 705f1440..5c569e35 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/configuration/QueryConfiguration.java @@ -93,6 +93,7 @@ public QueryConfiguration forQuery(QueryImpl query) { */ public void handleException(SQLException e) { exceptionHandler.accept(e); + //noinspection DataFlowIssue query.logException(e); if (throwExceptions) { throw (WrappedQueryExecutionException) new WrappedQueryExecutionException(e.getMessage()).initCause(e); @@ -118,9 +119,9 @@ public boolean throwExceptions() { } /** - * Retrieves the {@link RowMapperRegistry} object from the {@link QueryConfiguration}. + * Retrieves the {@link RowMapperRegistry} object from the QueryConfiguration. * - * @return The {@link RowMapperRegistry} object from the {@link QueryConfiguration}. + * @return The {@link RowMapperRegistry} object from the QueryConfiguration. */ public RowMapperRegistry rowMapperRegistry() { return rowMapperRegistry; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java index 11261483..cfd8fa6b 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/QueryExecutionException.java @@ -8,12 +8,15 @@ import de.chojo.sadu.queries.query.QueryImpl; +import java.io.Serial; import java.sql.SQLException; /** * Exception to wrap {@link Exception} as {@link Exception} thrown during queries executed by {@link QueryImpl} */ public class QueryExecutionException extends SQLException { + @Serial + private static final long serialVersionUID = 1; /** * Cause of the exception */ diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java index f39e52d2..69f3261b 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/exception/WrappedQueryExecutionException.java @@ -8,12 +8,16 @@ import de.chojo.sadu.queries.query.QueryImpl; +import java.io.Serial; import java.sql.SQLException; /** * Exception to wrap {@link Exception} as {@link RuntimeException} thrown during queries executed by {@link QueryImpl} */ public class WrappedQueryExecutionException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + /** * Cause of the exception */ diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java index 9fef53b8..baafaa32 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java @@ -8,6 +8,7 @@ import de.chojo.sadu.mapper.MapperConfig; import de.chojo.sadu.mapper.rowmapper.RowMapping; +import de.chojo.sadu.mapper.wrapper.Row; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.call.Call; import de.chojo.sadu.queries.api.execution.reading.Reader; @@ -20,7 +21,6 @@ import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; import de.chojo.sadu.queries.stages.results.reading.MultiResult; import de.chojo.sadu.queries.stages.results.reading.SingleResult; -import de.chojo.sadu.mapper.wrapper.Row; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java index 00dd3bbd..519b5c45 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java @@ -52,6 +52,7 @@ public Reader mapAs(Class clazz, MapperConfig config) { public ManipulationResult insert() { return query.callConnection(() -> new ManipulationResultImpl(this, 0), conn -> { var changed = 0; + //noinspection JDBCPrepareStatementWithNonConstantString try (var stmt = conn.prepareStatement(query.sql().tokenizedSql())) { //TODO find way to return generated keys ((CallImpl) call.call()).apply(query.sql(), stmt); @@ -67,6 +68,7 @@ public ManipulationResult insert() { public ManipulationResult update() { return query().callConnection(() -> new ManipulationResultImpl(this, 0), conn -> { var changed = 0; + //noinspection JDBCPrepareStatementWithNonConstantString try (var stmt = conn.prepareStatement(query.sql().tokenizedSql())) { ((CallImpl) call.call()).apply(query.sql(), stmt); changed = stmt.executeUpdate(); diff --git a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/databases/SqLite.java b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/databases/SqLite.java index ac69b38a..1c743965 100644 --- a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/databases/SqLite.java +++ b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/databases/SqLite.java @@ -15,7 +15,7 @@ /** * Represents a SqLite database. */ -public class SqLite extends DefaultDatabase> { +public class SqLite implements DefaultDatabase> { private static final SqLite type = new SqLite(); diff --git a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java index a00ae381..454b5b7d 100644 --- a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java +++ b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/mapper/SqLiteMapper.java @@ -34,6 +34,7 @@ public final class SqLiteMapper { public static final RowMapper STRING_MAPPER = createString(List.of(TEXT)); public static final RowMapper BYTES_MAPPER = createBytes(List.of(BLOB)); public static final RowMapper UUID_MAPPER = createUuid(List.of(TEXT), List.of(BLOB)); + private SqLiteMapper() { throw new UnsupportedOperationException("This is a utility class."); } diff --git a/sadu-testing/src/main/java/de/chojo/sadu/testing/DatabaseVersionChecks.java b/sadu-testing/src/main/java/de/chojo/sadu/testing/DatabaseVersionChecks.java index ad8fc9bb..486d5063 100644 --- a/sadu-testing/src/main/java/de/chojo/sadu/testing/DatabaseVersionChecks.java +++ b/sadu-testing/src/main/java/de/chojo/sadu/testing/DatabaseVersionChecks.java @@ -15,7 +15,11 @@ /** * The DatabaseVersionChecks class provides methods for checking the content of the version file. */ -public class DatabaseVersionChecks { +public final class DatabaseVersionChecks { + private DatabaseVersionChecks() { + throw new UnsupportedOperationException("This is a utility class."); + } + /** * Checks if the version file exists in the "database" directory. *

diff --git a/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java b/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java index 9fd6cbab..174f466d 100644 --- a/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java +++ b/sadu-testing/src/main/java/de/chojo/sadu/testing/PatchChecks.java @@ -130,17 +130,11 @@ public static void checkFiles(int baseVersion, String currentVersion, String... Assertions.assertTrue(unreachable.isEmpty(), "There are unreachable files:%n%s".formatted(files)); } - private static class Version { - final int major, patch; - - Version(int major, int patch) { - this.major = major; - this.patch = patch; - } + private record Version(int major, int patch) { static Version parse(String version) { - var split = version.split("\\."); - return new Version(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + var split = version.split("\\."); + return new Version(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } } - } } diff --git a/sadu-testing/src/main/java/de/chojo/sadu/testing/SaduTests.java b/sadu-testing/src/main/java/de/chojo/sadu/testing/SaduTests.java index a7261c15..fc4fc676 100644 --- a/sadu-testing/src/main/java/de/chojo/sadu/testing/SaduTests.java +++ b/sadu-testing/src/main/java/de/chojo/sadu/testing/SaduTests.java @@ -10,7 +10,12 @@ import java.io.IOException; -public class SaduTests { +public final class SaduTests { + + private SaduTests() { + throw new UnsupportedOperationException("This is a utility class."); + } + /** * Executes all sadu related tests * diff --git a/sadu-testing/src/main/java/de/chojo/sadu/testing/TestUtil.java b/sadu-testing/src/main/java/de/chojo/sadu/testing/TestUtil.java index a57b9f0d..e7fe34fa 100644 --- a/sadu-testing/src/main/java/de/chojo/sadu/testing/TestUtil.java +++ b/sadu-testing/src/main/java/de/chojo/sadu/testing/TestUtil.java @@ -23,7 +23,7 @@ public class TestUtil { * * @see Path */ - public static Path resourcePath = Path.of("src/main/resources"); + public static final Path resourcePath = Path.of("src/main/resources"); private TestUtil() { throw new UnsupportedOperationException("This is a utility class."); diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java index e0b4a4b7..cc301299 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/BaseSqlUpdaterBuilder.java @@ -29,8 +29,8 @@ public class BaseSqlUpdaterBuilder, S extends BaseSqlUpd protected final Database type; protected DataSource source; protected SqlVersion version; - protected Map> preUpdateHook = new HashMap<>(); - protected Map> postUpdateHook = new HashMap<>(); + protected final Map> preUpdateHook = new HashMap<>(); + protected final Map> postUpdateHook = new HashMap<>(); protected String versionTable = "version"; protected QueryReplacement[] replacements = new QueryReplacement[0]; protected ClassLoader classLoader = getClass().getClassLoader(); diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java index ba7708c0..d5cbf67b 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/Patch.java @@ -8,28 +8,7 @@ import de.chojo.sadu.core.updater.SqlVersion; -class Patch { - private final int major; - private final int patch; - private final String query; - - public Patch(int major, int patch, String query) { - this.major = major; - this.patch = patch; - this.query = query; - } - - public int major() { - return major; - } - - public int patch() { - return patch; - } - - public String query() { - return query; - } +record Patch(int major, int patch, String query) { public SqlVersion version() { return new SqlVersion(major, patch); diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java index 22ddbf56..e33673ac 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/SqlUpdater.java @@ -100,6 +100,7 @@ * - 2/patch_1.sql *

*/ +@SuppressWarnings("JDBCPrepareStatementWithNonConstantString") public class SqlUpdater, U extends BaseSqlUpdaterBuilder> { private static final Logger log = LoggerFactory.getLogger(SqlUpdater.class); private final SqlVersion version; @@ -131,29 +132,10 @@ protected SqlUpdater(DataSource source, String versionTable, QueryReplacement[] * @param type the sql type of the database * @param type of the database defined by the {@link Database} * @return new builder instance - * @throws IOException if the version file does not exist. */ @CheckReturnValue - public static , U extends UpdaterBuilder> U builder(DataSource dataSource, Database type) throws IOException { - return (U) type.newSqlUpdaterBuilder().setSource(dataSource); - } - - /** - * Creates a new {@link BaseSqlUpdaterBuilder} with a version set to a string located in {@code resources/database/version}. - * - * @param dataSource the data source to connect to the database - * @param version the version with {@code Major.Patch} - * @param type the sql type of the database - * @param type of the database defined by the {@link Database} - * @return builder instance - * @deprecated Use {{@link #builder(DataSource, Database)}} and use {@link UpdaterBuilder#setVersion(SqlVersion)}. - */ - @Deprecated(forRemoval = true) - public static , U extends UpdaterBuilder> U builder(DataSource dataSource, SqlVersion version, Database type) { - var builder = type.newSqlUpdaterBuilder(); - builder.setSource(dataSource); - builder.setVersion(version); - return (U) builder; + public static , U extends UpdaterBuilder> U builder(DataSource dataSource, Database type) { + return type.newSqlUpdaterBuilder().setSource(dataSource); } @ApiStatus.Internal @@ -204,6 +186,7 @@ private void performUpdate(Patch patch) throws SQLException { statement.execute(); } catch (SQLException e) { log.warn("Failed to execute statement:\n{}", query, e); + //noinspection ThrowCaughtLocally throw e; } } @@ -326,7 +309,7 @@ private String loadFromResource(Object... path) throws IOException { var patch = Arrays.stream(path).map(Object::toString).collect(Collectors.joining("/")); try (var patchFile = classLoader.getResourceAsStream("database/" + type.name() + "/" + patch)) { log.info("Loading resource {}", "database/" + type.name() + "/" + patch); - return new String(patchFile.readAllBytes(), StandardCharsets.UTF_8); + return new String(Objects.requireNonNull(patchFile, "Patch file not found").readAllBytes(), StandardCharsets.UTF_8); } } diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/UpdateException.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/UpdateException.java index dee3887f..4da89ccc 100644 --- a/sadu-updater/src/main/java/de/chojo/sadu/updater/UpdateException.java +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/UpdateException.java @@ -6,10 +6,15 @@ package de.chojo.sadu.updater; +import java.io.Serial; + /** * Represents an exception thrown while the database got updated. */ public class UpdateException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1; + /** * A new update exception * From f359235298a15f69496ede77dc0ce2c0eb409ac7 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:18:22 +0100 Subject: [PATCH 18/29] Add documentation --- .../src/main/java/de/chojo/sadu/core/base/package-info.java | 4 ++++ .../main/java/de/chojo/sadu/core/conversion/package-info.java | 4 ++++ .../de/chojo/sadu/core/databases/exceptions/package-info.java | 4 ++++ .../main/java/de/chojo/sadu/core/databases/package-info.java | 4 ++++ .../main/java/de/chojo/sadu/core/exceptions/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/core/jdbc/package-info.java | 4 ++++ sadu-core/src/main/java/de/chojo/sadu/core/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/core/types/package-info.java | 4 ++++ .../main/java/de/chojo/sadu/datasource/DataSourceCreator.java | 1 + .../{ => exceptions}/DriverClassNotFoundException.java | 2 +- .../de/chojo/sadu/datasource/exceptions/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/datasource/package-info.java | 4 ++++ .../java/de/chojo/sadu/datasource/stage/package-info.java | 4 ++++ sadu-datasource/src/main/java/module-info.java | 1 + .../java/de/chojo/sadu/mapper/exceptions/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/mapper/package-info.java | 4 ++++ .../java/de/chojo/sadu/mapper/rowmapper/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/mapper/util/package-info.java | 4 ++++ .../main/java/de/chojo/sadu/mapper/wrapper/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/mariadb/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/mysql/package-info.java | 4 ++++ .../java/de/chojo/sadu/postgresql/databases/PostgreSql.java | 2 +- .../src/main/java/de/chojo/sadu/postgresql/package-info.java | 4 ++++ .../postgresql/{update => updater}/PostgreSqlUpdater.java | 2 +- .../{update => updater}/PostgreSqlUpdaterBuilder.java | 2 +- sadu-postgresql/src/main/java/module-info.java | 2 +- .../src/main/java/de/chojo/sadu/queries/api/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/queries/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/sqlite/package-info.java | 4 ++++ .../src/main/java/de/chojo/sadu/updater/package-info.java | 4 ++++ 30 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/base/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/conversion/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/databases/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/exceptions/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/jdbc/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/package-info.java create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/types/package-info.java rename sadu-datasource/src/main/java/de/chojo/sadu/datasource/{ => exceptions}/DriverClassNotFoundException.java (90%) create mode 100644 sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/package-info.java create mode 100644 sadu-datasource/src/main/java/de/chojo/sadu/datasource/package-info.java create mode 100644 sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/package-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/package-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/package-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/package-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/package-info.java create mode 100644 sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/package-info.java create mode 100644 sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/package-info.java create mode 100644 sadu-mysql/src/main/java/de/chojo/sadu/mysql/package-info.java create mode 100644 sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/package-info.java rename sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/{update => updater}/PostgreSqlUpdater.java (98%) rename sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/{update => updater}/PostgreSqlUpdaterBuilder.java (97%) create mode 100644 sadu-queries/src/main/java/de/chojo/sadu/queries/api/package-info.java create mode 100644 sadu-queries/src/main/java/de/chojo/sadu/queries/package-info.java create mode 100644 sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/package-info.java create mode 100644 sadu-updater/src/main/java/de/chojo/sadu/updater/package-info.java diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/base/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/base/package-info.java new file mode 100644 index 00000000..c31de188 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/base/package-info.java @@ -0,0 +1,4 @@ +/** + * General base classes. + */ +package de.chojo.sadu.core.base; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/conversion/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/package-info.java new file mode 100644 index 00000000..bb50e8f0 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/package-info.java @@ -0,0 +1,4 @@ +/** + * Utilities to convert values + */ +package de.chojo.sadu.core.conversion; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/package-info.java new file mode 100644 index 00000000..fb07dd34 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/exceptions/package-info.java @@ -0,0 +1,4 @@ +/** + * Exceptions that might be thrown when working with a database implementation + */ +package de.chojo.sadu.core.databases.exceptions; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/databases/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/databases/package-info.java new file mode 100644 index 00000000..dfc8ecb7 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/databases/package-info.java @@ -0,0 +1,4 @@ +/** + * Base for defining a database implementation + */ +package de.chojo.sadu.core.databases; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/package-info.java new file mode 100644 index 00000000..c3976753 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/exceptions/package-info.java @@ -0,0 +1,4 @@ +/** + * Base for handling exceptions in functional interfaces + */ +package de.chojo.sadu.core.exceptions; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/package-info.java new file mode 100644 index 00000000..32a3e5d4 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/jdbc/package-info.java @@ -0,0 +1,4 @@ +/** + * Base for creating a jdbc url + */ +package de.chojo.sadu.core.jdbc; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/package-info.java new file mode 100644 index 00000000..67203106 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds the core interfaces and implementations used in sadu modules. + */ +package de.chojo.sadu.core; diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/types/package-info.java b/sadu-core/src/main/java/de/chojo/sadu/core/types/package-info.java new file mode 100644 index 00000000..7344df04 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/types/package-info.java @@ -0,0 +1,4 @@ +/** + * Base for implementing a new SQL type + */ +package de.chojo.sadu.core.types; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java index a65ae38c..03c96d6c 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DataSourceCreator.java @@ -11,6 +11,7 @@ import de.chojo.sadu.core.databases.Database; import de.chojo.sadu.core.jdbc.JdbcConfig; import de.chojo.sadu.core.jdbc.RemoteJdbcConfig; +import de.chojo.sadu.datasource.exceptions.DriverClassNotFoundException; import de.chojo.sadu.datasource.stage.ConfigurationStage; import de.chojo.sadu.datasource.stage.JdbcStage; import org.jetbrains.annotations.CheckReturnValue; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/DriverClassNotFoundException.java similarity index 90% rename from sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java rename to sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/DriverClassNotFoundException.java index f53443c7..a50d2334 100644 --- a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/DriverClassNotFoundException.java +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/DriverClassNotFoundException.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.datasource; +package de.chojo.sadu.datasource.exceptions; import java.io.Serial; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/package-info.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/package-info.java new file mode 100644 index 00000000..6da9b51a --- /dev/null +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/exceptions/package-info.java @@ -0,0 +1,4 @@ +/** + * Exceptions that might be thrown when creating a datasource + */ +package de.chojo.sadu.datasource.exceptions; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/package-info.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/package-info.java new file mode 100644 index 00000000..615f1160 --- /dev/null +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of a datasource creator + */ +package de.chojo.sadu.datasource; diff --git a/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/package-info.java b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/package-info.java new file mode 100644 index 00000000..f54abd03 --- /dev/null +++ b/sadu-datasource/src/main/java/de/chojo/sadu/datasource/stage/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the stages of a data source creator + */ +package de.chojo.sadu.datasource.stage; diff --git a/sadu-datasource/src/main/java/module-info.java b/sadu-datasource/src/main/java/module-info.java index 9b599f3f..6bb5804c 100644 --- a/sadu-datasource/src/main/java/module-info.java +++ b/sadu-datasource/src/main/java/module-info.java @@ -4,4 +4,5 @@ exports de.chojo.sadu.datasource.stage; exports de.chojo.sadu.datasource; + exports de.chojo.sadu.datasource.exceptions; } diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/package-info.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/package-info.java new file mode 100644 index 00000000..323f2e00 --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/exceptions/package-info.java @@ -0,0 +1,4 @@ +/** + * Exceptions that might be thrown when working with mappings. + */ +package de.chojo.sadu.mapper.exceptions; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/package-info.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/package-info.java new file mode 100644 index 00000000..fa18f32a --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/package-info.java @@ -0,0 +1,4 @@ +/** + * The mapper package is responsible to map rows into a java object. + */ +package de.chojo.sadu.mapper; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/package-info.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/package-info.java new file mode 100644 index 00000000..117e9511 --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/rowmapper/package-info.java @@ -0,0 +1,4 @@ +/** + * Classes and interfaces used to map rows + */ +package de.chojo.sadu.mapper.rowmapper; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/package-info.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/package-info.java new file mode 100644 index 00000000..b16f7275 --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/util/package-info.java @@ -0,0 +1,4 @@ +/** + * Utilities used by the mapper + */ +package de.chojo.sadu.mapper.util; diff --git a/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/package-info.java b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/package-info.java new file mode 100644 index 00000000..d610b896 --- /dev/null +++ b/sadu-mapper/src/main/java/de/chojo/sadu/mapper/wrapper/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds wrapper for java types + */ +package de.chojo.sadu.mapper.wrapper; diff --git a/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/package-info.java b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/package-info.java new file mode 100644 index 00000000..4f6fe5f2 --- /dev/null +++ b/sadu-mariadb/src/main/java/de/chojo/sadu/mariadb/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds database specific implementations for MariaDB + */ +package de.chojo.sadu.mariadb; diff --git a/sadu-mysql/src/main/java/de/chojo/sadu/mysql/package-info.java b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/package-info.java new file mode 100644 index 00000000..eb10bf53 --- /dev/null +++ b/sadu-mysql/src/main/java/de/chojo/sadu/mysql/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds database specific implementations for MySQL + */ +package de.chojo.sadu.mysql; diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java index ed2d8242..3c7d9040 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/databases/PostgreSql.java @@ -8,7 +8,7 @@ import de.chojo.sadu.core.databases.DefaultDatabase; import de.chojo.sadu.postgresql.jdbc.PostgreSqlJdbc; -import de.chojo.sadu.postgresql.update.PostgreSqlUpdaterBuilder; +import de.chojo.sadu.postgresql.updater.PostgreSqlUpdaterBuilder; import de.chojo.sadu.updater.BaseSqlUpdaterBuilder; /** diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/package-info.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/package-info.java new file mode 100644 index 00000000..a4bff492 --- /dev/null +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds database specific implementations for PostgreSQL + */ +package de.chojo.sadu.postgresql; diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdater.java similarity index 98% rename from sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdater.java index 554daa33..a2ed02ce 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdater.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdater.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.postgresql.update; +package de.chojo.sadu.postgresql.updater; import de.chojo.sadu.core.databases.Database; import de.chojo.sadu.core.updater.SqlVersion; diff --git a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdaterBuilder.java similarity index 97% rename from sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java rename to sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdaterBuilder.java index db50653b..bc0b4d85 100644 --- a/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/update/PostgreSqlUpdaterBuilder.java +++ b/sadu-postgresql/src/main/java/de/chojo/sadu/postgresql/updater/PostgreSqlUpdaterBuilder.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.postgresql.update; +package de.chojo.sadu.postgresql.updater; import de.chojo.sadu.core.databases.Database; import de.chojo.sadu.core.updater.SqlVersion; diff --git a/sadu-postgresql/src/main/java/module-info.java b/sadu-postgresql/src/main/java/module-info.java index 9daa1680..e550896f 100644 --- a/sadu-postgresql/src/main/java/module-info.java +++ b/sadu-postgresql/src/main/java/module-info.java @@ -6,5 +6,5 @@ exports de.chojo.sadu.postgresql.jdbc; exports de.chojo.sadu.postgresql.mapper; exports de.chojo.sadu.postgresql.types; - exports de.chojo.sadu.postgresql.update; + exports de.chojo.sadu.postgresql.updater; } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/package-info.java new file mode 100644 index 00000000..cef92fc3 --- /dev/null +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds the api for the query builder + */ +package de.chojo.sadu.queries.api; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/package-info.java new file mode 100644 index 00000000..858b74fb --- /dev/null +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of the sadu query builder + */ +package de.chojo.sadu.queries; diff --git a/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/package-info.java b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/package-info.java new file mode 100644 index 00000000..1a0238e9 --- /dev/null +++ b/sadu-sqlite/src/main/java/de/chojo/sadu/sqlite/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds database specific implementations for SqLite + */ +package de.chojo.sadu.sqlite; diff --git a/sadu-updater/src/main/java/de/chojo/sadu/updater/package-info.java b/sadu-updater/src/main/java/de/chojo/sadu/updater/package-info.java new file mode 100644 index 00000000..67eb0fbe --- /dev/null +++ b/sadu-updater/src/main/java/de/chojo/sadu/updater/package-info.java @@ -0,0 +1,4 @@ +/** + * Holds the implementation for the sql updater + */ +package de.chojo.sadu.updater; From d1d20a92e7542ac9e802d03aff6519f8f72ce392 Mon Sep 17 00:00:00 2001 From: Lilly Tempest <46890129+rainbowdashlabs@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:18:08 +0100 Subject: [PATCH 19/29] Feature: expose exceptions (#164) --- .../sadu/queries/api/results/BaseResult.java | 27 +++++++++++++++++++ .../queries/api/results/reading/Result.java | 5 ++-- .../results/writing/ManipulationResult.java | 4 ++- .../{stages => }/execution/package-info.java | 2 +- .../execution/reading/AutoMappedQuery.java | 4 +-- .../execution/reading/MappedQuery.java | 4 +-- .../execution/reading/ReaderImpl.java | 8 +++--- .../execution/reading/package-info.java | 2 +- .../writing/CalledBatchQueryImpl.java | 6 ++--- .../writing/CalledSingletonQueryImpl.java | 8 +++--- .../execution/writing/package-info.java | 2 +- .../sadu/queries/query/ParsedQueryImpl.java | 4 +-- .../{stages => }/results/package-info.java | 2 +- .../results/reading/MultiResult.java | 11 ++++++-- .../results/reading/SingleResult.java | 11 ++++++-- .../results/reading/package-info.java | 2 +- .../writing/ManipulationBatchQuery.java | 24 +++++------------ .../writing/ManipulationResultImpl.java | 21 +++++++-------- .../results/writing/package-info.java | 2 +- .../sadu/queries/stages/package-info.java | 4 --- sadu-queries/src/main/java/module-info.java | 8 +++--- 21 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/package-info.java (50%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/reading/AutoMappedQuery.java (88%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/reading/MappedQuery.java (79%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/reading/ReaderImpl.java (93%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/reading/package-info.java (50%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/writing/CalledBatchQueryImpl.java (91%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/writing/CalledSingletonQueryImpl.java (91%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/execution/writing/package-info.java (50%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/package-info.java (55%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/reading/MultiResult.java (77%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/reading/SingleResult.java (77%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/reading/package-info.java (56%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/writing/ManipulationBatchQuery.java (72%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/writing/ManipulationResultImpl.java (71%) rename sadu-queries/src/main/java/de/chojo/sadu/queries/{stages => }/results/writing/package-info.java (51%) delete mode 100644 sadu-queries/src/main/java/de/chojo/sadu/queries/stages/package-info.java diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java new file mode 100644 index 00000000..301e8dee --- /dev/null +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java @@ -0,0 +1,27 @@ +package de.chojo.sadu.queries.api.results; + +import java.util.List; + +/** + * The BaseResult interface represents the result of an operation. + * It provides methods to check if there are any exceptions and retrieve a list of exceptions, if any. + */ +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface BaseResult { + /** + * Returns a boolean value indicating whether there are any exceptions in the result. + * + * @return {@code true} if there are any exceptions in the result, {@code false} otherwise. + */ + default boolean hasExceptions() { + return !exceptions().isEmpty(); + } + + /** + * Returns a list of exceptions. + * + * @return a list of exceptions. If there are no exceptions, an empty list is returned. + */ + List exceptions(); + +} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java index 56ec0df4..4bfd9d91 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java @@ -6,7 +6,8 @@ package de.chojo.sadu.queries.api.results.reading; -import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; +import de.chojo.sadu.queries.api.results.BaseResult; +import de.chojo.sadu.queries.execution.reading.MappedQuery; import java.util.Optional; @@ -16,7 +17,7 @@ * @param type of returned object */ @SuppressWarnings("InterfaceMayBeAnnotatedFunctional") -public interface Result { +public interface Result extends BaseResult { /** * Get the result of the query * diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java index d5e7c921..cd5f601d 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java @@ -6,11 +6,13 @@ package de.chojo.sadu.queries.api.results.writing; +import de.chojo.sadu.queries.api.results.BaseResult; + /** * The ManipulationResult interface represents the result of a manipulation operation, * such as an insert, update, or delete operation. */ -public interface ManipulationResult { +public interface ManipulationResult extends BaseResult { /** * Returns the total number of changed rows resulting from a manipulation operation. * diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/package-info.java similarity index 50% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/package-info.java index 55c51454..9490f4b9 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/package-info.java @@ -1,4 +1,4 @@ /** * Implementation for executing queries. */ -package de.chojo.sadu.queries.stages.execution; +package de.chojo.sadu.queries.execution; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/AutoMappedQuery.java similarity index 88% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/AutoMappedQuery.java index f70c0bcc..592d32d5 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/AutoMappedQuery.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/AutoMappedQuery.java @@ -4,12 +4,12 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.execution.reading; +package de.chojo.sadu.queries.execution.reading; import de.chojo.sadu.mapper.MapperConfig; import de.chojo.sadu.mapper.RowMapperRegistry; import de.chojo.sadu.mapper.rowmapper.RowMapping; -import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; +import de.chojo.sadu.queries.execution.writing.CalledSingletonQueryImpl; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/MappedQuery.java similarity index 79% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/MappedQuery.java index d07cc11e..05e45b8b 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/MappedQuery.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/MappedQuery.java @@ -4,10 +4,10 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.execution.reading; +package de.chojo.sadu.queries.execution.reading; import de.chojo.sadu.mapper.rowmapper.RowMapping; -import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; +import de.chojo.sadu.queries.execution.writing.CalledSingletonQueryImpl; import java.sql.ResultSet; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/ReaderImpl.java similarity index 93% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/ReaderImpl.java index baafaa32..cf46ee21 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/ReaderImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/ReaderImpl.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.execution.reading; +package de.chojo.sadu.queries.execution.reading; import de.chojo.sadu.mapper.MapperConfig; import de.chojo.sadu.mapper.rowmapper.RowMapping; @@ -18,9 +18,9 @@ import de.chojo.sadu.queries.query.AppendedQueryImpl; import de.chojo.sadu.queries.query.QueryImpl; import de.chojo.sadu.queries.query.TokenizedQuery; -import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; -import de.chojo.sadu.queries.stages.results.reading.MultiResult; -import de.chojo.sadu.queries.stages.results.reading.SingleResult; +import de.chojo.sadu.queries.results.reading.MultiResult; +import de.chojo.sadu.queries.results.reading.SingleResult; +import de.chojo.sadu.queries.execution.writing.CalledSingletonQueryImpl; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/package-info.java similarity index 50% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/package-info.java index 7cbbdf28..a46326c7 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/reading/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/reading/package-info.java @@ -1,4 +1,4 @@ /** * Implementation for executing reading queries. */ -package de.chojo.sadu.queries.stages.execution.reading; +package de.chojo.sadu.queries.execution.reading; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledBatchQueryImpl.java similarity index 91% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledBatchQueryImpl.java index 33f10aa0..265adf1d 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledBatchQueryImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledBatchQueryImpl.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.execution.writing; +package de.chojo.sadu.queries.execution.writing; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.execution.writing.CalledBatchQuery; @@ -14,8 +14,8 @@ import de.chojo.sadu.queries.calls.BatchCall; import de.chojo.sadu.queries.query.ParsedQueryImpl; import de.chojo.sadu.queries.query.QueryImpl; -import de.chojo.sadu.queries.stages.results.writing.ManipulationBatchQuery; -import de.chojo.sadu.queries.stages.results.writing.ManipulationResultImpl; +import de.chojo.sadu.queries.results.writing.ManipulationBatchQuery; +import de.chojo.sadu.queries.results.writing.ManipulationResultImpl; import java.sql.SQLException; import java.util.ArrayList; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledSingletonQueryImpl.java similarity index 91% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledSingletonQueryImpl.java index 519b5c45..69f14c6d 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/CalledSingletonQueryImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/CalledSingletonQueryImpl.java @@ -4,7 +4,7 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.execution.writing; +package de.chojo.sadu.queries.execution.writing; import de.chojo.sadu.mapper.MapperConfig; import de.chojo.sadu.mapper.rowmapper.RowMapping; @@ -18,9 +18,9 @@ import de.chojo.sadu.queries.query.ParsedQueryImpl; import de.chojo.sadu.queries.query.QueryImpl; import de.chojo.sadu.queries.query.TokenizedQuery; -import de.chojo.sadu.queries.stages.execution.reading.AutoMappedQuery; -import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; -import de.chojo.sadu.queries.stages.results.writing.ManipulationResultImpl; +import de.chojo.sadu.queries.execution.reading.AutoMappedQuery; +import de.chojo.sadu.queries.execution.reading.MappedQuery; +import de.chojo.sadu.queries.results.writing.ManipulationResultImpl; import java.sql.SQLException; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/package-info.java similarity index 50% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/package-info.java index 4e4ed143..d51aecee 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/execution/writing/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/execution/writing/package-info.java @@ -1,4 +1,4 @@ /** * Implementatino for executing writing queries. */ -package de.chojo.sadu.queries.stages.execution.writing; +package de.chojo.sadu.queries.execution.writing; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java index 7cca71e1..de38e6e0 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/query/ParsedQueryImpl.java @@ -13,8 +13,8 @@ import de.chojo.sadu.queries.calls.BatchCall; import de.chojo.sadu.queries.calls.CallSupplier; import de.chojo.sadu.queries.calls.SingletonCall; -import de.chojo.sadu.queries.stages.execution.writing.CalledBatchQueryImpl; -import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; +import de.chojo.sadu.queries.execution.writing.CalledBatchQueryImpl; +import de.chojo.sadu.queries.execution.writing.CalledSingletonQueryImpl; public class ParsedQueryImpl implements QueryProvider, ParsedQuery { private final QueryProvider query; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/package-info.java similarity index 55% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/package-info.java index 9924abf4..27506c35 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/package-info.java @@ -1,4 +1,4 @@ /** * Implementation of stages for result retrieval */ -package de.chojo.sadu.queries.stages.results; +package de.chojo.sadu.queries.results; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/MultiResult.java similarity index 77% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/MultiResult.java index 0c4b6c88..9f6384e1 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/MultiResult.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/MultiResult.java @@ -4,12 +4,14 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.results.reading; +package de.chojo.sadu.queries.results.reading; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.results.reading.Result; import de.chojo.sadu.queries.query.QueryImpl; -import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; +import de.chojo.sadu.queries.execution.reading.MappedQuery; + +import java.util.List; /** * Result of a {@link MappedQuery#allResults()} call @@ -35,4 +37,9 @@ public QueryImpl query() { public T result() { return results; } + + @Override + public List exceptions() { + return query().exceptions(); + } } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/SingleResult.java similarity index 77% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/SingleResult.java index 08e539b9..0ab0315c 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/SingleResult.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/SingleResult.java @@ -4,12 +4,14 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.results.reading; +package de.chojo.sadu.queries.results.reading; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.results.reading.Result; import de.chojo.sadu.queries.query.QueryImpl; -import de.chojo.sadu.queries.stages.execution.reading.MappedQuery; +import de.chojo.sadu.queries.execution.reading.MappedQuery; + +import java.util.List; /** * Result of a {@link MappedQuery#firstResult()} call @@ -34,4 +36,9 @@ public T result() { public QueryImpl query() { return query.query(); } + + @Override + public List exceptions() { + return query().exceptions(); + } } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/package-info.java similarity index 56% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/package-info.java index 32a17940..87f11658 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/reading/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/reading/package-info.java @@ -1,4 +1,4 @@ /** * Implementation for retrieving results of a reading query. */ -package de.chojo.sadu.queries.stages.results.reading; +package de.chojo.sadu.queries.results.reading; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationBatchQuery.java similarity index 72% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationBatchQuery.java index 295f188f..5d371284 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationBatchQuery.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationBatchQuery.java @@ -4,13 +4,13 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.results.writing; +package de.chojo.sadu.queries.results.writing; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.results.writing.ManipulationBatchResult; import de.chojo.sadu.queries.api.results.writing.ManipulationResult; import de.chojo.sadu.queries.query.QueryImpl; -import de.chojo.sadu.queries.stages.execution.writing.CalledBatchQueryImpl; +import de.chojo.sadu.queries.execution.writing.CalledBatchQueryImpl; import java.util.List; @@ -26,31 +26,16 @@ public ManipulationBatchQuery(QueryProvider query, List resu this.results = results; } - /** - * List of results of all calls in the batch - * - * @return list of results - */ @Override public List results() { return results; } - /** - * total amount of changed rows - * - * @return total count - */ @Override public int rows() { return results.stream().mapToInt(ManipulationResult::rows).sum(); } - /** - * Checks whether at least one row was changed. - * - * @return true if one row or more were changed - */ @Override public boolean changed() { return results.stream().anyMatch(ManipulationResult::changed); @@ -60,4 +45,9 @@ public boolean changed() { public QueryImpl query() { return query.query(); } + + @Override + public List exceptions() { + return query().exceptions(); + } } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationResultImpl.java similarity index 71% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationResultImpl.java index e42e1c16..ac1be730 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/ManipulationResultImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/ManipulationResultImpl.java @@ -4,12 +4,14 @@ * Copyright (C) RainbowDashLabs and Contributor */ -package de.chojo.sadu.queries.stages.results.writing; +package de.chojo.sadu.queries.results.writing; import de.chojo.sadu.queries.api.base.QueryProvider; import de.chojo.sadu.queries.api.results.writing.ManipulationResult; +import de.chojo.sadu.queries.execution.writing.CalledSingletonQueryImpl; import de.chojo.sadu.queries.query.QueryImpl; -import de.chojo.sadu.queries.stages.execution.writing.CalledSingletonQueryImpl; + +import java.util.List; /** * Result of a {@link CalledSingletonQueryImpl}. @@ -23,21 +25,11 @@ public ManipulationResultImpl(QueryProvider query, int rows) { this.rows = rows; } - /** - * Amount of changed rows - * - * @return rows - */ @Override public int rows() { return rows; } - /** - * Checks whether at least one row was changed - * - * @return true if at least one row was changed - */ @Override public boolean changed() { return rows != 0; @@ -47,4 +39,9 @@ public boolean changed() { public QueryImpl query() { return query.query(); } + + @Override + public List exceptions() { + return query().exceptions(); + } } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/package-info.java similarity index 51% rename from sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java rename to sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/package-info.java index c7258e88..320259c7 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/results/writing/package-info.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/results/writing/package-info.java @@ -1,4 +1,4 @@ /** * Implementation for results of a writing query. */ -package de.chojo.sadu.queries.stages.results.writing; +package de.chojo.sadu.queries.results.writing; diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/package-info.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/package-info.java deleted file mode 100644 index face8c79..00000000 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/stages/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Implementation of the different stages of a query lifecycle. - */ -package de.chojo.sadu.queries.stages; diff --git a/sadu-queries/src/main/java/module-info.java b/sadu-queries/src/main/java/module-info.java index c927a7bd..8f101257 100644 --- a/sadu-queries/src/main/java/module-info.java +++ b/sadu-queries/src/main/java/module-info.java @@ -27,10 +27,10 @@ exports de.chojo.sadu.queries.query; - exports de.chojo.sadu.queries.stages.execution.reading; - exports de.chojo.sadu.queries.stages.execution.writing; - exports de.chojo.sadu.queries.stages.results.reading; - exports de.chojo.sadu.queries.stages.results.writing; + exports de.chojo.sadu.queries.execution.reading; + exports de.chojo.sadu.queries.execution.writing; + exports de.chojo.sadu.queries.results.reading; + exports de.chojo.sadu.queries.results.writing; exports de.chojo.sadu.queries.storage; } From 4ef0516a97b7868139ac31a6118865eef194e5a3 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:29:06 +0100 Subject: [PATCH 20/29] Add license header --- .../java/de/chojo/sadu/queries/api/results/BaseResult.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java index 301e8dee..a38ac3fe 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/BaseResult.java @@ -1,3 +1,9 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * Copyright (C) RainbowDashLabs and Contributor + */ + package de.chojo.sadu.queries.api.results; import java.util.List; From fb717085323169790ba1fb0c0a62fdd7ee4c21f4 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:15:49 +0100 Subject: [PATCH 21/29] Add consumer methods to handle result changes --- .../results/writing/ManipulationResult.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java index cd5f601d..c37ab371 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/writing/ManipulationResult.java @@ -8,6 +8,8 @@ import de.chojo.sadu.queries.api.results.BaseResult; +import java.util.function.Consumer; + /** * The ManipulationResult interface represents the result of a manipulation operation, * such as an insert, update, or delete operation. @@ -26,4 +28,50 @@ public interface ManipulationResult extends BaseResult { * @return true if one row or more were changed */ boolean changed(); + + /** + * Checks whether the manipulation operation was successful. + *

+ * Success is determined by the absence of any exceptions and at least one row being changed. + * + * @return {@code true} if the operation was successful, {@code false} otherwise. + */ + default boolean isSuccess() { + return !hasExceptions() && rows() > 0; + } + + /** + * Executes the given consumer if at least one row was changed. + * + * @param consumer the consumer to execute if rows were changed + */ + default void ifChanged(Consumer consumer) { + if (changed()) { + consumer.accept(rows()); + } + } + + /** + * Executes the given Consumer if the ManipulationResult has no changes. + * + * @param notChanged the Consumer to execute + */ + default void ifEmpty(Consumer notChanged) { + if (!changed()) { + notChanged.accept(this); + } + } + + /** + * Executes the provided consumers based on the result of a manipulation operation. + * + * @param changed The consumer to be executed if at least one row was changed. Holds the changed rows count + * @param notChanged The consumer to be executed if no rows were changed. Holds the result itself. + * @see ManipulationResult#rows() + * @see ManipulationResult#changed() + */ + default void ifChangedOrElse(Consumer changed, Consumer notChanged) { + ifChanged(changed); + ifEmpty(notChanged); + } } From 0a52d9e4f684961ef7455626fe22b2575f7f0775 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:22:33 +0100 Subject: [PATCH 22/29] Add mapping function to result --- .../de/chojo/sadu/queries/api/results/reading/Result.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java index 4bfd9d91..7cd85707 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java @@ -10,6 +10,7 @@ import de.chojo.sadu.queries.execution.reading.MappedQuery; import java.util.Optional; +import java.util.function.Function; /** * Base of a result returned by a {@link MappedQuery} @@ -25,7 +26,11 @@ public interface Result extends BaseResult { */ T result(); - default Optional ifPresent() { + default Optional getIfPresent() { return Optional.ofNullable(result()); } + + default R map(Function map) { + return map.apply(result()); + } } From ef43de4de50f9a0cadbd49b6ca75669db79f5dd6 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:24:31 +0100 Subject: [PATCH 23/29] Rename method --- .../sadu/queries/api/results/reading/Result.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java index 7cd85707..4857483f 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/results/reading/Result.java @@ -8,6 +8,7 @@ import de.chojo.sadu.queries.api.results.BaseResult; import de.chojo.sadu.queries.execution.reading.MappedQuery; +import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.function.Function; @@ -26,10 +27,22 @@ public interface Result extends BaseResult { */ T result(); - default Optional getIfPresent() { + /** + * Retrieves the result of the query as an optional value. + * + * @return an {@code Optional} containing the result of the query, or an empty {@code Optional} if the result is null. + */ + default Optional get() { return Optional.ofNullable(result()); } + /** + * Applies a map function to the result of a query. + * + * @param the type of the mapped result + * @param map the function to apply to the result + * @return the mapped result + */ default R map(Function map) { return map.apply(result()); } From 53e05487e81c71031fdaf45b2d2d07883dc68a86 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:00:44 +0100 Subject: [PATCH 24/29] Handle unboxing of primitive types --- .../chojo/sadu/core/conversion/Unboxing.java | 13 ++++++++ .../de/chojo/sadu/queries/api/call/Call.java | 32 +++++++++---------- .../de/chojo/sadu/queries/call/CallImpl.java | 32 +++++++++---------- .../queries/call/adapter/StandardAdapter.java | 4 ++- 4 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 sadu-core/src/main/java/de/chojo/sadu/core/conversion/Unboxing.java diff --git a/sadu-core/src/main/java/de/chojo/sadu/core/conversion/Unboxing.java b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/Unboxing.java new file mode 100644 index 00000000..65e75292 --- /dev/null +++ b/sadu-core/src/main/java/de/chojo/sadu/core/conversion/Unboxing.java @@ -0,0 +1,13 @@ +package de.chojo.sadu.core.conversion; + +public final class Unboxing { + private Unboxing() { + throw new UnsupportedOperationException("This is a utility class."); + } + + public static byte[] unbox(Byte[] array) { + var unboxed = new byte[array.length]; + for (var i = 0; i < array.length; i++) unboxed[i] = array[i]; + return unboxed; + } +} diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java index be7db150..07f0db47 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/api/call/Call.java @@ -57,41 +57,41 @@ static Call call() { Call bind(String token, Enum value); - Call bind(short value); + Call bind(Short value); - Call bind(String token, short value); + Call bind(String token, Short value); - Call bind(int value); + Call bind(Integer value); - Call bind(long value); + Call bind(Long value); - Call bind(String token, long value); + Call bind(String token, Long value); - Call bind(String token, int value); + Call bind(String token, Integer value); - Call bind(float value); + Call bind(Float value); - Call bind(String token, float value); + Call bind(String token, Float value); - Call bind(double value); + Call bind(Double value); - Call bind(String token, double value); + Call bind(String token, Double value); Call bind(BigDecimal value); Call bind(String token, BigDecimal value); - Call bind(boolean value); + Call bind(Boolean value); - Call bind(String token, boolean value); + Call bind(String token, Boolean value); - Call bind(byte value); + Call bind(Byte value); - Call bind(String token, byte value); + Call bind(String token, Byte value); - Call bind(byte[] value); + Call bind(Byte[] value); - Call bind(String token, byte[] value); + Call bind(String token, Byte[] value); Call bind(Date value); diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java index 7f376850..26e20148 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/CallImpl.java @@ -90,52 +90,52 @@ public Call bind(String token, Enum value) { } @Override - public Call bind(short value) { + public Call bind(Short value) { return bind(value, StandardAdapter.SHORT); } @Override - public Call bind(String token, short value) { + public Call bind(String token, Short value) { return bind(token, value, StandardAdapter.SHORT); } @Override - public Call bind(int value) { + public Call bind(Integer value) { return bind(value, StandardAdapter.INTEGER); } @Override - public Call bind(String token, int value) { + public Call bind(String token, Integer value) { return bind(token, value, StandardAdapter.INTEGER); } @Override - public Call bind(boolean value) { + public Call bind(Boolean value) { return bind(value, StandardAdapter.BOOLEAN); } @Override - public Call bind(String token, boolean value) { + public Call bind(String token, Boolean value) { return bind(token, value, StandardAdapter.BOOLEAN); } @Override - public Call bind(byte value) { + public Call bind(Byte value) { return bind(value, StandardAdapter.BYTE); } @Override - public Call bind(String token, byte value) { + public Call bind(String token, Byte value) { return bind(token, value, StandardAdapter.BYTE); } @Override - public Call bind(byte[] value) { + public Call bind(Byte[] value) { return bind(value, StandardAdapter.BYTE_ARRAY); } @Override - public Call bind(String token, byte[] value) { + public Call bind(String token, Byte[] value) { return bind(token, value, StandardAdapter.BYTE_ARRAY); } @@ -150,22 +150,22 @@ public Call bind(String token, Date value) { } @Override - public Call bind(long value) { + public Call bind(Long value) { return bind(value, StandardAdapter.LONG); } @Override - public Call bind(String token, long value) { + public Call bind(String token, Long value) { return bind(token, value, StandardAdapter.LONG); } @Override - public Call bind(double value) { + public Call bind(Double value) { return bind(value, StandardAdapter.DOUBLE); } @Override - public Call bind(String token, double value) { + public Call bind(String token, Double value) { return bind(token, value, StandardAdapter.DOUBLE); } @@ -180,12 +180,12 @@ public Call bind(String token, BigDecimal value) { } @Override - public Call bind(float value) { + public Call bind(Float value) { return bind(value, StandardAdapter.FLOAT); } @Override - public Call bind(String token, float value) { + public Call bind(String token, Float value) { return bind(token, value, StandardAdapter.FLOAT); } diff --git a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java index 99572659..b103b3b2 100644 --- a/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java +++ b/sadu-queries/src/main/java/de/chojo/sadu/queries/call/adapter/StandardAdapter.java @@ -6,6 +6,7 @@ package de.chojo.sadu.queries.call.adapter; +import de.chojo.sadu.core.conversion.Unboxing; import de.chojo.sadu.core.types.SqlType; import de.chojo.sadu.queries.api.call.adapter.Adapter; @@ -26,6 +27,7 @@ import java.time.OffsetDateTime; import java.time.OffsetTime; import java.time.ZonedDateTime; +import java.util.Arrays; import java.util.Collection; import static de.chojo.sadu.core.conversion.ArrayConverter.toSqlArray; @@ -45,7 +47,7 @@ public final class StandardAdapter { public static final Adapter LONG = Adapter.create(PreparedStatement::setLong, Types.BIGINT); public static final Adapter BOOLEAN = Adapter.create(PreparedStatement::setBoolean, Types.BOOLEAN); public static final Adapter BYTE = Adapter.create(PreparedStatement::setByte, Types.BIT); - public static final Adapter BYTE_ARRAY = Adapter.create(PreparedStatement::setBytes, Types.BINARY); + public static final Adapter BYTE_ARRAY = Adapter.create(PreparedStatement::setBytes, Types.BINARY, Unboxing::unbox); public static final Adapter DATE = Adapter.create(PreparedStatement::setDate, Types.DATE); public static final Adapter LOCAL_DATE = Adapter.create(PreparedStatement::setDate, Types.DATE, Date::valueOf); public static final Adapter