How to get information on UNIQUE keys on Apache Derby

It’s not easy to get information on derby keys once you created them. I was looking for a command like “SHOW CREATE TABLE ” but no luck. I realized that the answer should lay in SYS tables. After googling a while I found the following bit of wisdom: The following query will give you the UNIQUE constraints on a table: select c.constraintname, c.constraintid from sys.systables t, sys.sysconstraints c where t.tablename = ‘FOO’ and t.tableid = c.tableid and c.type = ‘U’; ...

October 16, 2007

Passing configuration parameter to Axis2 services

One way to pass parameters to you Axis2 service: write a tag inside your services.xml <?xml version="1.0" encoding="UTF-8"?> <!-- This file was auto-generated from WSDL --> <!-- by the Apache Axis2 version: 1.3 Built on : Aug 10, 2007 (04:45:47 LKT) --> <serviceGroup> <service name="xxxxxxx" class="MyServiceLifeCycleImpl"> .... <parameter name="jdbcConnectionString">jdbc:derby:c:/demoderby2b;create=true;user=a;password=b;</parameter> <parameter name="jdbcDriver">org.apache.derby.jdbc.EmbeddedDriver</parameter> ... </service> </serviceGroup> Write a ServiceLifeCycle class public class MyServiceLifeCycleImpl implements ServiceLifeCycle { private Log log = LogFactory.getLog(MyServiceLifeCycleImpl.class); public void startUp(ConfigurationContext confCtx, AxisService axisService) { try { String jdbcConnectionString = (String) axisService.getParameterValue("jdbcConnectionString"); String jdbcDriver = (String) axisService.getParameterValue("jdbcDriver"); Class.forName(jdbcDriver).newInstance(); Connection connection = DriverManager .getConnection(jdbcConnectionString); axisService.addParameter("jdbcConnection", connection); } catch (Exception e) { throw new RuntimeException(e); } } .... Add init method to your service .... private ServiceContext serviceContext; public void init(ServiceContext serviceContext) { this.serviceContext = serviceContext; } .... Access the parameter jdbcConnection from your service through serviceContext .... Connection conn = (Connection) serviceContext.getAxisService() .getParameterValue("jdbcConnection"); ....

October 16, 2007

Two web applications sharing the same Derby database

I just realized that to be able to open/share the same Derby database from two different web applications running in the same Tomcat instance (same JVM) you’ll need to put derby.jar in the $TOMCAT_HOME/common/lib and remove it from your applications WEB-INF/lib. I got the clue from this RIFE web page the jarfiles you need are derby.jar and derbytools.jar . Due to classloader peculiarities, don’t copy them to your application’s web/WEB-INF/lib/ subdirectory, or to Tomcat’s shared/lib/ directory. Tomcat’s common/lib/ directory works, and probably common/endorsed/ does too. ...

October 15, 2007

Dojo, JSON, Xstream and FLEXJSON

I’ve been trying to use XStream to generate JSON to be consumed by Dojo. But I can’t find the way to generate the right JSON from XStream, it keeps adding extraneous {} around. I even tried this but no luck . For example I want to generate this JSON output (taken from Dojo FilteringSelect example) : {"identifier":"abbreviation", "items": [ {"name":"Alaska", "label":"Alaska","abbreviation":"AK"}, {"name":"Wyoming", "label":"Wyoming","abbreviation":"WY"} ]} My attempt usign XStream: package com.rubenlaguna.json; import java.util.ArrayList; import java.util.Collection; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; class ItemCollection { public String identifier; public Collection<Item> items = new ArrayList<Item>(); public ItemCollection(String identifier) { this.identifier = identifier; } public boolean add(Item arg0) { return items.add(arg0); } } class Item { public String name; public String label; public String abbreviation; public Item(String name, String label, String abbreviation) { this.name = name; this.label = label; this.abbreviation = abbreviation; } } public class WriteXStreamDojoTest { public static void main(String[] args) { ItemCollection itemCollection = new ItemCollection("abbreviation"); itemCollection.add(new Item("Alaska","Alaska","AK")); itemCollection.add(new Item("Wyoming","Wyoming","WY")); XStream xstream = new XStream(new JettisonMappedXmlDriver()); String erroneousJsonStr = xstream.toXML(itemCollection); System.out.println(erroneousJsonStr); } } resulted in the following JSON Output (i added some space and breaklines for readability): ...

October 9, 2007

Eclipse Bug #201116 update: Switch compare viewer for java files

I’ve submitted a patch (Attachment #77777 and a couple of screenshots ( Attachment #77774 y Attachment #77776) to Bug #201116. It’s only a preliminary work but it enables the user to select with contentMergeViewer to use with each FileType/ContentType. Now it’s only useful if you use my java formatting compare plugin. Currently the org.eclipse.compare subsystem will allow only one contentMergeViewer per fileType or contentType and you cannot tell which one it will be as Szymon Brandys comments. With this patch the user can select/switch which one he wants to use among all viewer registered for a given file extension/content type. ...

September 6, 2007

Eclipse #201116 contentMergeViewers discarded

I filled Bug 201116 – Compare will silently discard additional contentMergeViewers associated with the same file extension a couple of days ago. As Szymon Brandys says eclipse should allow the user to switch between the differente merge viewer available for a given extension. He proposes two solutions: Having a mechanishm inside the compare view to do the switch or having a preference page to do the same I feel more inclined towards the second solution, as I’m used to change the defautl editor for .xml, etc though the preference page General -> Editors -> File Associations. Having a similar preference page would fit me. I’m trying to figure out how to integrate a preference page to org.eclipse.compare and send it back to eclipse.org to include it in the next release.

August 31, 2007

Updating the java compare plugin

I received some comments about my java compare plugin about my plugin ignoring preferences for text font and formatter settings. I didn’t address those at the beginning because I didn’t notice so as soon as I realized that was missing I put my hands at work. The java formatter settings was easy just modifying the old final Properties options = new Properties(); final CodeFormatter codeFormatter = ToolFactory .createCodeFormatter(options); with final Map options = JavaCore.getOptions(); final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); That’s easy. The font issue was also easy, just adding the following snippet to the plugin.xml did the trick: ...

August 23, 2007

Eclipse Compare. Ignoring java formatting changes not only whitespace.

I met some difficulties dealing with the default eclipse java compare. I got involved on a project where everybody likes to commit code to CVS formatted their way, so comparing between CVS revisions is almost impossible. So I decided to start investigating about Eclipse plugin development to make a Java Compare Viewer that not only ignores whitespace but also all java formatting changes. The result is the following *Before *ignore java formatting plugin: ...

August 18, 2007

Eclipse Error Reporting: Exception stacktrace details

I’m working with Eclipse 3.2.2 RCP right now and I’m getting an exception that I want to display on screen. I found in the eclipsepedia that we must use ErrorDialog to report errors: try { // ... } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, Application.ID, 1, "Exception found.", e.getCause()); ErrorDialog.openError(window.getShell(),"Error while loading file", null,status); } But using this code snippet will only print the e.getLocalizedMessage() in the Details pane of the ErrorDialog. See screenshot ...

July 25, 2007

Java bug producing SAAJ0511 error

I run onto the following exception a couple of days ago: Caused by: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces. at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr (CoreDocumentImpl.java:2421) the following log trace was also present in the log file SEVERE: SAAJ0511: Unable to create envelope from given source Apparently I run onto a known java bug present in jdk1.5.0_08 up to jdk1.5.0_11. Funny, I downgraded to jdk1.5.0_07.

July 5, 2007