Archive for the 'General' Category

Storing JasperReports in a database using iBATIS and Oracle 10g

I’ve used JasperReports in two different jobs now to provide reporting services for clients of the various web applications I’ve worked on. My first experience definitely turned out to be a great learning opportunity.

It was a great opportunity because I learned what not to do when designing a web-based reporting system the main lesson of which was:

  • Don’t store report defintions on the file system.

We experienced a lot of deployment headaches in the clustered application server environment that was provided to us because we were not provided any sort of shared file system for application assets such as reports. Each application server in the cluster only had access to it’s own file system.

This article shows how I solved the file system issue by storing JasperReports report definitions in a database. I’ll assume familiarity with the iBATIS “ORM” database framework since I am not showing a full iBATIS setup here.

Part 1: Oracle Setup

The first thing that I did was get my database tables in place. Our needs were pretty simple and I created two tables: one, REPORT, to hold the various pieces of information about the report such as the name, description, and ID and another, REPORT_XML, to hold the actual report definition. These are tied together via a foreign key on the ID column of the REPORT and a REPORT_ID column on the REPORT_XML table. The most important piece of information here is the choice of the datatype to hold the report definition.

To allow easy creation of reports we are using the iReport visual report designer and saving the reports in the JRXML format. I didn’t see any benefit to compiling the definition and putting that in the database. With XML it makes the report definition fairly easy to read and very easy to parse should that be necessary. With that in mind I chose to use the CLOB type in Oracle.

CLOBs are good for storing large pieces of character data and they are handled effortlessly by iBATIS since the only thing being passed in to the library are String objects. As of release 10g of the Oracle JDBC driver there is no longer a need to use the extensions that Oracle provided for dealing with CLOBs (oracle.sql.CLOB) in previous releases. The only requirement is setting a new Connection property, SetBigStringTryClob, to true. When this is done the String being passed in to a PreparedStatement (or to a ResultSet for data coming out of the CLOB column) is inspected to find it’s size and if its over 32k a different call is made, to an OraclePreparedStatement object, to set the CLOB value properly. This is handled transparently by the driver.

The iBATIS and Java Code

Let’s take a look at how this works. Here is an iBATIS XML snippet to handle inserting a report definition into the REPORT_XML table:

<insert id="addReportXML" parameterClass="map">
  insert into report_xml
  (id,last_modified_date,last_modified_by,description,report_id,xml_def)
  values (#id#,sysdate,user,#reportId#,#reportId#,#xmlData#)
</insert>

There is no special CLOB handling here. We are just dealing with standard types.

Here is the code in my DAO object that is calling the insert statement above:

private int addReportXML(String reportId, String xmlData)
{
 
  IdManager idMgr = IdManager.getIdManager();
  Connection connection = null;
  int result = 0;
 
  Map paramMap = new HashMap();
  paramMap.put("id", idMgr.getUniqueId());
  paramMap.put("reportId", reportId);
  paramMap.put("xmlData", xmlData);
 
try
{
  result = this.getSqlMapClientTemplate().update("ReportConfig.addReportXML", paramMap);
 
} catch (SQLException e) {
 
}
 
return result;
}

In my actual code I do have exception handling code in the catch block above ;) I am just trying to only include the important stuff here and for this posting database error handling isn’t important. I also left out the connection handling.

IdManager is just a class that will generate a unique ID string based on various bits of system information. We could use a sequence generator in the database as well the the ID generator works better for how we deploy our applications.

This code is obviously pretty straightforward. The only thing we are doing here is passing in a String that contains the full XML as well as the report ID this report definition corresponds to. Java Strings can be very large (char array indexed by an integer) so you’d have to have an awfully large report definition to reach that limit.

Just note again that we are only dealing with standard types here. There is no special handling being done by either the Java code or iBATIS. All of the heavy lifting is being done internally by the Oracle JDBC driver.

That is pretty much it. There is nothing special that needs to be done to store the JasperReports report definitions in the database. Had I known on the first project that it was this easy I certainly would have done it this way ;) It is better by far to centralize the storage of the reports when deploying in a clustered environment. It allows easy deployment and updating, easy backup and recovery, and easy access. How can those be bad things? :)

Perhaps the ultimate GTD tool?

The Livescribe Pulse Smartpen.

Not sleeping…just thinking :)

I posted here today with the subject ZZZzzz… and indicated I was going to be taking a break for a bit.  I decided soon afterwards to remove that post and continue posting.    I have my reasons for such an abrupt change.  Worry not fearless reader (the few of you out there)…. I’m still here ;)

