Skip to content

Commit

Permalink
Merge pull request #289 from hwbllmnn/add-hibernate-caching
Browse files Browse the repository at this point in the history
Add hibernate caching, bump some dependency versions
  • Loading branch information
buehner authored Jan 23, 2018
2 parents cc70a8f + 7eba252 commit 710e47a
Show file tree
Hide file tree
Showing 65 changed files with 549 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sudo: false

jdk:
- oraclejdk8
- openjdk7
- openjdk8

env:
global:
Expand Down
21 changes: 12 additions & 9 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@
<tomcat.version>8.5.20</tomcat.version>

<!-- Core -->
<spring.version>4.3.11.RELEASE</spring.version>
<spring-security.version>4.2.3.RELEASE</spring-security.version>
<!-- TODO: Raise log4j to version 2 -->
<log4j.version>1.2.17</log4j.version>
<spring.version>5.0.2.RELEASE</spring.version>
<spring-security.version>5.0.0.RELEASE</spring-security.version>
<log4j.version>2.10.0</log4j.version>
<slf4j.version>1.7.25</slf4j.version>
<jackson.version>2.9.1</jackson.version>
<opencsv.version>4.0</opencsv.version>
Expand All @@ -144,7 +143,7 @@
<!-- Persistence -->
<hibernate.version>5.1.10.Final</hibernate.version>
<hikari-jdk7.version>2.4.11</hikari-jdk7.version>
<hikari.version>2.6.1</hikari.version>
<hikari.version>2.7.6</hikari.version>
<h2.version>1.4.196</h2.version>

<!-- Testing -->
Expand Down Expand Up @@ -470,16 +469,20 @@

<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>

</dependencies>

<!-- The dependencyManagement section will make the configured (versions
Expand Down
11 changes: 11 additions & 0 deletions src/shogun2-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- Spring -->
<dependency>
Expand Down Expand Up @@ -189,6 +194,12 @@
<dependency>
<groupId>com.bedatadriven</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<exclusions>
<exclusion>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import de.terrestris.shogun2.model.PersistentObject;
Expand Down Expand Up @@ -48,6 +49,9 @@ public class GenericHibernateDao<E extends PersistentObject, ID extends Serializ
*/
private final Class<E> entityClass;

@Value("${hibernate.cache.use_query_cache}")
private Boolean useQueryCache;

/**
* Default constructor
*/
Expand Down Expand Up @@ -135,6 +139,7 @@ public List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity,
} else {
criteria.add(Restrictions.eq(fieldName, fieldEntity));
}
criteria.setCacheable(this.useQueryCache);

return (List<E>) criteria.list();
}
Expand Down Expand Up @@ -435,6 +440,7 @@ protected Criteria createDistinctRootEntityCriteria(Criterion... criterion) {
Criteria criteria = getSession().createCriteria(entityClass);
addCriterionsToCriteria(criteria, criterion);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setCacheable(this.useQueryCache);
return criteria;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Locale;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
Expand All @@ -17,6 +18,10 @@

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.joda.time.ReadableDateTime;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
Expand All @@ -37,6 +42,8 @@
@Entity
@Table
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Application extends PersistentObject {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -83,6 +90,8 @@ public class Application extends PersistentObject {
*
*/
@ManyToOne
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
private CompositeModule viewport;

/**
Expand All @@ -101,6 +110,8 @@ public class Application extends PersistentObject {
resolver = PluginIdResolver.class
)
@JsonIdentityReference(alwaysAsId = true)
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
private List<Plugin> plugins = new ArrayList<>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package de.terrestris.shogun2.model;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
Expand All @@ -11,6 +12,8 @@

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnore;

Expand All @@ -24,6 +27,8 @@
@Entity
@Table
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class File extends PersistentObject {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
*/
package de.terrestris.shogun2.model;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnore;

Expand All @@ -21,6 +24,8 @@
*/
@Entity
@Table
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class ImageFile extends File {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -20,6 +21,10 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.ReadableDateTime;
Expand All @@ -39,6 +44,8 @@
*
*/
@MappedSuperclass
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public abstract class PersistentObject implements Serializable {

/**
Expand Down Expand Up @@ -82,6 +89,8 @@ public abstract class PersistentObject implements Serializable {
name="USERPERMISSIONS",
joinColumns = @JoinColumn(name = "ENTITY_ID"))
@JsonIgnore
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
private Map<User, PermissionCollection> userPermissions = new HashMap<User, PermissionCollection>();

/**
Expand All @@ -92,6 +101,8 @@ public abstract class PersistentObject implements Serializable {
name="GROUPPERMISSIONS",
joinColumns = @JoinColumn(name = "ENTITY_ID"))
@JsonIgnore
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
private Map<UserGroup, PermissionCollection> groupPermissions = new HashMap<UserGroup, PermissionCollection>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Locale;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
Expand All @@ -11,6 +12,8 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;

Expand All @@ -21,6 +24,8 @@
@Entity
@Table
@Inheritance(strategy = InheritanceType.JOINED)
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Person extends PersistentObject {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
Expand All @@ -16,6 +17,10 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand All @@ -26,6 +31,8 @@
@Entity
@Table
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Plugin extends PersistentObject {

/**
Expand Down Expand Up @@ -61,6 +68,8 @@ public class Plugin extends PersistentObject {

/** A list of assigned {@link PluginUploadFile}s. */
@ManyToMany
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
@JoinTable(
joinColumns = { @JoinColumn(name = "PLUGIN_ID") },
inverseJoinColumns = { @JoinColumn(name = "FILE_ID") }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package de.terrestris.shogun2.model;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
* @author Nils Bühner
*
*/
@Entity
@Table
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Role extends PersistentObject {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.terrestris.shogun2.model;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
Expand All @@ -8,6 +9,8 @@

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.vividsolutions.jts.geom.MultiPolygon;

Expand All @@ -21,6 +24,8 @@
@Entity
@Table
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Territory extends PersistentObject {

/**
Expand Down
Loading

0 comments on commit 710e47a

Please sign in to comment.