June 2004 Archives

AddThis Social Bookmark Button

Not much time to do a detailed JavaOne rundown right now. This is partially the because I honestly haven’t had time to assimilate the various signs and portents, and I don’t have much interest in just recounting the announcements, which you can see anywhere. Speculating on the future of Sun, Java, the technology industry, and so forth, is a chicken-entrail reading activity, and extrapolations based on trade shows are about as accurate. Nonetheless, I will get around to it eventually.

One thing that did strike me was that the exhibitor floor was smaller. Sun’s space is larger than in previous years, and it does appear that they’re showing everything up to and including the kitchen sink, in what definitely appears to be an attempt to bulk up the show. Tools and infrastructure vendors who filled massive amounts of space in the past are absent completely or massively reduced in scope. So it’s tempting to take a look around and say that things must be going pretty badly.

I suspect that’s not the case, though. Shows like JavaOne are geared towards developers, so the logical exhibitors are the vendors of development and deployment tools. There’s been some commoditization in this space, which has reduced the number of players, and trade shows aren’t how vendors reach a development audience anymore - Google is. So the return on investment for a bid JavaOne presence may be, for all but the biggest players, not the best of all possible deals. Comdex, you’ll note, was cancelled this year - the former undisputed heavyweight champion of the technology world. But Comdex was an exhibitor oriented show, and things just don’t work that way anymore.

The Java community itself is vibrant enough, and my rough eyeball estimate of people in the keynote session showed as many as last year, at least. Sun has some interesting things to say about the development of the Java ecosystem (surprise! it’s growing!). So the developer base is still there. Back in May I spoke at the ServerSide.com Symposium, which was entirely presentation driven: no exhibition floor at all. I suspect that’s the way of the future, rather than a floor full of vendor reps.

Bill Siggelkow

AddThis Social Bookmark Button

If you are using Hibernate for your persistence layer, debugging can be a challenge. I recently had a problem that was driving me nuts …


In short, I was stepping through code in my IDE’s debugger. I had traced the problem to a query that I was executing with Hibernate. An exception was thrown when I attempted the query … here’s the stacktrace.

java.lang.ClassCastException
net.sf.hibernate.type.LongType.set(LongType.java:28)
net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:403)
net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:521)
net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:28)
net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2362)
net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2316)
net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1813)
net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1507)
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1472)
net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:45)

My first reaction was to analyze what was wrong with the query. I checked and found nothing wrong. The ClassCastException indicated that I had some incompatability in a Hibernate mapping file … this deduction was accurate.

The problem, however, was not with the object that I was performing the query. The problem was related to the mapping of a different object that I had inserted into the database earlier in the the life of this particular transaction. Two things clued me in — first, on inspection, the stack trace indicates that the error was on EntityPersister.insert(). Second, I turned “show SQL” on with the following Hibernate configuration setting:

        <property name="hibernate.show_sql">true</property>

Looking at the logs out of Tomcat clearly showed that the error occured when executing an SQL insert statement.

What was happening was that Hibernate had not flushed the insert to the database. It was not until I issued a query that Hibernate attempted to execute the insert statement. Once I realized that the offending object was not the one being queried but the one being inserted, I quickly located the problem in my mapping XML file. I had incorrectly defined the type of a property as a Long instead of a String. A quick change to the XML file and the problem was solved.

A few lessons I learned here:

  • Turn on Show SQL when debugging with Hibernate
  • Trust the log file
  • Don’t just scan the stack trace, read it carefully

In hindsight the problem is, of course, obvious — in the words of the great poet Homer — Doh!

Diego Doval

AddThis Social Bookmark Button

This Thursday, at JavaOne, there will be a panel titled “The Big Question.” The JavaOne page on the topic offers the following (cryptic) description:

Numerous individuals and organizations suggest that JavaTM technology adopt a new community and development model. This panel will dive into the tangle of granular technical and legal issues, including the potential tradeoff between technologist’s calls for openness vs. the market’s demand for compatibility. Panelists include leading technologists, experts on legal and copyright issues, top industry analysts, and mainstream users of the technology.

So is “a new community and development model” codespeak for open source? Even if the panel description doesn’t make it clear, that’s what everyone is expecting.


Open sourcing Java has been a hot topic in the community (particularly in Java-oriented weblogs) during the last few weeks. Most people seem to be for it, and I’d say that there’s been as much community pressure as anyone can imagine on Sun to do it.


