Posts Tagged ‘Java’

Hibernate Logging

January 30th, 2012

Through the years I’ve encountered a recurring requirement. Clients need to log changes to the database for auditing and legal purposes. To satisfy this requirement you could add logging to every save/update/delete call in your code. Or better yet, you could create an aspect that wraps these calls. While these would certainly work Hibernate provides a convenient interceptor.

In this article I will show you how to add a simple logger to Hibernate.
» Read more: Hibernate Logging

Debugging memory leaks with VisualVM

July 18th, 2011

At work I had run into a memory leak when scrolling through large result sets returned from Hibernate. I thought I had fixed it by performing a evict()/clear()/flush() in the HibernateTemplate that I was using but suddenly the leak was back. I was using VisualVm to monitor the heap so I started poking around to see if there was anything to help diagnose where the leak was.
» Read more: Debugging memory leaks with VisualVM

Would you start mocking me?

August 5th, 2010

One of the primary principles of unit testing is to test a small piece of functionality in isolation. In order to achieve this, mock objects are often necessary. Historically using mocks could be quite painful. After using several mock frameworks, my favorite by far is Mockito.

Tutorial

In this tutorial we will walk through examples of the most common features of Mockito. My sample project can be downloaded here.

Interfaces and Implementation

Some mocking frameworks only supported mocking interfaces. As a result our projects became bloated with useless interfaces that were only used for testing.  Mockito creates mock objects with interfaces or classes.
» Read more: Would you start mocking me?

Rendering Global t:messages After Redirect

March 8th, 2010

A common problem when working with JSF is getting global info messages  via <t:messages globalOnly="true"> or <f:messages globalOnly="true"> to display messages set in the previous request when you have a <redirect/> in your faces-config for a particular page You will not see your <t:messages> that are set on the previous page.

The Problem

For instance, say you have two pages – page1.xhtml and page2.xhtml. In your faces-config.xml, you will have 2 entries.

» Read more: Rendering Global t:messages After Redirect

Environment Specific Properties in Spring

March 1st, 2010

On many occasions I want to be able to inject environment specific property values into my Spring managed beans. These may be things like web service endpoints, database URLs, etc. Values I know for each environment at build time, but I want to use the same WAR/EAR file in each environment. I would like to keep the actual values separate from the Spring config files themselves. And I would really like to manage a set of default values for each property, so that I do not need to specify a value for every property in every environment (ex. my credit card processing URL for dev, test, uat is the same, but for production it is different.)

» Read more: Environment Specific Properties in Spring

Replacing and Patching Java Application and Core classes

February 15th, 2010

Why would you ever need that?

Say you get a jar file. After using the jar for a while you realise that there is a bug in a class in the jar file. Unfortunately you also find out that the jar is no longer supported and there is no way you will get a fix from the author (who is long gone fishing).

In order to solve this issue, you first need to get the source of the class. If you are lucky enough and the author did not obfuscate the class file you can decompile it with a decompiler (my favourite one is JD-GUI).

» Read more: Replacing and Patching Java Application and Core classes

Keep your dataTable clean with a custom popup

January 13th, 2010

The basic idea is to output some data to a user in a table and allow them to take an action on each row individually. A fairly straightforward solution is to create a separate page to link to, passing the necessary row information along. If the action is simple enough, like a single checkbox, you could just embed the necessary component(s) in each row of the table. Too many components, however, can bloat the table and make the UI cumbersome to the user. Instead we can create a popup window to overlay our page, containing whatever components are needed, and activate it by a link embedded in our table. Passing the row information is a little trickier, but the result is a cleaner interface and a better user experience.
» Read more: Keep your dataTable clean with a custom popup

Spring’s refreshable beans

January 8th, 2010

A couple of days ago I found out about a really nice feature in Spring, called ‘refreshable bean’.

Spring’s vision a refreshable bean is a dynamic-language-backed bean that monitors changes to its source code and then reloads itself when changes occur. And it is all this is done without restarting/re-deploying entire app. Sweet!
» Read more: Spring’s refreshable beans

Musings of a SpringOne 2009 Attendee – Day 3

October 26th, 2009

Agile Architecture – Technologies and Patterns – Kirk Knoernschild

Some of the questions this session set out to attempt to answer were

  1. What is architecture?
  2. What defines architecture?
  3. What are architectural decisions?
  4. Is architecture a forward only decision?

Several definitions of Architecture were quoted from prior literature. Such as architecture being the the shared understanding of the system being built. Shared understanding between a group of people who need to communicate about it — developers and architects, or technical and management etc.
Lean principles are you delay » Read more: Musings of a SpringOne 2009 Attendee – Day 3

Musings of a SpringOne 2009 Attendee – Day 2

October 21st, 2009

Running a day late on my posts. Here’s day two (yesterday)

Grails Quick Start – David Klien

David walked through the creation of a Grails web application to track a JUG’s meeting schedule. I liked his presentation style or maybe because the room wasn’t very crowded things just registered better. Picked up a few tips such as the Bootstrap class. Grails still has a ways to go in the eclipse tooling. It would’ve been nice to have been able to File –> New Project and follow along. Too bad IntelliJIDEA CE doesn’t support grails though there has been plenty of buzz on the latest STS. Downloading this right now. Only 3 more hours for the download to complete!

I think I’m beginning to dig duck typing. All in all the presentation encouraged me to put my head down and hammer out a sample app to start building some grails knowledge. More homework! » Read more: Musings of a SpringOne 2009 Attendee – Day 2