All that is necessary to be a saint is to want to be one

But Lax said: “No, All that is necessary to be a saint is to want to be one. Don’t you believe that God will make you what He created you to be, if you will consent to let Him do it? All you have to do is desire it.”

So says Thomas Merton in “The Seven Storey Mountain”. I ask “is it really that easy”?

I’m not a religious person by any stretch of the imagination. Spiritual yes, but not religious. So in reading this book by Merton my eyes start to glaze over when he starts expounding the virtues of religion and the necessity of faith in God to complete one’s life. Having said that if I try to take a broader view a more interesting picture begins to take shape.

I’ve had enough experiences in my life that proves, to me at least, that there is some “higher power”. I don’t necessarily believe that higher power is God, or resembles God in any way. I don’t think this higher power is watching over us and I certainly don’t think this higher power cares about my sins. But I do think this power is available for us to channel when we need to which is why I’ve found this passage by Merton so interesting.

Is it really that obvious that by thinking about something you can make that thing happen? Is simply asking for it enough? I’ve tried and it has worked in the past. I’ve asked for proof and been given that proof but somehow I always struggle with these ideas. What, in the words of Merton, did God create me to be? How do I figure it out?

In my current situation in life I struggle a lot. Something doesn’t feel right and I feel disconnected, without purpose. Is the answer simply to stop struggling, ask for help, and just be?

Sayonara U-verse…it’s been a slice

“So when are you actually going to do something about the noise the Tivo is making?” I’d only been talking about fixing the whining hard drive in the DirecTivo for about a year and my wife was reminding me again that I’d been talking about doing something about it, well, for a year. “Soon” I said. “But the places that sell the drive replacements online aren’t exactly cheap and we’ve got a bunch of other stuff coming up that are a higher priority.”. But damn that whining was annoying.

Coincidentally I was talking with a friend, Brian, about AT&T and their U-verse product because at some point they’ll probably start working on fiber-to-the-curb like Verizon has been doing with FIOS. I had checked the U-verse page quite awhile ago to see if it had been available at my house and at the time I was out of luck. I checked again though right after I finished talking with Brian and it turned out that U-verse was available at my house. Even more shocking was the fact that I could get the system installed the next day if I wanted. I signed up for an install and thought I was saying so long to DirectTV.

Let me talk about DirecTV for just a moment because I’ve had their DirectTivo service almost since it was first available. The price has always been right, the programming selection has always been good, and I’ve always had good results with their customer service. The two strikes that they always had against them, even though both happened only sporadically, were rain fade and snow on the dish.

Rain fade, in most storms, affected almost every channel but the local channels I was receiving via DirecTV. During a big storn, that could be miles away from us but still between us and the satellites, we’d lose every channel that wasn’t on a spot beam. A spot beam is how DirecTV broadcasts your local channels and the signal area is much tighter than the general signal and generally much higher power. In the worst storms we’d lose those as well but most of the time they were OK.

The other big hit was snow build up on the dish out in our backyard. Simple enough to clean off but in any significant storm, and we had a lot of those this past winter, it is a drag to have to trudge out in the snow to brush off the damn dish to be able to watch TV. Admittedly this hasn’t been too much of a problem but it was really annoying this past winter. U-verse had the promise, like cable TV, of no rain fade and no concerns about snow. Enter U-verse.

For $60 We’d get more channels than we had with DirecTV. We’d also get a DVR unit that would record up to four standard definition (ie: regular TV) shows at once which is great because we don’t currently have HDTV. With the DirecTivo we’d had only 2 recordings at once as a possibility. Oh, and not contracts. I wasn’t really sure what else to expect aside from those things but it sounded like a good trade-off so that is why I ordered the service.

The serivce guy shows up. He does a nice install job. The new wiring required for the DSL line was very cleanly done. He didn’t ask me where I wanted things installed but he was a nice guy and did a nice job overall so I really didn’t care much. I could always move it myself. When he left I had an upgraded DSL circuit with a bit more download speed and a significant boost in upload speed. I had a new router which I wasn’t too happy about initially since I really like my Linksys WRT54g but since I didn’t have a choice and hadn’t explored the 2wire unit that was installed yet it really wasn’t that big of a deal.

I also had the DVR unit upstairs which was connected to the 2wire “Residential Gateway” in the basement by coax cable. The installer had it easy because the only thing he had to do was disconnect one of my two wires coming in from the DirecTV dish outside and hook it up to the 2wire gateway device. He didn’t have to cut anything since the installer for DirecTV did a great job way back when I had DirecTV service first installed. The AT&T guy only needed to unscrew the coax from the grounding block on the wall for the satellite and screw it in to the gateway device. The other end only needed to be unscrewed from the old DirecTivo unit to the new U-verse DVR. Pretty simple stuff.

So how is the service? Pretty good.

  • The picture quality for standard definition is better than what I was getting with DirecTV.
  • How can you complain about 4 recordings at once? T
  • The system is snappy and channels change quickly.
  • Since the system is integrated with DSL I can access some AT&T Yahoo! stuff pretty easily like
    • My Flickr account and all the photostreams in it.
    • Some AT&T Yahoo! games.
    • Via the “U-bar” my local weather, stock portfolio, etc.
  • Video on demand which we didn’t have with DirecTV.
  • You can program recordings and delete old recordings remotely.

So I’m speaking in the past tense here about DirecTV yet the title of this post is bye-bye AT&T so what gives? Well, the initial honeymoon was short lived and my wife and I quickly started to not like the service. We had three major complaints with the service that caused me to go crawling back on my knees to DirecTV (well, not really but I’ll talk about that in a moment).

  1. We lost the ability of the the DirecTivo to have two shows being buffered for playback at the same time.

    The DirecTivo has two physical tuners built in and via the remote control you could switch between the two. Want to have the local news buffering in the background while you watch something else and then, during commercial breaks in the important show, go back and scan the news? Easy as pie on the DirecTivo. Switch each buffer to a different channel and you’re set. All of this without having to worry about recording something. Turns out losing this feature is one of the biggest complaints people have about the newer, non-Tivo, DirecTV DVRs as well. More on that later.

    With the AT&T unit any change away from the channel you’re watching clears out the buffer. The scenario I laid out above simply isn’t possible and quite frankly that was a show-stopper. The unit even clears out the buffer of the currently watched channel even if you stay on that channel but watch something that has already been recorded.

  2. We lost the XM music channels that are provided by DirecTV.

    You might think I’m nuts but that was a big deal for me. I’m a classical music freak and I listened to the XM classical stations a lot.AT&T, which apparently provided Music Choice at some point and which I had with DirecTV before (maybe it was Dish), switched their music to URGE which, quite frankly, sucks. The classical selection really stunk. Based on reports I’ve read on various U-verse-related forums I was not the only person not happy with those music channels.

  3. No FitTV.

    Laugh if you will but it is an important channel for my wife.

    The thing that was odd was how AT&T had their programming. FitTV was actually available with their U Family package which was the low-end offering. It wasn’t available (along with others) in the next two tiers, U100 and U200. U200 was the offering I chose for $60 a month. It was available in the U300 tier which is an extra $20 a month but includes some movie channels.I don’t give a damn about movie channels. I’ve tried them multiple times with DirecTV and always end up dropping them because they play the same stuff far too often to make it worth my money.

    I can’t understand why FitTV wasn’t in the U200 offering. It seemed very odd since almost every other channel is included in that tier aside from the movie channel offerings.

Given those things I wasn’t too comfortable sticking with AT&T for TV service and decided to hightail it back to DirecTV and hope they’d take me back (OK I’m exaggerating..I hadn’t canceled my service yet).

I called DirecTV last Tuesday, less than a week after having U-verse installed, to cancel my account. Not surprisingly they offered me incentives to stick with them having been a customer for so long. I was offered $10/month off my bill for a year plus a new DVR unit for free. The DVR upgrade means I will be sticking with DirecTV for another two years but I guess that is OK as I’ve been with them for six years already ;) Given the issues I wrote about above I accepted their offer. Last Friday I received the new DVR unit, an R15 model, via second-day FedEx and hooked it up.

A bit later I will post about the R15 and the annoyances we have with it but I’ve got XM back, my wife has FitTV back, we still have two tuners, and life is good. Oh, and DirecTV added the ability to at least set up new recordings remotely. The feature isn’t as good as what AT&T offers but it’s close and very convenient.

Overall the AT&T service was pretty good but some issues were just too much for us to overcome. I’d actually recommend the service to other people if they didn’t care about the types of things I outlined above. The price is fair, there is no contract, and you get good DSL service too boot.

Amiga “Still Alive”

After the Commodore 64 I became an Amiga fanatic. It was easy as the machine was so far ahead of anything else at the time. The Amiga came to an early demise thanks to the spectacular mismanagement at Commodore.

I haven’t thought about the Amiga in a long time but wow did this one bring back the memories

