Example usage for org.hibernate.event.spi PostUpdateEvent getEntity

List of usage examples for org.hibernate.event.spi PostUpdateEvent getEntity

Introduction

In this page you can find the example usage for org.hibernate.event.spi PostUpdateEvent getEntity.

Prototype

public Object getEntity() 

Source Link

Usage

From source file:at.molindo.esi4j.module.hibernate.HibernateEventListener.java

License:Apache License

@Override
public void onPostUpdate(PostUpdateEvent event) {
    EventSession eventSession = findEventSession(event.getSession());
    if (eventSession != null) {
        eventSession.onPostUpdate(event.getEntity());
    } else {//from  w w  w  .  j  a  va2  s.c o m
        _batchedEventProcessor.onPostUpdate(event.getEntity());
    }
}

From source file:com.corundumstudio.hibernate.dsc.QueryCacheEntityListener.java

License:Apache License

@Override
public void onPostUpdate(PostUpdateEvent event) {
    Set<Entry<String, QueryListenerEntry>> values = getValue(event.getPersister());
    for (Entry<String, QueryListenerEntry> entry : values) {
        UpdateCommand command = new UpdateCommand();
        CacheCallback handler = entry.getValue().getHandler();
        handler.commonParams(command, event.getEntity());
        handler.onUpdate(command, event.getEntity());

        DynamicQueryCache queryCache = getQueryCache(event.getPersister(), entry.getKey(), entry.getValue());
        if (command.isAddResult() || command.isUniqueResult()) {
            addResult(queryCache, entry.getValue(), command, event.getSession());
        }//from w  w  w .  j  av  a 2  s  .  co m
        if (command.isRemoveResult()) {
            removeResult(queryCache, entry.getValue(), command, event.getSession());
        }
    }
}

From source file:com.googlecode.hibernate.audit.listener.AuditListener.java

License:Open Source License

public void onPostUpdate(PostUpdateEvent event) {
    try {// w w  w.j  a  v  a 2 s  . c om
        String entityName = event.getPersister().getEntityName();

        if (auditConfiguration.getExtensionManager().getAuditableInformationProvider()
                .isAuditable(entityName)) {
            AuditProcess auditProcess = auditConfiguration.getAuditProcessManager().get(event.getSession());

            AuditWorkUnit workUnit = new UpdateAuditWorkUnit(entityName, event.getId(), event.getEntity(),
                    event.getPersister(), event.getOldState(), event.getState());
            auditProcess.addWorkUnit(workUnit);
        }
    } catch (RuntimeException e) {
        if (log.isErrorEnabled()) {
            log.error("RuntimeException occured during onPostUpdate, will re-throw the exception", e);
        }
        throw e;
    }
}

From source file:com.invariantproperties.sandbox.springentitylistener.listener.HibernateEntityListenersAdapter.java

License:Apache License

/**
 * @see org.hibernate.event.spi.PostUpdateEventListener#onPostUpdate(org.hibernate
 *      .event.spi.PostUpdateEvent)//from   ww  w. jav a2 s . c  om
 */
@Override
public void onPostUpdate(PostUpdateEvent event) {
    execute(postUpdate, event.getEntity());
}

From source file:debop4k.data.orm.hibernate.listener.PersistentObjectListener.java

License:Apache License

@Override
public void onPostUpdate(PostUpdateEvent event) {
    if (isPersistentObject(event.getEntity())) {
        ((PersistentObject) event.getEntity()).onSave();
    }//from  w ww . ja  v a2 s  .c  om
}

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

License:Apache License

@Override
public void onPostUpdate(PostUpdateEvent pue) {
    autowired();/*w w w. j  av  a  2s . co 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.PostUpdate.class,
            RuleGroupPredefined.PostInsertOrUpdate.class, RuleGroupPredefined.PostUpdateOrDelete.class,
            RuleGroupPredefined.PostInsertOrUpdateOrDelete.class);
}

From source file:org.audit4j.integration.hibernate.listener.AuditPostUpdateEventListenerImpl.java

License:Apache License

@Override
public void onPostUpdate(PostUpdateEvent event) {
    AuditManager.getInstance()/*from   w w w.java  2 s  .  c o  m*/
            .audit(new EventBuilder().addAction("update " + event.getEntity().getClass().toString())
                    .addField(event.getEntity().getClass().toString(), event.getEntity()).build());
}

From source file:org.cgiar.ccafs.marlo.data.HibernateAuditLogListener.java

License:Open Source License

