Skip to content

Commit

Permalink
split repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 7, 2024
1 parent 9a5f032 commit 2f014ba
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 105 deletions.
6 changes: 6 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"generator-jhipster": {
"additionalSubGenerators": "detekt,ktlint,kotlin,migration,spring-boot-v2",
"baseName": "kotlin",
"blueprints": [
{
"name": "generator-jhipster-kotlin",
"version": "1.16.0"
}
],
"cli": true,
"cliName": "khipster",
"entities": [],
Expand Down
3 changes: 0 additions & 3 deletions generators/spring-boot/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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.ReactiveCassandraRepository
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 %>> {}
Original file line number Diff line number Diff line change
@@ -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 %>>
<%_ } _%>
}
Original file line number Diff line number Diff line change
@@ -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 %>>
<%_ } _%>
}
Original file line number Diff line number Diff line change
@@ -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 %>><% } %> {}
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -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) { _%>
Expand All @@ -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.
Expand All @@ -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) { %>)<% } %>
}
Expand All @@ -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 %><% } } %>",
Expand All @@ -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 %>>
<%_ } _%>
<%_ } _%>
<%_ } _%>
}
Loading

0 comments on commit 2f014ba

Please sign in to comment.