|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.dbutils.wrappers.SqlNullCheckedResultSet
Decorates a ResultSet
with checks for a SQL NULL value on each
getXXX
method. If a column value obtained by a
getXXX
method is not SQL NULL, the column value is returned. If
the column value is SQL null, an alternate value is returned. The alternate
value defaults to the Java null
value, which can be overridden
for instances of the class.
Usage example:
Connection conn = // somehow get a connection Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT col1, col2 FROM table1"); // Wrap the result set for SQL NULL checking SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(rs); wrapper.setNullString("---N/A---"); // Set null string wrapper.setNullInt(-999); // Set null integer rs = ProxyFactory.instance().createResultSet(wrapper); while (rs.next()) { // If col1 is SQL NULL, value returned will be "---N/A---" String col1 = rs.getString("col1"); // If col2 is SQL NULL, value returned will be -999 int col2 = rs.getInt("col2"); } rs.close();
Field Summary | |
private static ProxyFactory |
factory
The factory to create proxies with. |
private InputStream |
nullAsciiStream
|
private BigDecimal |
nullBigDecimal
|
private InputStream |
nullBinaryStream
|
private Blob |
nullBlob
|
private boolean |
nullBoolean
|
private byte |
nullByte
|
private byte[] |
nullBytes
|
private Reader |
nullCharacterStream
|
private Clob |
nullClob
|
private Date |
nullDate
|
private double |
nullDouble
|
private float |
nullFloat
|
private int |
nullInt
|
private long |
nullLong
|
private static Map |
nullMethods
Maps normal method names (ie. |
private Object |
nullObject
|
private Ref |
nullRef
|
private short |
nullShort
|
private String |
nullString
|
private Time |
nullTime
|
private Timestamp |
nullTimestamp
|
private URL |
nullURL
|
private ResultSet |
rs
The wrapped result. |
Constructor Summary | |
SqlNullCheckedResultSet(ResultSet rs)
Constructs a new instance of SqlNullCheckedResultSet
to wrap the specified ResultSet . |
Method Summary | |
InputStream |
getNullAsciiStream()
Returns the value when a SQL null is encountered as the result of invoking a getAsciiStream method. |
BigDecimal |
getNullBigDecimal()
Returns the value when a SQL null is encountered as the result of invoking a getBigDecimal method. |
InputStream |
getNullBinaryStream()
Returns the value when a SQL null is encountered as the result of invoking a getBinaryStream method. |
Blob |
getNullBlob()
Returns the value when a SQL null is encountered as the result of invoking a getBlob method. |
boolean |
getNullBoolean()
Returns the value when a SQL null is encountered as the result of invoking a getBoolean method. |
byte |
getNullByte()
Returns the value when a SQL null is encountered as the result of invoking a getByte method. |
byte[] |
getNullBytes()
Returns the value when a SQL null is encountered as the result of invoking a getBytes method. |
Reader |
getNullCharacterStream()
Returns the value when a SQL null is encountered as the result of invoking a getCharacterStream method. |
Clob |
getNullClob()
Returns the value when a SQL null is encountered as the result of invoking a getClob method. |
Date |
getNullDate()
Returns the value when a SQL null is encountered as the result of invoking a getDate method. |
double |
getNullDouble()
Returns the value when a SQL null is encountered as the result of invoking a getDouble method. |
float |
getNullFloat()
Returns the value when a SQL null is encountered as the result of invoking a getFloat method. |
int |
getNullInt()
Returns the value when a SQL null is encountered as the result of invoking a getInt method. |
long |
getNullLong()
Returns the value when a SQL null is encountered as the result of invoking a getLong method. |
Object |
getNullObject()
Returns the value when a SQL null is encountered as the result of invoking a getObject method. |
Ref |
getNullRef()
Returns the value when a SQL null is encountered as the result of invoking a getRef method. |
short |
getNullShort()
Returns the value when a SQL null is encountered as the result of invoking a getShort method. |
String |
getNullString()
Returns the value when a SQL null is encountered as the result of invoking a getString method. |
Time |
getNullTime()
Returns the value when a SQL null is encountered as the result of invoking a getTime method. |
Timestamp |
getNullTimestamp()
Returns the value when a SQL null is encountered as the result of invoking a getTimestamp method. |
URL |
getNullURL()
Returns the value when a SQL null is encountered as the result of invoking a getURL method. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
Intercepts calls to get* methods and calls the appropriate
getNull* method if the ResultSet returned
null . |
void |
setNullAsciiStream(InputStream nullAsciiStream)
Sets the value to return when a SQL null is encountered as the result of invoking a getAsciiStream method. |
void |
setNullBigDecimal(BigDecimal nullBigDecimal)
Sets the value to return when a SQL null is encountered as the result of invoking a getBigDecimal method. |
void |
setNullBinaryStream(InputStream nullBinaryStream)
Sets the value to return when a SQL null is encountered as the result of invoking a getBinaryStream method. |
void |
setNullBlob(Blob nullBlob)
Sets the value to return when a SQL null is encountered as the result of invoking a getBlob method. |
void |
setNullBoolean(boolean nullBoolean)
Sets the value to return when a SQL null is encountered as the result of invoking a getBoolean method. |
void |
setNullByte(byte nullByte)
Sets the value to return when a SQL null is encountered as the result of invoking a getByte method. |
void |
setNullBytes(byte[] nullBytes)
Sets the value to return when a SQL null is encountered as the result of invoking a getBytes method. |
void |
setNullCharacterStream(Reader nullCharacterStream)
Sets the value to return when a SQL null is encountered as the result of invoking a getCharacterStream method. |
void |
setNullClob(Clob nullClob)
Sets the value to return when a SQL null is encountered as the result of invoking a getClob method. |
void |
setNullDate(Date nullDate)
Sets the value to return when a SQL null is encountered as the result of invoking a getDate method. |
void |
setNullDouble(double nullDouble)
Sets the value to return when a SQL null is encountered as the result of invoking a getDouble method. |
void |
setNullFloat(float nullFloat)
Sets the value to return when a SQL null is encountered as the result of invoking a getFloat method. |
void |
setNullInt(int nullInt)
Sets the value to return when a SQL null is encountered as the result of invoking a getInt method. |
void |
setNullLong(long nullLong)
Sets the value to return when a SQL null is encountered as the result of invoking a getLong method. |
void |
setNullObject(Object nullObject)
Sets the value to return when a SQL null is encountered as the result of invoking a getObject method. |
void |
setNullRef(Ref nullRef)
Sets the value to return when a SQL null is encountered as the result of invoking a getRef method. |
void |
setNullShort(short nullShort)
Sets the value to return when a SQL null is encountered as the result of invoking a getShort method. |
void |
setNullString(String nullString)
Sets the value to return when a SQL null is encountered as the result of invoking a getString method. |
void |
setNullTime(Time nullTime)
Sets the value to return when a SQL null is encountered as the result of invoking a getTime method. |
void |
setNullTimestamp(Timestamp nullTimestamp)
Sets the value to return when a SQL null is encountered as the result of invoking a getTimestamp method. |
void |
setNullURL(URL nullURL)
Sets the value to return when a SQL null is encountered as the result of invoking a getURL method. |
static ResultSet |
wrap(ResultSet rs)
Wraps the ResultSet in an instance of this class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final Map nullMethods
private static final ProxyFactory factory
private InputStream nullAsciiStream
private BigDecimal nullBigDecimal
private InputStream nullBinaryStream
private Blob nullBlob
private boolean nullBoolean
private byte nullByte
private byte[] nullBytes
private Reader nullCharacterStream
private Clob nullClob
private Date nullDate
private double nullDouble
private float nullFloat
private int nullInt
private long nullLong
private Object nullObject
private Ref nullRef
private short nullShort
private String nullString
private Time nullTime
private Timestamp nullTimestamp
private URL nullURL
private final ResultSet rs
Constructor Detail |
public SqlNullCheckedResultSet(ResultSet rs)
SqlNullCheckedResultSet
to wrap the specified ResultSet
.
Method Detail |
public static ResultSet wrap(ResultSet rs)
ResultSet
in an instance of this class. This is
equivalent to:
ProxyFactory.instance().createResultSet(new SqlNullCheckedResultSet(rs));
rs
- The ResultSet
to wrap.public InputStream getNullAsciiStream()
getAsciiStream
method.
public BigDecimal getNullBigDecimal()
getBigDecimal
method.
public InputStream getNullBinaryStream()
getBinaryStream
method.
public Blob getNullBlob()
getBlob
method.
public boolean getNullBoolean()
getBoolean
method.
public byte getNullByte()
getByte
method.
public byte[] getNullBytes()
getBytes
method.
public Reader getNullCharacterStream()
getCharacterStream
method.
public Clob getNullClob()
getClob
method.
public Date getNullDate()
getDate
method.
public double getNullDouble()
getDouble
method.
public float getNullFloat()
getFloat
method.
public int getNullInt()
getInt
method.
public long getNullLong()
getLong
method.
public Object getNullObject()
getObject
method.
public Ref getNullRef()
getRef
method.
public short getNullShort()
getShort
method.
public String getNullString()
getString
method.
public Time getNullTime()
getTime
method.
public Timestamp getNullTimestamp()
getTimestamp
method.
public URL getNullURL()
getURL
method.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
get*
methods and calls the appropriate
getNull*
method if the ResultSet
returned
null
.
invoke
in interface InvocationHandler
Throwable
InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
public void setNullAsciiStream(InputStream nullAsciiStream)
getAsciiStream
method.
nullAsciiStream
- the valuepublic void setNullBigDecimal(BigDecimal nullBigDecimal)
getBigDecimal
method.
nullBigDecimal
- the valuepublic void setNullBinaryStream(InputStream nullBinaryStream)
getBinaryStream
method.
nullBinaryStream
- the valuepublic void setNullBlob(Blob nullBlob)
getBlob
method.
nullBlob
- the valuepublic void setNullBoolean(boolean nullBoolean)
getBoolean
method.
nullBoolean
- the valuepublic void setNullByte(byte nullByte)
getByte
method.
nullByte
- the valuepublic void setNullBytes(byte[] nullBytes)
getBytes
method.
nullBytes
- the valuepublic void setNullCharacterStream(Reader nullCharacterStream)
getCharacterStream
method.
nullCharacterStream
- the valuepublic void setNullClob(Clob nullClob)
getClob
method.
nullClob
- the valuepublic void setNullDate(Date nullDate)
getDate
method.
nullDate
- the valuepublic void setNullDouble(double nullDouble)
getDouble
method.
nullDouble
- the valuepublic void setNullFloat(float nullFloat)
getFloat
method.
nullFloat
- the valuepublic void setNullInt(int nullInt)
getInt
method.
nullInt
- the valuepublic void setNullLong(long nullLong)
getLong
method.
nullLong
- the valuepublic void setNullObject(Object nullObject)
getObject
method.
nullObject
- the valuepublic void setNullRef(Ref nullRef)
getRef
method.
nullRef
- the valuepublic void setNullShort(short nullShort)
getShort
method.
nullShort
- the valuepublic void setNullString(String nullString)
getString
method.
nullString
- the valuepublic void setNullTime(Time nullTime)
getTime
method.
nullTime
- the valuepublic void setNullTimestamp(Timestamp nullTimestamp)
getTimestamp
method.
nullTimestamp
- the valuepublic void setNullURL(URL nullURL)
getURL
method.
nullURL
- the value
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |