From 44b603c738f4cd11d4df12c2661715bae92d4086 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 31 Jan 2025 16:40:33 -0300 Subject: [PATCH] Replace AuthorityRepository with r2dbc generic repository --- generators/spring-boot-v2/generator.js | 3 + .../repository/AuthorityRepository.kt.ejs | 71 ------------------- .../_entityClass_Repository_r2dbc.kt.ejs | 34 +++++++++ test/__snapshots__/app.spec.js.snap | 3 - 4 files changed, 37 insertions(+), 74 deletions(-) delete mode 100644 generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs create mode 100644 generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs diff --git a/generators/spring-boot-v2/generator.js b/generators/spring-boot-v2/generator.js index ab12a72e1..194fb09c4 100644 --- a/generators/spring-boot-v2/generator.js +++ b/generators/spring-boot-v2/generator.js @@ -110,6 +110,9 @@ export default class extends BaseApplicationGenerator { if (application.user && destinationFile.endsWith('UserCallback.java')) { return undefined; } + if (application.generateBuiltInAuthorityEntity && destinationFile.endsWith('AuthorityRepository.java')) { + return undefined; + } if ( sourceFile.endsWith('/TestContainersSpringContextCustomizerFactory.java') && diff --git a/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs b/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs deleted file mode 100644 index 78bcf8732..000000000 --- a/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs +++ /dev/null @@ -1,71 +0,0 @@ -<%# - Copyright 2013-2025 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. --%> -package <%= packageName %>.repository - -import <%= packageName %>.domain.Authority -<%_ if (databaseTypeCouchbase) { _%> -import org.springframework.stereotype.Repository -<%_ } _%> -<%_ if (databaseTypeSql) { _%> - <%_ if (reactive) { _%> -import org.springframework.data.r2dbc.repository.R2dbcRepository - <%_ } else { _%> -import org.springframework.data.jpa.repository.JpaRepository - <%_ } _%> -<%_ } _%> -<%_ if (databaseTypeMongodb) { _%> -import org.springframework.data.mongodb.repository.<% if (reactive) { %>Reactive<% } %>MongoRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<% } %>Neo4jRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -<%_ if (reactive) { _%> -import reactor.core.publisher.Flux -<%_ } _%> -<%_ } _%> -<% if (databaseTypeSql) { %> -/** - * Spring Data <% if (reactive) { %>R2DBC<% } else { %>JPA<% } %> repository for the [Authority] entity. - */ -<% } %><% if (databaseTypeMongodb) { %> -/** - * Spring Data MongoDB repository for the [Authority] entity. - */ -<% } %><%_ if (databaseTypeNeo4j) { _%> -/** -* Spring Data Neo4j repository for the {@link Authority} entity. -*/ -<%_ } _%><% if (databaseTypeCouchbase) { %> -/** - * Spring Data Couchbase repository for the [Authority] entity. - */ -<% } %> -<% if (databaseTypeCouchbase) { %> -@Repository -<%_ } _%> -<%_ - let listOrFlux = reactive ? 'Flux' : 'List'; -_%> -interface AuthorityRepository : <% if (databaseTypeSql) { %><% if (reactive) { %>R2dbc<% } else { %>Jpa<% } %>Repository<% } else { %><% if (reactive && !databaseTypeCouchbase) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCouchbase) { %>JHipsterCouchbaseRepository<% } %><% } %> { - <%_ if (databaseTypeNeo4j) { _%> - <% if (!reactive) { %>// See https://github.com/neo4j/sdn-rx/issues/51<%_ } _%> - override fun findAll(): <% if (reactive) { %>Flux<% } else { %>List<% } %> - <%_ } _%> -} diff --git a/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs new file mode 100644 index 000000000..a5d3c5e15 --- /dev/null +++ b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs @@ -0,0 +1,34 @@ +<%# + 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. +-%> +package <%= entityAbsolutePackage %>.repository + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> + +import org.springframework.data.r2dbc.repository.R2dbcRepository +import org.springframework.stereotype.Repository +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** + * <%= springDataDescription %> repository for the [<%= persistClass %>] entity. + */ +@Repository +interface <%= entityClass %>Repository : R2dbcRepository<<%= persistClass %>, <%= primaryKey.type %>> diff --git a/test/__snapshots__/app.spec.js.snap b/test/__snapshots__/app.spec.js.snap index 66a5c03ab..ac50765f1 100644 --- a/test/__snapshots__/app.spec.js.snap +++ b/test/__snapshots__/app.spec.js.snap @@ -2469,9 +2469,6 @@ exports[`JHipster generator for App generator > Application with other options > "src/main/kotlin/com/test/reactui/domain/User.kt": { "stateCleared": "modified", }, - "src/main/kotlin/com/test/reactui/repository/AuthorityRepository.kt": { - "stateCleared": "modified", - }, "src/main/kotlin/com/test/reactui/security/AuthoritiesConstants.kt": { "stateCleared": "modified", },