A DESCRIPTION OF THE REQUEST :
Currently, interfaces SQLInput, SQLOutput provide plenty accessors for distinct type, and one general read/writeObject().
The latter could be generified to cover all other non-primitive types, with the effect pushing the root of a possible ClassCastException to the call site layer.
The non-primitive distinct ones could be deprecated.
JUSTIFICATION :
- general convenience
- save the additional external cast for readObject()
- in the javax.sql.rowset.serial implementation, the dictinct accessors could internally cause a ClassCastException, which would be unfathomable for users
- less code to maintain, especially for future extensions
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
E.G.:
boolean b = sqlInput.readBoolean();
Boolean b = sqlInput.readObject();
String s = sqlInput.readObject();
Blob b = sqlInput.readObject();
...
ACTUAL -
E.G.:
boolean b = sqlInput.readBoolean();
Boolean b = (Boolean)sqlInput.readObject();
String s = sqlInput.readString();
Blob b = sqlInput.readBlob();
...
---------- BEGIN SOURCE ----------
proposed source changes for javax.sql.rowset.serial.SQLInputImpl
private int idx = 0; // init with 0 instead -1
private Object attribs[]; // rename attrib to attribs
public boolean readBoolean() throws SQLException {
Boolean attrib = readObject(); // replace old (Boolean)getNextAttribute()
return (attrib == null) ? false : attrib.booleanValue();
}
public <T> T readObject() throws SQLException {
if (idx >= attribs.length) {
throw new SQLException( " SQLInputImpl exception: Invalid read " +
" position " );
}
T attrib = (T)attribs[idx++];
lastValueWasNull = attrib == null;
if (attrib instanceof Struct) {
... // maybe move to extra method to enhance possibility
... // for JIT to compile + inline the main path
...
}
return attrib;
}
---------- END SOURCE ----------
Currently, interfaces SQLInput, SQLOutput provide plenty accessors for distinct type, and one general read/writeObject().
The latter could be generified to cover all other non-primitive types, with the effect pushing the root of a possible ClassCastException to the call site layer.
The non-primitive distinct ones could be deprecated.
JUSTIFICATION :
- general convenience
- save the additional external cast for readObject()
- in the javax.sql.rowset.serial implementation, the dictinct accessors could internally cause a ClassCastException, which would be unfathomable for users
- less code to maintain, especially for future extensions
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
E.G.:
boolean b = sqlInput.readBoolean();
Boolean b = sqlInput.readObject();
String s = sqlInput.readObject();
Blob b = sqlInput.readObject();
...
ACTUAL -
E.G.:
boolean b = sqlInput.readBoolean();
Boolean b = (Boolean)sqlInput.readObject();
String s = sqlInput.readString();
Blob b = sqlInput.readBlob();
...
---------- BEGIN SOURCE ----------
proposed source changes for javax.sql.rowset.serial.SQLInputImpl
private int idx = 0; // init with 0 instead -1
private Object attribs[]; // rename attrib to attribs
public boolean readBoolean() throws SQLException {
Boolean attrib = readObject(); // replace old (Boolean)getNextAttribute()
return (attrib == null) ? false : attrib.booleanValue();
}
public <T> T readObject() throws SQLException {
if (idx >= attribs.length) {
throw new SQLException( " SQLInputImpl exception: Invalid read " +
" position " );
}
T attrib = (T)attribs[idx++];
lastValueWasNull = attrib == null;
if (attrib instanceof Struct) {
... // maybe move to extra method to enhance possibility
... // for JIT to compile + inline the main path
...
}
return attrib;
}
---------- END SOURCE ----------