There has been a lot of argument over whether Sun would gain or lose with this, but little over how Java, or the developers that work with it, such as myself, would benefit from such a move. Note for example, open source notable Eric Raymond’s Let Java Go open-letter to Scott McNealy, where he makes several points on how open sourcing Java would benefit Sun (to the point of making a much-disputed stock price comparison), but very little on how this would be good for Java. As a contrast, columns like this one by Dan Gillmor with more focus on Java itself are few and far between.


So, there must be an implicit belief that open sourcing Java would “be good”, or would suddenly bring droves of developers into the Java world (how exactly would this happen is unclear–presumably because now that Java is “free” they would feel comfortable using it?), or would suddenly “fix” whenever is a problem for each of us, and so on. I’ll come back at the end to some of the advantages that I think open source would have for Java, given the right context, but my point is that these will vary from person to person, and yet there is little mention of them–and how can that be possible unless every proponent assumes that it will solve their problems?


What comes to mind is a quote from Jamie Zawinski from the Cathedral and the Bazaar:

[…] in 1999 one of [Mozilla]’s principals [Jamie Zawinski] caused a bit of a sensation by resigning, complaining of poor management and missed opportunities. “Open source,” he correctly observed, “is not magic pixie dust.”

And yet, from all the buzz (dare I say hype?) surrounding open source and Java, one could be forgiven for thinking otherwise.


Eclipse


But why this belief? In my opinion, Eclipse has had a lot to do with it –as has Jakarta– but Eclipse in particular is the shining star of the Java world right now. Look! A great platform! Open Source! Blasting barriers! Fast turnaround! Quality code! This is what Sun should do!


But we forget some things. Like the three or four dozen full-time developers that IBM devoted to this project. For a couple of years.


Or the fact that versions keep being pushed out against arbitrary deadlines. Not that deadlines are bad, necessarily, but as Don has noted it is possible that products that depend on Eclipse needed the release on a certain schedule, and maybe even for it to be ready for JavaOne. The many delays in the Linux Kernel come to mind here–delays for increased quality and because its development is less centrally managed.


Or the forty million dollars that IBM put into it.


Or the fact that several other companies are providing substantial amounts of money and resources to the project, post-IBM-spinoff.


(Btw, is all of this open source, Linux-style? Really? How many of its unique elements, such as the process, are present here?).


In any case, my point is not that Eclipse is “bad”, but rather that open sourcing to any degree an already existing platform takes time, a lot of money (if you want to bootstrap it quickly), and direction. Even so, Eclipse’s development has been as opaque to many people as Sun’s for core Java. Nearing the end of the “Mx” releases there was a change on the look and feel, which many people complained about–because it caught most outsiders by surprise. And they couldn’t really “go in and change it”. Why? Complexity, lack of documentation, etc.


So if the JDK/JRE is just open sourced, maybe IBM or Oracle or BEA can benefit. But is that the point of open source?


Or rather, to go back to my original question, why is open source good for Java?


The problem with Java: direction, or lack thereof


In my opinion many Java developers that advocate open sourcing it are simply frustrated with Sun’s management of it. (At least, I know I am). This doesn’t mean, again, that an open source Java would be a bad idea, I’m just saying that maybe it’s being pushed for the wrong reasons, and consequently doing it would deflect attention from the real problem for a while, not solve it, and maybe even exacerbate it.


By “Sun’s management of Java” I am referring to their focus. Sun deserves a lot of credit for its stewardship of Java, but it’s always been mildly schizophrenic about it. First it was all about thin-clients. Then it was all about server-side. Then it was actually about web services. Then it was about mobiles. And so on. In themselves these shifts are not necessarily a problem; what’s a problem is the sudden nearly constant change of focus on certain APIs and not others. Year-in, year-out, APIs are suddenly elevated to high-priority status and then nearly abandoned (the case with JavaSound), or kept in life support. Lately, Sun has put a lot of work into Java Desktop System integration of the JDK, while ignoring pressing platform problems such as proper desktop integration, installation systems, size reduction, multiple JRE management, modularization, or HTML parsing/display support.


Or, rather, not ignoring, but doing something worse, “open sourcing” them.


Case in point is JDIC which provides desktop-integration capabilities that are little more than a band-aid considering where Java should be today. But what’s the solution? “It’s open source!”


