Java 类org.hibernate.event.PreUpdateEvent 实例源码

项目:cacheonix-core    文件:EntityUpdateAction.java   
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;
}
项目:cacheonix-core    文件:JACCPreUpdateEventListener.java   
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;
    }
项目:Lucee4    文件:EventListener.java   
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;
}
项目:TechnologyReadinessTool    文件:AuditedEntityListener.java   
@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;
}
项目:Lucee4    文件:AllEventListener.java   
public boolean onPreUpdate(PreUpdateEvent event) {
    return preUpdate(event);
}
项目:Lucee4    文件:PreUpdateEventListenerImpl.java   
public boolean onPreUpdate(PreUpdateEvent event) {
    return preUpdate(event);
}
项目:further-open-core    文件:PreUpdatePreventNullOverwriteListener.java   
@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;
}