The Power of Feedback – book review

Tuesday, November 23rd, 2010

I’ve just read great book: The Power of Feedback. The book is awesome, and everyone who wants to improve yourself should read it. Here is brief, chapter by chapter short description, to keep important ideas.

  1. Reacting to Feedback: The main problem is our reaction to feedback, most of the time we deny feedback with the person who gave us, that does not help us at all. Let’s cite principle seven: “The process of change begins with accepting the feedback given.
  2. Why did I Get That Feedback? The feedback is always true, of course from the others perspective, and once somebody forms opinion on us it is hard to change that. The same on our side, as principle eleven: “When we provide feedback, we tend to base our perceptions on our own performance and personality“.
  3. Improving Your Ability to Accept Feedback: First step is to accept feedback. Principle fourteen: “One way of improving a skill is to improve your performance in companion skills“. There are a lot of companion skills: Integrity, Honesty, Optimism, Friendly, Respects others, Listens, Develops others, Coaching, Willing to Set Stretch Goals and so on.
  4. Why Change? Why we should bother of changing if we perform well, the answer is principle seventeen: “To maintain a perception of high performance, you must change over time.” Otherwise we will become less and less performant.
  5. Deciding What to Change. We have the list, but what should be the first item in our agenda? The answer is to prioritize against three criteria: “Felt need”, “Easy of Change” and “Relative Impact”. After that we may chose more accurately, and remember principle twenty-two: “Issues dealing with things are easier to change than issues dealing with people.”
  6. Fixing Weaknesses or Building Strengths? People tend to think about weaknesses, and try to fix them, but in fact it is easier and it will have more impact to focus on ours strengths. Principle twenty-four: “Doing something well has a dramatic impact on perceived effectiveness.”
  7. Making Change Happen. How to start working on change and how to avoid giving up. So to start principle twenty-seven is the best: “Redefining negative feedback in a positive light creates increased motivation to change”, and to continue with change we have to first try it, enjoy it and practice it, from time to time we may reward ourself to keep high motivation.
  8. Making Change Stick: The most important chapter in the book, how to make change permanent. I’m even not able to summarize this chapter here, so principle thirty-five: “You can only make significant life changes if you have the necessary desire, strength, and motivation to cause those changes to happen.”
  9. Working Harder or Working Smarter? Final chapter is about the list of companion behaviors with real life examples.

Yes we cannot improve without feedback, so next time if somebody give you, even negative, feedback, than you should be happy. Thanks to feedback we can discover our strengths and weaknesses. So if you have opportunity to give somebody feedback, don’t think just do it.

Go buy or borrow this book, and read it carefully.

Pedro Newsletter 16.07.2010

Friday, July 16th, 2010

Spring jdbc namespace

Thursday, July 1st, 2010

One of the new feature of Spring Framework 3.0 is more namespaces. Today I want to write about jdbc namespace, which I’m using in last project.

The namespace is really simple, it has two main elements

  • initialize-database – which allow us to initialize database with scripts.
  • embedded-database – which allow us to start embedded database.

initialize-database

So we can use that xml tag to initialize our datasource with SQL scripts. There are some properties we should set:

  • data-source – which is javax.sql.DataSource bean reference. It will be used to connect and execute all the scripts.
  • enabled – if we should do anything so if we are enabled or not. (remember it can be property ${} or even spring EL), by default it is enabled.
  • ignore-failures – if we should ignore when statements end with errors.
    • NONE – do not ignore default value.
    • DROPS – we are ignoring failed DROP statements.
    • ALL – we ignore all failed statements.

And what is more important this tag has zero or more scripts tags. All this tags has location property which behave exactly the same as spring resources. In my application I create schema for production (I don’t use any ORM) and for tests I have the same schema with one more script (test data/fixtures – no more DbUnit problems :) ).

It is soooo simple.

<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:/schema.sql">
</jdbc:script></jdbc:initialize-database>

embedded-database

The second tag, is really helpful when you want to use embedded database. Embedded database is helpful for things like storing configuration or other persistent application stuff.

It allow to simple start embedded database and make them visible as javax.sql.DataSource, ready to be injected to our JDBCTemplete objects. It has just two attributes:

  • id – which value becomes the bean name.
  • type – embedded database type

Actually those types are supported:


        
        
    

Under The Hood

All things starts at JdbcNamespaceHandler class, which register two parsers for elements. There is EmbeddedDatabaseBeanDefinitionParser for embedded-database element and InitializeDatabaseBeanDefinitionParser for initialize-database.

When everything is ok this elements build and configure two beans.

And that’s all.


Spring MVC Exception Handler

Saturday, June 19th, 2010

In previous version of Spring Framework to handle exception we used HandlerExceptionResolver interface. Spring also provides simple implementations which was suitable in most of cases. Since 3.0 version we have few additional exception resolvers plus we can use annotation to specify our exception handler methods or classes without implementing HandleExceptionResolver interface.

  1. AnnotationMethodHandlerExceptionResolver (new in 3.0)
  2. ResponseStatusExceptionResolver (new in 3.0)
  3. DefaultHandlerExceptionResolver (new in 3.0)
  4. SimpleMappingExceptionResolver

SimpleMappingExceptionResolver