Which I invariably read as: “we don’t care enough about this technology to make it a priority, so we’ll push it out in the open and see if anybody works on it”.


But open source or not, Java needs some refocusing on the components that are missing from the platform: desktop integration through APIs that are properly ported and supported on the three major OSes (Linux, OS X and Windows), including installers, properties, web browsing, and so on. A clear plan regarding current APIs, including core Java APIs:

  • If the API is still evolving, what’s the goal, what’s missing, when can we expect it will be done, and how can the community contribute? (Open source would be ideal to inject energy into this process)
  • If, on the other hand, the API is in maintenance mode, can the process for fixes and requests be clarified? Here open source becomes almost crucial in the long run, as without it, minor bugs in rarely used APIs might remain unfixed through several cycles.
  • For new, or proposed APIs, do we still need JSRs, or can we provide a simpler, better mechanism, like what Apache does?

In this context, it is clear that an open source Java would be valuable. But without clear direction, and commitment, from Sun and others to drive the platform, guide it, and keep it from splintering, open sourcing Java could potentially create even more confusion.


Because open source is not magic pixie dust.

William Grosso

AddThis Social Bookmark Button

Related link: http://www.apple.com/macosx/tiger/safari.html

Today, at the WWDC, Apple announced RSS support for Safari.

Scripting News immediately noticed, as did NetNewsWire.
Scripting news even pointed to this Quicktime Video demoing features.

I like the “article length” slider (about halfway through the quicktime). You can slide it around to get different length summaries of the articles. I’m not sure how useful it is in practice (not being a mac person, and not having a copy of Safari with RSS reader in any case), but it sure looks interesting. And like a genuinely new feature (neither Bloglines nor FeedDemon have it).

Would you use an article length slider if your RSS reader had it?

Eric M. Burke

AddThis Social Bookmark Button

Related link: http://www.usatoday.com/tech/news/2004-06-24-aol-tick-tock_x.htm

An AOL insider recently sold a bunch of AOL usernames to a spammer. All the big media outlets picked up on this story. As a consultant who has worked for numerous companies, I’m not at all surprised this happened.

Here is a dirty little secret our industry does not talk about. Many companies do not protect sensitive information from so-called “insiders”. In fact, just about every company I have consulted for over the years has given me unfettered access to tens of thousands of SSNs, names, addresses, even employee salaries.

None of these companies did a background check on me, nor did they ever make me sign any confidentiality agreement.

In most cases, lack of privacy is directly attributable to laziness. In every case I can think of, I had access to this sensitive information because that’s how many companies create so-called “test” databases. They just do a raw dump of live data and give the entire programming staff complete access to the data.

This must stop. We must be more careful with private information! As a consumer who is also a programmer, I know that my own personal information (like address, SSN, account numbers) is freely available to thousands of programmers worldwide within company walls. Yep, I’m scared. And I also know that when my identity is stolen, the burden is on ME to cleanup the mess.

When a “big leak” like the AOL leak occurs, companies are exposed to tremendous legal and financial risk. Is it worth the cost just because you are too lazy to scrub your test data?

William Grosso

AddThis Social Bookmark Button

Related link: http://jroller.com/page/rickard/Weblog

A little over a month ago, the JBoss Astroturfing controversy erupted. It quickly died down, especially after Marc Fleury banned astroturfing by JBoss Employees.

At the time, I didn’t pay much attention, for a variety of reasons. Among them were:

  • I don’t find JBoss all that interesting. They make a good cheap J2EE appserver. Useful stuff, but not the sort of thing I think about on a daily basis.
  • Rightly or wrongly, it didn’t surprise me at all. “JBoss caught astroturfing” struck me as having all the news value of “Bear shits in woods.”
  • I had a few beers with Bela Ban about a week after the news broke. Bela’s the author of JGroups and a member of JBoss. And he was mortified by it; he thought it should never have been going on. That reassured me quite a bit.
  • Marc Fleury, the CEO of JBoss “banned” it.

But now, I’m feeling more disturbed. For one thing, the ban is a model of not admitting anything. In fact, some of it (”I personally don’t need a mask to speak my mind and one thing I can’t stand is two faced hypocrisy.”) sounds more like a denial than anything else..

For another, there’s Rickard Oberg’s weblog. In which he points out some very disturbing things. The least important of which is that in the comments on the note “banning” astroturfing at JBoss, there’s some obvious “astroturfing” going on.

