From 73b663f9f3a14264d2106cf45f51333ddaed2195 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 7 Aug 2024 12:01:04 -0300 Subject: [PATCH 1/5] update CONTRIBUTING --- CONTRIBUTING.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cae0500f5..5d7adf3eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,7 @@ ## To run the application in development -### Step 1 👍 : install [yeoman](https://yeoman.io/) - -`npm install -g yo | yarn global add yo` - -### Step 2 ✌️ : to setup JHipster-Kotlin generator +### Step 1 ✌️ : to setup JHipster-Kotlin generator `git clone https://github.com/jhipster/jhipster-kotlin` @@ -18,7 +14,7 @@ ( 🏁 Kudos, you just setup JHipster-Kotlin and linked to it locally ) -### Step 3 🤟 : before generating your application, go to your application folder +### Step 2 🤟 : before generating your application, go to your application folder `yarn link "generator-jhipster-kotlin"` @@ -32,6 +28,19 @@ or Fix / Code / Document and create a pull request 💯 +### Synchronizing generator-jhipster templates + +Run: + +```sh +khipster synchronize +``` + +In the conflict resolution, check diff and press `i` if the template is synchronized. +`i` choice will add that file to be ignored in `.yo-resolve` file. + +When synchronization is done revert `.yo-resolve` file to the initial previous state. + ### Regular Contributor Guidelines These are some of the guidelines that we would like you to follow if you are a regular contributor to the project From 531d4cb8f9d4d9a456aedd61479cb65a58f93981 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 7 Aug 2024 09:40:31 -0300 Subject: [PATCH 2/5] add synchronize generator --- .blueprint/cli/commands.mjs | 4 ++ .blueprint/synchronize/command.js | 40 +++++++++++++ .blueprint/synchronize/generator.js | 89 +++++++++++++++++++++++++++++ .blueprint/synchronize/index.js | 20 +++++++ .yo-resolve | 2 +- 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 .blueprint/synchronize/command.js create mode 100644 .blueprint/synchronize/generator.js create mode 100644 .blueprint/synchronize/index.js diff --git a/.blueprint/cli/commands.mjs b/.blueprint/cli/commands.mjs index f6076cc42..528ce9e0f 100644 --- a/.blueprint/cli/commands.mjs +++ b/.blueprint/cli/commands.mjs @@ -22,6 +22,10 @@ const defaultCommands = { desc: 'Generate a test sample', blueprint: '@jhipster/jhipster-dev', }, + synchronize: { + desc: 'Synchronize templates from generator-jhipster', + blueprint: '@jhipster/jhipster-dev', + }, }; export default defaultCommands; diff --git a/.blueprint/synchronize/command.js b/.blueprint/synchronize/command.js new file mode 100644 index 000000000..627ff6aaf --- /dev/null +++ b/.blueprint/synchronize/command.js @@ -0,0 +1,40 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const command = { + configs: { + newFiles: { + description: 'Add new files only', + cli: { + type: Boolean, + }, + scope: 'generator', + }, + convert: { + description: 'Apply Partial Java files to Kotlin files convertion', + cli: { + type: Boolean, + alias: 'c', + }, + scope: 'generator', + }, + }, + import: [], +}; + +export default command; diff --git a/.blueprint/synchronize/generator.js b/.blueprint/synchronize/generator.js new file mode 100644 index 000000000..766014bd0 --- /dev/null +++ b/.blueprint/synchronize/generator.js @@ -0,0 +1,89 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { basename, dirname, join, relative } from 'path'; +import { fileURLToPath } from 'url'; +import { existsSync } from 'fs'; +import BaseGenerator from 'generator-jhipster/generators/base'; +import { globby } from 'globby'; +import { passthrough } from '@yeoman/transform'; +import { convertToKotlinFile } from '../../generators/kotlin/support/index.js'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +// const jhipster7TemplatesPackage = dirname(fileURLToPath(import.meta.resolve('jhipster-7-templates/package.json'))); +const jhipster8Generators = join(__dirname, '../../node_modules/generator-jhipster/dist/generators'); + +export default class SynchronizeGenerator extends BaseGenerator { + constructor(args, options, features) { + super(args, options, { queueCommandTasks: true, ...features }); + } + + get [BaseGenerator.DEFAULT]() { + return this.asDefaultTaskGroup({ + default() { + if (this.options.convert === false) { + return; + } + this.queueTransformStream( + { + name: 'convert to kt file', + filter: file => file.path.endsWith('.kt.ejs'), + }, + passthrough(file => { + file.contents = Buffer.from( + file.contents + .toString() + .replaceAll(';\n', '\n') + .replaceAll('\nimport static ', '\nimport ') + .replaceAll('public class ', 'class ') + .replaceAll('.class', '::class') + .replaceAll(/ (?:extends|implements) (\w+)/g, ' : $1') + .replaceAll(/ (?:extends|implements) /g, ' : ') + .replaceAll(/@Override\n(\s*)/g, 'override ') + .replaceAll(/\n( {4})(private |)?(?:final )?(\w+) (\w+)(\n| = )/g, '\n$1$2lateinit var $4: $3$5') + .replaceAll(/private static final (\w+) /g, 'private val ') + .replaceAll(/(?:public |protected )?(\w+) (\w+)\((.*)\) {/g, 'fun $2($3): $1 {') + .replaceAll(': void', ''), + ); + }), + ); + }, + }); + } + + get [BaseGenerator.WRITING]() { + return this.asWritingTaskGroup({ + async writing() { + const files = await globby(`${jhipster8Generators}/**/*.java.ejs`); + const ktTemplatesPath = this.destinationPath('generators/spring-boot/templates'); + for (const file of files.filter( + file => !file.includes('/spring-data-couchbase/') && !['GeneratedByJHipster.java.ejs'].includes(basename(file)), + )) { + const relativeDestinationFile = convertToKotlinFile(relative(jhipster8Generators, file)) + .replace('spring-boot/templates/', '') + .replace('server/templates/', '') + .replace(/(?:(?:.*)\/generators\/)?(.*)\/templates/, '$1'); + const destinationFile = join(ktTemplatesPath, relativeDestinationFile); + if (this.options.newFiles !== true || !existsSync(destinationFile)) { + this.copyTemplate(file, destinationFile); + } + } + }, + }); + } +} diff --git a/.blueprint/synchronize/index.js b/.blueprint/synchronize/index.js new file mode 100644 index 000000000..1cfadd692 --- /dev/null +++ b/.blueprint/synchronize/index.js @@ -0,0 +1,20 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { default } from './generator.js'; +export { default as command } from './command.js'; diff --git a/.yo-resolve b/.yo-resolve index 4437701ac..aa88891ff 100644 --- a/.yo-resolve +++ b/.yo-resolve @@ -1,4 +1,4 @@ -generators/** +generators/*.* .prettierrc.yml skip cli/cli.cjs skip README.md skip From 3531505c9451fd593f0e7a2284eb276258760d44 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 7 Aug 2024 15:15:00 -0300 Subject: [PATCH 3/5] cleanup --- .blueprint/synchronize/generator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.blueprint/synchronize/generator.js b/.blueprint/synchronize/generator.js index 766014bd0..cc759f320 100644 --- a/.blueprint/synchronize/generator.js +++ b/.blueprint/synchronize/generator.js @@ -25,7 +25,6 @@ import { passthrough } from '@yeoman/transform'; import { convertToKotlinFile } from '../../generators/kotlin/support/index.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); -// const jhipster7TemplatesPackage = dirname(fileURLToPath(import.meta.resolve('jhipster-7-templates/package.json'))); const jhipster8Generators = join(__dirname, '../../node_modules/generator-jhipster/dist/generators'); export default class SynchronizeGenerator extends BaseGenerator { From 49ccb418beba716ecc1870e59376a577851f3e75 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 7 Aug 2024 13:44:08 -0300 Subject: [PATCH 4/5] move Enum to v8 place --- generators/spring-boot-v2/generator.js | 3 ++- .../_entityPackage_/domain/enumeration/_enumName_.kt.ejs} | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename generators/{spring-boot-v2/templates/src/main/kotlin/_package_/domain/enumeration/Enum.kt.ejs => spring-boot/templates/domain/src/main/kotlin/_package_/_entityPackage_/domain/enumeration/_enumName_.kt.ejs} (100%) diff --git a/generators/spring-boot-v2/generator.js b/generators/spring-boot-v2/generator.js index c91d8c69b..cd616f976 100644 --- a/generators/spring-boot-v2/generator.js +++ b/generators/spring-boot-v2/generator.js @@ -329,13 +329,14 @@ export default class extends BaseApplicationGenerator { { templates: [ { - file: `${SERVER_MAIN_SRC_KOTLIN_DIR}_package_/domain/enumeration/Enum.kt`, + file: `${SERVER_MAIN_SRC_KOTLIN_DIR}_package_/_entityPackage_/domain/enumeration/_enumName_.kt`, renameTo: () => `${SERVER_MAIN_SRC_KOTLIN_DIR}${entity.entityAbsoluteFolder}/domain/enumeration/${field.fieldType}.kt`, }, ], }, ], + rootTemplatesPath: ['../../spring-boot/templates/domain/'], context: enumInfo, }); } diff --git a/generators/spring-boot-v2/templates/src/main/kotlin/_package_/domain/enumeration/Enum.kt.ejs b/generators/spring-boot/templates/domain/src/main/kotlin/_package_/_entityPackage_/domain/enumeration/_enumName_.kt.ejs similarity index 100% rename from generators/spring-boot-v2/templates/src/main/kotlin/_package_/domain/enumeration/Enum.kt.ejs rename to generators/spring-boot/templates/domain/src/main/kotlin/_package_/_entityPackage_/domain/enumeration/_enumName_.kt.ejs From 2c907c43d634c7b73d4dcc7aafe1831e68d3e446 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 7 Aug 2024 14:24:50 -0300 Subject: [PATCH 5/5] split repositories --- generators/spring-boot/generator.js | 3 - .../repository/_entityClass_Repository.kt.ejs | 33 ++++++++ .../repository/_entityClass_Repository.kt.ejs | 56 +++++++++++++ .../_entityClass_Repository_reactive.kt.ejs | 62 ++++++++++++++ .../repository/_entityClass_Repository.kt.ejs | 80 +++++++++++++++++++ .../repository/_entityClass_Repository.kt.ejs | 55 ++++--------- .../_entityClass_Repository_reactive.kt.ejs | 79 ++++-------------- 7 files changed, 260 insertions(+), 108 deletions(-) create mode 100644 generators/spring-boot/templates/spring-data-cassandra/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs create mode 100644 generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs create mode 100644 generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs create mode 100644 generators/spring-boot/templates/spring-data-neo4j/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs rename generators/spring-boot/templates/{ => spring-data-relational}/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs (71%) rename generators/spring-boot/templates/{ => spring-data-relational}/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs (57%) diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index 3b87fdc06..0c31d6f00 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -120,9 +120,6 @@ export default class extends BaseApplicationGenerator { const isCommonFile = filename => { const sourceBasename = basename(filename); - if (['_entityClass_Repository.kt', '_entityClass_Repository_reactive.kt'].includes(sourceBasename)) { - return ns !== 'spring-data-couchbase'; - } return ['TestContainersSpringContextCustomizerFactory.kt'].includes(sourceBasename); }; diff --git a/generators/spring-boot/templates/spring-data-cassandra/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs b/generators/spring-boot/templates/spring-data-cassandra/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs new file mode 100644 index 000000000..ff6453e14 --- /dev/null +++ b/generators/spring-boot/templates/spring-data-cassandra/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs @@ -0,0 +1,33 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the " + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= entityAbsolutePackage %>.repository + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> +import org.springframework.data.cassandra.repository.<% if (reactive) { %>Reactive<% } %>CassandraRepository +import org.springframework.stereotype.Repository +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** + * <%= springDataDescription %> repository for the <%= persistClass %> entity. + */ +@Repository +interface <%= entityClass %>Repository: <% if (reactive) { %>Reactive<% } %>CassandraRepository<<%= persistClass %>, <%= primaryKey.type %>> {} diff --git a/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs b/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs new file mode 100644 index 000000000..a286e2f85 --- /dev/null +++ b/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs @@ -0,0 +1,56 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the " + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= entityAbsolutePackage %>.repository + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> +<%_ if (implementsEagerLoadApis) { _%> +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable +<%_ } _%> +import org.springframework.data.mongodb.repository.Query +import org.springframework.data.mongodb.repository.MongoRepository +import org.springframework.stereotype.Repository +<%_ if (implementsEagerLoadApis) { _%> +import java.util.Optional +<%_ } _%> +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** + * <%= springDataDescription %> repository for the <%= persistClass %> entity. + */ +<%_ if (!implementsEagerLoadApis) { _%> +@Suppress("unused") +<%_ } _%> +@Repository +interface <%=entityClass%>Repository : MongoRepository<<%=persistClass%>, <%= primaryKey.type %>> { +<%_ if (implementsEagerLoadApis) { _%> + + @Query("{}") + fun findAllWithEagerRelationships(pageable: Pageable): Page<<%= persistClass %>> + + @Query("{}") + fun findAllWithEagerRelationships(): MutableList<<%= persistClass %>> + + @Query("{'id': ?0}") + fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Optional<<%= persistClass %>> +<%_ } _%> +} diff --git a/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs b/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs new file mode 100644 index 000000000..a34b574fd --- /dev/null +++ b/generators/spring-boot/templates/spring-data-mongodb/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs @@ -0,0 +1,62 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the " + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= entityAbsolutePackage %>.repository + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> +<%_ if (!paginationNo || implementsEagerLoadApis) { _%> +import org.springframework.data.domain.Pageable +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> +import org.springframework.data.mongodb.repository.Query +<%_ } _%> +import org.springframework.data.mongodb.repository.ReactiveMongoRepository +import org.springframework.stereotype.Repository +<%_ if (!paginationNo || implementsEagerLoadApis) { _%> +import reactor.core.publisher.Flux +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> +import reactor.core.publisher.Mono +<%_ } _%> +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** +* <%= springDataDescription %> repository for the <%= persistClass %> entity. +*/ +@SuppressWarnings("unused") +@Repository +interface <%= entityClass %>Repository: ReactiveMongoRepository<<%= persistClass %>, <%= primaryKey.type %>> { + +<%_ if (!paginationNo) { _%> + fun findAllBy(pageable: Pageable?): Flux<<%= persistClass %>> + +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> + @Query("{}") + fun findAllWithEagerRelationships(pageable: Pageable): Flux<<%= persistClass %>> + + @Query("{}") + fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> + + @Query("{'id': ?0}") + fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Mono<<%= persistClass %>> +<%_ } _%> +} diff --git a/generators/spring-boot/templates/spring-data-neo4j/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs b/generators/spring-boot/templates/spring-data-neo4j/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs new file mode 100644 index 000000000..a740499dc --- /dev/null +++ b/generators/spring-boot/templates/spring-data-neo4j/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs @@ -0,0 +1,80 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the " + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= entityAbsolutePackage %>.repository +<%_ if (reactive) { _%> + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> +import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository +import org.springframework.data.neo4j.repository.query.Query +<%_ if (!paginationNo || implementsEagerLoadApis) { _%> +import org.springframework.data.domain.Pageable +<%_ } _%> +import org.springframework.stereotype.Repository +<%_ if (!paginationNo || implementsEagerLoadApis) { _%> +import reactor.core.publisher.Flux +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> +import reactor.core.publisher.Mono +<%_ } _%> +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** +* <%= springDataDescription %> repository for the <%= persistClass %> entity. +*/ +@SuppressWarnings("unused") +@Repository +interface <%= entityClass %>Repository: ReactiveNeo4jRepository<<%= persistClass %>, <%= primaryKey.type %>> { + +<%_ if (!paginationNo) { _%> + fun findAllBy(pageable: Pageable?): Flux<<%= persistClass %>> +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> + @Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m") + fun findAllWithEagerRelationships(pageable: Pageable): Flux<<%= persistClass %>> + + @Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m") + fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> + + @Query("MATCH (e:<%= persistClass %> {id: $id}) RETURN e") + fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Mono<<%= persistClass %>> +<%_ } _%> +} +<%_ } else { _%> + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> +<%_ if (implementsEagerLoadApis) { _%> +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable +<%_ } _%> +import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<% } %>Neo4jRepository +import org.springframework.stereotype.Repository +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** + * <%= springDataDescription %> repository for the <%= persistClass %> entity. + */ +@Repository +interface <%=entityClass%>Repository : <% if (reactive) { %>Reactive<% } %>Neo4jRepository<<%=persistClass%>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %> {} +<%_ } _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs similarity index 71% rename from generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs rename to generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs index 009ea67b8..bfd7fa2c7 100644 --- a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs +++ b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository.kt.ejs @@ -23,31 +23,17 @@ import <%= entityAbsolutePackage %>.domain.<%= persistClass %> import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable <%_ } _%> -<%_ if (databaseTypeSql) { _%> import org.springframework.data.jpa.repository.JpaRepository - <%_ if (jpaMetamodelFiltering) { _%> +<%_ if (jpaMetamodelFiltering) { _%> import org.springframework.data.jpa.repository.JpaSpecificationExecutor - <%_ } _%> +<%_ } _%> import org.springframework.data.jpa.repository.Query - <%_ if (implementsEagerLoadApis) { _%> +<%_ if (implementsEagerLoadApis) { _%> import org.springframework.data.repository.query.Param - <%_ } _%> -<%_ } _%> -<%_ if (databaseTypeMongodb) { _%> -import org.springframework.data.mongodb.repository.Query -import org.springframework.data.mongodb.repository.MongoRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<% } %>Neo4jRepository -<%_ } _%> -<%_ if (databaseTypeCassandra) { _%> -import org.springframework.data.cassandra.repository.CassandraRepository <%_ } _%> import org.springframework.stereotype.Repository -<%_ if (databaseTypeSql || databaseTypeMongodb) { _%> - <%_ if (implementsEagerLoadApis) { _%> +<%_ if (implementsEagerLoadApis) { _%> import java.util.Optional - <%_ } _%> <%_ } _%> <%_ if (primaryKey.typeUUID) { _%> @@ -56,7 +42,7 @@ import java.util.UUID /** * <%= springDataDescription %> repository for the <%= persistClass %> entity. -<%_ if (containsBagRelationships && databaseTypeSql) { _%> +<%_ if (containsBagRelationships) { _%> * * When extending this class, extend <%= entityClass %>RepositoryWithBagRelationships too. * For more information refer to https://github.com/jhipster/generator-jhipster/issues/17990. @@ -66,17 +52,17 @@ import java.util.UUID @Suppress("unused") <%_ } _%> @Repository -interface <%=entityClass%>Repository : <% if (containsBagRelationships && databaseTypeSql) { %><%= entityClass %>RepositoryWithBagRelationships, <% } %><% if (databaseTypeSql) { %>JpaRepository<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %><% if (reactive) { %>Reactive<% } %>Neo4jRepository<% } %><% if (databaseTypeCassandra) { %>CassandraRepository<% } %><<%=persistClass%>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %> { - <%_ for (const relationship of relationships) { _%> - <%_ if (relationship.relationshipManyToOne && relationship.otherEntityName === 'user' && databaseTypeSql) { _%> - +interface <%=entityClass%>Repository : <% if (containsBagRelationships) { %><%= entityClass %>RepositoryWithBagRelationships, <% } %>JpaRepository<<%=persistClass%>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %> { +<%_ for (const relationship of relationships) { _%> + <%_ if (relationship.relationshipManyToOne && relationship.otherEntityName === 'user') { _%> @Query("select <%= entityInstanceDbSafe %> from <%= persistClass %> <%= entityInstanceDbSafe %> where <%= entityInstanceDbSafe %>.<%= relationship.relationshipFieldName %>.login = ?#{principal.<% if (authenticationTypeOauth2) { %>preferredUsername<% } else { %>username<% } %>}") fun findBy<%= relationship.relationshipNameCapitalized %>IsCurrentUser(): MutableList<<%= persistClass %>> - <%_ } } _%> - <%_ if (implementsEagerLoadApis) { _%> - <%_ if (databaseTypeSql) { _%> - <%_ const containsToOneEagerRelationship = relationships.some(relationship => relationship.relationshipEagerLoad && !relationship.bagRelationship); _%> + <%_ } _%> +<%_ } _%> +<%_ if (implementsEagerLoadApis) { _%> + + <%_ const containsToOneEagerRelationship = relationships.some(relationship => relationship.relationshipEagerLoad && !relationship.bagRelationship); _%> fun findOneWithEagerRelationships(<%= primaryKey.name %>: <%= primaryKey.type %>): Optional<<%= persistClass %>> { return <% if (containsBagRelationships) { %>this.fetchBagRelationships(<% } %>this.<% if (containsToOneEagerRelationship) { %>findOneWithToOneRelationships<% } else { %>findById<% } %>(<%= primaryKey.name %>)<% if (containsBagRelationships) { %>)<% } %> } @@ -88,7 +74,7 @@ interface <%=entityClass%>Repository : <% if (containsBagRelationships && databa fun findAllWithEagerRelationships(pageable: Pageable): Page<<%= persistClass %>> { return <% if (containsBagRelationships) { %>this.fetchBagRelationships(<% } %>this.<% if (containsToOneEagerRelationship) { %>findAllWithToOneRelationships<% } else { %>findAll<% } %>(pageable)<% if (containsBagRelationships) { %>)<% } %> } - <%_ if (containsToOneEagerRelationship) { _%> + <%_ if (containsToOneEagerRelationship) { _%> @Query(value = "select distinct <%= entityInstanceDbSafe %> from <%= persistClass %> <%= entityInstanceDbSafe %><% for (const relationship of relationships) { if (relationship.relationshipEagerLoad && !relationship.bagRelationship) { %> left join fetch <%= entityInstanceDbSafe %>.<%= relationship.reference.name %><% } } %>", @@ -102,17 +88,6 @@ interface <%=entityClass%>Repository : <% if (containsBagRelationships && databa @Query("select <%= entityInstanceDbSafe %> from <%= persistClass %> <%= entityInstanceDbSafe %><% for (const relationship of relationships) { if (relationship.relationshipEagerLoad && !relationship.bagRelationship) { %> left join fetch <%= entityInstanceDbSafe %>.<%= relationship.reference.name %><% } } %> where <%= entityInstanceDbSafe %>.id =:id") fun findOneWithToOneRelationships(@Param("id") id: <%= primaryKey.type %>): Optional<<%= persistClass %>> - <%_ } _%> - <%_ } else if (databaseTypeMongodb) { _%> - - @Query("{}") - fun findAllWithEagerRelationships(pageable: Pageable): Page<<%= persistClass %>> - - @Query("{}") - fun findAllWithEagerRelationships(): MutableList<<%= persistClass %>> - - @Query("{'id': ?0}") - fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Optional<<%= persistClass %>> - <%_ } _%> + <%_ } _%> <%_ } _%> } diff --git a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs similarity index 57% rename from generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs rename to generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs index e0c3b39c1..455735873 100644 --- a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs +++ b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_reactive.kt.ejs @@ -19,34 +19,13 @@ package <%= entityAbsolutePackage %>.repository import <%= entityAbsolutePackage %>.domain.<%= persistClass %> -<%_ if (databaseTypeCassandra) { _%> -import org.springframework.data.cassandra.repository.ReactiveCassandraRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository -import org.springframework.data.neo4j.repository.query.Query -<%_ } _%> -<%_ if (!paginationNo || implementsEagerLoadApis || databaseTypeSql) { _%> import org.springframework.data.domain.Pageable -<%_ } _%> -<%_ if (databaseTypeSql) { _%> import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.data.relational.core.query.Criteria -<%_ } _%> -<%_ if (databaseTypeMongodb) { _%> - <%_ if (implementsEagerLoadApis) { _%> -import org.springframework.data.mongodb.repository.Query - <%_ } _%> -import org.springframework.data.mongodb.repository.ReactiveMongoRepository -<%_ } _%> import org.springframework.stereotype.Repository -<%_ if (databaseTypeSql || !paginationNo || implementsEagerLoadApis) { _%> import reactor.core.publisher.Flux -<%_ } _%> -<%_ if (implementsEagerLoadApis || databaseTypeSql) { _%> import reactor.core.publisher.Mono -<%_ } _%> <%_ if (primaryKey.typeUUID) { _%> import java.util.UUID @@ -57,70 +36,42 @@ import java.util.UUID */ @SuppressWarnings("unused") @Repository -interface <%= entityClass %>Repository: <% if (databaseTypeSql) { %>ReactiveCrud<% } if (databaseTypeMongodb) { %>ReactiveMongo<% } if (databaseTypeNeo4j) { %>ReactiveNeo4j<% } if (databaseTypeCassandra) { %>ReactiveCassandra<% } %>Repository<<%= persistClass %>, <%= primaryKey.type %>><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %><% if (databaseTypeSql) { %>, <%= entityClass %>RepositoryInternal<% } %> { +interface <%= entityClass %>Repository: ReactiveCrudRepository<<%= persistClass %>, <%= primaryKey.type %>>, <%= entityClass %>RepositoryInternal { <%_ if (!paginationNo) { _%> - <% if (databaseTypeSql) { %>override<% } %> fun findAllBy(pageable: Pageable?): Flux<<%= persistClass %>> -<%_ } _%> -<%_ if (implementsEagerLoadApis) { _%> - <%_ if (databaseTypeMongodb) { _%> - - @Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>") - fun findAllWithEagerRelationships(pageable: Pageable): Flux<<%= persistClass %>> - - @Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>") - fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> - - @Query("<%- (databaseTypeMongodb) ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>") - fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Mono<<%= persistClass %>> - <%_ } _%> - <%_ if (databaseTypeNeo4j) { _%> - @Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m") - fun findAllWithEagerRelationships(pageable: Pageable): Flux<<%= persistClass %>> + override fun findAllBy(pageable: Pageable?): Flux<<%= persistClass %>> - @Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m") - fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> - - @Query("MATCH (e:<%= persistClass %> {id: $id}) RETURN e") - fun findOneWithEagerRelationships(id: <%= primaryKey.type %>): Mono<<%= persistClass %>> - <%_ } _%> <%_ } _%> - -<%_ if (databaseTypeSql) { _%> - <%_ if (implementsEagerLoadApis) { _%> - +<%_ if (implementsEagerLoadApis) { _%> override fun findOneWithEagerRelationships(id: <%= primaryKey.type %>?): Mono<<%= persistClass %>> override fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> override fun findAllWithEagerRelationships(page: Pageable): Flux<<%= persistClass %>> - <%_ } _%> - - <%_ for (const relationship of relationships) { - let relationshipName = relationship.relationshipName; - let ownerSide = relationship.ownerSide; _%> - <%_ if (relationship.relationshipManyToOne || (relationship.relationshipOneToOne && ownerSide)) { _%> - +<%_ } _%> +<%_ for (const relationship of relationships) { + let relationshipName = relationship.relationshipName; + let ownerSide = relationship.ownerSide; _%> + <%_ if (relationship.relationshipManyToOne || (relationship.relationshipOneToOne && ownerSide)) { _%> @Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.<%= relationship.joinColumnNames[0] %> = :id") fun findBy<%= relationship.relationshipNameCapitalized %>(id: <%= primaryKey.type %>): Flux<<%= persistClass %>> @Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.<%= relationship.joinColumnNames[0] %> IS NULL") fun findAllWhere<%= relationship.relationshipNameCapitalized %>IsNull(): Flux<<%= persistClass %>> - <%_ } else if (relationship.shouldWriteJoinTable) { _%> + <%_ } else if (relationship.shouldWriteJoinTable) { _%> @Query("SELECT entity.* FROM <%= entityTableName %> entity JOIN <%= relationship.joinTable.name %> joinTable ON entity.<%= primaryKey.fields[0].columnName %> = joinTable.<%= relationship.joinColumnNames[0] %> WHERE joinTable.<%= relationship.joinColumnNames[0] %> = :id") fun findBy<%= relationship.relationshipNameCapitalized %>(id: <%= primaryKey.type %>): Flux<<%= persistClass %>> - <%_ } else if (relationship.relationshipOneToOne && ownerSide === false) { + <%_ } else if (relationship.relationshipOneToOne && ownerSide === false) { let otherEntityRelationshipName = relationship.otherEntityRelationshipName; let otherEntityTableName = relationship.otherEntityTableName; - _%> - + _%> @Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.<%= primaryKey.fields[0].columnName %> not in (select <%= relationship.joinColumnNames[0]%> from <%= otherEntityTableName %>)") fun findAllWhere<%= relationship.relationshipNameCapitalized %>IsNull(): Flux<<%= persistClass %>> - <%_ } _%> - <%_ } _%> + <%_ } _%> +<%_ } _%> override fun > save(entity: S): Mono override fun findAll(): Flux<<%= persistClass %>> @@ -143,8 +94,7 @@ interface <%= entityClass %>RepositoryInternal { // this is not supported at the moment because of https://github.com/jhipster/generator-jhipster/issues/18269 // fun findAllBy(pageable: Pageable, criteria: Criteria): Flux<<%= persistClass %>> - <%_ if (implementsEagerLoadApis) { _%> - +<%_ if (implementsEagerLoadApis) { _%> fun findOneWithEagerRelationships(id: <%= primaryKey.type %>?): Mono<<%= persistClass %>> fun findAllWithEagerRelationships(): Flux<<%= persistClass %>> @@ -153,6 +103,5 @@ interface <%= entityClass %>RepositoryInternal { fun deleteById(id: <%= primaryKey.type %>?): Mono - <%_ } _%> <%_ } _%> }