Monday, August 13, 2007

A Money Class for Free

I am working in the insurance IT sector for almost ten years. There is usually no rocket science in the insurance software - the few things they should do reasonably well is calculating money and performing date arithmetic. I have been always surprised how weak are implementations of money and date arithmetic in these systems. In an attempt to save the world (again), here is my Money class, with documentation. I have made the class immutable as I am now a proud member of the Mutability haters group :-).

Sunday, January 07, 2007

Generating OFX database schema using hyperjaxb

There is a great project at java.net called hyperjaxb (and hyperjaxb2 and hyperjaxb3). It provides JAXB objects with a relational persistence layer, in other words, you can generate database schema right from your XML schema definitions. In the last few days, I tested generating database schema for OFX 2.1.1. The process was not so straightforward, but the following worked in my machine: Download and use hyperjaxb2 (full version). Create a build script. Basically, the whole magic is in two custom ant tasks:
<xjc target="${dir.generated}" schema="${dir.schema.ofx}${file.separator}OFX3_Protocol.xsd" package="${ofx.package.name}" removeOldOutput="yes" extension="true"> <depends dir="${dir.schema.ofx}" includes="*.xsd" /> <produces dir="${dir.generated}" /> <arg line="-Xhyperjaxb2" /> <!-- <arg line="-Xhyperjaxb3" /> //--> </xjc> <taskdef name="export.schema" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="classpath.xjc" /> <export.schema properties="hibernate.properties" quiet="no" text="yes" drop="no" delimiter=";" output="${basedir}/sql/schema.sql"> <fileset dir="${dir.generated}${file.separator}${ofx.package.dir}"> <include name="**/*.hbm.xml" /> </fileset> </export.schema>
I've omitted property definitions, which are obvious. The generated schema file needs some adjustment, but for a large schema, hyperjaxb would save you months of hard work. So far, I had no luck running the whole build process using hyperjaxb3. Hyperjaxb3 is version 0.1.0, so there are some issues... Anyway, I'm looking forward to a stable release (right now, you can get Hyperjaxb3 out of CVS and build yourself). Hyperjaxb3 supports JAXB 2.0, which generates much cleaner code than JAXB 1.X. There are issues to resolve, but hyperjaxb seems to be under active development and the results are promising. More on the development process can be found at lexicore.blogspot.com .

Monday, August 21, 2006

Could not resolve to JVMPI interface

The above error from Eclipse appears when you try to profile an application using TPTP. The whole text looks like this:
FATAL ERROR: JVMPI, an experimental interface, is no longer supported.
Please use the supported interface: the JVM Tool Interface (JVM TI).
For information on temporary workarounds contact: jvmpi_eol@xxxxxxx
Error occurred during initialization of VM
-Xrun library failed to init: piAgent
In my opinion, it is a great example of completely cryptic message. Have I done something wrong? Or have I missed something?

Fortunately, the workaround is quite simple:

Go to Window > Preferences > Agent Controller > Integrated Agent Controller.

Click on the Environment tab.

Change the path of the Java executable to Java 1.4 or 5.

Thanks Ali, now it works!

Friday, March 03, 2006

JavaBlackBelt - Java skills evaluation platform

If you want to assess your Java skills, JavaBlackBelt is a great page for you - it's free, the questions are tough, and there is more to come... (or at least, it seems so).

Monday, February 13, 2006

Loading Video from a Database Table (Update)

In my previous post I described a way of loading video from a BLOB stored in a database table. Now I am presenting a different solution, the BlobDataSource class. BlobDataSource is an implementation of javax.media.protocol.PullDataSource, which creates the data source from a database BLOB and a specified content type. You can get the whole package here.

Thursday, January 26, 2006

Another Potato Medal

Today I tried a free Java 1 test at Brainbench. I am number 4 in Slovakia with score 4.08.

Thursday, November 24, 2005

It compiles! Ship it!

Few days ago I decided to release source code of my (small) financial package.

Now you can download the whole thing in one zip, bundled with javadocs and source code. The build number at the end of file name means that it took me while to make my ant script work... :-)

In my opinion, the interesting classes are AssetCalculator and BondCalculator. They calculate present value, future value, period payment, interest payment, bond prices, bond duration, discount rate, modified duration, yield to maturity, periodic yield, and more. My unit tests show that the results are comparable to values calculated by Excel. So, it's time to ship it!