Oracle Jdbc Driver 10.2.0.2.0 fails to render Euro (€) when db is set to WE8MSWIN1252 encoding

We just spent a few glorious hours or so trawling the internet and writing old skool jdbc code, to discover this little beauty. Simply upgrade to 10.2.0.5 of the jdbc driver and it goes away.

Thanks to this post http://efreedom.com/Question/1-377745/Oracle-JDBC-Euro-Character we discovered our problem.

For the full details on the euro….

http://www.fileformat.info/info/unicode/char/20ac/index.htm

And if your really bored:

http://www.fileformat.info/info/unicode/char/1f47e/index.htm

Share

Installing JRuby with Intellij (OS X)

GET it from http://jruby.org/

There is a download page, download and exract the tar file somehwere.

I put it in /System/Library/Frameworks/JRuby.framework/jruby-1.5.1

I then created a symbolic link to jruby_current

ln -s jruby-1.5.1/ jruby_current

And then simply add it to my ~/.bash_profile

$vi ~/.bash_profile
export PATH=/System/Library/Frameworks/JRuby.framework/jruby_current/bin:$PATH
#Reload the profile…
$. ~/.bash_profile
#Try out jruby…
$jruby -v
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]

Now you can add the JRuby SDK to your Java Module in Intellij:

Now you can have ruby and Java in the same project. Awesome.

Share

Link from log console output to a line of code in IntelliJ

Whilst playing around with some code analysis I thought it would be useful to be able to output a hyperlink back to a line of code in the IDE console. As it happens, you can “Trick” IntelliJ to do this with the following log statement:

    @Test
    public void canClickOnAFileInTheConsoleAndGoToTheLineOfCode() {
        log.info(String.format(“Check it at %s. (%s.java:%d)”,
            getClass().getName(), getClass().getSimpleName(), 15));
    }

The pattern it seems to match is something like at {classFullName}.{identifier}({classSimpleName}.java)

classFullName has to be a valid class name.
identifier is usually used for the method name, but it can be anything. The full stop is nescessary. So in the example above, I put a space in there and so it reads like a sentance.

Anyone know a another way to do this?

UPDATE:

Actually it seems that you can get something similar if you output a full path name, e.g.:

    File f = new File(“./src/test/resource/testfiles/level_01/level_01_01/file_01_01_A.txt”);
    log.info(f.getAbsolutePath() + “:” + 34);

This will create a link in the output window to the line of the file. Nice.

Share

XStream collections: when is an ArrayList not an ArrayList ?

I was just getting the following output from XStream when trying to serialize an object which has a collection property:

<addresses class="java.util.Arrays$ArrayList">
<a class="address-array">
<address>

It had to step through the code to see what was going on.

The key is in the subtlety of the type of the list that I was putting in there. Notice that actually its not an java.util.ArrayList its actually an inner class of the Arrays, called, happily $ArrayList, so I had been staring at it the whole time and not noticed.

When XStream serializes its doing the following:

        Class actualType = newObj.getClass();
        Class defaultType = mapper.defaultImplementationOf(fieldType);
        if (!actualType.equals(defaultType)) {
            String serializedClassName = mapper.serializedClass(actualType);
            if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
                String attributeName = mapper.aliasForSystemAttribute(“class”);
                if (attributeName != null) {
                    writer.addAttribute(attributeName, serializedClassName);
                 }
            }
        }

From version 1.3.1 – AbstractReflectionConverter:127

So its asking the mapper what the default implementation of the type is. The type in this case was java.util.List and the default implementation is of course java.util.ArrayList. It is not seeing java.util.Arrays$ArrayList as the same thing and so thinks it needs to specify it.

Now you might be asking, how come I have a strange inner class version of ArrayList ? Well the thing is, I thought I was being clever in the set up of my test data and im using:

       addresses = Arrays.asList(
                new AddressBuilder().addressType(“home”).streetAddress(“1 The street”).build(),
                new AddressBuilder().addressType(“work”).streetAddress(“2 The street”).build(),
                new AddressBuilder().addressType(“holiday”).streetAddress(“3 The street”).build()
        );

To set up my test data. asList does this:

 public static  List asList(T… a) {
	return new ArrayList(a);
    }
    private static class ArrayList extends AbstractList
	implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
	private Object[] a;

Where it uses its own implementation of ArrayList.

Phew, another fun couple of hours spent there.

Share

MacWidgets – Java Swing looking native on OS X

I just discovered Exploding Pixels’ MacWidgets. Its a beautiful library. Literally just pasted a couple of lines of code into my Java app and now it looks right at home on the os x desktop. I’m running JDK 1.6 on Leopard.

Here is is in action:

macwidgets-demo

And here is the code (its been edited slightly so may not copy and paste, but you get the idea) …

 
        MacUtils.makeWindowLeopardStyle(getRootPane());
 
        UnifiedToolBar toolBar = new UnifiedToolBar();
 
        JButton button = new JButton(“My Button”);
        button.putClientProperty(“JButton.buttonType”, “textured”);
        toolBar.addComponentToLeft(button);
 
        getContentPane().add(toolBar.getComponent(), BorderLayout.NORTH);
 
        BottomBar bottomBar = new BottomBar(BottomBarSize.SMALL);
        bottomBar.addComponentToLeft(MacWidgetFactory.createEmphasizedLabel(” Status”));
 
        getContentPane().add(bottomBar.getComponent(), BorderLayout.SOUTH);
 
Share