Class SilverpeasJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- java.lang.Object
-
- org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<E,I>
-
- org.silverpeas.core.persistence.datasource.model.jpa.SilverpeasJpaEntity<E,I>
-
- Type Parameters:
E
- the class name of the represented entity.I
- the unique identifier class used by the entity to identify it uniquely in the persistence context.
- All Implemented Interfaces:
Serializable
,Entity<E,I>
,IdentifiableEntity
- Direct Known Subclasses:
Attendee
,Calendar
,CalendarComponent
,PersistentResourceDateReminder
,ReplacementImpl
,Variable
,VariableScheduledValue
@MappedSuperclass public abstract class SilverpeasJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier> extends AbstractJpaEntity<E,I> implements Entity<E,I>
This abstract class must be extended by all Silverpeas JPA entities that satisfy all the rules of the Silverpeas Persistence API. All the creation and update related data are managed by this class.Please be careful into the child entity classes about the use of @PrePersist and @PreUpdate annotations. In most of cases you don't need to use them, but to override
performBeforePersist()
orperformBeforeUpdate()
methods without forgetting to invoke the super call.- Author:
- Yohann Chastagnier
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SilverpeasJpaEntity()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
createdBy(String creatorId)
Sets the identifier of the user that has persisted this entity the first time.E
createdBy(User creator)
Sets explicitly the user who has created the entity (in the persistence context).E
createdBy(User creator, Date creationDate)
sets the user who has created the entity (in the persistence environment) with the date of the creation.boolean
equals(Object obj)
Date
getCreationDate()
Gets the date at which this entity has been persisted into the data store the first time.User
getCreator()
Gets the user which has created the entity (in the persistence environment).String
getCreatorId()
Gets the identifier of the user that has persisted this entity the first time.Date
getLastUpdateDate()
Gets the last date and time of the entity update (in the persistence context).User
getLastUpdater()
Gets the last user which has updated the entity (in the persistence context).String
getLastUpdaterId()
Gets the identifier of the user that has updated this entity the last time.Long
getVersion()
Gets the version of this entity.boolean
hasBeenModified()
Indicates if the entity has been modified at least one time.int
hashCode()
E
lastUpdatedBy(String lastUpdaterId)
Sets the identifier of the user that has updated this entity the last time.void
markAsModified()
By default, if no functional data is changed, last update date, last updated by and version technical data are not automatically updated on entity save operation.protected void
performBeforePersist()
Performs some treatments before this entity is persisted into a repository.protected void
performBeforeRemove()
Performs some treatments before this entity is removed from a repository.protected void
performBeforeUpdate()
Performs some treatments before its counterpart in a repository is updated with the changes in this entity.protected SilverpeasJpaEntity<E,I>
setCreationDate(Date creationDate)
Sets the date at which this entity has been persisted the first time.protected SilverpeasJpaEntity<E,I>
setCreator(User creator)
Sets the user that has created this entity.protected SilverpeasJpaEntity<E,I>
setLastUpdateDate(Date lastUpdateDate)
Sets the date at which this entity has been updated the last time.protected SilverpeasJpaEntity<E,I>
setLastUpdater(User updater)
Sets the user that has updated this entity the last time.protected E
setVersion(Long version)
Sets the version of this entity in the data source.E
updatedBy(User updater)
Sets explicitly the last user who has updated the entity (in the persistence context).E
updatedBy(User updater, Date updateDate)
sets the user who has updated the entity (in the persistence context) with the date of the update.-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity
getId, getNativeId, isPersisted, setId
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.persistence.datasource.model.IdentifiableEntity
getId, isPersisted
-
-
-
-
Method Detail
-
hasBeenModified
public boolean hasBeenModified()
Description copied from interface:Entity
Indicates if the entity has been modified at least one time.- Specified by:
hasBeenModified
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- true if this entity was modified since its first fetching from the database. False otherwise.
-
getCreator
public final User getCreator()
Description copied from interface:Entity
Gets the user which has created the entity (in the persistence environment). (if "created by" is a known user id)- Specified by:
getCreator
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the creator.
-
createdBy
public E createdBy(User creator)
Description copied from interface:Entity
Sets explicitly the user who has created the entity (in the persistence context). The creation date will be set at now.The Silverpeas persistence system sets automatically the creator from the operation context in the current thread and it sets automatically the creation date at the date the entity is persisted. By using this method, you overrides this behaviour.
-
createdBy
public E createdBy(User creator, Date creationDate)
Description copied from interface:Entity
sets the user who has created the entity (in the persistence environment) with the date of the creation.The Silverpeas persistence system sets automatically the creator from the operation context in the current thread and it sets automatically the creation date at the date the entity is persisted. By using this method, you overrides this behaviour.
-
getLastUpdater
public final User getLastUpdater()
Description copied from interface:Entity
Gets the last user which has updated the entity (in the persistence context). If the entity hasn't yet been updated since its inception, then the creator is considered the last user that touched the entity and hence it is returned.- Specified by:
getLastUpdater
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the last updater.
-
updatedBy
public E updatedBy(User updater)
Description copied from interface:Entity
Sets explicitly the last user who has updated the entity (in the persistence context). The last update date will be set at now.The Silverpeas persistence system sets automatically the updater from the operation context in the current thread and it sets automatically the update date at the date the entity is updated in the persistence context. By using this method, you overrides this behaviour.
-
updatedBy
public E updatedBy(User updater, Date updateDate)
Description copied from interface:Entity
sets the user who has updated the entity (in the persistence context) with the date of the update.The Silverpeas persistence system sets automatically the updater from the operation context in the current thread and it sets automatically the update date at the date the entity is updated in the persistence cotnext. By using this method, you overrides this behaviour.
-
getCreatorId
public String getCreatorId()
Gets the identifier of the user that has persisted this entity the first time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Specified by:
getCreatorId
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the unique identifier of the creator.
-
createdBy
public E createdBy(String creatorId)
Sets the identifier of the user that has persisted this entity the first time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
creatorId
- the unique identifier of the user that has created this entity.- Returns:
- the entity itself.
-
getCreationDate
public Date getCreationDate()
Gets the date at which this entity has been persisted into the data store the first time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Specified by:
getCreationDate
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the entity's creation date.
-
setCreationDate
protected SilverpeasJpaEntity<E,I> setCreationDate(Date creationDate)
Sets the date at which this entity has been persisted the first time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
creationDate
- the creation date- Returns:
- the entity itself.
-
setCreator
protected SilverpeasJpaEntity<E,I> setCreator(User creator)
Sets the user that has created this entity.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
creator
- the user that has created this entity.- Returns:
- the entity itself.
-
getLastUpdateDate
public Date getLastUpdateDate()
Description copied from interface:Entity
Gets the last date and time of the entity update (in the persistence context). If the entity wasn't yet updated since its inception, then the creation date is returned.- Specified by:
getLastUpdateDate
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the last date at which this entity was updated.
-
setLastUpdateDate
protected SilverpeasJpaEntity<E,I> setLastUpdateDate(Date lastUpdateDate)
Sets the date at which this entity has been updated the last time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
lastUpdateDate
- the date of the last update.- Returns:
- the entity itself.
-
setLastUpdater
protected SilverpeasJpaEntity<E,I> setLastUpdater(User updater)
Sets the user that has updated this entity the last time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
updater
- the user that has updated this entity.- Returns:
- the entity itself.
-
getLastUpdaterId
public String getLastUpdaterId()
Gets the identifier of the user that has updated this entity the last time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Specified by:
getLastUpdaterId
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the unique identifier of the user that has updated lastly this entity.
-
lastUpdatedBy
public E lastUpdatedBy(String lastUpdaterId)
Sets the identifier of the user that has updated this entity the last time.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
lastUpdaterId
- the unique identifier of the user that has updated this entity.- Returns:
- the entity itself.
-
getVersion
public Long getVersion()
Gets the version of this entity. To be used for optimistic locking in update.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Specified by:
getVersion
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
- Returns:
- the entity version.
-
setVersion
protected E setVersion(Long version)
Sets the version of this entity in the data source.Don't override this method. It cannot be final to be proxied by the JPA implementation in lazy loadings.
- Parameters:
version
- the version of the entity.- Returns:
- the entity itself.
-
markAsModified
public final void markAsModified()
Description copied from interface:Entity
By default, if no functional data is changed, last update date, last updated by and version technical data are not automatically updated on entity save operation. But in some cases, it could be useful that this three above technical data are updated, even if functional data are not changed. So, calling this method ensures that last update date, last updated by and version will be updated.- Specified by:
markAsModified
in interfaceEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classAbstractJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
performBeforePersist
protected void performBeforePersist()
Description copied from class:AbstractJpaEntity
Performs some treatments before this entity is persisted into a repository.- Specified by:
performBeforePersist
in classAbstractJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
performBeforeUpdate
protected void performBeforeUpdate()
Description copied from class:AbstractJpaEntity
Performs some treatments before its counterpart in a repository is updated with the changes in this entity.- Specified by:
performBeforeUpdate
in classAbstractJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
performBeforeRemove
protected void performBeforeRemove()
Description copied from class:AbstractJpaEntity
Performs some treatments before this entity is removed from a repository.- Specified by:
performBeforeRemove
in classAbstractJpaEntity<E extends Entity<E,I>,I extends EntityIdentifier>
-
-