private boolean preUpdate() { PreUpdateEventListener[] preListeners = getSession().getListeners() .getPreUpdateEventListeners(); boolean veto = false; if (preListeners.length>0) { PreUpdateEvent preEvent = new PreUpdateEvent( getInstance(), getId(), state, previousState, getPersister(), getSession() ); for ( int i = 0; i < preListeners.length; i++ ) { veto = preListeners[i].onPreUpdate(preEvent) || veto; } } return veto; }
public boolean onPreUpdate(PreUpdateEvent event) { EJBMethodPermission updatePermission = new EJBMethodPermission( event.getPersister().getEntityName(), HibernatePermission.UPDATE, null, null ); JACCPermissions.checkPermission( event.getEntity().getClass(), contextID, updatePermission ); return false; }
protected boolean preUpdate(PreUpdateEvent event) { Struct oldData=CommonUtil.createStruct(); Property[] properties = HibernateUtil.getProperties(component,HibernateUtil.FIELDTYPE_COLUMN,null); Object[] data = event.getOldState(); if(data!=null && properties!=null && data.length==properties.length) { for(int i=0;i<data.length;i++){ oldData.setEL(CommonUtil.createKey(properties[i].getName()), data[i]); } } invoke(CommonUtil.PRE_UPDATE, event.getEntity(),oldData); return false; }
@Override public boolean onPreUpdate(PreUpdateEvent event) { if (event.getEntity() instanceof AuditedBaseEntity) { AuditedBaseEntity e = (AuditedBaseEntity) event.getEntity(); e.setChangeUser(serviceContext.getUserName()); setValue(event.getState(), event.getPersister().getEntityMetamodel().getPropertyNames(), "changeUser", e.getChangeUser()); } return false; }
public boolean onPreUpdate(PreUpdateEvent event) { return preUpdate(event); }
@SuppressWarnings("resource") @Override public boolean onPreUpdate(final PreUpdateEvent event) { if (log.isDebugEnabled()) { log.debug("Received pre-update event"); } final EntityPersister entityPersister = event.getPersister(); final EntityMode entityMode = entityPersister.guessEntityMode(event.getEntity()); final Connection connection = getConnection(entityPersister); final StatelessSession session = entityPersister .getFactory() .openStatelessSession(connection); session.beginTransaction(); final Serializable entityId = entityPersister.getIdentifier(event.getEntity(), (SessionImplementor)session); final Object existingEntity = session.get(event.getEntity().getClass(), entityId); if (log.isDebugEnabled()) { log.debug("Loaded existing entity " + existingEntity); } boolean updatedExistingEntity = false; for (int i = 0; i < entityPersister.getPropertyNames().length; i++) { final Object oldPropValue = entityPersister.getPropertyValue(existingEntity, i, entityMode); if (oldPropValue == null) { if (log.isDebugEnabled()) { log.debug("Found a property in the existing " + "entity that was null, checking new entity"); } final Object newPropValue = entityPersister.getPropertyValue( event.getEntity(), i, entityMode); if (!(newPropValue instanceof Collection<?>) && newPropValue != null) { if (log.isDebugEnabled()) { log.debug("The new entity contains a non-null " + "value, updating existing entity"); } entityPersister.setPropertyValue(existingEntity, i, newPropValue, entityMode); updatedExistingEntity = true; } } } if (updatedExistingEntity) { entityPersister.getFactory().getCurrentSession().cancelQuery(); session.update(existingEntity); } session.getTransaction().commit(); session.close(); return updatedExistingEntity; }