Archive for the 'Programming' Category

Eclipse UI Elements: the Vertical Ruler and Overview Ruler

Maybe I’m blind but I’ve looked all over the Eclipse help files and there are references to both the “vertical ruler” and the “overview ruler” yet there isn’t an explanation as to what those terms mean.  Similar searches on Google don’t turn up anything other than Eclipse API references and the Platform programming documentation.  Those do explain what these items are but I think its kind of crazy that there isn’t an explanation right in the Workbench (or Java Editor) docs.  Here is what they mean:

  • Vertical Ruler - the vertical space on the far left of an editor window (next to the gutter that shows line numbers if you have them enabled) that area scrolls along with the content of the editor.  Markers placed here aren’t in view if the line they’re on isn’t in view.    For example: debugger breakpoint indicators are set here and scroll in and out of view as you scroll the editor.
  • Overview Ruler - the vertical space on the far right side of an editor window (to the right of the editor scrollbar). This area shows markers for the whole file being edited and it does not scroll along with the editor window.   This area is used to place markers for such things as errors and occurrences of methods, etc.  For example: this allows you to see approximately where all errors occur in a file.  If you click on one of the indicators it will move the editor to that specific line.

Not earth-shattering information but useful nonetheless ;)

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? :)

Java Posse Podcast #188 - are you guys for real?

I was just listening to the guys describing the Livescribe Pulse Smartpen demo at JavaOne and how great it was but then lamenting that the desktop component only worked on Windows. I know these guys are developers, and I know they’re Mac heads (and in the case of Dick…a Linux guy), but c’mon. This product, while very cool for a demo to developers at JavaOne, really is geared towards business and the general public, in other words people who mainly use Windows. It’s a business and they have to sell to the market that is going to make them money.

I’m not sure how it could be so shocking that the company would market to those people first and maybe add a version of the desktop software for the Mac later. Joe mentioned that he really hated Windows. Good for you Joe and good for them you’re not the guy running the company (into the ground) by worrying about a miniscule market (the Mac) first.

Can you guys ever just point out that something only works on Windows without all of the side commentary? Given the lackluster support of Java on the Mac by Apple (ie: a small segment of the overall Mac market) I’m surprised you guys even mention this kind of stuff.

JavaFX: too little too late?

I know there have been many articles discussing the point of JavaFX and is it too little too late.  After trying out AdobeAIR, and reading DIon’s comments here,  I’m throwing my own brief comment out there.

AIR is what the Java desktop experience should have been a long time ago.  I was amazed at how easy the install process for AIR was.  I already had the Flash plug-in installed (who doesn’t?) and the AIR install was a couple of simple clicks and a really fast download and I was off and running.

Maybe more specifically AIR is what Java Web Start should have been a long time ago.  Kudos to Sun to making the whole thing work a lot better but I think it’s a little too late to make any difference.  I’m just not sure how much relevance Java has on the desktop in the space AIR is sitting comfortably in at the moment.

We’re not going to write every app with AIR but that seems to be the market JavaFX is after and it seems almost ridiculous now.   I guess time will tell but I think they’re wasting resources.

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

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 ;)

This is a comparison?? Eclipse 3.3 or NetBeans 6.0 from JavaWorld

Update: I’m getting quite a few eyes on this posting because of the link from dzone so I wanted to clarify a couple of things. I am referring to the NB project importer that brings Eclipse projects into NetBeans….not the other way around.

Again I want to state that I am not flaming NetBeans ;) I know that people usually have very strong feelings about the environment they use. I am a big fan of the Eclipse/MyEclipse combination. It’s cheap, it offers a lot of functionality, and the support is very good.

I also really like what is happening with NetBeans. 6 is a fantastic release and I wish it fit my workflow better because there are some things that I really like more like the code editor, diff viewer, etc. I think the out of the box experience is far better for NetBeans but I’m already paying for MyEclipse so for me thats where the comparison is most relevant.

——

I saw this link this morning on dzone where the author compares Eclipse and NetBeans with the intention of giving the reader some sort of guidelines as to which environment to choose for development work. Too bad it is just a laundry list of features.

