Skip to content

Commit

Permalink
#139 Migrate entity classes to nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
kozub committed Sep 21, 2019
1 parent d2c0723 commit ebcae3a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
const returnPrefix = returnDirectly ? 'return' : 'val ' + instanceName + ' =';
if (!viaService) {
%>
<%- returnPrefix %> <%= entityInstance %>Repository.<% if (fieldsContainOwnerManyToMany === true) { %>findOneWithEagerRelationships(id)<% } else { %>findById(id)<% } %><% if (dto !== 'mapstruct') { %><% } else { %>
.map(<%= entityToDtoReference %>)<% } } else { %>
<%- returnPrefix %> <%= entityInstance %>Repository.<% if (fieldsContainOwnerManyToMany === true) { %>findOneWithEagerRelationships(id)<% } else { %>findByIdOrNull((id)<% } %><% if (dto !== 'mapstruct') { %><% } else { %>
?.let(<%= entityToDtoReference %>)<% } } else { %>
<%- returnPrefix %> <%= entityInstance %>Service.findOne(id)<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import org.springframework.stereotype.Repository
<%_ if (databaseType === 'sql' || databaseType === 'mongodb') { _%>
<%_ if (fieldsContainOwnerManyToMany) { _%>

import java.util.Optional
<%_ } _%>
<%_ } _%>
<%_ if (databaseType === 'cassandra') { _%>
Expand Down Expand Up @@ -82,7 +81,7 @@ interface <%=entityClass%>Repository : <% if (databaseType === 'sql') { %>JpaRep

@Query("select <%= entityInstance %> from <%= asEntity(entityClass) %> <%= entityInstance %><% for (idx in relationships) {
if (relationships[idx].relationshipType === 'many-to-many' && relationships[idx].ownerSide === true) { %> left join fetch <%=entityInstance%>.<%=relationships[idx].relationshipFieldNamePlural%><%} }%> where <%=entityInstance%>.id =:id")
fun findOneWithEagerRelationships(@Param("id") id: <%= pkType %>): Optional<<%= asEntity(entityClass) %>>
fun findOneWithEagerRelationships(@Param("id") id: <%= pkType %>): <%= asEntity(entityClass) %>?
<%_
} else if (databaseType === 'mongodb') { _%>

Expand All @@ -93,7 +92,7 @@ interface <%=entityClass%>Repository : <% if (databaseType === 'sql') { %>JpaRep
fun findAllWithEagerRelationships(): MutableList<<%= asEntity(entityClass) %>>

@Query("{'id': ?0}")
fun findOneWithEagerRelationships(id: <%= pkType %>): Optional<<%= asEntity(entityClass) %>>
fun findOneWithEagerRelationships(id: <%= pkType %>): <%= asEntity(entityClass) %>?
<%_ }
} _%>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.springframework.data.domain.Pageable
import reactor.core.publisher.Flux
<%_ } _%>

import java.util.Optional
<%_ if (databaseType === 'cassandra') { _%>
import java.util.UUID
<%_ } _%>
Expand Down Expand Up @@ -90,7 +89,7 @@ interface <%= entityClass %>Service {
* @param id the id of the entity.
* @return the entity.
*/
fun findOne(id: <%= pkType %>): Optional<<%= instanceType %>>
fun findOne(id: <%= pkType %>): <%= instanceType %>?

/**
* Delete the "id" <%= entityInstance %>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import org.springframework.transaction.annotation.Transactional
import reactor.core.publisher.Flux
<%_ } _%>

import java.util.Optional
<%_ if (databaseType === 'cassandra') { _%>
import java.util.UUID
<%_ } _%>
Expand Down Expand Up @@ -151,7 +150,7 @@ class <%= serviceClassName %>(
<%_ if (databaseType === 'sql') { _%>
@Transactional(readOnly = true)
<%_ } _%>
<% if (service === 'serviceImpl') { %>override <% } %>fun findOne(id: <%= pkType %>): Optional<<%= instanceType %>> {
<% if (service === 'serviceImpl') { %>override <% } %>fun findOne(id: <%= pkType %>): <%= instanceType %>? {
log.debug("Request to get <%= entityClass %> : {}", id)<%- include('../../common/get_template', {asEntity, asDto, viaService, returnDirectly:true}); -%>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import javax.validation.Valid
<%_ } _%>
import java.net.URI
import java.net.URISyntaxException<% if (isUsingMapsId === true) { %>
import java.util.Objects<% } %>
import java.util.*<% } %>
<%_ if (databaseType === 'cassandra') { _%>
import java.util.UUID<% } %><% if (searchEngine === 'elasticsearch') { %>

Expand Down Expand Up @@ -249,7 +249,7 @@ _%><%- include('../../common/inject_template', {viaService: viaService, construc
<%_ } _%>
fun get<%= entityClass %>(@PathVariable id: <%= pkType %>): ResponseEntity<<%= instanceType %>> {
log.debug("REST request to get <%= entityClass %> : {}", id)<%- include('../../common/get_template', {asEntity, asDto, viaService, returnDirectly:false}); -%>
return ResponseUtil.wrapOrNotFound(<%= instanceName %>)
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(<%= instanceName %>))
}

/**
Expand Down

0 comments on commit ebcae3a

Please sign in to comment.