org.jdom.contrib.input
Class ResultSetBuilder

java.lang.Object
  |
  +--org.jdom.contrib.input.ResultSetBuilder

public class ResultSetBuilder
extends java.lang.Object

ResultSetBuilder builds a JDOM tree from a java.sql.ResultSet. Many good ideas were leveraged from SQLBuilder written from Jon Baer.

Notes: Uses name returned by rsmd.getColumnName(), not getColumnLabel() because that is less likely to be a valid XML element title. Null values are given empty bodies, but you can mark them as empty with an attribute using the setNullAttribute() method. Be aware that databases may change the case of column names. setAsXXX() methods are case insensitive on input column name. Assign each one a proper output name if you're worried. Only build() throws JDOMException. Any exceptions encountered in the set methods are thrown during the build(). The setAsXXX(String columnName, ...) methods do not verify that a column with the given name actually exists. Still needs method-by-method Javadocs.

Issues: Do attributes have to be added in a namespace?

Version:
0.5
Author:
Jason Hunter, Jon Baer, David Bartle, Robert J. Munro

Constructor Summary
ResultSetBuilder(java.sql.ResultSet rs)
           This sets up a java.sql.ResultSet to be built as a Document.
ResultSetBuilder(java.sql.ResultSet rs, java.lang.String rootName, java.lang.String rowName)
           This sets up a java.sql.ResultSet to be built as a Document.
ResultSetBuilder(java.sql.ResultSet rs, java.lang.String rootName, java.lang.String rowName, org.jdom.Namespace ns)
           This sets up a java.sql.ResultSet to be built as a Document.
 
Method Summary
 org.jdom.Document build()
           This builds a Document from the java.sql.ResultSet.
protected  java.lang.String getString(java.sql.ResultSet rs, int column, int columnType)
           
 void setAsAttribute(int columnNum)
           Set a column as an Attribute of a row using the column number.
 void setAsAttribute(int columnNum, java.lang.String attribName)
           Set a column as an Attribute of a row using the column number.
 void setAsAttribute(java.lang.String columnName)
           Set a column as an Attribute of a row using the original column name.
 void setAsAttribute(java.lang.String columnName, java.lang.String attribName)
           Set a column as an Attribute of a row using the column name.
 void setAsElement(int columnNum, java.lang.String elemName)
           Set a column as an Element of a row using the column number.
 void setAsElement(java.lang.String columnName, java.lang.String elemName)
           Set a column as an Element of a row using the column name.
 void setMaxRows(int maxRows)
           Set the maximum number of rows to add to your Document.
 void setNamespace(org.jdom.Namespace ns)
           Set the Namespace to use for each Element in the Document.
 void setNullAttribute(java.lang.String nullAttribName, java.lang.String nullAttribValue)
           Set a specific attribute to use to mark that a value in the database was null, not just an empty string.
 void setRootName(java.lang.String rootName)
           Set the name to use as the root element in the Document
 void setRowName(java.lang.String rowName)
           Set the name to use as the row element in the Document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetBuilder

public ResultSetBuilder(java.sql.ResultSet rs)

This sets up a java.sql.ResultSet to be built as a Document.

Parameters:
rs - java.sql.ResultSet to build

ResultSetBuilder

public ResultSetBuilder(java.sql.ResultSet rs,
                        java.lang.String rootName,
                        java.lang.String rowName)

This sets up a java.sql.ResultSet to be built as a Document.

Parameters:
rs - java.sql.ResultSet to build from
rootName - String name for the root Element of the Document
rowName - String name for the each immediate child Element of the root

ResultSetBuilder

public ResultSetBuilder(java.sql.ResultSet rs,
                        java.lang.String rootName,
                        java.lang.String rowName,
                        org.jdom.Namespace ns)

This sets up a java.sql.ResultSet to be built as a Document.

Parameters:
rs - java.sql.ResultSet to build from
rootName - String name for the root Element of the Document
rowName - String name for the each immediate child Element of the root
ns - Namespace to use for each Element
Method Detail

build

public org.jdom.Document build()
                        throws org.jdom.JDOMException

This builds a Document from the java.sql.ResultSet.

Returns:
Document - resultant Document object.
Throws:
JDOMException - when there is a problem with the build.

getString

protected java.lang.String getString(java.sql.ResultSet rs,
                                     int column,
                                     int columnType)
                              throws java.sql.SQLException

setRootName

public void setRootName(java.lang.String rootName)

Set the name to use as the root element in the Document

Parameters:
rootName - String the new name.

setRowName

public void setRowName(java.lang.String rowName)

Set the name to use as the row element in the Document

Parameters:
rowName - String the new name.

setNamespace

public void setNamespace(org.jdom.Namespace ns)

Set the Namespace to use for each Element in the Document.

Parameters:
ns - String the namespace to use.

setMaxRows

public void setMaxRows(int maxRows)

Set the maximum number of rows to add to your Document.

Parameters:
maxRows - int

setAsAttribute

public void setAsAttribute(java.lang.String columnName)

Set a column as an Attribute of a row using the original column name. The attribute will appear as the original column name.

Parameters:
columnName - String the original column name

setAsAttribute

public void setAsAttribute(java.lang.String columnName,
                           java.lang.String attribName)

Set a column as an Attribute of a row using the column name. The attribute will appear as the new name provided.

Parameters:
columnName - String original column name
attribName - String new name to use for the attribute

setAsAttribute

public void setAsAttribute(int columnNum)

Set a column as an Attribute of a row using the column number. The attribute will appear as the original column name.

Parameters:
columnNum - int

setAsAttribute

public void setAsAttribute(int columnNum,
                           java.lang.String attribName)

Set a column as an Attribute of a row using the column number. The attribute will appear as new name provided.

Parameters:
columnNum - int
attribName - String new name to use for the attribute

setAsElement

public void setAsElement(java.lang.String columnName,
                         java.lang.String elemName)

Set a column as an Element of a row using the column name. The element name will appear as the new name provided.

Parameters:
columnName - String original column name
elemName - String new name to use for the element

setAsElement

public void setAsElement(int columnNum,
                         java.lang.String elemName)

Set a column as an Element of a row using the column number. The element name will appear as new name provided.

Parameters:
columnNum - int
elemName - String new name to use for the element

setNullAttribute

public void setNullAttribute(java.lang.String nullAttribName,
                             java.lang.String nullAttribValue)

Set a specific attribute to use to mark that a value in the database was null, not just an empty string. This is necessary because <foo/> semantically represents both null and empty. This method lets you have <foo null="true">.

Parameters:
nullAttribName - String name of attribute to add
nullAttribValue - String value to set it to.


Copyright © 2004 Jason Hunter, Brett McLaughlin. All Rights Reserved.