Andrew E. Bruno

A sourceful of secrets

Archive for July 2007

MySQL bigint types and iBATIS

with one comment

One nuance I recently ran into while using iBATIS was inserting data into MySQL bigint unsigned columns. iBATIS doesn’t seem to have a way to handle BigInteger data types and throws an exception when attempting to do an insert. Fetching data out seemed to work OK because if iBATIS doesn’t know how to handle a certain type it just returns a java.lang.Object. The way to go about inserting BigInteger types is to set up a type handler. Here’s an example type handler for BigInteger types:

package org.qnot.util;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.SQLException;
import java.sql.Types;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

public class BigIntegerTypeHandler implements TypeHandlerCallback {

    public Object getResult(ResultGetter getter) throws SQLException {
        if(getter.wasNull()) {
            return null;
        }

        Object o = getter.getObject();
        if(o instanceof BigDecimal) {
            BigDecimal bd = (BigDecimal)o;
            return bd.toBigInteger();
        } else if(o instanceof BigInteger) {
            return (BigInteger)o;
        } else {
            return o;
        }
    }

    public void setParameter(ParameterSetter setter, Object parameter)
            throws SQLException {
        if (parameter == null) {
            setter.setNull(Types.BIGINT);
        } else {
            BigInteger i = (BigInteger) parameter;
            setter.setBigDecimal(new BigDecimal(i));
        }
    }

    public Object valueOf(String s) {
        return s;
    }
}

Written by Andrew

2007/07/16 at 13:22

Posted in Java

Buffalo Going Green

leave a comment »

Eight windmills now line up the shore of Lake Erie at the site which was once home to the old Bethlehem Steel plant. It’s exciting to see Buffalo on the forefront of renewable energy and this new wind farm dubbed “Steel Winds” is the first urban wind farm in the country. It’s also the world’s first commercial project to use Clipper Windpower’s Liberty series turbines.

Here’s some quick stats about the turbines:

  • Stand approximately 255 feet tall (410 feet with blades extended)
  • Can potentially produce 20 megawatts of pollution-free electric power
  • Could provide the annual electrical needs of more than 6,000 homes
  • Total project cost around $40 million

There’s also talk about expanding the project to include as many as 19 additional windmills.

Sources:
1. http://www.buffaloniagara.org/Home/LatestNews/WindmillPoweraReality
2. http://buffalo.bizjournals.com/buffalo/stories/2007/06/04/daily21.html
3. http://buffalo.bizjournals.com/buffalo/stories/2007/04/16/story9.html

Written by Andrew

2007/07/13 at 20:12

Posted in Personal

Customizing Pidgin Chat Windows

with 4 comments

In my previous post I discussed customizing Gaim chat windows. Since then Gaim has formally changed it’s name to Pidgin due to legal issues with AOL. I finally upgraded to Pidgin and had to do a few minor tweaks to get the same chat window customizations as before. I updated ~/.purple/gtkrc-2.0 which previously resided in ~/.gaim and changed the widget names from gaim_gtkconv_* to pidgin_conv_*. Here’s my updated ~/.purple/gtkrc-2.0 file:

style "pidgin-dark" {
    base[NORMAL]="#000000"
    text[NORMAL]="#00FF00"
    GtkIMHtml::hyperlink-color="#007FFF"
    GtkWidget::cursor-color="#60AFFE"
    GtkWidget::secondary-cursor-color="#A4D3EE"
}
widget "*pidgin_conv_imhtml" style "pidgin-dark"
widget "*pidgin_conv_entry" style "pidgin-dark"

Written by Andrew

2007/07/06 at 21:53

Posted in Hacks, Linux

Follow

Get every new post delivered to your Inbox.