More importantly, some of the astroturfing comments were very personal. I don’t know a lot of the history, and I might be being naive here, but I think there’s a big difference between anonymously puffing your product (or dissing your competitor’s product) and anonymously attacking people. I, for one, hadn’t realized what was being said in some of the anonymous comments.

But what bothers me more than anything else is the following comment, also excerpted from Rickard’s blog.


It only took Marc a week to resume his behaviour as he began posting as “Race Condition” over at TSS.

Has anyone else verified this? It strikes me that astroturfing was amazingly juvenile and unprofessional in ways that boggle me completely. But it’s also the sort of thing that I can see happening by slippery slope, especially at a company that is hypercompetitive and trying to rise above the noise.

But claiming to have banned it, and then surreptitiously resuming the practice? That’s quite a different level of dishonesty. If I were an investor, that’s the sort of thing that would cause me to wonder if I had the right CEO.

Of course, it also causes me to wonder about the state of our profession. The reason astroturfing is so tempting for so many people is that we don’t really have independent testing labs. What’s the best database for a particular task? What’s the best application server? What are the benefits and disadvantages of various pieces of technology? In an atmosphere where there are very few concrete and verifiable facts, the temptation to astroturf, and the reward for doing so, is much stronger.

Can anyone shed some light on this? Did JBoss really resume astroturfing?

Eric M. Burke

AddThis Social Bookmark Button

Related link: http://suned.sun.com/US/certification/java/

A few years ago, back in the good ol’ days of Java, Sun really promoted their certification programs. At the time, this was a hot issue so I took the first two exams.

Two issues discouraged me from continuing with additional Java certifications. First, Sun would not let me put any statement like “Certified Java Developer” on my business card without a verbose legal disclaimer that probably would not fit on the business card. This really is not a big problem, it is just annoying.

The second annoyance was the way my programming assignment was graded (or not). Before I took my test, a co-worker with a LOT of experience took his test. He received a very poor score, barely passing. He speculated that maybe they gave him a “rubber stamp” approval rather than really studying his solution. I then took the Developer certification exam and received the exact same lousy score. What are the odds of that? I did not receive any feedback as to what I did wrong. Why were our scores so low? I know damn well that my solution was correct and well written. Was it mere coincidence that my coworker got the exact same score, or did we get a rubber stamp approval?

So I quit pursuing additional certifications. Now, several years later, a client actually asked for a Java instructor who has some sort of Sun certification. This surprised me because I have not heard much about certifications in recent years. People don’t seem to care as much as they used to.

Should we care? I can think of a few limited reasons why certifications matter:

  • There is a remote possibility that some companies prefer certified programmers over non-certified programmers. Regardless of whether this means anything, being certified might help you get your foot in the door.
  • Given two otherwise identical programmers, would you hire the one who is certified or the one who is not? Perhaps the certification gives one a slight edge. This is a weak argument, though. I’m a “hard” technical interviewer, and I find it pretty easy to distinguish between someone who really knows Java versus someone with limited knowledge.
  • The mere act of studying for certification helps you learn more about Java. This is particularly important for people new to Java, such as those switching from some other language.

Looking back at these points, I’m coming to the conclusion that certifications are most important for beginners. Studying for the tests give you something concrete to focus on, and being certified gives you one extra bullet point on a resume.

Bill Siggelkow

AddThis Social Bookmark Button

Related link: http://java.sun.com/products/jsp/tags/12/syntaxref1211.html#8780

It seems that despite the fact that JSP 1.2 has been out for quite a while; many developers are not aware of how to eliminate the annoying web.xml taglib directives using absolute URIs.
Personally, I’ve always been annoyed when I have
to create entries in the web.xml for the tag libraries and then essentially repeat myself by specifying a matching taglib directive on my JSPs. This always seemed to violate the DRY principle of software development. JSP 1.2 provides a nice solution to this problem by using absolute taglib URIs.

With JSP 1.2, a tag library’s absolute URI is specified in that library’s tag library descriptor (TLD) file. For example, here’s this declaration from the struts-bean.tld file:

<taglib>
  <tlibversion>1.0</tlibversion>
  <jspversion>1.1</jspversion>
  <shortname>bean</shortname>
<uri>http://jakarta.apache.org/struts/tags-bean</uri>

Any JSP page that needs to use this tag library can reference it with the following page-level directive. The tag library does not need to be referenced in the web.xml file!