Should be configured in XML, there are few properties which drives this resolver behaviors.

  • defaultErrorView -> this view name will be returned if no mapping will be found.
  • defaultStatusCode -> once the view name was resolved if the view hasn’t status code the defaultStatusCode will be applied.
  • statusCodes -> Map with “view name” to “status code” mapping.
  • exceptionAttribute -> the name of attribute where exception is hold by default “exception” is used.
  • exceptionMappings -> Properties which maps Exception “class name” to “view name”. Watch out as you can easily maps more than you want, this is because only String.contains is checked, so a=viewName mapping will catch all exception with “a” in the name.
    Another thing to consider is that if you provide deep Exception hierarchy (n) and you provide a lot of exception mapping (m), you will end up with O(n*m) lookup algorithm. It may seem not problem, but if somebody spots that (Error page which render time is quite long), than it may be used with DDOS to increase load on ours machines.

DefaultHandlerExceptionResolver

First at all it has pageNotFound logger which is org.springframework.web.servlet.PageNotFound logger category, second it decides what to do depending on exception type, it is base class to extend when we want change default behavior:

  • NoSuchRequestHandlingMethodException : no request handler method was found by default it sends 404 error. Override handleNoSuchRequestHandlingMethod.
  • HttpRequestMethodNotSupportedException : no request handler method was found for the particular HTTP request method by default 405 error.Override handleHttpRequestMethodNotSupported.
  • HttpMediaTypeNotSupportedException : no HttpMessageConverter were found for the PUT or POSTed content by default 415 error. Override handleHttpMediaTypeNotSupported.
  • HttpMediaTypeNotAcceptableException : no HttpMessageConverter were found that were acceptable for the client (Accept header) by default 406 error. Override handleHttpMediaTypeNotAcceptable.
  • MissingServletRequestParameterException : required parameter is missing by default 400 error. Override handleMissingServletRequestParameter.
  • ConversionNotSupportedException : WebDataBinder conversion cannot occur by default 500 error. Override handleConversionNotSupported.
  • TypeMismatchException : WebDataBinder conversion error occurs by default 400. Override handleTypeMismatch.
  • HttpMessageNotReadableException : HttpMessageConverter cannot read from HTTP request by default 400 error. Override handleHttpMessageNotReadable.
  • HttpMessageNotWritableException : HttpMessageConverter cannot write to HTTP response by default 500 error. Override handleHttpMessageNotWritable.

ResponseStatusExceptionResolver

This resolver allows us to use @ResponseStatus annotation. If we annotate our Exception with @ResponseStatus annotation than the response will get status code from annotation.

  • ResponseStatus.value as status code (it is HttpStatus enum)
  • ResponseStatus.reason as reason or default HttpResponse reason if not set.

AnnotationMethodHandlerExceptionResolver

Last but not least, and from my point of view this resolver is the most important. This exception resolver allows us to use @ExceptionHandler annotation, every method annotated by @ExceptionHandler will become exception handler. As parameters @ExceptionHandler need an array of Throwable. We also should use @ResponseStatus to indicate status code.

The method signatures possibilities are vary so see documentation to get all the proper combinations of parameters and return types.

The idea is pretty simple, for all the ExceptionHandler.value exception the exception -> Method handler is created, when Exception happens Method will be invoked.

Conclusions

Since 3.0 we rather has no need to setup handlers by ourself, the most useful way is to use @ExceptionHandler annotation. By default DispatcherServlet will setup AnnotationMethodHandlerExceptionResolver, ResponseStatusExceptionResolver and DefaultHandlerExceptionResolver as handlers resolvers. So we are ready to start with annotation based approach.

My approach is that I try to create moduleExceptionHandler class which has all methods annotated by @ExceptionHandler (except utility methods of course) and I always annotate them by @ResponseStatus as well. The methods parameters and return type vary depending on my needs. It a little bit central approach but it avoids problem with more than one handler per Exception.

UPDATE :: I’ve downloaded code to Bitbucket, you can clone it: hg clone https://pedrowaty@bitbucket.org/pedrowaty/spring-tryouts and than go to mvc-error-handlers directory.


Pedro Newsletter 11.06.2010

Saturday, June 12th, 2010

Today is shopping day @ SF, I’ve got a long list of stuff to buy, we’ll see if I manage that :) .


about me

My name is Sebastian Pietrowski. I've finished Warsaw University as Master degree. During my studies I started work for merlin.pl. The primary language I use is Java but I have also programmed in Python, Ruby and Scala. I worked as a technical solution architect at merlin.pl. infrastructure when we were moving from PL/SQL to J2EE. I engineering a great performance optimized solution that made the application 10 times faster than requirements and 85 times faster as original solution.

Currently, I am working as a Senior Expert at F.Hoffmann-La Roche to help define future roadmap in design and development of Enterprise software at Roche and Genentech and build adoption for new technologies. I'm continuously mentoring new developers, helping them understand how important test driven development is and empowering them to get better at their daily job. I'm involved in many activities which brings new technologies for better and faster development. You can find more details on my LinkedIn profile.

But don’t get me wrong, I am not your typical nerd. I'm a pleasant guy that you can drink a glass of wine with me and talk about a range of topics with. My leisure activities include playing basketball, soccer and listening to music. I try to be pragmatic while staying focused on application performance and tuning with success in my daily work.

My favorite quote from Yoda's and my life’s motto is: Do, or do not. There is no try.