@Override
public void onPostUpdate(PostUpdateEvent postUpdateEvent) {
    Object entity = postUpdateEvent.getEntity();

    LOG.debug("begin onPostUpdatefor Entity : " + entity);

    AuditLogContext auditLogContext = AuditLogContextProvider.getAuditLogContext();

    /**//from  w  w  w. ja  v  a2s. co  m
     * This is because our save(entity), update(entity) and delete(entity) methods on our DAOs should not
     * execute the listeners. There might be a better way to do this like conditionally activate the listeners.
     */
    if (auditLogContext.getActionName() == null
            && CollectionUtils.isEmpty(auditLogContext.getRelationsNames())) {
        LOG.debug("No audit log context setup for update on entity: " + entity);
        return;
    }

    /**
     * We might save many entities on a single request, but we only want to do the audit logging on one.
     */
    if (!entity.getClass().getCanonicalName().equals(auditLogContext.getEntityCanonicalName())) {
        LOG.debug("Entity : " + entity + " , is not the entity we want to audit log");
        return;
    }

    HashMap<String, Object> updateRecord = new HashMap<>();
    if (entity instanceof IAuditLog) {
        IAuditLog iAuditLog = (IAuditLog) entity;
        String name = iAuditLog.getClass().getName();
        Class<?> className = null;
        try {
            className = Class.forName(name);
        } catch (ClassNotFoundException e) {

        }
        Object obj = postUpdateEvent.getSession().get(className, iAuditLog.getId());

        ClassMetadata classMetadata = postUpdateEvent.getSession().getSessionFactory()
                .getClassMetadata(obj.getClass());
        Type[] types = classMetadata.getPropertyTypes();

        String[] propertyNamesRelation = classMetadata.getPropertyNames();
        Phase phaseObject = null;
        boolean hasPhase = false;
        for (String nameAtrribute : propertyNamesRelation) {
            if (nameAtrribute.equals("phase")) {
                try {
                    phaseObject = (Phase) classMetadata.getPropertyValue(entity, nameAtrribute);
                } catch (Exception e) {
                    // The attribute is not a Phase Model Class
                    phaseObject = null;
                }
                if (phaseObject != null) {
                    phaseObject = (Phase) postUpdateEvent.getSession().get(Phase.class, phaseObject.getId());
                    if (phaseObject != null) {
                        hasPhase = true;
                    }
                }
            }
        }
        /*
         * if have phase and the phase is the current we are checking , we load the info
         */
        if (hasPhase || entity instanceof Project || entity instanceof FundingSource
                || entity instanceof Deliverable || entity instanceof ProjectOutcome
                || entity instanceof CrpProgram || entity instanceof ProjectExpectedStudy
                || entity instanceof ProjectInnovation) {
            if (hasPhase && (entity instanceof Deliverable == false)) {
                if (AuditLogContextProvider.getAuditLogContext().getPhase().equals(phaseObject)) {
                    updateRecord.put(IAuditLog.ENTITY, entity);
                    updateRecord.put(IAuditLog.PRINCIPAL, new Long(1));
                    auditLogContext.getUpdates().add(updateRecord);

                    auditLogContext.getUpdates().addAll(this.relations(postUpdateEvent.getState(), types,
                            ((IAuditLog) entity).getId(), true, postUpdateEvent.getSession(), obj));
                    postUpdateEvent.getSession().getActionQueue()
                            .registerProcess(new MARLOAuditBeforeTransactionCompletionProcess());

                }
            } else {
                updateRecord.put(IAuditLog.ENTITY, entity);
                updateRecord.put(IAuditLog.PRINCIPAL, new Long(1));
                auditLogContext.getUpdates().add(updateRecord);

                auditLogContext.getUpdates().addAll(this.relations(postUpdateEvent.getState(), types,
                        ((IAuditLog) entity).getId(), true, postUpdateEvent.getSession(), entity));
                postUpdateEvent.getSession().getActionQueue()
                        .registerProcess(new MARLOAuditBeforeTransactionCompletionProcess());
            }

        }

        // LOG.debug("COMPARE LOGS WITH STAGING BRANCH: " + auditLogContext.getUpdates().toString());

    }
}

From source file:org.flowerplatform.web.security.sandbox.SecurityEntityListener.java

License:Open Source License

/**
 * When an ISecurityEntity or a PermissionEntity is updated or deleted, the
 * policy needs to properly clear its caches.
 * //from  w  w  w .  ja  va 2 s  .  c  om
 * @author Florin
 * @author Cristi
 * 
 */
@Override
public void onPostUpdate(PostUpdateEvent evt) {
    if (evt.getEntity() instanceof User) {
        final Entity entity = (Entity) evt.getEntity();
        // when user is deleted we do not clear it from the principal, because the can still be logged on

        CommunicationPlugin.getInstance().getCommunicationChannelManager()
                .iterateCommunicationChannels(new RunnableWithParam<Boolean, CommunicationChannel>() {

                    @Override
                    public Boolean run(CommunicationChannel param) {
                        if (param.getPrincipal() != null
                                && param.getPrincipal().getUserId() == entity.getId()) {
                            param.getPrincipal().clearCachedUser();
                        }
                        return null;
                    }

                });

    }

    entityUpdatedOrDeleted(evt.getEntity());
}

From source file:org.grails.orm.hibernate.event.listener.HibernateEventListener.java

License:Apache License

public void onPostUpdate(PostUpdateEvent event) {
    ClosureEventListener eventListener = findEventListener(event.getEntity(),
            event.getPersister().getFactory());
    if (eventListener != null) {
        eventListener.onPostUpdate(event);
    }/*from www.  java2s .c  o  m*/
}