org.brains2b.sql
Class SQLRecord

java.lang.Object
  extended by org.brains2b.sql.SQLRecord
All Implemented Interfaces:
java.lang.Cloneable

public class SQLRecord
extends java.lang.Object
implements java.lang.Cloneable

Object for containing results from a Select statement

Version:
1.01 [23-10-2007]
Author:
dennis@brains2b.nl

Constructor Summary
SQLRecord()
          Constructor for SQLRecord.
SQLRecord(int initialSize)
          Constructor for SQLRecord.
 
Method Summary
 java.lang.Object clone()
          
 SQLRecord cloneDefinition()
          clone the definition of this record, but not the values set for any of the columns
static SQLRecord createEmptyRecord(java.sql.ResultSetMetaData meta)
          automatically create a new SQLRecord structure from ResultSetMeta
static SQLRecord createRecord(java.sql.ResultSet rs)
          automatically create a new SQLRecord from a ResultSet
 boolean equals(java.lang.Object obj)
          determines if two objects are equal by comparing their hashCodes
 boolean getBoolValue(int idx)
          get the value of the column at the given index as a boolean.
 boolean getBoolValue(java.lang.String name)
          get the boolean value belonging to the column identified by name
 java.lang.String getColumn(int idx)
          get the column identifier for the column at the given index
 int getColumnCount()
          get the number of fields in this cursor data object
 java.lang.Class getColumnType(int idx)
          get the column type for the column given by the specified index
 java.lang.Class getColumnType(java.lang.String name)
          get the column type for the column identified by name
 double getDoubleValue(int idx)
          get the value of the column at the given index as a double.
 double getDoubleValue(java.lang.String name)
          get the double value belonging to the column identified by name
 int getIndex(java.lang.String name)
          get the index of the column identified by name
 int getIntValue(int idx)
          get the value of the column at the given index as an integer.
 int getIntValue(java.lang.String name)
          get the intValue belonging to the column identified by name
 long getLongValue(int idx)
          get the value of the column at the given index as a long.
 long getLongValue(java.lang.String name)
          get the longValue belonging to the column identified by name
 java.lang.String getString(int idx)
           
 java.lang.String getString(java.lang.String name)
           
 java.lang.Object getValue(int idx)
          get the value of the column at the given index as an Object
 java.lang.Object getValue(java.lang.String name)
          get the value of the column identified by name as an Object
 int hashCode()
           
 void setColumn(int idx, java.lang.String name)
          set a column identified by name at the specified position
 void setColumn(int idx, java.lang.String name, java.lang.Class c)
          convinience method to set the column name,class and value at once at a given index
 void setColumn(int idx, java.lang.String name, java.lang.Class c, java.lang.Object value)
          convinience method to set the column name,class and value at once at a given index
 void setColumnType(int idx, java.lang.Class c)
          set the Class identifying the type of content for this column by index.
 void setValue(int idx, java.lang.Object value)
          set the content value for the specified index
 void setValue(java.lang.String name, java.lang.Object value)
          set the content value for the column identified by name
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLRecord

public SQLRecord()
Constructor for SQLRecord.

Sets the initial size to 0


SQLRecord

public SQLRecord(int initialSize)
Constructor for SQLRecord.

Parameters:
initialSize - int, the number of columns to create for this Record
Method Detail

getColumnCount

public int getColumnCount()
get the number of fields in this cursor data object

Returns:
int, the number of columns

setColumn

public void setColumn(int idx,
                      java.lang.String name)
set a column identified by name at the specified position

Parameters:
idx - int, the index to set the column to
name - String, the identifier for this column

getColumn

public java.lang.String getColumn(int idx)
get the column identifier for the column at the given index

Parameters:
idx - int, the index of the column
Returns:
String, the column identifier

setColumnType

public void setColumnType(int idx,
                          java.lang.Class c)
set the Class identifying the type of content for this column by index.

Parameters:
idx - int, the index of the column
c - Class, the class identifying the content for this column. Use the Integer.TYPE, Boolean.TYPE, etc. for the primitives

getColumnType

public java.lang.Class getColumnType(java.lang.String name)
get the column type for the column identified by name

Parameters:
name - String, the column identifier
Returns:
Class, the Class-definition of the column, for primitives are returned as Integer.TYPE, Double.TYPE, etc.

getColumnType

public java.lang.Class getColumnType(int idx)
get the column type for the column given by the specified index

Parameters:
idx - int, the index of the column
Returns:
Class, the Class-definition of the column, for primitives are returned as Integer.TYPE, Double.TYPE, etc.

setValue

