Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize #430

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion generators/spring-boot-v2/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
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.<% 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 %>> {}
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
Loading