-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add caffeine cache implementation (#117)
* Add Quarkus cache dependency * Add cache UserService.java * Follow JHipster cache implementation for User entity * Enable Hibernate second cache level for user * Enable Hibernate second level cache for Authority * Improve code style * Provide Quarkus cache each time we choose a cache * Add cache dependency in Gradle * Override cacheManagerIsAvailable property with Quarkus caches * Make integration-tests more consistent * Enable User methods caching when enableHibernateCache * Add gradle tests * Remove unused file * Add Hibernate cache support in Entity (with ReadOnly option too) * Add application.properties for tests purpose * Move generation context into api and builder class to avoid duplicate code * Move server test generation context into api builder * Move client test generation context into api builder * Move common test generation context into api builder * Add default cache properties for User and Authority entities * Add needle api for hibernate second cache entity and relationships * Remove hints feature * add cache default properties
- Loading branch information
Showing
33 changed files
with
856 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
const DEFAULT_DATA_ACCESS = 'activeRecord'; | ||
const QUARKUS_VERSION = '1.10.2.Final'; | ||
|
||
const CACHE_MAXIMUM_SIZE = 100; | ||
const CACHE_EXPIRE_AFTER_WRITE = '3600S'; | ||
|
||
const constants = { | ||
DEFAULT_DATA_ACCESS, | ||
QUARKUS_VERSION | ||
QUARKUS_VERSION, | ||
CACHE_MAXIMUM_SIZE, | ||
CACHE_EXPIRE_AFTER_WRITE | ||
}; | ||
|
||
module.exports = constants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2013-2020 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 | ||
* | ||
* 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. | ||
*/ | ||
const ServerCache = require('./server/needle-api/needle-server-cache'); | ||
|
||
module.exports = class NeedleApi { | ||
constructor(generator) { | ||
this.quarkusServerCache = new ServerCache(generator); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const chalk = require('chalk'); | ||
const needleServerCache = require('generator-jhipster/generators/server/needle-api/needle-server-cache'); | ||
const constants = require('generator-jhipster/generators/generator-constants'); | ||
const { CACHE_MAXIMUM_SIZE, CACHE_EXPIRE_AFTER_WRITE } = require('../../generator-quarkus-constants'); | ||
|
||
const { SERVER_MAIN_RES_DIR } = constants; | ||
|
||
module.exports = class extends needleServerCache { | ||
addEntityConfigurationToPropertiesFile(entityClass, relationships, packageName) { | ||
const errorMessage = chalk.yellow(`\nUnable to add ${entityClass} to application.properties file.`); | ||
const cacheName = `${packageName}.domain.${entityClass}`; | ||
const applicationPropertiesFileName = `${SERVER_MAIN_RES_DIR}application.properties`; | ||
const needle = 'jhipster-quarkus-needle-hibernate-cache-add-entry'; | ||
const rewriteFileModel = this.generateFileModel( | ||
applicationPropertiesFileName, | ||
needle, | ||
`quarkus.hibernate-orm.cache."${cacheName}".expiration.max-idle=${CACHE_EXPIRE_AFTER_WRITE}\n` + | ||
`quarkus.hibernate-orm.cache."${cacheName}".memory.object-count=${CACHE_MAXIMUM_SIZE}` | ||
); | ||
|
||
this.addBlockContentToFile(rewriteFileModel, errorMessage); | ||
|
||
relationships.forEach(relationship => { | ||
const relationshipType = relationship.relationshipType; | ||
if (relationshipType === 'one-to-many' || relationshipType === 'many-to-many') { | ||
const rewriteFileModelWithRelationships = this.generateFileModel( | ||
applicationPropertiesFileName, | ||
needle, | ||
`quarkus.hibernate-orm.cache."${cacheName}.${ | ||
relationship.relationshipFieldNamePlural | ||
}".expiration.max-idle=${CACHE_EXPIRE_AFTER_WRITE}\n` + | ||
`quarkus.hibernate-orm.cache."${cacheName}.${ | ||
relationship.relationshipFieldNamePlural | ||
}".memory.object-count=${CACHE_MAXIMUM_SIZE}` | ||
); | ||
this.addBlockContentToFile(rewriteFileModelWithRelationships, errorMessage); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.