List of usage examples for org.hibernate.event.spi PostUpdateEvent getState
public Object[] getState()
From source file:com.googlecode.hibernate.audit.listener.AuditListener.java
License:Open Source License
public void onPostUpdate(PostUpdateEvent event) { try {//from w w w. j a v a 2s .com 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:es.logongas.ix3.dao.impl.rules.EventListenerImplRuleEngine.java
License:Apache License
@Override public void onPostUpdate(PostUpdateEvent pue) { autowired();// ww w. j a va 2 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.PostUpdate.class, RuleGroupPredefined.PostInsertOrUpdate.class, RuleGroupPredefined.PostUpdateOrDelete.class, RuleGroupPredefined.PostInsertOrUpdateOrDelete.class); }
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 ww . j av a 2 s. c om * 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.granite.tide.hibernate4.HibernateDataChangePublishListener.java
License:Open Source License
public void onPostUpdate(PostUpdateEvent event) { if (DataPublishListener.handleExclude(event.getEntity())) return;// w w w.j av a2s . c o m if (event.getDirtyProperties() != null && event.getDirtyProperties().length > 0) { Object change = getChange(event.getPersister(), event.getSession(), event.getPersister().getEntityName(), event.getId(), event.getEntity()); if (change instanceof Change) { for (int i = 0; i < event.getDirtyProperties().length; i++) { int pidx = event.getDirtyProperties()[i]; String pname = event.getPersister().getPropertyNames()[pidx]; if (AnnotationUtils.isAnnotatedWith(event.getEntity(), pname, ExcludeFromDataPublish.class)) continue; ((Change) change).getChanges().put(pname, event.getState()[pidx]); } } else if (change == null) DataContext.addUpdate(EntityUpdateType.UPDATE, event.getEntity(), event.getEntity()); } }