Example usage for org.hibernate.event.spi PreUpdateEvent getOldState

List of usage examples for org.hibernate.event.spi PreUpdateEvent getOldState

Introduction

In this page you can find the example usage for org.hibernate.event.spi PreUpdateEvent getOldState.

Prototype

public Object[] getOldState() 

Source Link

Document

The old state of the entity at the time it was last loaded from the database; can be null in the case of detached entities.

Usage

From source file:de.dktk.dd.rpb.portal.audit.AuditLogListener.java

License:Open Source License

private String buildUpdateMessage(PreUpdateEvent event) {
    String[] propertyNames = event.getPersister().getEntityMetamodel().getPropertyNames();
    Object[] oldStates = event.getOldState();
    Object[] newStates = event.getState();
    int index = 0;
    StringBuilder message = new StringBuilder(128);
    for (String propertyName : propertyNames) {
        message.append(message(propertyName, oldStates[index], newStates[index]));
        index++;//  www.j a  v  a2s . c  om
    }
    return message.toString();
}

From source file:es.logongas.ix3.dao.impl.rules.EventListenerImplRuleEngine.java

License:Apache License

@Override
public boolean onPreUpdate(PreUpdateEvent pue) {
    autowired();//from w ww  .j a v a2 s. c o m
    EntityMode entityMode = pue.getPersister().getEntityMode();

    RuleContext ruleContext = new RuleContextImplNoPrincipal(pue.getEntity(),
            getOriginalEntity(pue.getOldState(), pue.getPersister()));

    fireRules(ruleContext, pue.getPersister(), pue.getState(), entityMode, RuleGroupPredefined.PreUpdate.class,
            RuleGroupPredefined.PreInsertOrUpdate.class, RuleGroupPredefined.PreUpdateOrDelete.class,
            RuleGroupPredefined.PreInsertOrUpdateOrDelete.class);

    return false;
}

From source file:org.meruvian.yama.service.jpa.hibernate.LogInformationListener.java

License:Apache License

@Override
public boolean onPreUpdate(PreUpdateEvent event) {
    String userId = getCurrentUserId();

    if (event.getEntity() instanceof DefaultPersistence) {
        DefaultPersistence p = (DefaultPersistence) event.getEntity();
        LogInformation logInfo = p.getLogInformation();

        Object[] oldState = event.getOldState();

        for (int i = 0; i < oldState.length; i++) {
            if (oldState[i] instanceof LogInformation) {
                LogInformation oldLogInfo = (LogInformation) oldState[i];

                logInfo.setCreateDate(oldLogInfo.getCreateDate());
                logInfo.setLastUpdateDate(new Date());
                logInfo.setCreateBy(oldLogInfo.getCreateBy());
                logInfo.setLastUpdateBy(userId);
                logInfo.setActiveFlag(oldLogInfo.getActiveFlag());

                break;
            }/*  ww  w  .  j a  va 2 s  .  c  o  m*/
        }
    }

    return false;
}