Skip to content

Commit

Permalink
Merge pull request #5971 from srinivasa-vasu/infinispan_r_b_1.1
Browse files Browse the repository at this point in the history
initial commit: jcache stats
  • Loading branch information
jdubois authored Jun 23, 2017
2 parents e8c062b + dfd017f commit d307b92
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h3 jhiTranslate="metrics.servicesstats.title">Services statistics (time in mill
</tbody>
</table>
</div>
<% if (hibernateCache === 'ehcache') { %>
<% if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { %>
<h3 jhiTranslate="metrics.cache.title">Cache statistics</h3>
<div class="table-responsive" *ngIf="!updatingMetrics">
<table class="table table-striped">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
function <%=jhiPrefixCapitalized%>MetricsMonitoringController ($scope, <%=jhiPrefixCapitalized%>MetricsService, $uibModal) {
var vm = this;

<%_ if (hibernateCache === 'ehcache') { _%>
<%_ if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { _%>
vm.cachesStats = {};
<%_ } _%>
vm.metrics = {};
Expand All @@ -47,7 +47,7 @@
}
});

<%_ if (hibernateCache === 'ehcache') { _%>
<%_ if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { _%>
vm.cachesStats = {};
angular.forEach(newValue.gauges, function (value, key) {
if (key.indexOf('jcache.statistics') !== -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ <h3 data-translate="metrics.servicesstats.title">Services statistics (time in mi
</tbody>
</table>
</div>
<%_ if (hibernateCache === 'ehcache') { _%>
<%_ if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { _%>
<h3 data-translate="metrics.cache.title">Cache statistics</h3>
<div class="table-responsive">
<table class="table table-striped">
Expand Down
4 changes: 2 additions & 2 deletions generators/entity/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ function writeFiles() {
}
this.addChangelogToLiquibase(`${this.changelogDate}_added_entity_${this.entityClass}`);

if (this.hibernateCache === 'ehcache') {
this.addEntityToEhcache(this.entityClass, this.relationships, this.packageName, this.packageFolder);
if (this.hibernateCache === 'ehcache' || this.hibernateCache === 'infinispan') {
this.addEntityToCache(this.entityClass, this.relationships, this.packageName, this.packageFolder, this.hibernateCache);
}
}
},
Expand Down
65 changes: 51 additions & 14 deletions generators/generator-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,40 +707,77 @@ module.exports = class extends Generator {
}

/**
* Add a new entity to the Ehcache, for the 2nd level cache of an entity and its relationships.
* Add a new entity to Ehcache, for the 2nd level cache of an entity and its relationships.
*
* @param {string} entityClass - the entity to cache.
* @param {string} entityClass - the entity to cache
* @param {array} relationships - the relationships of this entity
* @param {string} packageName - the Java package name
* @param {string} packageFolder - the Java package folder
*/
addEntityToEhcache(entityClass, relationships, packageName, packageFolder) {
this.addEntityToCache(entityClass, relationships, packageName, packageFolder, 'ehcache');
}

/**
* Add a new entry to Ehcache in CacheConfiguration.java
*
* @param {string} entry - the entry (including package name) to cache
* @param {string} packageFolder - the Java package folder
*/
addEntryToEhcache(entry, packageFolder) {
this.addEntryToCache(entry, packageFolder, 'ehcache');
}

/**
* Add a new entity to the chosen cache provider, for the 2nd level cache of an entity and its relationships.
*
* @param {string} entityClass - the entity to cache
* @param {array} relationships - the relationships of this entity
* @param {string} packageName - the Java package name
* @param {string} packageFolder - the Java package folder
* @param {string} cacheProvider - the cache provider
*/
addEntityToCache(entityClass, relationships, packageName, packageFolder, cacheProvider) {
// Add the entity to ehcache
this.addEntryToEhcache(`${packageName}.domain.${entityClass}.class.getName()`, packageFolder);
this.addEntryToCache(`${packageName}.domain.${entityClass}.class.getName()`, packageFolder, cacheProvider);
// Add the collections linked to that entity to ehcache
relationships.forEach((relationship) => {
const relationshipType = relationship.relationshipType;
if (relationshipType === 'one-to-many' || relationshipType === 'many-to-many') {
this.addEntryToEhcache(`${packageName}.domain.${entityClass}.class.getName() + ".${relationship.relationshipFieldNamePlural}"`, packageFolder);
this.addEntryToCache(`${packageName}.domain.${entityClass}.class.getName() + ".${relationship.relationshipFieldNamePlural}"`, packageFolder, cacheProvider);
}
});
}

/**
* Add a new entry to Ehcache in CacheConfiguration.java
* Add a new entry to the chosen cache provider in CacheConfiguration.java
*
* @param {string} entry - the entry (including package name) to cache.
* @param {string} entry - the entry (including package name) to cache
* @param {string} packageFolder - the Java package folder
* @param {string} cacheProvider - the cache provider
*/
addEntryToEhcache(entry, packageFolder) {
addEntryToCache(entry, packageFolder, cacheProvider) {
try {
const ehcachePath = `${SERVER_MAIN_SRC_DIR}${packageFolder}/config/CacheConfiguration.java`;
jhipsterUtils.rewriteFile({
file: ehcachePath,
needle: 'jhipster-needle-ehcache-add-entry',
splicable: [`cm.createCache(${entry}, jcacheConfiguration);`
]
}, this);
const cachePath = `${SERVER_MAIN_SRC_DIR}${packageFolder}/config/CacheConfiguration.java`;
if (cacheProvider === 'ehcache') {
jhipsterUtils.rewriteFile({
file: cachePath,
needle: 'jhipster-needle-ehcache-add-entry',
splicable: [`cm.createCache(${entry}, jcacheConfiguration);`
]
}, this);
} else if (cacheProvider === 'infinispan') {
jhipsterUtils.rewriteFile({
file: cachePath,
needle: 'jhipster-needle-infinispan-add-entry',
splicable: [`registerPredefinedCache(${entry}, new JCache<Object, Object>(
cacheManager.getCache(${entry}).getAdvancedCache(), this,
ConfigurationAdapter.create()));`
]
}, this);
} else {
// do nothing
}
} catch (e) {
this.log(chalk.yellow(`\nUnable to add ${entry} to CacheConfiguration.java file.\n\t${e.message}`));
}
Expand Down
5 changes: 3 additions & 2 deletions generators/server/templates/_build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ repositories {
dependencies {
compile "io.github.jhipster:jhipster:${jhipster_server_version}"
compile "io.dropwizard.metrics:metrics-core:${dropwizard_metrics_version}"
<%_ if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { _%>
compile "io.dropwizard.metrics:metrics-jcache:${dropwizard_metrics_version}"
<%_ } _%>
compile "io.dropwizard.metrics:metrics-jvm:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-servlet:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-json:${dropwizard_metrics_version}"
Expand Down Expand Up @@ -253,8 +255,7 @@ dependencies {
<%_ if (hibernateCache === 'infinispan') {_%>
compile "org.infinispan:infinispan-spring-boot-starter:${infinispan_boot_starter_version}"
compile "org.infinispan:infinispan-core"
compile "org.infinispan:infinispan-spring4-embedded:${infinispan_cloud_version}"
compile "org.infinispan:infinispan-spring4-common:${infinispan_cloud_version}"
compile "org.infinispan:infinispan-jcache"
compile ("org.infinispan:infinispan-cloud:${infinispan_cloud_version}") {
exclude module: 'undertow-core'
}
Expand Down
10 changes: 2 additions & 8 deletions generators/server/templates/_pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
<artifactId>metrics-json</artifactId>
<version>${dropwizard-metrics.version}</version>
</dependency>
<%_ if (hibernateCache === 'ehcache') { _%>
<%_ if (hibernateCache === 'ehcache' || hibernateCache === 'infinispan') { _%>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jcache</artifactId>
Expand Down Expand Up @@ -349,13 +349,7 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring4-embedded</artifactId>
<version>${infinispan.cloud.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring4-common</artifactId>
<version>${infinispan.cloud.version}</version>
<artifactId>infinispan-jcache</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
Expand Down
Loading

0 comments on commit d307b92

Please sign in to comment.