Search in sources :

Example 6 with PrePersist

use of javax.persistence.PrePersist in project simplejpa by appoxy.

the class SomeEntityListener method prePersist.

@PrePersist
public void prePersist(Object object) {
    System.out.println("prePersist");
    if (object instanceof Timestamped) {
        System.out.println("Setting timestamps.");
        Timestamped timestamped = (Timestamped) object;
        Date now = new Date();
        timestamped.setCreated(now);
        timestamped.setUpdated(now);
    }
}
Also used : Timestamped(com.spaceprogram.simplejpa.model.Timestamped) Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Example 7 with PrePersist

use of javax.persistence.PrePersist in project simplejpa by appoxy.

the class TimestampEntityListener method prePersist.

@PrePersist
public void prePersist(Object object) {
    if (object instanceof Timestamped) {
        Timestamped timestamped = (Timestamped) object;
        Date now = new Date();
        timestamped.setCreated(now);
        timestamped.setUpdated(now);
    }
}
Also used : Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Example 8 with PrePersist

use of javax.persistence.PrePersist in project hibernate-orm by hibernate.

the class LastUpdateListener method setLastUpdate.

@PreUpdate
@PrePersist
public void setLastUpdate(Cat o) {
    o.setLastUpdate(new Date());
    o.setManualVersion(o.getManualVersion() + 1);
}
Also used : Date(java.util.Date) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 9 with PrePersist

use of javax.persistence.PrePersist in project CzechIdMng by bcvsolutions.

the class AuditableEntityListener method touchForCreate.

/**
 * Sets creation date and creator on the target object in case it implements {@link Auditable} on
 * persist events.
 *
 * @param target
 */
@PrePersist
public void touchForCreate(Object target) {
    if (target instanceof Auditable) {
        AutowireHelper.autowire(this, this.securityService);
        // 
        DateTime date = new DateTime();
        Auditable entity = (Auditable) target;
        // 
        if (entity.getCreated() == null) {
            entity.setCreated(date);
        }
        // 
        AbstractAuthentication authentication = securityService.getAuthentication();
        IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
        IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
        if (entity.getCreator() == null) {
            String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
            entity.setCreator(creator);
            // 
            UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
            entity.setCreatorId(creatorId);
        }
        // could be filled in wf (applicant) ...
        if (entity.getOriginalCreator() == null) {
            String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
            entity.setOriginalCreator(originalCreator);
            // 
            UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
            entity.setOriginalCreatorId(originalCreatorId);
        }
    }
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) PrePersist(javax.persistence.PrePersist)

Example 10 with PrePersist

use of javax.persistence.PrePersist in project plumdo-work by wengwh.

the class BaseEntity method prePersist.

@PrePersist
public void prePersist() {
    this.createTime = new Timestamp(new Date().getTime());
    this.lastUpdateTime = this.createTime;
}
Also used : Timestamp(java.sql.Timestamp) Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Aggregations

PrePersist (javax.persistence.PrePersist)10 Date (java.util.Date)7 PreUpdate (javax.persistence.PreUpdate)3 Timestamp (java.sql.Timestamp)2 Timestamped (com.spaceprogram.simplejpa.model.Timestamped)1 Auditable (eu.bcvsolutions.idm.core.api.domain.Auditable)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 AbstractAuthentication (eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication)1 UUID (java.util.UUID)1 EJBContext (javax.ejb.EJBContext)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 DateTime (org.joda.time.DateTime)1