Eric Schwartz did a lot of fantastic stuff on the Amiga and now we have an animation for the song Still Alive from the game Portal done on an Amiga 4000.

Enjoy!

Digg: http://digg.com/comics_animation/Amiga_Still_Alive

Today’s Political Funny

From Talking Points Memo:

And how pathetic is the Clinton campaign that they cannot come up with the name of just one freakin’ economist to throw back at the talking heads when they ask their favorite question of the moment “Just name one economist that agrees with the gas tax holiday.” You can’t find some hack Econ prof at East Jesus State University that will go on the record in favor? Are you kidding me? And this is the “grown up” campaign that is ready to roll on “day one”? I wouldn’t hire these people to wash my car.

Great act of sportsmanship

This was a nice story to see especially given most of the horrible stories we normally see in the news (or just plain old crap)

[vodpod id=ExternalVideo.526677&w=425&h=350&fv=id%3D7635680] from brainfreezeblog.word posted with vodpod

Dashing to beat procrastination - trying out (10+2)*5

Yeah…(10+2)*5. I0 minutes of work, 2 minutes of break repeated for 5 cycles.  This is Merlin Mann’s system to beat procrastination which he first wrote about back in 2005.  I had read about this ages ago on 43 Folders (the article is pretty old already) but never tried it.  Today I started.

I’ve had feats of concentration so heroic there should be epic stories (you know…like the Odyssey) written about them.  Those are few and far between though ;) Normally I have a real problem getting things going.  I can procrastinate with the best of them and I’ve been that way my whole life.  I’m not sure what it is but it seems that I have two problems: being able to break tasks down into manageable pieces and, these days,  being too attracted to the many distractions that is the internet.  Overall it hasn’t hurt my effectiveness because I get things done on time.  I just don’t like how I get there so it was time to give anything a shot that might help.  That is where (10+2)*5 comes in.

I was reading the other day about an application for Windows called Instant Boss that was designed specifically to time the dashes.  It actually isn’t limited to (10+2)*5, you can set the values to whatever you want.  The default is (10+2)*5 and that’s what I’ve started with.  So far it is working great.

One of the things all of these dashes seem to do (at least according to the authors) is get you to the point of working to where you start to skip the breaks.  This was true for me even on this first day of trying it.  The 10 minutes go by, you get the signal from the application to take a break, but you are in the middle of something and don’t want to stop so you hit the “skip break” button and go on for another 10 minutes.   This whole thing is fantastic because I’m moving towards a goal, sometimes in 10 minute chunks, sometimes longer, with what seems like little effort.   I suppose the knowledge that after 10 minutes you are free to let your mind wander for a bit is the key.

There is also another dash from Jeff Covey called The Progressive Dash which also sounds fascinating but again leads to the same thing as the other dashes:

By the end of that time, I wish I could continue and get more done. Pretty soon, I’m wanting to get back to it and finish it instead of procrastinating about it.

Exactly how the (10+2)*5 thing worked for me.  Amazing in it’s simplicity.  Limitless in its power for Good.  ;)

If you’re going to set up a wiki (or anything like it) take the time to do it right

Had a conversation with a coworker the other day about the sorry state of our “intranet” at work. Drupal was set up prior to my having started there and to date nothing has been done to make it worth using. I mentioned that we should just get Confluence in and try it out. I’ve had lots of experience with it at my past employer and it’s fantastic software. The out-of-the-box functionality is great. Also, given that the plug-in architecture makes it very easy to add plug-ins, expanding the capabilities is very easy. Oh, and it isn’t expensive. Not free, but not expensive.

The response I received was basically that well, we had installed Drupal but we haven’t really done much with it. Ummm…yeah. That is exactly my point and why I mentioned Confluence. We don’t have the time to be dinking around with Drupal and, given that we also use JIRA it might be a good idea to give Confluence a look. Yet we keep adding documents and attachments to Drupal with no real guidelines and it’s already a mess.

I’m all for a content repository but if you’re not going to give it some love then it really isn’t any better than a shared network drive. Out of the box Confluence will index Word, Excel, PowerPoint, PDF, etc. so searching for stuff is really easy. Drupal? Nope. Charting of data (which we do all the time via Excel files either emailed or attached to a Drupal page)? Confluence: you bet. With a plug-in it will even chart Excel and CSV data (or SQL queries for that matter). Drupal? Nope. JasperReports (which we are starting to use for a product)? Confluence: yep. Drupal? Nope.

I guess I just don’t get it. In *my* opinion the answer is staring us in the face and its about $2,200 with source code ;)

« Previous PageNext Page »