Oct
14
2009

Use OpenJPA with MySQL: Some Tips


OpenJPA is an implementation of the JPA (Java Persistence API) standards. Initially, I used OpenJPA with Derby which is also known as JavaDB. It works well. However, when i tried to use MySQL as the backend database, I encountered a few issues. Here are a few small tips i would like to share when using OpenJPA with MySQL:

Change the default storage engine

By default, OpenJPA uses innodb as the storage engine. While my application does not need to support transactions and other fancy db features, i’d like to use more plain and “traditional” myisam storage engine. To do so, I just need to set the property “openjpa.jdbc.DBDictionary” with the value “TableType=myisam”. This property object is the one passed to the method “Persistence.createEntityManagerFactory(String, Properties)”.

Allow to store bigger objects (blobs)
By default, OpenJPA maps the java object to mysql data type “blob”. However, as you may be aware of, blob type in mysql only can store up to 65536(216) bytes of data (check http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html), which is quite smaller than the blob in JavaDB or Derby (2G).

Mysql does provide other data types which supports larger storage. mediumblob supports up to 16M while longblob up to 4G. So if I want to store objects other than 64K, I need to change the mapping in OpenJPA. To change the mapping, just set the same property “openjpa.jdbc.DBDictionary”, but with value “blobTypeName=mediumblob”.

If I want both myisam as storage engine and mediumblob as mapped blob type, the property should be set as: “TableType=myisam,blobTypeName=mediumblob”.

Avoid the error “Packet too large”
Now i can save objects up to 16M in size to the database. I run my program, only to find another exception popped up. It says something like “Packet too large”.

This requires the change of mysql server setting as indicated in mysql documentation. The setting “max_allowed_packet“, default to 1M bytes, is too small in my case.

Sep
10
2009

Methods/Software to convert RMVB to AVI

Most current DVD players support playback of Divx or Xvid (usually files with .avi extention) encoded files, but few supports RMVB files which are in real media format.

If you have some RMVB files and want to play them on the DVD player, Then you need to convert the RMVB format to AVI.

Currently, I found out two methods to do this.

The first method is from this article: “How to Convert RMVB“. This method requires you install/download several pieces of software to do this. It’s a bit troublesome, but the article provides very detailed step-by-step instructions and it works.

The other method is to use the open source software alltoavi. It’s quite straight forward to use this software to convert RMVB. And it seems that this method takes less time to do the conversion compared with the first method.

The above two methods both use free software to accomplish the task. There are of course other software that can do this task and they may allow you to have better control for the conversion. Well, you have to pay for it.

Sep
2
2009

Use Ant to Generate ChangeLogs From CVS ang Group by Date

Since version 1.6.1, Ant, the java build tool, has a core task called “cvschangelog“. It is quite useful to use this task to grab a list of recent changes committed to the CVS repository. The output of this task is in XML format. Something like the following:

<changelog>
<entry>
<date>2009-09-02</date>
<time>12:00</time>
<author>robin</author>
<file>
<name>test/ant/task/ChangeLog.txt</name>
<revision>1.2</revision>
<prevrevision>1.1</prevrevision>
</file>
<msg><![CDATA[A commit message]]></msg>
</entry>
<entry>

</entry>

</changelog>

To transform the xml formatted changelog into a human friendly html, you can do an XSL transformation with a XSL file. There is a default one in the Ant distribution, so you can use the following task to get a change log in html format.

<style in=”changelog.xml”
out=”changelog.html”
style=”${ant.home}/etc/changelog.xsl”>
<param name=”title” expression=”Ant ChangeLog”/>
<param name=”module” expression=”the_module”/>
<param name=”cvsweb” expression=”the_url”/>
</style>

The default generated html lists each commit change one by one. In some cases, we want to group the commit changes by dates. To do so, we have to change the default xsl file.

It seems that the new XSLT version 2.0 has specified a group functionality. However, it turns out only a few XSLT tools support this new feature. Fortunately, There is a way that allows us to do the grouping using XSLT version 1.0. By applying this method, we have the following looking xsl code for the HTML <BODY> part.

<body>
<h1>
<a name=”top”><xsl:value-of select=”$title”/></a>
</h1>
<p style=”text-align: right”>Designed for use with <a href=”http://ant.apache.org/”>Apache Ant</a>.</p>
<hr/>

<xsl:key name=”log-by-date” match=”entry” use=”date” />

