Class SqlNullCheckedResultSet
java.lang.Object
org.apache.commons.dbutils.wrappers.SqlNullCheckedResultSet
- All Implemented Interfaces:
InvocationHandler
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:
</p>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();
Unlike some other classes in DbUtils, this class is NOT thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ProxyFactory
The factory to create proxies with.private static final String
ThegetNull
string prefix.private InputStream
private BigDecimal
private InputStream
private Blob
private boolean
private byte
private byte[]
private Reader
private Clob
private Date
private double
private float
private int
private long
Maps normal method names (ie.private Object
private Ref
private short
private String
private Time
private Timestamp
private URL
private final ResultSet
The wrapped result. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance ofSqlNullCheckedResultSet
to wrap the specifiedResultSet
. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value when a SQL null is encountered as the result of invoking agetAsciiStream
method.Returns the value when a SQL null is encountered as the result of invoking agetBigDecimal
method.Returns the value when a SQL null is encountered as the result of invoking agetBinaryStream
method.Returns the value when a SQL null is encountered as the result of invoking agetBlob
method.boolean
Returns the value when a SQL null is encountered as the result of invoking agetBoolean
method.byte
Returns the value when a SQL null is encountered as the result of invoking agetByte
method.byte[]
Returns the value when a SQL null is encountered as the result of invoking agetBytes
method.Returns the value when a SQL null is encountered as the result of invoking agetCharacterStream
method.Returns the value when a SQL null is encountered as the result of invoking agetClob
method.Returns the value when a SQL null is encountered as the result of invoking agetDate
method.double
Returns the value when a SQL null is encountered as the result of invoking agetDouble
method.float
Returns the value when a SQL null is encountered as the result of invoking agetFloat
method.int
Returns the value when a SQL null is encountered as the result of invoking agetInt
method.long
Returns the value when a SQL null is encountered as the result of invoking agetLong
method.Returns the value when a SQL null is encountered as the result of invoking agetObject
method.Returns the value when a SQL null is encountered as the result of invoking agetRef
method.short
Returns the value when a SQL null is encountered as the result of invoking agetShort
method.Returns the value when a SQL null is encountered as the result of invoking agetString
method.Returns the value when a SQL null is encountered as the result of invoking agetTime
method.Returns the value when a SQL null is encountered as the result of invoking agetTimestamp
method.Returns the value when a SQL null is encountered as the result of invoking agetURL
method.Intercepts calls toget*
methods and calls the appropriategetNull*
method if theResultSet
returnednull
.void
setNullAsciiStream
(InputStream nullAsciiStream) Sets the value to return when a SQL null is encountered as the result of invoking agetAsciiStream
method.void
setNullBigDecimal
(BigDecimal nullBigDecimal) Sets the value to return when a SQL null is encountered as the result of invoking agetBigDecimal
method.void
setNullBinaryStream
(InputStream nullBinaryStream) Sets the value to return when a SQL null is encountered as the result of invoking agetBinaryStream
method.void
setNullBlob
(Blob nullBlob) Sets the value to return when a SQL null is encountered as the result of invoking agetBlob
method.void
setNullBoolean
(boolean nullBoolean) Sets the value to return when a SQL null is encountered as the result of invoking agetBoolean
method.void
setNullByte
(byte nullByte) Sets the value to return when a SQL null is encountered as the result of invoking agetByte
method.void
setNullBytes
(byte[] nullBytes) Sets the value to return when a SQL null is encountered as the result of invoking agetBytes
method.void
setNullCharacterStream
(Reader nullCharacterStream) Sets the value to return when a SQL null is encountered as the result of invoking agetCharacterStream
method.void
setNullClob
(Clob nullClob) Sets the value to return when a SQL null is encountered as the result of invoking agetClob
method.void
setNullDate
(Date nullDate) Sets the value to return when a SQL null is encountered as the result of invoking agetDate
method.void
setNullDouble
(double nullDouble) Sets the value to return when a SQL null is encountered as the result of invoking agetDouble
method.void
setNullFloat
(float nullFloat) Sets the value to return when a SQL null is encountered as the result of invoking agetFloat
method.void
setNullInt
(int nullInt) Sets the value to return when a SQL null is encountered as the result of invoking agetInt
method.void
setNullLong
(long nullLong) Sets the value to return when a SQL null is encountered as the result of invoking agetLong
method.void
setNullObject
(Object nullObject) Sets the value to return when a SQL null is encountered as the result of invoking agetObject
method.void
setNullRef
(Ref nullRef) Sets the value to return when a SQL null is encountered as the result of invoking agetRef
method.void
setNullShort
(short nullShort) Sets the value to return when a SQL null is encountered as the result of invoking agetShort
method.void
setNullString
(String nullString) Sets the value to return when a SQL null is encountered as the result of invoking agetString
method.void
setNullTime
(Time nullTime) Sets the value to return when a SQL null is encountered as the result of invoking agetTime
method.void
setNullTimestamp
(Timestamp nullTimestamp) Sets the value to return when a SQL null is encountered as the result of invoking agetTimestamp
method.void
setNullURL
(URL nullURL) Sets the value to return when a SQL null is encountered as the result of invoking agetURL
method.static ResultSet
Wraps theResultSet
in an instance of this class.
-
Field Details
-
nullMethods
Maps normal method names (ie. "getBigDecimal") to the corresponding null Method object (ie. getNullBigDecimal). -
GET_NULL_PREFIX
ThegetNull
string prefix.- Since:
- 1.4
- See Also:
-
factory
The factory to create proxies with. -
nullAsciiStream
-
nullBigDecimal
-
nullBinaryStream
-
nullBlob
-
nullBoolean
private boolean nullBoolean -
nullByte
private byte nullByte -
nullBytes
private byte[] nullBytes -
nullCharacterStream
-
nullClob
-
nullDate
-
nullDouble
private double nullDouble -
nullFloat
private float nullFloat -
nullInt
private int nullInt -
nullLong
private long nullLong -
nullObject
-
nullRef
-
nullShort
private short nullShort -
nullString
-
nullTime
-
nullTimestamp
-
nullURL
-
rs
The wrapped result.
-
-
Constructor Details
-
SqlNullCheckedResultSet
Constructs a new instance ofSqlNullCheckedResultSet
to wrap the specifiedResultSet
.- Parameters:
rs
- ResultSet to wrap
-
-
Method Details
-
wrap
Wraps theResultSet
in an instance of this class. This is equivalent to:ProxyFactory.instance().createResultSet(new SqlNullCheckedResultSet(rs));
- Parameters:
rs
- TheResultSet
to wrap.- Returns:
- wrapped ResultSet
-
getNullAsciiStream
Returns the value when a SQL null is encountered as the result of invoking agetAsciiStream
method.- Returns:
- the value
-
getNullBigDecimal
Returns the value when a SQL null is encountered as the result of invoking agetBigDecimal
method.- Returns:
- the value
-
getNullBinaryStream
Returns the value when a SQL null is encountered as the result of invoking agetBinaryStream
method.- Returns:
- the value
-
getNullBlob
Returns the value when a SQL null is encountered as the result of invoking agetBlob
method.- Returns:
- the value
-
getNullBoolean
public boolean getNullBoolean()Returns the value when a SQL null is encountered as the result of invoking agetBoolean
method.- Returns:
- the value
-
getNullByte
public byte getNullByte()Returns the value when a SQL null is encountered as the result of invoking agetByte
method.- Returns:
- the value
-
getNullBytes
public byte[] getNullBytes()Returns the value when a SQL null is encountered as the result of invoking agetBytes
method.- Returns:
- the value
-
getNullCharacterStream
Returns the value when a SQL null is encountered as the result of invoking agetCharacterStream
method.- Returns:
- the value
-
getNullClob
Returns the value when a SQL null is encountered as the result of invoking agetClob
method.- Returns:
- the value
-
getNullDate
Returns the value when a SQL null is encountered as the result of invoking agetDate
method.- Returns:
- the value
-
getNullDouble
public double getNullDouble()Returns the value when a SQL null is encountered as the result of invoking agetDouble
method.- Returns:
- the value
-
getNullFloat
public float getNullFloat()Returns the value when a SQL null is encountered as the result of invoking agetFloat
method.- Returns:
- the value
-
getNullInt
public int getNullInt()Returns the value when a SQL null is encountered as the result of invoking agetInt
method.- Returns:
- the value
-
getNullLong
public long getNullLong()Returns the value when a SQL null is encountered as the result of invoking agetLong
method.- Returns:
- the value
-
getNullObject
Returns the value when a SQL null is encountered as the result of invoking agetObject
method.- Returns:
- the value
-
getNullRef
Returns the value when a SQL null is encountered as the result of invoking agetRef
method.- Returns:
- the value
-
getNullShort
public short getNullShort()Returns the value when a SQL null is encountered as the result of invoking agetShort
method.- Returns:
- the value
-
getNullString
Returns the value when a SQL null is encountered as the result of invoking agetString
method.- Returns:
- the value
-
getNullTime
Returns the value when a SQL null is encountered as the result of invoking agetTime
method.- Returns:
- the value
-
getNullTimestamp
Returns the value when a SQL null is encountered as the result of invoking agetTimestamp
method.- Returns:
- the value
-
getNullURL
Returns the value when a SQL null is encountered as the result of invoking agetURL
method.- Returns:
- the value
-
invoke
Intercepts calls toget*
methods and calls the appropriategetNull*
method if theResultSet
returnednull
.- Specified by:
invoke
in interfaceInvocationHandler
- Parameters:
proxy
- Not used; all method calls go to the internal result setmethod
- The method to invoke on the result setargs
- The arguments to pass to the result set- Returns:
- null checked result
- Throws:
Throwable
- error- See Also:
-
setNullAsciiStream
Sets the value to return when a SQL null is encountered as the result of invoking agetAsciiStream
method.- Parameters:
nullAsciiStream
- the value
-
setNullBigDecimal
Sets the value to return when a SQL null is encountered as the result of invoking agetBigDecimal
method.- Parameters:
nullBigDecimal
- the value
-
setNullBinaryStream
Sets the value to return when a SQL null is encountered as the result of invoking agetBinaryStream
method.- Parameters:
nullBinaryStream
- the value
-
setNullBlob
Sets the value to return when a SQL null is encountered as the result of invoking agetBlob
method.- Parameters:
nullBlob
- the value
-
setNullBoolean
public void setNullBoolean(boolean nullBoolean) Sets the value to return when a SQL null is encountered as the result of invoking agetBoolean
method.- Parameters:
nullBoolean
- the value
-
setNullByte
public void setNullByte(byte nullByte) Sets the value to return when a SQL null is encountered as the result of invoking agetByte
method.- Parameters:
nullByte
- the value
-
setNullBytes
public void setNullBytes(byte[] nullBytes) Sets the value to return when a SQL null is encountered as the result of invoking agetBytes
method.- Parameters:
nullBytes
- the value
-
setNullCharacterStream
Sets the value to return when a SQL null is encountered as the result of invoking agetCharacterStream
method.- Parameters:
nullCharacterStream
- the value
-
setNullClob
Sets the value to return when a SQL null is encountered as the result of invoking agetClob
method.- Parameters:
nullClob
- the value
-
setNullDate
Sets the value to return when a SQL null is encountered as the result of invoking agetDate
method.- Parameters:
nullDate
- the value
-
setNullDouble
public void setNullDouble(double nullDouble) Sets the value to return when a SQL null is encountered as the result of invoking agetDouble
method.- Parameters:
nullDouble
- the value
-
setNullFloat
public void setNullFloat(float nullFloat) Sets the value to return when a SQL null is encountered as the result of invoking agetFloat
method.- Parameters:
nullFloat
- the value
-
setNullInt
public void setNullInt(int nullInt) Sets the value to return when a SQL null is encountered as the result of invoking agetInt
method.- Parameters:
nullInt
- the value
-
setNullLong
public void setNullLong(long nullLong) Sets the value to return when a SQL null is encountered as the result of invoking agetLong
method.- Parameters:
nullLong
- the value
-
setNullObject
Sets the value to return when a SQL null is encountered as the result of invoking agetObject
method.- Parameters:
nullObject
- the value
-
setNullRef
Sets the value to return when a SQL null is encountered as the result of invoking agetRef
method.- Parameters:
nullRef
- the value
-
setNullShort
public void setNullShort(short nullShort) Sets the value to return when a SQL null is encountered as the result of invoking agetShort
method.- Parameters:
nullShort
- the value
-
setNullString
Sets the value to return when a SQL null is encountered as the result of invoking agetString
method.- Parameters:
nullString
- the value
-
setNullTime
Sets the value to return when a SQL null is encountered as the result of invoking agetTime
method.- Parameters:
nullTime
- the value
-
setNullTimestamp
Sets the value to return when a SQL null is encountered as the result of invoking agetTimestamp
method.- Parameters:
nullTimestamp
- the value
-
setNullURL
Sets the value to return when a SQL null is encountered as the result of invoking agetURL
method.- Parameters:
nullURL
- the value
-