Blog Insights
Code Quality Metrics with Sonar, Part I
I was fortunate to be able to attend the 2011 edition of No Fluff Just Stuff. One of my favorite presentations was by Matthew McCullough on Sonar. Hence, when the issue of code metrics was raised at a partner, Sonar seemed like the right tool to use. Our partner wanted to explore ways...Parallel Programming With Barrier Synchronization
Parallel Programming is an emerging computer science field that studies the opportunity of splitting data into small chucks and process them on multiple processors simultaneously which provides a faster execution time. Parallel programming is useful in sorting, image processing, network processing and may other memory intensive tasks. For parallel program execution...Injecting Spring Beans into Java Servlets
If you are working in a Java Web Application and you are using Spring IoC Container in your application, there is a chance that you might have to inject Spring Beans into a Java Servlet. Since there is not a direct way to inject Spring Beans into a Java Servlet, you...Static Caching in Drupal
If you’re a PHP veteran, then you know static caching is a relatively simple thing to do in PHP, but it can result in inconsistent behavior and sloppy code, such as adding an extra parameter to a function for the sole purpose of resetting that function’s internal cache. Drupal’s static caching...Hibernate Date vs Timestamp
I encountered a subtle hibernate mapping issue involving Dates and Timestamps. The following test recreates this issue. package com.sourceallies.logging; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.apache.commons.lang.time.DateUtils; import org.hibernate.Criteria; import org.hibernate.SessionFactory; import org.hibernate.classic.Session; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; import com.sourceallies.Person; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @TransactionConfiguration(defaultRollback=false) public class HibernateDateTimeTest { @Resource ...Hibernate Logging
Through the years I've encountered a recurring requirement. Partners 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...Back to Basics: hashCode() & equals()
So we all know that if we implement equals() we must override hashCode() too. But why? The best explanation of this commandment can be found in Effective Java (2nd Edition) starting on page 45. If you're like me, you like to see a problem in running code....Learning a new Language
I attended a No Fluff Just Stuff Symposium a few weeks ago. One of the main emphasis during the weekend was learning new languages that are available on the JVM. While there are a variety of reasons that we need to take time to learn new programming languages, one of...Spring Injection with @Resource, @Autowired and @Inject
Annotations public interface Party { } 'Person' is a component and it implements 'Party'. package com.sourceallies.person; ... @Component public class Person implements Party { } 'Organization' is a component and it implements 'Party'. package com.sourceallies.organization; ... @Component public class Organization implements Party { } I setup a Spring context that scans both of these packages for beans marked with '@Component'. <context:component-scan base-package="com.sourceallies.organization"/> <context:component-scan base-package="com.sourceallies.person"/> @Resource private Party party;</pre> ```java @Autowired private Party...Debugging memory leaks with VisualVM
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...