Skip to content

Commit

Permalink
Merge pull request #43 from axonivy-market/feature/APS-158
Browse files Browse the repository at this point in the history
Feature/aps 158
  • Loading branch information
juergen-plohn authored Aug 25, 2023
2 parents 54e60bd + 2a67280 commit 47e4c62
Show file tree
Hide file tree
Showing 24 changed files with 327 additions and 53 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
16 changes: 12 additions & 4 deletions persistence-utils-product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ Axon Ivy's JPA Persistence Lib utility helps you accelerate process automation i
- [APS-156](https://1ivy.atlassian.net/browse/APS-156) Fix handling of session in CriteriaQueryContext
- [APS-86](https://1ivy.atlassian.net/browse/APS-86) Use Instant for Auditable Entities create/update/delete
- [APS-87](https://1ivy.atlassian.net/browse/APS-87) Rename isEnabled in ToggleableEntity
- [APS-158](https://1ivy.atlassian.net/browse/APS-158) Refactor Type hirachy for Auditable- and ToggleableEntity

*Incompatibilities*
- Datatype of **AuditableEntity**s **Header** attributes for create/update and delete date where changed to *Instant*
- Attribute **expiryDate** of **ToggleableEntity** has been renamed to **expiry** and its datatype changed to *Instant*
- Attribute **ToggleableEntity**s **isEnabled** has been renamed to **enabled** and its datatype changed to *boolean*

:exclamation::exclamation: **NOTE: This update contains major changes to column names and datatypes as well as refactoring of entity and DAO structure.**
**Please refer to the list of changes mentioned here and in the recommendations** :exclamation::exclamation:

- Datatype of `AuditableEntity`s `Header` attributes for create/update and delete date where changed to `Instant`
- Attribute `expiryDate` of `ToggleableEntity` has been renamed to **expiry** and its datatype changed to `Instant`
- Attribute `ToggleableEntity`s **isEnabled** has been renamed to **enabled** and its datatype changed to `boolean`
- `AuditableEntity` and `ToggleableEntity` are now derived from `VersionableEntity` instead of `GenericIdEntity`
- To provide a version of the changed Entities with a predefined `String` id the new Entities `AuditableIdEntity` and `ToggleableIdEntity` and matching DAOs have been introduced

*Recommendations*
- rename the expiry column to **expiry** unless you have customized the column names anyways. e.g. ALTER TABLE **yourtable** RENAME COLUMN **expiryDate** TO **expiry**.
- rename the isEnabled column to **enabled** unless you have customized the column names anyways. e.g. ALTER TABLE **yourtable** RENAME COLUMN **isEnabled** TO **enabled**.
- Make sure there are no *NULL* values for the **enabled** column in your database. The column was defined as not nullable, so only manual changes in the database should have lead to *NULL* values
- use *get/set...AsDate* or *get/set...AsLocalDateTime* methods to get converted datatypes of create/update/delete/expiry *Instant*s
- use `get/set...AsDate` or `get/set...AsLocalDateTime` methods if you need to get converted datatypes of create/modify/delete/expiry `Instant`s
- Change usage of `AuditableEntity` and `ToggleableEntity` to `AuditableIdEntity` and `ToggleableIdEntity`. Use matching DAOs

### 10.0.3
*Changes*
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
Loading

0 comments on commit 47e4c62

Please sign in to comment.