<xsl:template match=”changelog”>
<xsl:for-each select=”entry[count(. | key('log-by-date', date)[1]) = 1]”>
<xsl:sort select=”date” order=”descending” />
<h2><xsl:value-of select=”date”/><xsl:text></xsl:text></h2>
<xsl:for-each select=”key(’log-by-date’, date)”>

<xsl:sort select=”time” order=”descending” />

<table border=”0″ width=”100%” cellspacing=”1″>
<tr>
<td class=”dateAndAuthor”>
<!– <xsl:value-of select=”date”/><xsl:text> </xsl:text> –>
<xsl:value-of select=”time”/><xsl:text> </xsl:text><xsl:value-of select=”author”/>
</td>
</tr>
<tr>
<td>
<pre><xsl:apply-templates select=”msg”/></pre>
<ul>
<xsl:apply-templates select=”file”/>
</ul>
</td>
</tr>
</table>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

</body>

Use the above code to replace the <body> part in the original changelog.xsl file, then it  will allow you to group the change logs by date.

Jul
23
2009

JSP Expression Language in GWT’s embedded Jetty

JSP expression language (EL) is quite handy. but it only works when you indicate your web application is using version 2.4 or higher. That means you have the following in your <Your-Web-App>/WEB-INF/web.xml:

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app id=”WebApp_ID” version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>

Google Web Toolkit (GWT) is a handy Ajax Web application development tool. Since version 1.6.4, GWT uses Jetty instead of Tomcat as the embedded Web application container.

However, when I installed GWT plugin (version 1.6.4) for Eclipse, the default generated web application used the version 2.3. So when i used expression language in the jsp pages, it didn’t evaluate. Something like “${title}” as the output in the hosted mode running on jetty. It should also be the same result even i deployed to a tomcat container, as the web app version is still 2.3. This is understandable, as Expression Language is part of JSP version 2.0 standard, which is bound with Servlet (Web App) version 2.4. So if you want to make the expression language work, make sure your web app is using 2.4 or higher.

However, while using version 2.4 works fine, i’ve got the same problem when i use version 2.5, which is hard to understand why. This problem seems only in Jetty, not in Tomcat. I don’t know if anyone else have encountered the same problem as I did, but the following link seems to explain the reason behind: http://docs.codehaus.org/display/JETTY/JSP+expression+do+not+evaluate

Apart from this problem (which can be worked around), the use of GWT plugin seems more convenient than the traditional web app development in eclipse. :)

Apr
3
2009

List of Personal Finance Software / Websites for Money Management

It’s a good habit to keep an eye on your money and know how much you have spent in the past and how much you can spend in the future.

Although bank statements, credit card statement or online bank accounts provide all such information, these pieces of information scatter here and there and you lose track quickly and don’t have a whole picture to see where you are going. It gets worse when there are several bank / credit card accounts. So having a software or web sites to consolidate all such information seems a good idea.

Other than using a spread sheet to keep all the information together, there are quite a few sophisticated software or web site to do this job, some cost your money, some just free. The following lists some choices.

Desktop Financial Software – not free
Quicken, Microsoft Money. They are traditional desktop applications. That means you have to install them one your computer before you want to use them to manage your money. I haven’t used them but it should be easy to get started for a normal person.
It seems that quicken has a free online version for money management. However, don’t know how “free” it is and how many features it has.

Desktop Financial Software – free
GnuCash, jGnash. Both of them are free and probably open source software. GnuCash is actually beyond the personal level and can be used for catering small business (seems equivalent to Microsoft office accounting software). To use them, you may probably need to have a little bit of financial knowledge. For example, what is double entry?

Websites / online services / personal finance 2.0?

If you are confident enough to allow third party websites to handle your financial information, then you may embrace such so-called personal finance 2.0 websites. Among them are greensherpa.com, justthrive.com, rudder.com, mint.com and etc.

Most of them can retrieve your transactions from your nominated financial institutions or banks and aggregate them automatically for you and provide basic financial advice based on the data. Some of them charge you subscribe fee to use the online service, while some of them have free versions. However, it seems most of them are US version, i.e., they can only retrieve data from US banks.

Finally, a few words on the financial data formats and standards.
Quicken Interchange Format (QIF) is an open specification for reading and writing financial data to media.
Open Financial Exchange (OFX) comes from Microsoft and Intuit (the maker of Quicken) and it is a data-stream format for exchanging financial information.

The above two formats are quite popular and most of the financial software support the importation and exportation of the files in such formats. And most of the online banking system support them as well.