Skip to content

Commit 6e4c6da

Browse files
authored
couchbase: enable cache in sample (#28040)
1 parent 2d5edbf commit 6e4c6da

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

.blueprint/github-build-matrix/support/git-changes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getGitChanges = async (options: { allTrue?: boolean } = {}) => {
2424
hasPatternChanges('lib/**') ||
2525
hasPatternChanges('generators/*') ||
2626
hasPatternChanges('generators/{base*,bootstrap*,git,jdl,project-name}/**'),
27-
ci: hasPatternChanges('.github/{actions,workflows}/**'),
27+
ci: hasPatternChanges('.github/{actions,workflows}/**') || hasPatternChanges('test-integration/{,jdl}samples/**'),
2828
devBlueprint: hasPatternChanges('.blueprint/**'),
2929
devserverWorkflow: hasPatternChanges('.github/workflows/devserver.yml'),
3030
common: hasPatternChanges('generators/{app,common,docker,languages}/**'),

generators/spring-boot/templates/src/main/java/_package_/_entityPackage_/repository/UserRepository.java.ejs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepositor
203203
<%_ if (!authenticationTypeOauth2) { _%>
204204
<%_ if (databaseTypeCouchbase || databaseTypeMongodb || databaseTypeNeo4j) { _%>
205205
<%_ if (cacheProviderAny) { _%>
206-
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
206+
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE, unless="#result == null")
207207
<%_ } _%>
208208
<%_ } _%>
209209
<% if (databaseTypeCouchbase) { %>default <% } %><%= optionalOrMono %><<%= user.persistClass %>> findOneByEmailIgnoreCase(String email)<% if (!databaseTypeCouchbase) { %>;<% } else { %> {
@@ -219,14 +219,14 @@ public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepositor
219219
<%_ } _%>
220220
<%_ if (databaseTypeCouchbase) { _%>
221221
<%_ if (cacheProviderAny) { _%>
222-
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
222+
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE, unless="#result == null")
223223
<%_ } _%>
224224
default <%= optionalOrMono %><<%= user.persistClass %>> findOneByLogin(String login) {
225225
return findById(login);
226226
}
227227
<%_ } else if (databaseTypeMongodb || databaseTypeNeo4j) { _%>
228228
<%_ if (cacheProviderAny) { _%>
229-
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
229+
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE, unless="#result == null")
230230
<%_ } _%>
231231
<%= optionalOrMono %><<%= user.persistClass %>> findOneByLogin(String login);
232232
<%_ } else { _%>
@@ -241,14 +241,14 @@ public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepositor
241241
<%_ if (databaseTypeSql) { _%>
242242
@EntityGraph(attributePaths = "authorities")
243243
<%_ if (cacheProviderAny) { _%>
244-
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
244+
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE, unless="#result == null")
245245
<%_ } _%>
246246
Optional<<%= user.persistClass %>> findOneWithAuthoritiesByLogin(String login);
247247
248248
<%_ if (!authenticationTypeOauth2) { _%>
249249
@EntityGraph(attributePaths = "authorities")
250250
<%_ if (cacheProviderAny) { _%>
251-
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
251+
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE, unless="#result == null")
252252
<%_ } _%>
253253
Optional<<%= user.persistClass %>> findOneWithAuthoritiesByEmailIgnoreCase(String email);
254254
@@ -609,15 +609,15 @@ public class UserRepository {
609609
}
610610
611611
<%_ if (cacheProviderAny) { _%>
612-
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
612+
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE, unless="#result == null")
613613
<%_ } _%>
614614
public <%= optionalOrMono %><<%= user.persistClass %>> findOneByEmailIgnoreCase(String email) {
615615
BoundStatement stmt = findOneByEmailStmt.bind().setString("email", email.toLowerCase());
616616
return findOneFromIndex(stmt);
617617
}
618618
619619
<%_ if (cacheProviderAny) { _%>
620-
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
620+
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE, unless="#result == null")
621621
<%_ } _%>
622622
public <%= optionalOrMono %><<%= user.persistClass %>> findOneByLogin(String login) {
623623
BoundStatement stmt = findOneByLoginStmt.bind().setString("login", login);

generators/spring-boot/templates/src/main/java/_package_/_entityPackage_/service/UserService.java.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,9 @@ public class UserService {
10971097
<%_ if (cacheProviderAny && !databaseTypeNo) { _%>
10981098
10991099
private void clearUserCaches(<%= user.persistClass %> user) {
1100-
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)).evict(user.getLogin());
1100+
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)).evictIfPresent(user.getLogin());
11011101
if (user.getEmail() != null) {
1102-
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_EMAIL_CACHE)).evict(user.getEmail());
1102+
Objects.requireNonNull(cacheManager.getCache(UserRepository.USERS_BY_EMAIL_CACHE)).evictIfPresent(user.getEmail());
11031103
}
11041104
}
11051105
<%_ } _%>

generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/UserResourceIT.java.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ class UserResourceIT {
276276

277277
@AfterEach
278278
public void cleanupAndCheck() {
279-
<%_ if (cacheProviderAny) { _%>
280-
cacheManager.getCacheNames().stream()
281-
.map(cacheName -> this.cacheManager.getCache(cacheName))
282-
.filter(Objects::nonNull)
283-
.forEach(Cache::clear);
284-
<%_ } _%>
285279
<%_ if (requiresDeleteAllUsers) { _%>
286280
<%_ if (databaseTypeSql && reactive) { _%>
287281
userRepository.deleteAllUserAuthorities()<%- reactorBlock %>;
@@ -296,6 +290,12 @@ class UserResourceIT {
296290
<%_ if (!databaseTypeCassandra && !requiresDeleteAllUsers) { _%>
297291
assertThat(userRepository.count()<%- reactorBlock %>).isEqualTo(numberOfUsers);
298292
numberOfUsers = null;
293+
<%_ } _%>
294+
<%_ if (cacheProviderAny) { _%>
295+
cacheManager.getCacheNames().stream()
296+
.map(cacheName -> this.cacheManager.getCache(cacheName))
297+
.filter(Objects::nonNull)
298+
.forEach(Cache::invalidate);
299299
<%_ } _%>
300300
}
301301
<%_ if (!authenticationTypeOauth2) { _%>

test-integration/samples/ng-couchbase/.yo-rc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"generator-jhipster": {
33
"applicationType": "monolith",
44
"authenticationType": "jwt",
5-
"baseName": "sampleCouchbaseNoCache",
5+
"baseName": "sampleCouchbaseCache",
66
"buildTool": "maven",
7-
"cacheProvider": "no",
7+
"cacheProvider": "ehcache",
88
"clientFramework": "angular",
99
"clientPackageManager": "npm",
1010
"creationTimestamp": 1596513172471,

0 commit comments

Comments
 (0)