Add new CacheableDSpaceObject abstract class for Hibernate second-level caching. Required in Hibernate 6 as subclasses cannot use @Cache annotation

This commit is contained in:
Tim Donohue
2024-03-26 15:01:06 -05:00
parent 0ff9fa0f49
commit befef7f7b1
7 changed files with 27 additions and 11 deletions

View File

@@ -0,0 +1,20 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content;
import jakarta.persistence.Cacheable;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* Abstract class for DSpaceObjects which are safe to cache in Hibernate's second level cache.
* See hibernate-ehcache-config.xml for caching configurations for each DSpaceObject which extends this class.
*/
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "non-lazy")
public abstract class CacheableDSpaceObject extends DSpaceObject {
}

View File

@@ -52,7 +52,7 @@ import org.dspace.eperson.Group;
*/ */
@Entity @Entity
@Table(name = "collection") @Table(name = "collection")
public class Collection extends DSpaceObject implements DSpaceObjectLegacySupport { public class Collection extends CacheableDSpaceObject implements DSpaceObjectLegacySupport {
@Column(name = "collection_id", insertable = false, updatable = false) @Column(name = "collection_id", insertable = false, updatable = false)
private Integer legacyId; private Integer legacyId;

View File

@@ -45,7 +45,7 @@ import org.dspace.eperson.Group;
*/ */
@Entity @Entity
@Table(name = "community") @Table(name = "community")
public class Community extends DSpaceObject implements DSpaceObjectLegacySupport { public class Community extends CacheableDSpaceObject implements DSpaceObjectLegacySupport {
@Column(name = "community_id", insertable = false, updatable = false) @Column(name = "community_id", insertable = false, updatable = false)
private Integer legacyId; private Integer legacyId;

View File

@@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@@ -29,7 +28,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.dspace.authorize.ResourcePolicy; import org.dspace.authorize.ResourcePolicy;
import org.dspace.core.ReloadableEntity; import org.dspace.core.ReloadableEntity;
import org.dspace.handle.Handle; import org.dspace.handle.Handle;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
/** /**
@@ -38,8 +36,6 @@ import org.hibernate.annotations.GenericGenerator;
@Entity @Entity
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "dspaceobject") @Table(name = "dspaceobject")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, includeLazy = false)
public abstract class DSpaceObject implements Serializable, ReloadableEntity<java.util.UUID> { public abstract class DSpaceObject implements Serializable, ReloadableEntity<java.util.UUID> {
@Id @Id
@GeneratedValue(generator = "predefined-uuid") @GeneratedValue(generator = "predefined-uuid")

View File

@@ -23,7 +23,7 @@ import org.dspace.services.factory.DSpaceServicesFactory;
*/ */
@Entity @Entity
@Table(name = "site") @Table(name = "site")
public class Site extends DSpaceObject { public class Site extends CacheableDSpaceObject {
@Transient @Transient
private transient SiteService siteService; private transient SiteService siteService;

View File

@@ -22,7 +22,7 @@ import jakarta.persistence.TemporalType;
import jakarta.persistence.Transient; import jakarta.persistence.Transient;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dspace.content.DSpaceObject; import org.dspace.content.CacheableDSpaceObject;
import org.dspace.content.DSpaceObjectLegacySupport; import org.dspace.content.DSpaceObjectLegacySupport;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.Constants; import org.dspace.core.Constants;
@@ -38,7 +38,7 @@ import org.dspace.eperson.service.EPersonService;
*/ */
@Entity @Entity
@Table(name = "eperson") @Table(name = "eperson")
public class EPerson extends DSpaceObject implements DSpaceObjectLegacySupport { public class EPerson extends CacheableDSpaceObject implements DSpaceObjectLegacySupport {
@Column(name = "eperson_id", insertable = false, updatable = false) @Column(name = "eperson_id", insertable = false, updatable = false)
private Integer legacyId; private Integer legacyId;

View File

@@ -20,7 +20,7 @@ import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.persistence.Transient; import jakarta.persistence.Transient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dspace.content.DSpaceObject; import org.dspace.content.CacheableDSpaceObject;
import org.dspace.content.DSpaceObjectLegacySupport; import org.dspace.content.DSpaceObjectLegacySupport;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
@@ -33,7 +33,7 @@ import org.dspace.core.HibernateProxyHelper;
*/ */
@Entity @Entity
@Table(name = "epersongroup") @Table(name = "epersongroup")
public class Group extends DSpaceObject implements DSpaceObjectLegacySupport { public class Group extends CacheableDSpaceObject implements DSpaceObjectLegacySupport {
@Transient @Transient
public static final String ANONYMOUS = "Anonymous"; public static final String ANONYMOUS = "Anonymous";