<%@ taglib
        uri="http://jakarta.apache.org/struts/tags-bean"
        prefix="bean" %>

Using this approach is convenient and easy; however, some developers frown on it. They feel that having the extra level of indirection is beneficial. If the taglib URI changes then you only need to change the web.xml. Yet, since a majority of my web development is with Struts, I almost never touch the web.xml file.

One way to work around this problem is to put all your taglib directives in a single JSP that you include throughout your application.

First, create a JSP file containing taglib directives that use the absolute URIs for the tag libraries you are using. The example below shows a JSP file containing the taglib declarations for the Struts bean, html, and logic tag libraries as well as the JSTL core and formatting tag libraries.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

Then include this file at the top of your JSP pages using the include directive:


<%@ include file="/includes/taglibs.inc.jsp" %>

Since you are using the absolute URIs in the taglib directives, you are not required to enter a corresponding taglib element in the application’s web.xml file!

I have good success with this approach but YMMV — I’d be interested in your experiences.

William Grosso

AddThis Social Bookmark Button

Related link: http://www.nextag.com/serv/main/about/jobs/java.jsp

A friend sent me the following programming problem, which comes from the NextTag website.


Given a deck of nCards unique cards, cut the deck iCut cards from top and perform a perfect shuffle. A perfect shuffle begins by putting down the bottom card from the top portion of the deck followed by the bottom card from the bottom portion of the deck followed by the next card from the top portion, etc., alternating cards until one portion is used up. The remaining cards go on top. The problem is to find the number of perfect shuffles required to return the deck to its original order. Your function should be declared as:

static long shuffles(int nCards,int iCut);

On their site, they’re using this as a screening function for software developers. As they put it:


We are looking for Java developers to help build our e-commerce web application. Try out this Programming Problem and see if you can make it run within a few minutes or less.

I’m not certain I understand why this is related to an e-commerce application, but it’s an interesting challenge. Or, at least, I thought it was (Call me a dang-fool-coder, but sometimes I just like to hack away at problems).

After 4 hours, I’ve got it down to 31 milliseconds on the machine I’m using. I think that’s good enough.

The fun part, for me, was realizing just how computationally intensive this problem really is, and, consequently, how bad my initial guess at how to do solve it was. At the end of the day, a few cute tricks and a little bit of thought about prime factorizations solved the problem in ways that objects named “deck” and “shuffler” didn’t.

The hard question: is there a closed form solution for this problem?

Russell Miles

AddThis Social Bookmark Button

Related link: http://www.oreilly.com/catalog/hackpaint/index.html

I don’t normally come up with the more philosophical or ’state of the union’ type blogs that I enjoy reading from other contributors but I wanted to share my thoughts on a subject that’s very dear to my heart (as well as my job , spare time and hobbies!). That subject is Software Tools.

After I finished reading the book ‘Hackers and Painters’ from O’Reilly (excellent book by the way: accurate, interesting, thoughtful, personal and written with a sense of humor that makes it a truly enjoyable read) I really got to thinking about what makes a difference to how I work every day. I’m a software developer and the easy answers would be things like ‘Java’ or ‘Object Orientation’ or even ‘Aspect Orientation’ but what enables all these things was the question that started to bug me. Is it open source, free software, hard work and sweat or a combination of all of these things and more that combine to make my coding day much more of a pleasure that it would normally be.

Open Source and Free Software combined have given us Operating Systems and Applications galore. From kernels to word processing to graphics and photo editing through to video and music playback - it’s all out there and it’s free or at least open.

But what’s the one thing that’s been there from the beginning? I mean, apart from the figureheads, contributors and activists that make up these different but intertwined communities such as Richard Stallman, Linus Torvalds et al. From the beginning open source and free software (I believe there is a distinction, others are welcome to their own opinion) have had at their very core the development of software tools.

Even proprietary software development owes a huge debt to the software tools it uses and provides. Just take a quick look at the often great tools from software houses such as Borland, Sun and even, yes, Microsoft. Tools are crucially important in future technology adoption and I don’t think anyone should underestimate that.

Ever since we climbed out of the primordial soup and developed digits we’ve been building tools. It’s something that’s at the very core of our existence, and it can’t get much more philosophical and fundamental than that! When Richard Stallman began his crusade towards a free operating system he began it with the tools by which such a goal could be achieved. Tools that were then picked up by people who wanted to realize the vision of free operating systems and applications such as Linus (ok, the goals may have been simpler at the time but the end result speaks for itself). Tools are the first step in building anything, and that’s a fun paradox to begin with! Ask yourself ‘what came first, the tool or the software …’ and it can tie your head in knots.

