Skip to content

Commit

Permalink
draft implementation of APS-158
Browse files Browse the repository at this point in the history
  • Loading branch information
juergen-plohn committed Aug 25, 2023
1 parent a4c7f46 commit 4701684
Show file tree
Hide file tree
Showing 23 changed files with 315 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.axonivy.utils.persistence.daos;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.entities.Car;
import com.axonivy.utils.persistence.entities.Car_;


public class CarDAO extends AuditableDAO<Car_, Car> implements BaseDAO {
public class CarDAO extends AuditableIdDAO<Car_, Car> implements BaseDAO {
private static final CarDAO instance = new CarDAO();


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.axonivy.utils.persistence.daos;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.entities.HistorizedPerson;
import com.axonivy.utils.persistence.entities.HistorizedPerson_;


public class HistorizedPersonDAO extends AuditableDAO<HistorizedPerson_, HistorizedPerson> implements BaseDAO {
public class HistorizedPersonDAO extends AuditableIdDAO<HistorizedPerson_, HistorizedPerson> implements BaseDAO {

private static final HistorizedPersonDAO instance = new HistorizedPersonDAO();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.axonivy.utils.persistence.daos;

import com.axonivy.utils.persistence.dao.ToggleableDAO;
import com.axonivy.utils.persistence.demo.daos.BaseDAO;
import com.axonivy.utils.persistence.dao.ToggleableIdDAO;
import com.axonivy.utils.persistence.entities.Option;
import com.axonivy.utils.persistence.entities.Option_;

public class OptionDAO extends ToggleableDAO<Option_, Option> implements BaseDAO {
public class OptionDAO extends ToggleableIdDAO<Option_, Option> implements BaseDAO {

private static final OptionDAO INSTANCE = new OptionDAO();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.axonivy.utils.persistence.daos;

import com.axonivy.utils.persistence.dao.ToggleableDAO;
import com.axonivy.utils.persistence.dao.ToggleableIdDAO;
import com.axonivy.utils.persistence.entities.Producer;
import com.axonivy.utils.persistence.entities.Producer_;

public class ProducerDAO extends ToggleableDAO<Producer_, Producer> implements BaseDAO {
public class ProducerDAO extends ToggleableIdDAO<Producer_, Producer> implements BaseDAO {

@Override
protected Class<Producer> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javax.persistence.criteria.Expression;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.dao.CriteriaQueryGenericContext;
import com.axonivy.utils.persistence.dao.ExpressionMap;
import com.axonivy.utils.persistence.entities.Product;
Expand All @@ -12,7 +12,7 @@
import com.axonivy.utils.persistence.search.FilterPredicate;


public class ProductDAO extends AuditableDAO<Product_, Product> implements BaseDAO {
public class ProductDAO extends AuditableIdDAO<Product_, Product> implements BaseDAO {

@Override
protected Class<Product> getType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.axonivy.utils.persistence.daos;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.entities.Vehicle;
import com.axonivy.utils.persistence.entities.Vehicle_;


public class VehicleDAO extends AuditableDAO<Vehicle_, Vehicle> implements BaseDAO {
public class VehicleDAO extends AuditableIdDAO<Vehicle_, Vehicle> implements BaseDAO {
private static final VehicleDAO instance = new VehicleDAO();

private VehicleDAO() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import javax.persistence.Entity;

import com.axonivy.utils.persistence.annotations.Audit;
import com.axonivy.utils.persistence.beans.AuditableEntity;
import com.axonivy.utils.persistence.beans.AuditableIdEntity;
import com.axonivy.utils.persistence.daos.AuditHandler;

@Entity
@Audit(handler = AuditHandler.class)
public class HistorizedPerson extends AuditableEntity {
public class HistorizedPerson extends AuditableIdEntity {

/**
* auto generated id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import javax.persistence.Entity;

import com.axonivy.utils.persistence.beans.ToggleableEntity;
import com.axonivy.utils.persistence.beans.ToggleableIdEntity;

@Entity
public class Option extends ToggleableEntity {
public class Option extends ToggleableIdEntity {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.axonivy.utils.persistence.beans.ToggleableEntity;
import com.axonivy.utils.persistence.beans.ToggleableIdEntity;

@Entity
@Table(name = "producer")
public class Producer extends ToggleableEntity {
public class Producer extends ToggleableIdEntity {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.axonivy.utils.persistence.beans.AuditableEntity;
import com.axonivy.utils.persistence.beans.AuditableIdEntity;

@Entity
@Table(name = "product")
public class Product extends AuditableEntity {
public class Product extends AuditableIdEntity {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import javax.persistence.Column;
import javax.persistence.Entity;

import com.axonivy.utils.persistence.beans.AuditableEntity;
import com.axonivy.utils.persistence.beans.AuditableIdEntity;

@Entity
public class Vehicle extends AuditableEntity {
public class Vehicle extends AuditableIdEntity {
private static final long serialVersionUID = 1L;

@Column(length = 64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import javax.persistence.criteria.Expression;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.dao.CriteriaQueryContext;
import com.axonivy.utils.persistence.dao.QuerySettings;
import com.axonivy.utils.persistence.demo.entities.Department;
import com.axonivy.utils.persistence.demo.entities.Department_;


public class DepartmentDAO extends AuditableDAO<Department_, Department> implements BaseDAO {
public class DepartmentDAO extends AuditableIdDAO<Department_, Department> implements BaseDAO {
private static final DepartmentDAO instance = new DepartmentDAO();

private DepartmentDAO() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery;

import com.axonivy.utils.persistence.dao.AuditableDAO;
import com.axonivy.utils.persistence.dao.AuditableIdDAO;
import com.axonivy.utils.persistence.dao.CriteriaQueryContext;
import com.axonivy.utils.persistence.dao.CriteriaQueryGenericContext;
import com.axonivy.utils.persistence.dao.ExpressionMap;
Expand All @@ -34,7 +34,7 @@
import com.axonivy.utils.persistence.service.DateService;


public class PersonDAO extends AuditableDAO<Person_, Person> implements BaseDAO {
public class PersonDAO extends AuditableIdDAO<Person_, Person> implements BaseDAO {
private static final Logger LOG = Logger.getLogger(PersonDAO.class);
private static final PersonDAO instance = new PersonDAO();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.axonivy.utils.persistence.beans.AuditableEntity;
import com.axonivy.utils.persistence.beans.AuditableIdEntity;
import com.axonivy.utils.persistence.validation.IvyNotBlank;
import com.axonivy.utils.persistence.validation.IvySizeMax;
import com.axonivy.utils.persistence.validation.groups.SaveErrorGroup;


@Entity
@Table(uniqueConstraints = @UniqueConstraint(name = "UC_Department_name", columnNames = {"name"}))
public class Department extends AuditableEntity {
public class Department extends AuditableIdEntity {
private static final long serialVersionUID = 1L;

@Column(length = 64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.axonivy.utils.persistence.beans.AuditableEntity;
import com.axonivy.utils.persistence.beans.AuditableIdEntity;
import com.axonivy.utils.persistence.demo.enums.MaritalStatus;
import com.axonivy.utils.persistence.demo.validation.ValidIvyUserName;
import com.axonivy.utils.persistence.demo.validation.ValidUniqueIvyUserName;
Expand All @@ -28,7 +28,7 @@
@Table(uniqueConstraints = @UniqueConstraint(name = "UC_Person_ivyUserName", columnNames = {"ivyUserName"}))
@ValidIvyUserName(groups = {SaveWarnGroup.class})
@ValidUniqueIvyUserName(groups = {SaveErrorGroup.class})
public class Person extends AuditableEntity {
public class Person extends AuditableIdEntity {
private static final long serialVersionUID = 1L;

@Column(length = 32)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.axonivy.utils.persistence.beans;

import java.io.Serializable;
import java.time.Instant;
import java.util.Comparator;

Expand All @@ -17,7 +18,7 @@
*
*/
@MappedSuperclass
public abstract class AuditableEntity extends GenericIdEntity {
public abstract class AuditableEntity<ID extends Serializable> extends VersionableEntity<ID> {

private static final long serialVersionUID = 758520274735110178L;

Expand Down Expand Up @@ -120,7 +121,7 @@ public void setAuditingDisabled(boolean auditingDisabled) {
/**
* @return Comparator comparing only according to createdDate field
*/
public static Comparator<AuditableEntity> createCreatedOnComparator() {
public static <ID extends Serializable> Comparator<AuditableEntity<ID>> createCreatedOnComparator() {
return (entity1, entity2) -> {
Instant createdOn1 = entity1.getHeader() != null ? entity1.getHeader().getCreatedDate() : null;
Instant createdOn2 = entity2.getHeader() != null ? entity2.getHeader().getCreatedDate() : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.axonivy.utils.persistence.beans;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;

import ch.ivyteam.ivy.environment.Ivy;

/**
* Auditable entity class which allows header manipulation
*
*/
@MappedSuperclass
public abstract class AuditableIdEntity extends AuditableEntity<String> {

private static final long serialVersionUID = 8298601078993069192L;

@Id
@Column(length = 32, nullable = false)
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Access(AccessType.PROPERTY)
protected String id;

/* (non-Javadoc)
* @see com.axonivy.persistence.beans.GenericEntity#getId()
*/
@Override
public String getId() {
return id;
}

/* (non-Javadoc)
* @see com.axonivy.persistence.beans.GenericEntity#setId(java.io.Serializable)
*/
@Override
public void setId(String id) {
this.id = id;
}

/**
* Get Ivy.session().getSessionUserName() as default session username, or override it later.
*/
@Override
public String getSessionUsername() {
return Ivy.session().getSessionUserName();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.axonivy.utils.persistence.beans;

import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
Expand All @@ -14,7 +15,7 @@
*
*/
@MappedSuperclass
public abstract class ToggleableEntity extends AuditableEntity {
public abstract class ToggleableEntity<ID extends Serializable> extends AuditableEntity<ID> {

private static final long serialVersionUID = 5872211233738039349L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.axonivy.utils.persistence.beans;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;

import ch.ivyteam.ivy.environment.Ivy;

/**
* Base for all entities which can be enabled and disabled.
*
*/
@MappedSuperclass
public abstract class ToggleableIdEntity extends ToggleableEntity<String> {

private static final long serialVersionUID = -8780884685375253549L;

@Id
@Column(length = 32, nullable = false)
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Access(AccessType.PROPERTY)
protected String id;

/* (non-Javadoc)
* @see com.axonivy.persistence.beans.GenericEntity#getId()
*/
@Override
public String getId() {
return id;
}

/* (non-Javadoc)
* @see com.axonivy.persistence.beans.GenericEntity#setId(java.io.Serializable)
*/
@Override
public void setId(String id) {
this.id = id;
}

/**
* Get Ivy.session().getSessionUserName() as default session username, or override it later.
*/
@Override
public String getSessionUsername() {
return Ivy.session().getSessionUserName();
}

}
Loading

0 comments on commit 4701684

Please sign in to comment.