From 8a1d36d1faa45b2b173f87831001ae54fa2634c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Ho=C3=9F?= Date: Sat, 24 Apr 2021 00:16:51 +0200 Subject: [PATCH] configure plugin & source sets --- .../build.gradle.kts | 35 ++++++-- .../example/gradle}/jdbc/java16/ExampleApp.java | 14 ++-- .../jdbc/java16/converter/ToItemConverter.java | 25 ++++++ .../example/gradle/jdbc/java16/model/Item.java | 36 ++++++++ .../main/yosql/company/findCompanies.sql} | 32 +++----- .../main/yosql/company/findCompanyByName.sql} | 29 ++----- .../main/yosql/company/insertCompany.sql} | 29 ++----- .../main/yosql/company/queryAllCompanies.sql} | 25 ++---- .../main/yosql/item/callItem.sql} | 23 +----- .../src/main/yosql/item/findItem.sql | 61 ++++++++++++++ .../main/yosql/person/findPerson.sql} | 44 ++++++---- .../main/yosql/schema/createCompaniesTable.sql} | 28 ++----- .../main/yosql/schema/createItemsTable.sql} | 28 ++----- .../main/yosql/schema/createPersonsTable.sql} | 33 ++++---- .../main/yosql/schema/dropCompaniesTable.sql} | 22 +---- .../main/yosql/schema/dropItemsTable.sql} | 22 +---- .../main/yosql/schema/dropPersonsTable.sql} | 22 +---- .../main/yosql/user/insertUser.sql} | 27 ++---- .../main/yosql/user/queryAllUsers.sql} | 25 ++---- .../main/yosql/user/queryInAnotherRepository.sql} | 28 ++----- .../main/yosql/user/querySingleUser.sql} | 32 +++----- .../main/yosql/user/querySpecialUser.sql} | 27 ++---- .../main/yosql/user/queryUnnamedUser.sql} | 26 ++---- .../main/yosql/user/queryWithoutFrontMatter.sql} | 26 ++---- .../main/yosql/user/updateUser.sql} | 29 ++----- .../main/yosql/user/updateUserStatic.sql} | 27 ++---- .../example/maven/jdbc/java16/ExampleApp.java | 2 + .../yosql/internals/jdk/SupportedLocales.java | 28 +++++++ .../yosql-tooling-gradle/build.gradle.kts | 1 + .../tooling/gradle/DefaultResultRowConverter.java | 61 ++++++++++++++ .../java/wtf/metio/yosql/tooling/gradle/Files.java | 14 ++++ .../metio/yosql/tooling/gradle/GenerateTask.java | 41 +++++---- .../java/wtf/metio/yosql/tooling/gradle/Java.java | 35 ++++++++ .../java/wtf/metio/yosql/tooling/gradle/Jdbc.java | 96 ++++++++++++++++++++++ .../metio/yosql/tooling/gradle/Repositories.java | 43 ++++++++++ .../tooling/gradle/UserResultRowConverter.java | 56 +++++++++++++ .../metio/yosql/tooling/gradle/YoSqlExtension.java | 41 ++++++++- .../metio/yosql/tooling/gradle/YoSqlPlugin.java | 27 +++--- .../metio/yosql/tooling/maven/GenerateMojo.java | 13 +-- 39 files changed, 747 insertions(+), 466 deletions(-) copy yosql-examples/{yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven => yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle}/jdbc/java16/ExampleApp.java (89%) create mode 100644 yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/converter/ToItemConverter.java create mode 100644 yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/model/Item.java copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/company/findCompanies.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/company/findCompanyByName.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/company/insertCompany.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/company/queryAllCompanies.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/item/callItem.sql} (53%) create mode 100644 yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/findItem.sql copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/person/findPerson.sql} (52%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/createCompaniesTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/createItemsTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/createPersonsTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/dropCompaniesTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/dropItemsTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/schema/dropPersonsTable.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/insertUser.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/queryAllUsers.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/queryInAnotherRepository.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/querySingleUser.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/querySpecialUser.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/queryUnnamedUser.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/queryWithoutFrontMatter.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/updateUser.sql} (53%) copy yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/{build.gradle.kts => src/main/yosql/user/updateUserStatic.sql} (53%) create mode 100644 yosql-internals/yosql-internals-jdk-utils/src/main/java/wtf/metio/yosql/internals/jdk/SupportedLocales.java create mode 100644 yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/DefaultResultRowConverter.java create mode 100644 yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Java.java create mode 100644 yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Jdbc.java create mode 100644 yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Repositories.java create mode 100644 yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/UserResultRowConverter.java diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts index 4dcc270b..09f60ac5 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts @@ -16,12 +16,37 @@ java { } } -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - yosql { files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) + skipLines.set(6) } + repositories { + basePackageName.set("wtf.metio.yosql.example.gradle.jdbc.java16.persistence") + } + jdbc { + utilityPackageName.set("wtf.metio.yosql.example.gradle.jdbc.java16.persistence.util") + userTypes { + register("itemConverter") { + converterType.set("wtf.metio.yosql.example.gradle.jdbc.java16.converter.ToItemConverter") + methodName.set("asUserType") + resultType.set("wtf.metio.yosql.example.gradle.jdbc.java16.model.Item") + } + } + } +} + +dependencies { + implementation("com.zaxxer:HikariCP:latest.release") { + because("we want to use a connection pool") + } + implementation("com.h2database:h2:latest.release") { + because("we want to use an in-memory database") + } + implementation("io.reactivex.rxjava2:rxjava:latest.release") { + because("we want to show reactive access") + } +} + +tasks.named("wrapper") { + distributionType = Wrapper.DistributionType.ALL } diff --git a/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/ExampleApp.java similarity index 89% copy from yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/ExampleApp.java index e7039cd0..794d451e 100644 --- a/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/ExampleApp.java @@ -4,13 +4,12 @@ * including this file, may be copied, modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ -package wtf.metio.yosql.example.maven.jdbc.java16; +package wtf.metio.yosql.example.gradle.jdbc.java16; import com.zaxxer.hikari.HikariDataSource; -import wtf.metio.yosql.example.maven.jdbc.java16.persistence.CompanyRepository; -import wtf.metio.yosql.example.maven.jdbc.java16.persistence.PersonRepository; -import wtf.metio.yosql.example.maven.jdbc.java16.persistence.SchemaRepository; -import wtf.metio.yosql.example.maven.jdbc.java16.persistence.util.ToResultRowConverter; +import wtf.metio.yosql.example.gradle.jdbc.java16.persistence.CompanyRepository; +import wtf.metio.yosql.example.gradle.jdbc.java16.persistence.PersonRepository; +import wtf.metio.yosql.example.gradle.jdbc.java16.persistence.SchemaRepository; import javax.sql.DataSource; import java.util.Arrays; @@ -43,9 +42,8 @@ public class ExampleApp { private static void runTests(final String[] arguments, final DataSource dataSource) { final var schemaRepository = new SchemaRepository(dataSource); - final var resultRow = new ToResultRowConverter(); - final var companyRepository = new CompanyRepository(dataSource, resultRow); - final var personRepository = new PersonRepository(dataSource, resultRow); + final var companyRepository = new CompanyRepository(dataSource); + final var personRepository = new PersonRepository(dataSource); if (match(arguments, "generic", "stream", "rxjava")) { initializeDatabase(schemaRepository, companyRepository, personRepository); diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/converter/ToItemConverter.java b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/converter/ToItemConverter.java new file mode 100644 index 00000000..385a7293 --- /dev/null +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/converter/ToItemConverter.java @@ -0,0 +1,25 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ +package wtf.metio.yosql.example.gradle.jdbc.java16.converter; + +import wtf.metio.yosql.example.gradle.jdbc.java16.model.Item; +import wtf.metio.yosql.example.gradle.jdbc.java16.persistence.util.ResultState; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public final class ToItemConverter { + + public final Item asUserType(final ResultState result) throws SQLException { + final ResultSet resultSet = result.getResultSet(); + final Item pojo = new Item(); + pojo.setId(resultSet.getInt("id")); + pojo.setName(resultSet.getString("name")); + return pojo; + } + +} diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/model/Item.java b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/model/Item.java new file mode 100644 index 00000000..b4775635 --- /dev/null +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/java/wtf/metio/yosql/example/gradle/jdbc/java16/model/Item.java @@ -0,0 +1,36 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ +package wtf.metio.yosql.example.gradle.jdbc.java16.model; + +public class Item { + + private int id; + private String name; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + public void setId(final int id) { + this.id = id; + } + + public void setName(final String name) { + this.name = name; + } + +} diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanies.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanies.sql index 4dcc270b..f7a405b9 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanies.sql @@ -5,23 +5,15 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- parameters: +-- - name: min +-- type: int +-- - name: max +-- type: int +-- +select * +from companies +where id < :max + and id > :min +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanyByName.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanyByName.sql index 4dcc270b..ae2c0f79 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/findCompanyByName.sql @@ -5,23 +5,12 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- parameters: +-- - name: name +-- type: java.lang.String +-- +select * +from companies +where name = :name +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/insertCompany.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/insertCompany.sql index 4dcc270b..24b95b09 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/insertCompany.sql @@ -5,23 +5,12 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- returningMode: ONE +-- parameters: +-- - name: id +-- type: int +-- - name: name +-- type: java.lang.String +INSERT INTO companies (id, name) +VALUES (:id, :name) +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/queryAllCompanies.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/queryAllCompanies.sql index 4dcc270b..31c3c5ef 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/company/queryAllCompanies.sql @@ -5,23 +5,8 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- +select * +from companies +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/callItem.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/callItem.sql index 4dcc270b..e7aa7580 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/callItem.sql @@ -5,23 +5,8 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} +select * +from items +where name = :name +; -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/findItem.sql b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/findItem.sql new file mode 100644 index 00000000..9dca20cf --- /dev/null +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/item/findItem.sql @@ -0,0 +1,61 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +-- +-- name: findItemByName +-- parameters: +-- - name: name +-- type: java.lang.String +-- resultRowConverter: +-- alias: itemConverter +-- +select * +from items +where name = :name +; + +-- +-- name: findItemByName +-- vendor: H2 +-- parameters: +-- - name: name +-- type: java.lang.String +-- resultRowConverter: +-- alias: itemConverter +-- +select * +from items +where other_name = :name +; + +-- +-- name: findItemByAllNames +-- parameters: +-- - name: name +-- type: java.lang.String +-- resultRowConverter: +-- alias: itemConverter +-- +select * +from items +where name = :name + or other_name = :name + or last_name = :name +; + +-- +-- name: findItemBySnakeCaseName +-- parameters: +-- - name: name_of_item +-- type: java.lang.String +-- resultRowConverter: +-- alias: itemConverter +-- +select * +from items +where name = :name_of_item +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/person/findPerson.sql similarity index 52% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/person/findPerson.sql index 4dcc270b..af756ebd 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/person/findPerson.sql @@ -5,23 +5,31 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} +-- +-- name: findPerson +-- vendor: Microsoft SQL Server +-- parameters: +-- - name: name +-- type: java.lang.String +-- +select * +from persons +where name = :name +; -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} +-- +-- name: findPerson +-- vendor: H2 +-- +select * +from persons +where name = :name +; -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- name: findPerson +-- +select * +from persons +where name = :name +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createCompaniesTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createCompaniesTable.sql index 4dcc270b..25e69f9b 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createCompaniesTable.sql @@ -5,23 +5,11 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- +CREATE TABLE companies +( + id INTEGER, + name VARCHAR(50) +) +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createItemsTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createItemsTable.sql index 4dcc270b..237fe7ae 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createItemsTable.sql @@ -5,23 +5,11 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- +CREATE TABLE items +( + id INTEGER, + name VARCHAR(50) +) +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createPersonsTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createPersonsTable.sql index 4dcc270b..a09f2de7 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/createPersonsTable.sql @@ -5,23 +5,18 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} +-- +-- +CREATE TABLE persons +( + id INTEGER, + name VARCHAR(50) +) +; -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +CREATE TABLE person_to_company +( + person_id INTEGER, + company_id INTEGER +) +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropCompaniesTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropCompaniesTable.sql index 4dcc270b..c83584fa 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropCompaniesTable.sql @@ -5,23 +5,5 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +DROP TABLE IF EXISTS companies +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropItemsTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropItemsTable.sql index 4dcc270b..26034242 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropItemsTable.sql @@ -5,23 +5,5 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +DROP TABLE IF EXISTS items +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropPersonsTable.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropPersonsTable.sql index 4dcc270b..561e5045 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/schema/dropPersonsTable.sql @@ -5,23 +5,5 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +DROP TABLE IF EXISTS persons +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/insertUser.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/insertUser.sql index 4dcc270b..c000eedb 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/insertUser.sql @@ -5,23 +5,10 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- returningMode: ONE +-- parameters: +-- - name: userId +-- type: int +-- - name: name +-- type: java.lang.String +INSERT INTO users (id, name) VALUES (:userId, :name) RETURNING *; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryAllUsers.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryAllUsers.sql index 4dcc270b..06efd445 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryAllUsers.sql @@ -5,23 +5,8 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- +select * +from users +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryInAnotherRepository.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryInAnotherRepository.sql index 4dcc270b..3e1992e6 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryInAnotherRepository.sql @@ -5,23 +5,11 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- name: queryAdminUser +-- repository: Admin +-- +select * +from users +where id = -1 +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySingleUser.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySingleUser.sql index 4dcc270b..d48b135f 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySingleUser.sql @@ -5,23 +5,15 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- returningMode: ONE +-- parameters: +-- - name: userId +-- type: int +-- - name: name +-- type: java.lang.String +-- +select * +from users +where id = :userId + and name = :name +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySpecialUser.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySpecialUser.sql index 4dcc270b..f3425faa 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/querySpecialUser.sql @@ -5,23 +5,10 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- name: queryAdminUser +-- +select * +from users +where id = -1 +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryUnnamedUser.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryUnnamedUser.sql index 4dcc270b..3200b013 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryUnnamedUser.sql @@ -5,23 +5,9 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- returningMode: ONE +select * +from users +where name = ? + and id = :userId +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryWithoutFrontMatter.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryWithoutFrontMatter.sql index 4dcc270b..fcb7bc86 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/queryWithoutFrontMatter.sql @@ -5,23 +5,9 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +select * +from users +where id = :id + and name = :name + and other = :id +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUser.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUser.sql index 4dcc270b..043f6134 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUser.sql @@ -5,23 +5,12 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- name: updateUser +-- repository: wtf.metio.yosql.example.gradle.jdbc.java16.persistence.AdminRepository +-- +update users +set id = 1 +where id = :id + and name = :name +; diff --git a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUserStatic.sql similarity index 53% copy from yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts copy to yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUserStatic.sql index 4dcc270b..58205f71 100644 --- a/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/build.gradle.kts +++ b/yosql-examples/yosql-examples-gradle/yosql-examples-gradle-jdbc-java16/src/main/yosql/user/updateUserStatic.sql @@ -5,23 +5,10 @@ * in the LICENSE file. */ -plugins { - java - id("wtf.metio.yosql") -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) - } -} - -tasks.named("wrapper") { - distributionType = Wrapper.DistributionType.ALL -} - -yosql { - files { - inputBaseDirectory.set(layout.projectDirectory.dir("yosql")) - } -} +-- +-- repository: wtf.metio.yosql.example.gradle.jdbc.java16.persistence.AdminRepository +-- +update users +set id = 1 +where id = 2 +; diff --git a/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java b/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java index e7039cd0..286dd4ad 100644 --- a/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java +++ b/yosql-examples/yosql-examples-maven/yosql-examples-maven-jdbc-java16/src/main/java/wtf/metio/yosql/example/maven/jdbc/java16/ExampleApp.java @@ -9,6 +9,8 @@ package wtf.metio.yosql.example.maven.jdbc.java16; import com.zaxxer.hikari.HikariDataSource; import wtf.metio.yosql.example.maven.jdbc.java16.persistence.CompanyRepository; import wtf.metio.yosql.example.maven.jdbc.java16.persistence.PersonRepository; +import wtf.metio.yosql.example.maven.jdbc.java16.persistence.CompanyRepository; +import wtf.metio.yosql.example.maven.jdbc.java16.persistence.PersonRepository; import wtf.metio.yosql.example.maven.jdbc.java16.persistence.SchemaRepository; import wtf.metio.yosql.example.maven.jdbc.java16.persistence.util.ToResultRowConverter; diff --git a/yosql-internals/yosql-internals-jdk-utils/src/main/java/wtf/metio/yosql/internals/jdk/SupportedLocales.java b/yosql-internals/yosql-internals-jdk-utils/src/main/java/wtf/metio/yosql/internals/jdk/SupportedLocales.java new file mode 100644 index 00000000..9a49eb54 --- /dev/null +++ b/yosql-internals/yosql-internals-jdk-utils/src/main/java/wtf/metio/yosql/internals/jdk/SupportedLocales.java @@ -0,0 +1,28 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ +package wtf.metio.yosql.internals.jdk; + +import java.util.List; +import java.util.Locale; + +/** + * Lists all supported locales within YoSQL. + */ +public class SupportedLocales { + + public static final Locale ENGLISH = Locale.ENGLISH; + public static final Locale GERMAN = Locale.GERMAN; + public static final List ALL = List.of(ENGLISH, GERMAN); + + public static Locale defaultLocale() { + return ALL.stream() + .filter(Locale.getDefault()::equals) + .findFirst() + .orElse(Locale.ENGLISH); + } + +} diff --git a/yosql-tooling/yosql-tooling-gradle/build.gradle.kts b/yosql-tooling/yosql-tooling-gradle/build.gradle.kts index 6ea0a07a..b449da15 100644 --- a/yosql-tooling/yosql-tooling-gradle/build.gradle.kts +++ b/yosql-tooling/yosql-tooling-gradle/build.gradle.kts @@ -34,6 +34,7 @@ pluginBundle { dependencies { implementation("wtf.metio.yosql.tooling:yosql-tooling-dagger:${version}") + implementation("wtf.metio.yosql.internals:yosql-internals-jdk-utils:${version}") testImplementation(gradleTestKit()) } diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/DefaultResultRowConverter.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/DefaultResultRowConverter.java new file mode 100644 index 00000000..b1660d69 --- /dev/null +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/DefaultResultRowConverter.java @@ -0,0 +1,61 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +package wtf.metio.yosql.tooling.gradle; + +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import wtf.metio.yosql.models.sql.ResultRowConverter; + +import javax.inject.Inject; + +/** + * Configures a single ResultRowConverter. + */ +public abstract class DefaultResultRowConverter { + + /** + * @return The short alias for the converter. + */ + @Input + public abstract Property getAlias(); + + /** + * @return The fully-qualified name of the converter class. + */ + @Input + public abstract Property getConverterType(); + + /** + * @return The name of the method to call. + */ + @Input + public abstract Property getMethodName(); + + /** + * @return The fully-qualified name of the result class. + */ + @Input + public abstract Property getResultType(); + + /** + * Provided for Gradle for unknown reasons. + */ + @Inject + public DefaultResultRowConverter() { + } + + ResultRowConverter asResultRowConverter(final String basePackageName) { + return ResultRowConverter.builder() + .setAlias(getAlias().get()) + .setConverterType(basePackageName + "." + getConverterType().get()) + .setMethodName(getMethodName().get()) + .setResultType(basePackageName + "." + getResultType().get()) + .build(); + } + +} diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Files.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Files.java index 13dea7d7..1460634a 100644 --- a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Files.java +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Files.java @@ -11,6 +11,7 @@ import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.ProjectLayout; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputDirectory; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputDirectory; @@ -33,11 +34,24 @@ public abstract class Files { @OutputDirectory public abstract DirectoryProperty getOutputBaseDirectory(); + /** + * @return The number of lines to skip in each .sql file. + */ + @Input + public abstract Property getSkipLines(); + FilesConfiguration asConfiguration() { return FilesConfiguration.usingDefaults() .setInputBaseDirectory(getInputBaseDirectory().get().getAsFile().toPath()) .setOutputBaseDirectory(getOutputBaseDirectory().get().getAsFile().toPath()) + .setSkipLines(getSkipLines().get()) .build(); } + void configureConventions(final ProjectLayout layout) { + getInputBaseDirectory().convention(layout.getProjectDirectory().dir("src/main/yosql")); + getOutputBaseDirectory().convention(layout.getBuildDirectory().dir("generated/sources/yosql")); + getSkipLines().convention(0); + } + } diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/GenerateTask.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/GenerateTask.java index baddec86..b6682bc4 100644 --- a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/GenerateTask.java +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/GenerateTask.java @@ -11,19 +11,18 @@ import org.gradle.api.DefaultTask; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; +import wtf.metio.yosql.internals.jdk.SupportedLocales; import wtf.metio.yosql.models.immutables.*; +import wtf.metio.yosql.models.sql.ResultRowConverter; import wtf.metio.yosql.tooling.dagger.DaggerYoSQLComponent; import java.util.List; -import java.util.Locale; /** * Generate Java code by reading SQL code. */ public abstract class GenerateTask extends DefaultTask { - private static final List SUPPORTED_LOCALES = List.of(Locale.ENGLISH, Locale.GERMAN); - /** * @return The file configuration to use. */ @@ -31,34 +30,46 @@ public abstract class GenerateTask extends DefaultTask { public abstract Property getFiles(); /** + * @return The JDBC configuration to use. + */ + @Input + public abstract Property getJdbc(); + + /** + * @return The Java configuration to use. + */ + @Input + public abstract Property getJava(); + + /** + * @return The repositories configuration to use. + */ + @Input + public abstract Property getRepositories(); + + /** * Generate Java code. */ @TaskAction public void generateCode() { DaggerYoSQLComponent.builder() .runtimeConfiguration(createConfiguration()) - .locale(determineLocale()) + .locale(SupportedLocales.defaultLocale()) .build() - .yosql(); + .yosql() + .generateCode(); } private RuntimeConfiguration createConfiguration() { return RuntimeConfiguration.builder() .setFiles(getFiles().get()) + .setJdbc(getJdbc().get()) + .setJava(getJava().get()) + .setRepositories(getRepositories().get()) .setAnnotations(AnnotationsConfiguration.usingDefaults().build()) - .setJava(JavaConfiguration.usingDefaults().build()) .setApi(ApiConfiguration.usingDefaults().build()) - .setRepositories(RepositoriesConfiguration.usingDefaults().build()) .setResources(ResourcesConfiguration.usingDefaults().build()) - .setJdbc(JdbcConfiguration.usingDefaults().build()) .build(); } - private Locale determineLocale() { - return SUPPORTED_LOCALES.stream() - .filter(Locale.getDefault()::equals) - .findFirst() - .orElse(Locale.ENGLISH); - } - } diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Java.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Java.java new file mode 100644 index 00000000..7ada0d35 --- /dev/null +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Java.java @@ -0,0 +1,35 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +package wtf.metio.yosql.tooling.gradle; + +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import wtf.metio.yosql.models.immutables.JavaConfiguration; + +/** + * Configures Java related options. + */ +public abstract class Java { + + /** + * @return The Java SDK API version to use. + */ + @Input + public abstract Property getApiVersion(); + + JavaConfiguration asConfiguration() { + return JavaConfiguration.usingDefaults() + .setApiVersion(getApiVersion().get()) + .build(); + } + + void configureConventions() { + getApiVersion().convention(16); + } + +} diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Jdbc.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Jdbc.java new file mode 100644 index 00000000..5f6ceba1 --- /dev/null +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Jdbc.java @@ -0,0 +1,96 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +package wtf.metio.yosql.tooling.gradle; + +import org.gradle.api.Action; +import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.model.ObjectFactory; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import wtf.metio.yosql.internals.jdk.Strings; +import wtf.metio.yosql.models.immutables.JdbcConfiguration; +import wtf.metio.yosql.models.sql.ResultRowConverter; + +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * Configures JDBC related options. + */ +public abstract class Jdbc { + + /** + * @return The default result row converter in case no other is specified. + */ + @Input + public abstract Property getDefaultConverter(); + + /** + * @return The list of custom converters provided by the user. + */ + @Input + public abstract NamedDomainObjectContainer getUserTypes(); + + /** + * @return The package name for all utility classes. + */ + @Input + public abstract Property getUtilityPackageName(); + + /** + * @param action The files config to apply. + */ + public void defaultConverter(Action action) { + action.execute(getDefaultConverter().get()); + } + + JdbcConfiguration asConfiguration() { + return JdbcConfiguration.usingDefaults() + .setDefaultConverter(getDefaultConverter().get().asResultRowConverter(getUtilityPackageName().get())) + .setUserTypes(createRowConverters()) + .setUtilityPackageName(getUtilityPackageName().get()) + .build(); + } + + void configureConventions(final ObjectFactory objects) { + final var defaultConverter = objects.newInstance(DefaultResultRowConverter.class); + defaultConverter.getAlias().set("resultRow"); + defaultConverter.getConverterType().set("ToResultRowConverter"); + defaultConverter.getMethodName().set("asUserType"); + defaultConverter.getResultType().set("ResultRow"); + getDefaultConverter().convention(defaultConverter); + getUtilityPackageName().convention("com.example.persistence.util"); + } + + private List createRowConverters() { + return getUserTypes().stream() + .map(UserResultRowConverter::asResultRowConverter) + .collect(Collectors.toList()); + } + + private ResultRowConverter createRowConverter(final String converterDefinition) { + return Optional.ofNullable(converterDefinition) + .map(String::strip) + .filter(Predicate.not(Strings::isBlank)) + .map(value -> value.split(":")) + .map(values -> ResultRowConverter.builder() + .setAlias(values[0]) + .setConverterType(values[1]) + .setMethodName(values[2]) + .setResultType(values[3]) + .build()) + .orElse(ResultRowConverter.builder() + .setAlias("resultRow") + .setConverterType("com.example.persistence.util.ToResultRowConverter") + .setMethodName("asUserType") + .setResultType("com.example.persistence.util.ResultRow") + .build()); + } +} diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Repositories.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Repositories.java new file mode 100644 index 00000000..026f717c --- /dev/null +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/Repositories.java @@ -0,0 +1,43 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +package wtf.metio.yosql.tooling.gradle; + +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import wtf.metio.yosql.models.immutables.RepositoriesConfiguration; + +/** + * Configures repository related options. + */ +public abstract class Repositories { + + /** + * @return The base package name for all repositories + */ + @Input + public abstract Property getBasePackageName(); + + /** + * @return The repository name suffix to use. + */ + @Input + public abstract Property getRepositoryNameSuffix(); + + RepositoriesConfiguration asConfiguration() { + return RepositoriesConfiguration.usingDefaults() + .setBasePackageName(getBasePackageName().get()) + .setRepositoryNameSuffix(getRepositoryNameSuffix().get()) + .build(); + } + + void configureConventions() { + getBasePackageName().convention("com.example.persistence"); + getRepositoryNameSuffix().convention("Repository"); + } + +} diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/UserResultRowConverter.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/UserResultRowConverter.java new file mode 100644 index 00000000..571091c8 --- /dev/null +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/UserResultRowConverter.java @@ -0,0 +1,56 @@ +/* + * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, + * including this file, may be copied, modified, propagated, or distributed except according to the terms contained + * in the LICENSE file. + */ + +package wtf.metio.yosql.tooling.gradle; + +import org.gradle.api.Named; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import wtf.metio.yosql.models.sql.ResultRowConverter; + +import javax.inject.Inject; + +/** + * Configures a single ResultRowConverter. + */ +public abstract class UserResultRowConverter implements Named { + + /** + * @return The fully-qualified name of the converter class. + */ + @Input + public abstract Property getConverterType(); + + /** + * @return The name of the method to call. + */ + @Input + public abstract Property getMethodName(); + + /** + * @return The fully-qualified name of the result class. + */ + @Input + public abstract Property getResultType(); + + /** + * Provided for Gradle for unknown reasons. + */ + @Inject + public UserResultRowConverter() { + } + + ResultRowConverter asResultRowConverter() { + return ResultRowConverter.builder() + .setAlias(getName()) + .setConverterType(getConverterType().get()) + .setMethodName(getMethodName().get()) + .setResultType(getResultType().get()) + .build(); + } + +} diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlExtension.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlExtension.java index 0a5a4c05..7a2d7594 100644 --- a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlExtension.java +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlExtension.java @@ -22,10 +22,49 @@ public abstract class YoSqlExtension { public abstract Files getFiles(); /** - * @param action The config block to apply. + * @return The JDBC configuration. + */ + @Nested + public abstract Jdbc getJdbc(); + + /** + * @return The JDBC configuration. + */ + @Nested + public abstract Java getJava(); + + /** + * @return The JDBC configuration. + */ + @Nested + public abstract Repositories getRepositories(); + + /** + * @param action The files config to apply. */ public void files(Action action) { action.execute(getFiles()); } + /** + * @param action The JDBC config to apply. + */ + public void jdbc(Action action) { + action.execute(getJdbc()); + } + + /** + * @param action The JDBC config to apply. + */ + public void java(Action action) { + action.execute(getJava()); + } + + /** + * @param action The JDBC config to apply. + */ + public void repositories(Action action) { + action.execute(getRepositories()); + } + } diff --git a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlPlugin.java b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlPlugin.java index 1217a5d2..dd8985af 100644 --- a/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlPlugin.java +++ b/yosql-tooling/yosql-tooling-gradle/src/main/java/wtf/metio/yosql/tooling/gradle/YoSqlPlugin.java @@ -10,10 +10,11 @@ package wtf.metio.yosql.tooling.gradle; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.file.ProjectLayout; +import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; -import wtf.metio.yosql.models.immutables.FilesConfiguration; +import org.gradle.api.tasks.compile.JavaCompile; /** * The YoSQL Gradle plugin. It configures the {@link YoSqlExtension} and registers the {@link GenerateTask}. @@ -23,7 +24,7 @@ public class YoSqlPlugin implements Plugin { @Override public void apply(final Project project) { final var extension = configureExtension(project); - configureConventions(extension, project.getLayout()); + configureConventions(extension, project.getLayout(), project.getObjects()); configureTask(project, extension); configureSourceSets(project, extension); } @@ -32,15 +33,21 @@ public class YoSqlPlugin implements Plugin { return project.getExtensions().create("yosql", YoSqlExtension.class); } - private void configureConventions(final YoSqlExtension extension, final ProjectLayout layout) { - final var files = extension.getFiles(); - files.getInputBaseDirectory().convention(layout.getProjectDirectory().dir("src").dir("main").dir("yosql")); - files.getOutputBaseDirectory().convention(layout.getBuildDirectory().dir("generated").map(d -> d.dir("sources").dir("yosql"))); + private void configureConventions(final YoSqlExtension extension, final ProjectLayout layout, final ObjectFactory objects) { + extension.getFiles().configureConventions(layout); + extension.getJdbc().configureConventions(objects); + extension.getRepositories().configureConventions(); + extension.getJava().configureConventions(); } private void configureTask(final Project project, final YoSqlExtension extension) { - project.getTasks().register("generateJavaCode", GenerateTask.class, task -> - task.getFiles().set(extension.getFiles().asConfiguration())); + final var generate = project.getTasks().register("generateJavaCode", GenerateTask.class, task -> { + task.getFiles().set(extension.getFiles().asConfiguration()); + task.getJdbc().set(extension.getJdbc().asConfiguration()); + task.getJava().set(extension.getJava().asConfiguration()); + task.getRepositories().set(extension.getRepositories().asConfiguration()); + }); + project.getTasks().withType(JavaCompile.class, task -> task.doFirst("yosql", action -> generate.get().generateCode())); } private void configureSourceSets(final Project project, final YoSqlExtension extension) { @@ -52,8 +59,8 @@ public class YoSqlPlugin implements Plugin { .getPlugin(JavaPluginConvention.class) .getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME) - .getAllSource() - .srcDir(extension.getFiles().getOutputBaseDirectory()); + .getJava() + .srcDir(extension.getFiles().getOutputBaseDirectory().get()); } } diff --git a/yosql-tooling/yosql-tooling-maven/src/main/java/wtf/metio/yosql/tooling/maven/GenerateMojo.java b/yosql-tooling/yosql-tooling-maven/src/main/java/wtf/metio/yosql/tooling/maven/GenerateMojo.java index d2ad9aa8..bb2f224c 100644 --- a/yosql-tooling/yosql-tooling-maven/src/main/java/wtf/metio/yosql/tooling/maven/GenerateMojo.java +++ b/yosql-tooling/yosql-tooling-maven/src/main/java/wtf/metio/yosql/tooling/maven/GenerateMojo.java @@ -17,12 +17,11 @@ import org.slf4j.LoggerFactory; import wtf.metio.yosql.codegen.api.YoSQL; import wtf.metio.yosql.codegen.exceptions.CodeGenerationException; import wtf.metio.yosql.codegen.logging.Loggers; +import wtf.metio.yosql.internals.jdk.SupportedLocales; import wtf.metio.yosql.models.immutables.RuntimeConfiguration; import wtf.metio.yosql.tooling.dagger.DaggerYoSQLComponent; import java.util.Arrays; -import java.util.List; -import java.util.Locale; /** * The generate goal generates Java code based on SQL files. @@ -36,7 +35,6 @@ import java.util.Locale; public class GenerateMojo extends AbstractMojo { private static final Logger LOG = LoggerFactory.getLogger(Loggers.EXECUTIONS.loggerName); - private static final List SUPPORTED_LOCALES = List.of(Locale.ENGLISH, Locale.GERMAN); @Parameter(required = true, defaultValue = "${classObject}") Files files; @@ -76,7 +74,7 @@ public class GenerateMojo extends AbstractMojo { private YoSQL buildYoSQL() { return DaggerYoSQLComponent.builder() .runtimeConfiguration(createConfiguration()) - .locale(determineLocale()) + .locale(SupportedLocales.defaultLocale()) .build() .yosql(); } @@ -93,11 +91,4 @@ public class GenerateMojo extends AbstractMojo { .build(); } - private Locale determineLocale() { - return SUPPORTED_LOCALES.stream() - .filter(Locale.getDefault()::equals) - .findFirst() - .orElse(Locale.ENGLISH); - } - } -- 2.11.4.GIT