Tools are the often overlooked aspect of the hacker ethos. Not only are we spurred on to get closer to the machine, to develop more and more complex and beautiful software, to share and communicate, to intellectually challenge ourselves or to simply have some fun with these interesting boxes. We want to make things easier for ourselves and our community to attain these goals, and that is why we develop tools and why tools are crucial to the enjoyment of software development.

Whew! now I’m getting into very dark and geeky waters so I’ll sum things up. What’s my point? I’m not sure I have anything profound to point out and some would call what I do have common sense.

My point is simply this, that without open source, free software and even proprietary software development tools we’d all be much sorrier computer users than we’d ever realize because without those tools we’d have nothing.
So my thanks go out to anyone that has developed tools in the past, and my strongest encouragement goes out to everyone to get involved in software tools development projects whether they be open source, free or proprietary depending on your inclination. Get involved now if you are not already doing so because nothing makes this industry richer and brings us closer to the killer apps for technology of the future than the development of tools today.

Without open source and free software my software toolbox would be pretty sparse, what would yours be like?

James Elliott

AddThis Social Bookmark Button

I recently started using Eclipse as my development environment. People already familiar with Eclipse are now spluttering "Recently?! What took you so long?" while the rest of you wonder what the fuss is. Let me try to explain for both groups. Eclipse is an incredibly powerful (and, even more incredibly, free) open-source IDE, with a plug-in architecture that supports deep and rich extension and customization. It ships with the "Java Development Tooling," an add-on that teaches Eclipse how to support the development, testing and maintenance of Java programs. The JDT works so very well that I can no longer imagine developing Java code without it. Although most people probably think of Eclipse as a Java editing environment, the JDT is only one possible tool for the platform, and people are working on others. (I’m particularly interested in the Eclipse Web Tools proposal, which ought to add JDT-style psychic support for editing JavaServer Pages and other artifacts of J2EE web applications).

So if Eclipse is all that, why haven’t I been using it for a while? Well, I have a couple of excuses, some better than others. As a Swing "partisan" (you can’t work on a book as massive as Java Swing and avoid bonding with the material at least a little) I was concerned about Eclipse’s use of the competing "non-standard" SWT graphical toolkit. And in truth, partly because of SWT, early releases of Eclipse didn’t work well at all on Mac OS X, one of my two main platforms. I was only slightly joking when speaking of partisanship, too. There has definitely been some tension, at least, between folks at Sun (and those who strongly support the Java Community Process) and the SWT/Eclipse camp. I like Sun and am grateful for Java… and you have to admit that even the name "Eclipse" seems like a jab. What’s being eclipsed, after all? I had some uneasy feelings upon learning that there was a parallel Eclipse convention nearby during last year’s Java One. We don’t need to fracture our community; the real enemies are still out there! <grin>

Finally, I’d heard some frightening stories from coworkers about bad experiences with WSAD, an ancestor of Eclipse used as the development environment for IBM’s WebSphere Commerce Suite. WSAD insisted on keeping all your source in a DB2 database, rather than text files like you might expect. Not only was this an awkward change for some developers, eliminating their ability to apply many familiar and powerful text-processing command-line tools to the source tree, but the database sometimes got corrupted, causing loss of work. Happily, Eclipse did not inherit this quirk. It works with a normal file system source tree just like an editor should.

When you get right down to it, my biggest obstacle was inertia, which should surprise nobody. I had been using Visual SlickEdit for years, and it had grown into a very powerful and productive environment for me. I had a hard time believing that a free tool could come close. A month ago I was finally pushed into trying it out by my friend Tim who wanted me to build a Swing interface for his hobby project (a program to help people build skill in the game of Go by presenting instructive problems, "tsumego," to explore). Because I’d be working on it at home, where I’ve only got my Mac, I wouldn’t be able to use SlickEdit. I’ve been bugging them for years to release a Mac port, which should be really easy because they already support a ton of other Unix platforms, and I’d be willing to put up with an X Window System interface in order to have the editor at all. But evidently their own marketing studies convinced them I was in the minority, and they never did. Tim told me he was having good luck with Eclipse, and offered to help me get started with it.

