Concurrency Strategies for Hibernate Caching

Caching and concurrency management are tricky. If you have a cache that lives in memory but you have updates to the database that the objects originally came from, how are you going to make sure that the cached objects still reflect the contents of the database?

This really depends on what type of data you are dealing with. Data types that are mostly read (news, notices, articles) probably benefit from whatever caching you can provide, while areas of data that change a lot (shopping carts, server status records) probably won’t benefit from caching at all.

Here are the concurrency strategies on hibernate caching explained:

technorati tags:

Continue reading “Concurrency Strategies for Hibernate Caching”

On the topic of assertions

Every assertion should be thought from the standpoint of

  1. What was expected
  2. What actually happened

Translation: assertTrue should always, always have a message.

Consider the following:

assertTrue(mv.getViewName()
    .startsWith(myController.getSuccessView()));

This will only return “assertion failed”. Which is great, but how do we know what happened? If this is buried on one of the lunt automated remote builds, how am I supposed to know what is going wrong? Which is the expected? What actually happened?

A much better version of the same looks like this:

assertTrue(
    "Was expecting something like "
        + myController.getSuccessView() + " but was "
        + mv.getViewName(),
    mv.getViewName()
        .startsWith(myController.getSuccessView()));

Same assertion, but now it tells me more specifically what’s going on and I can fix bugs with it. Once I set this on the test, it becomes easy to see what was going on.

I recently had a Saturday with some other Bay Area developers where we did a lot of thinking about testing, so expect some more advice in the future as I collect my notes.

Remember the goal of unit tests is to “find bugs” (thanks Harry!). An assertion without an associated message merely notifies you that a bug occurred but doesn’t actually “find it”. As you are writing your unit tests, make sure you find it as well.

technorati tags:, , ,

Wazaabi – XUL for RCP.

This opens pretty interesting possibilities:

Via TheServerSide:

Wazaabi includes a GUI framework that brings XUL to Eclipse RCP plugin developers and a set of components that link the client-side XUL based viewers and forms to server-side business components. Thus, rich client developers can use XUL to code a GUI, rather than using SWT.

Wazaabi brings XUL to Eclipse RCP based rich client applications

This is an actual XUL viewer, not a similar syntax like XSWT or similar attempts. They use servlets to communicate between the XUL side and your application, to keep the flexibility of sending the XUL to a mozilla browser. Very interesting.

technorati tags:, ,

Google Web toolkit

Okay, it’s official. Now everybody has a web 2.0 solution.

With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler to translates your Java application to browser-compliant JavaScript and HTML.

Google Web Toolkit – Product Overview

 
Haven’t tried it, but it looks like it would work. Of course, the devil is in the details :-)

Myself, I’ve been using prototype and scriptaculous "raw" (just some JSP tags of my own here and there) on my web application pretty successfully. Remember, in scriptable languages, testing is key.

You also learn a lot from reading their source code. But if you are source code illiterate (what a handicap for a programmer!) a cheatsheet or documentation can help.

technorati tags: , , ,

Eckel on Java vs Rails: The departure of the hyper-enthusiasts

As always Bruce Eckel is a great read..


The Java hyper-enthusiasts have left the building, leaving a significant contingent of Java programmers behind, blinking in the bright lights without the constant drumbeat of boosterism.

But the majority of programmers, who have been relatively quiet all this time, always knew that Java is a combination of strengths and weaknesses. These folks are not left with any feelings of surprise, but instead they welcome the silence, because it’s easier to think and work….

Clearly Ruby is making important contributions to the programming world. I think we’re seeing the effects sooner in Python than elsewhere, but I suspect it will have an effect on Java as well, eventually, if only in the web-framework aspects. Java-on-rails might actually tempt me into creating a web app using Java again.However, I can’t see Ruby, or anything other than C#, impacting the direction of the Java language, because of the way things have always happened in the Java world. And I think the direction that C# 3.0 may be too forward-thinking for Java to catch up to.

Weblogs Forum – The departure of the hyper-enthusiasts

Mainly, I think a pragmatic approach to a language is to assign value based on a) what you can accomplish with it, and b) how easy it is to write in the first place and maintain in the long run. So far Ruby is starting to become interesting on (a) – it was always interesting on (b) -, although we still have to do a lot of stuff in Java if we want to take advantage of a lot of features.

However, in Java there has been a lot of work already done to get you libraries and automated tools. I have been looking for some good IDEs for Ruby and I can’t seem to find anything that is better than just using vim (I’ve looked, but that’s another story) – Eclipse is my yardstick for comparison.

That means that I may want to switch to rails for web app development and maybe scripting, but not for any type of development where I have to apply deep pattern thinking and where I anticipate refactorings to come along as the system grows. It may be easier conceptually to do refactoring in Ruby, but that fact is superceded by the automatedness of doing it in Eclipse. It doesn’t matter if it impacts a lot more files to, say change a member variable name in a domain object, in Java vs. Ruby if I can do it with Alt-R in Eclipse and in Ruby I have to go and change it manually – the masses will not switch until you give them this kind of capability.

On the other hand, I really do like the fact that you can get started in ruby from scratch in a few minutes using things like “gem install rails”, vs. setting up a giant ant/java/spring/hibernate/tomcat on the java side.

technorati tags: , , , ,

RIFE vs Rails side by side

Like many other java developers, I am currently using Spring and
Hibernate, so I can’t attest to the quality of RIFE. But I thought this
was interesting: This is a side-by-side
comparison
of the RIFE source vs. the Rails source for the
same feature (Ta-da list
vs Bla bla list).
Just another thing to add to the ever-growing list of things to check
out.

Note that I don’t have an opinion on this because I don’t know both
toolsets (and like many others I don’t sound very smart when comparing
something I know vs something I don’t know). :-)