Search in sources :

Example 1 with PrePersist

use of javax.persistence.PrePersist in project Protocol-Adapter-IEC61850 by OSGP.

the class Device method prePersist.

/**
     * Method for actions to be taken before inserting.
     */
@PrePersist
private void prePersist() {
    final Date now = new Date();
    this.creationTime = now;
    this.modificationTime = now;
}
Also used : Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Example 2 with PrePersist

use of javax.persistence.PrePersist in project wildfly by wildfly.

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 3 with PrePersist

use of javax.persistence.PrePersist in project deltaspike by apache.

the class AuditEntityListener method persist.

@PrePersist
public void persist(Object entity) {
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    Set<Bean<?>> beans = beanManager.getBeans(PrePersistAuditListener.class);
    for (Bean<?> bean : beans) {
        PrePersistAuditListener result = (PrePersistAuditListener) beanManager.getReference(bean, PrePersistAuditListener.class, beanManager.createCreationalContext(bean));
        result.prePersist(entity);
    }
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean) PrePersist(javax.persistence.PrePersist)

Example 4 with PrePersist

use of javax.persistence.PrePersist in project wildfly by wildfly.

the class MyListener method onEntityCallback.

@PrePersist
@PreUpdate
public void onEntityCallback(Object entity) {
    try {
        invocationCount++;
        InitialContext jndiContext = new InitialContext();
        EJBContext ctx = (EJBContext) jndiContext.lookup("java:comp/EJBContext");
    //System.out.println(ctx.getCallerPrincipal().getName() + ", entity=" + entity);
    } catch (NamingException e) {
        throw new RuntimeException("initial context error", e);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 5 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)

Aggregations

PrePersist (javax.persistence.PrePersist)7 Date (java.util.Date)5 PreUpdate (javax.persistence.PreUpdate)3 Timestamped (com.spaceprogram.simplejpa.model.Timestamped)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