@Override public UpdateCommand newUpdateCommand(Dao dao, EntityMapping em) { return new DefaultUpdateCommand(dao, em); }
@Override public int execute() { prepare(); if(eventHandler.isHandleUpdateEvent(context, em)) { return doExecuteWithEvent(); }else{ return doExecuteUpdate(); } }
protected void prepare(){ for(FieldMapping fm : em.getFieldMappings()){ if(fm.isOptimisticLock()){ prepareOptimisticLock(fm); }else{ Object value = entity.get(fm.getFieldName()); if(null == value) { Expression expression = fm.getUpdateValue(); if (null != expression) { value = expression.getValue(entity); setGeneratedValue(fm, value); } } } } if(em.isAutoValidate()) { EntityValidator validator = context.getEntityValidator(); Errors errors = validator.validate(entity, entity.getFieldNames()); if(!errors.isEmpty()) { throw new ValidationException(errors); } } }
prepareIdAndSerialization(id, map); "], may be an optimistic locking conflict occurred"); }else{ setGeneratedValue(em.getOptimisticLockField(), newOptimisticLockValue);
protected int doExecuteWithEvent() { int result; EntityEventWithWrapperImpl e = new EntityEventWithWrapperImpl(context, entity, id); //pre without transaction. eventHandler.preUpdateEntityNoTrans(context, em, e); if(em.hasSecondaryTable() || eventHandler.isUpdateEventTransactional(context, em)) { result = dao.doTransaction((status) -> { e.setTransactionStatus(status); //pre with transaction. eventHandler.preUpdateEntityInTrans(context, em, e); int affected = doExecuteUpdate(); //post with transaction. eventHandler.postUpdateEntityInTrans(context, em, e); e.setTransactionStatus(null); return affected; }); }else{ result = doExecuteUpdate(); } //post without transaction. eventHandler.postUpdateEntityNoTrans(context, em, e); return result; }