Well, I’m no longer waiting for SlickEdit to be ported to the Mac. In fact, I’ve switched to using Eclipse on my Linux machine at work too. It’s that much better at supporting Java development. In fairness, I’m still using SlickEdit for editing the JSPs, because it’s still better at that (and their development focus covers a lot more languages and environments than Java). But it won’t surprise me if soon I find enough Eclipse plugins to address all the areas for which I write code, and stop running Slick at all. Eclipse is a great example of the power of an open, extensible environment in which people all around the world can contribute.

Do you use Eclipse? If so, for how long, and what do you think? If not, what is holding you back?

Dejan Bosanac

AddThis Social Bookmark Button

On one project, I had to build standalone Java server application that will occasionally save some objects into existing database. I’ve chosen to use Hibernate for all database related work (O/R mapping, sessions handling, etc.) and I found it very reliable and easy to use. One thing that I didn’t manage to do straightforward was the key generation.

This was a little piece of a large project with database structure defined a few years ago and one thing that was fixed is the way to obtain unique keys. A database table with name-value pairs was defined and all counters were supposed to be in there. This has proven to be a solid solution. Project had to be easy to port to any client’s choice of database vendor and it was not Java-only project, so idea was to avoid usage of vendor specific sequences. Also, we used this structure not only for unique database keys, but for all other counters that we needed in the project (such as invoice numbers, which are client specific and usually has to be reset yearly).

For the key generation from the database table, Hibernate provides net.sf.hibernate.id.TableGenerator which is using a table that has only one column with the ‘next key value’ in it. So you have to have as many tables as many different generators you want to use. This method is surely a bit faster than one described above, but it is not convenient to use it when you need more then few counters in your system (and even if I want to use it was not possible at this moment).

TableGenerator class is used to execute SQL queries in a separate transaction and TableHiLoGenerator is used to generate the key value using HiLo algorithm (using the value returned from TableGenerator). Also, you can’t use TableGenerator directly. I’m not sure why, I suppose because it is not efficient, but it makes it impossible to use this key generator when Hibernate is not the only tool you’re using to persist data in the database. So idea was to extend TableGenerator to collect appropriate configuration parameters and issue queries that match table structure that I had. But this part of Hibernate wasn’t looking like it was made for any customisation. Instead of writing my own class from the beginning, I’ve reorganized class structure so that it can be easily adapted to any SQL queries that you want to perform to get the next key value. Also, I wanted to provide simple way to apply any high level algorithm to it. For now that would be HiLo algorithm and “incremental” algorithm that will only return the next key value from the database (it’s all I wanted to do in the first place).

For the unique key generation, you need to issue two queries. One to get next key value from the database and one to update the table with the new ‘next value’. Original TableGenerator class, defines these two queries in the configure method. This is fine, because these definitions depends on the configuration parameters that are submitted (such as table name) and SQL dialect. Prepared statements are created from these queries in the generate method and if you want to execute query that has different number of parameters than one in the original TableGenerator you have to override this method. I wanted to avoid that, so I defined two methods prepareQuery and prepareUpdate, which you can override to match your queries. The logic of the generate method remains the same. Also, I changed TableGenerator so that it can be used directly.

One more improvement comes to my mind, but I left it out because it would break the compatibility with current Hibernate features. High level algorithms, such as HiLo, are implemented with subclassing and you can see that TableHiLoGenerator and SequenceHiLoGenerator looks the same (just extends different parent class). I was tempted to decouple this using Strategy pattern, and to make a new interface Algorithm, that will implement this high level behaviour. Later generator could be configured with whatever algorithm we choose, independent of the way we are getting the keys from the database. Currently there is only HiLo algorithm and maybe this refactoring is not justified, but it would enable quick implementation and configuration of new algorithms. Example configuration could be something like this


<id name="id" type="long" column="cat_id">
        <generator class="table">
                <param name="table">hi_value</param>
                <param name="column">next_value</param>
		<algorithm class="hilo">
                	<param name="max_lo">100</param>
		</algorithm>
        </generator>
</id>

This is just an idea, that could be easily implemented and is left for future improvements.

Here you can find the source code and instructions how to configure net.nighttale.hibernate.TableGenerator and net.nighttale.hibernate.MultipleTableGenerator (one that works with name-value tables). It works for me, and I hope it can work for you too. If you find any bugs, inconsistencies or a way to improve it, please contact me.

Advertisement