Muestra las diferencias entre dos versiones de la página.
unidades:07_arquitectura:02_excepciones [2012/09/24 09:34] admin [BussinessException] |
unidades:07_arquitectura:02_excepciones [2016/07/03 20:35] (actual) |
||
---|---|---|---|
Línea 22: | Línea 22: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
throw new BussinessException(cve); | throw new BussinessException(cve); | ||
Línea 31: | Línea 31: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
throw new BussinessException(cve); | throw new BussinessException(cve); | ||
Línea 40: | Línea 40: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
throw ex; | throw ex; | ||
Línea 49: | Línea 49: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
throw ex; | throw ex; | ||
Línea 58: | Línea 58: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
throw new RuntimeException(ex); | throw new RuntimeException(ex); | ||
Línea 72: | Línea 72: | ||
} | } | ||
} catch (Exception exc) { | } catch (Exception exc) { | ||
- | log.error("Falló al hacer un rollback", exc); | + | LOGGER.log(Level.WARNING,"Falló al hacer un rollback", exc); |
} | } | ||
</code> | </code> | ||
- | La propiedad ''log'' la definiremos como una propiedad a nivel de clase usando [[http://commons.apache.org/logging/|Apache Common Loggin]] de la siguiente forma: | + | La propiedad estática ''LOGGER'' la definiremos como una propiedad a nivel de clase usando [[http://docs.oracle.com/javase/6/docs/technotes/guides/logging/|Java Logging APIs]] de la siguiente forma: |
<code java> | <code java> | ||
- | protected final Log log = LogFactory.getLog(getClass()); | + | private final static Logger LOGGER = Logger.getLogger(ProfesorController.class .getName()); |
</code> | </code> | ||
Veamos ahora el tratamiento individualizado para cada una de ellas: | Veamos ahora el tratamiento individualizado para cada una de ellas: | ||
- | |||
==== RuntimeException ==== | ==== RuntimeException ==== | ||
Si la excepción es de tipo ''RuntimeException'' lo único que hacemos es volver a relanzar la misma excepción mediante: | Si la excepción es de tipo ''RuntimeException'' lo único que hacemos es volver a relanzar la misma excepción mediante: | ||
Línea 154: | Línea 153: | ||
<uml> | <uml> | ||
class BussinessException | class BussinessException | ||
+ | BussinessException : Set<BussinessMessage> getBussinessMessages() | ||
+ | |||
class BussinessMessage | class BussinessMessage | ||
Línea 162: | Línea 163: | ||
class ConstraintViolationException | class ConstraintViolationException | ||
+ | ConstraintViolationException : Set<ConstraintViolation> getConstraintViolations() | ||
+ | |||
class ConstraintViolation | class ConstraintViolation | ||
Línea 487: | Línea 490: | ||
fieldName=getCaptions(constraintViolation.getRootBeanClass(), constraintViolation.getPropertyPath()); | fieldName=getCaptions(constraintViolation.getRootBeanClass(), constraintViolation.getPropertyPath()); | ||
</code> | </code> | ||
+ | |||
+ | <note> | ||
+ | Para la realización de éste código se han usado las clases <javadoc s31>org.springframework.util.ReflectionUtils</javadoc> y <javadoc s31>org.springframework.util.StringUtils</javadoc> del framework Spring. Estas clases son simple clases de utilidad con funciones sencillas. Para poder usarlas se ha incluido el jar ''org.springframework.core-3.1.2.RELEASE.jar''. En la siguiente sesión trataremos en profundidad el framework de Spring y explicaremos como instalarlo adecuadamente.Por ahora simplemente recordar el incluir el jar ''org.springframework.core-3.1.2.RELEASE.jar'' en los ejercicios que se realicen. | ||
+ | </note> |