public void setValue(int idx,
                     java.lang.Object value)
set the content value for the specified index

Parameters:
idx - int, the index of the column
value - Object, the value for this specific column. The type of Object should be consistent with the type of column you defined through setColumnType(int,Class)
See Also:
setColumnType(int, Class)

setValue

public void setValue(java.lang.String name,
                     java.lang.Object value)
set the content value for the column identified by name

Parameters:
name - String, the column identifier
value - Object, the value for this specific column. The type of Object should be consistent with the type of column you defined through setColumnType(int,Class)
See Also:
setColumnType(int, Class)

setColumn

public void setColumn(int idx,
                      java.lang.String name,
                      java.lang.Class c,
                      java.lang.Object value)
convinience method to set the column name,class and value at once at a given index

Parameters:
idx - int, the index of the column
name - String, the column identifier
value - Object, the value for this specific column. You can set the column type afterwards. The value and type should be consistent

setColumn

public void setColumn(int idx,
                      java.lang.String name,
                      java.lang.Class c)
convinience method to set the column name,class and value at once at a given index

Parameters:
idx - int, the index of the column
name - String, the column identifier
value - Object, the value for this specific column. You can set the column type afterwards. The value and type should be consistent

getValue

public java.lang.Object getValue(int idx)
get the value of the column at the given index as an Object

Parameters:
idx - int, the index of the column
Returns:
Object, the value of this column, will return null if no previous value was set

getBoolValue

public boolean getBoolValue(java.lang.String name)
get the boolean value belonging to the column identified by name

Parameters:
name - String, the name of the column
Returns:
boolean, the value for this column, false if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getBoolValue

public boolean getBoolValue(int idx)
get the value of the column at the given index as a boolean.

Parameters:
idx - int, the index of the column
Returns:
double, the boolean value for this column, false if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getDoubleValue

public double getDoubleValue(int idx)
get the value of the column at the given index as a double.

Parameters:
idx - int, the index of the column
Returns:
double, the double value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getDoubleValue

public double getDoubleValue(java.lang.String name)
get the double value belonging to the column identified by name

Parameters:
name - String, the name of the column
Returns:
double, the value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getIntValue

public int getIntValue(int idx)
get the value of the column at the given index as an integer.

Parameters:
idx - int, the index of the column
Returns:
int, the int value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getLongValue

public long getLongValue(int idx)
get the value of the column at the given index as a long.

Parameters:
idx - int, the index of the column
Returns:
long, the long value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getLongValue

public long getLongValue(java.lang.String name)
get the longValue belonging to the column identified by name

Parameters:
name - String, the name of the column
Returns:
long, the value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getString

public java.lang.String getString(java.lang.String name)

getString

public java.lang.String getString(int idx)

getValue

public java.lang.Object getValue(java.lang.String name)
get the value of the column identified by name as an Object

Parameters:
name - String, the column identifier
Returns:
Object, the value for this column

getIntValue

public int getIntValue(java.lang.String name)
get the intValue belonging to the column identified by name

Parameters:
name - String, the name of the column
Returns:
int, the value for this column, 0 (zero) if the column is not defined (yet)
Throws:
NumberFormatException, - If the value set to this specific column cannot be cast to an int

getIndex

public int getIndex(java.lang.String name)
get the index of the column identified by name

Parameters:
name - String, the column identifier ignoring case
Returns:
int, the index of the column

equals

public boolean equals(java.lang.Object obj)
determines if two objects are equal by comparing their hashCodes

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

cloneDefinition

public SQLRecord cloneDefinition()
clone the definition of this record, but not the values set for any of the columns

Returns:
SQLRecord

clone

public java.lang.Object clone()

Overrides:
clone in class java.lang.Object

createRecord

public static final SQLRecord createRecord(java.sql.ResultSet rs)
                                    throws java.sql.SQLException
automatically create a new SQLRecord from a ResultSet

Parameters:
rs - ResultSet, expects a previous successful call to rs.next()
Returns:
SQLRecord, a record filled with the same values as the resultset
Throws:
java.sql.SQLException - thrown if ResultSet throws the Exception

createEmptyRecord

public static final SQLRecord createEmptyRecord(java.sql.ResultSetMetaData meta)
                                         throws java.sql.SQLException
automatically create a new SQLRecord structure from ResultSetMeta

The name and type are set, the value for this column is not set. This can be used when the resultset is empty and a new record needs to be created.

Parameters:
rs - ResultSetMeta
Returns:
SQLRecord, a record filled with the same values as the resultset
Throws:
java.sql.SQLException - thrown if ResultSet throws the Exception