These types of comparisons are really hard to do. You really have to use the products extensively on a real project before you can come to any sort of conclusion and the waters may still be muddy even after that. I’m currently working with both products on a large project and NetBeans still has a way to go before it can compare with Eclipse with MyEclipse (for me). Why?

  • The build process for large projects can be excruciatingly slow.
  • Is there some reason the Eclipse project importer is rewriting my EJB deployment descriptors as EJB 3.0 when they’re EJB 2.1 beans without asking me if that is what I want to do?
  • The CVS support, for those still using CVS, is completely geared toward the branch you’re currently working on. Want to compare some code to another branch? This is easy in Eclipse but apparently not doable in NetBeans.
  • No workspaces. To me this feature is critical because it makes working with various branches of code very easy. I can have totally custom settings for the IDE in the different workspaces as I chose. NetBeans comes closer with Project Groups but it still isn’t quite the same thing.
  • No exploded deployment options for servers other than Glassfish?

You don’t get to these types of things until you start working more in-depth with two products and really start comparing the workflows. Certainly if this is doable by me it’s doable by a journalist.

Don’t get me wrong though as I still really do like NetBeans. Version 6 has a lot going for it and a for an out of the box experience I think it beats Eclipse since Eclipse really requires a lot of extras to get you to the same level. On that note given the cheap price of MyEclipse it is really hard to beat.

NB6: CVS module has no way to compare a file to another branch?

Once again trying out NetBeans and as a long time Eclipse/MyEclipse user I’m pretty frustrated by what seem like limitations but then I’m not sure if it really is a limitation or I’m just not seeing an option somewhere.

In Eclipse and its built-in CVS support you can easily compare a file you’re working on with another branch. This does not seem possible in NetBeans 6 and this is a huge inconvenience. Sure its fine to be able to compare to the server copy of the file in the same branch but when having to work in multiple branches at the same time its nice to be able to see changes between branches. NetBeans only seems to give me the option of switching to another branch or merge from another branch neither of which I want to do. I simply want to see what the differences are between a copy of a file in one branch to another.

Is this possible inside the NetBeans IDE?

NB6: error on “illegal reference to static field” solved

Easy solution (even though it still appears the old way is legal code): move the initializer code into a static method. Instead of:

private static Map byDBValue;

private AssetImporterTypeEnum(String dbvalue) {
this.dbValue = dbvalue;

if (AssetImporterTypeEnum.byDBValue == null) {
AssetImporterTypeEnum.byDBValue = new HashMap();
}

AssetImporterTypeEnum.byDBValue.put(dbvalue, this);
}

We have something more along the lines of:

private static Map byDBValue;

private AssetImporterTypeEnum(String dbvalue) {
this.dbValue = dbvalue;

AssetImporterTypeEnum.init(dbvalue,this);
}

private static void init(String dbvalue, AssetImporterTypeEnum i) {
if (AssetImporterTypeEnum.byDBValue == null) {
AssetImporterTypeEnum.byDBValue = new HashMap();
}

AssetImporterTypeEnum.byDBValue.put(dbvalue, i);
}

The errors magically disappear.

Now, I just hope the code works properly…. :)

NetBeans 6 problem: editor flags error that doesn’t show up in a compile

OK. I’m about to pull my hair out on this one because it’s driving me completely nuts.

Just a bit of background first: I’m giving NetBeans 6 a test run with the current project I’m on to compare it to Eclipse (with the MyEclipse plugins). I keep hearing great things about it and now that I have my projects set up I am noticing a very odd problem that doesn’t happen in Eclipse. We have the following code in one of our enum classes (actually this same pattern is followed in other enums as well):

private static Map byDBValue;

private AssetImporterTypeEnum(String dbvalue) {
this.dbValue = dbvalue;

if (AssetImporterTypeEnum.byDBValue == null) {
AssetImporterTypeEnum.byDBValue = new HashMap();
}

AssetImporterTypeEnum.byDBValue.put(dbvalue, this);
}

The NetBeans editor is flagging the lines that set AssetImporterTypeEnum.byDBValue as an error of type ‘illegal reference to static field from initializer’. From what I can tell this is completely legal code (enums are initialized before any static initializers are run) and the compiler output doesn’t indicate the same error. Actually the compiler output doesn’t indicate any errors. The compile is perfect. I don’t get this error in Eclipse either (neither in the editor or the compiler output)

It’s driving me crazy that I don’t really have errors in the code but the the flag is still showing up both in the editor and in the project tree. Is there some way to change this behavior? Is it a bug (I searched on the bug tracking site for netbeans with no luck)?

Next Page »