Skip to content

Commit

Permalink
Reimplemented Blob fixes
Browse files Browse the repository at this point in the history
removed arraylist to avoid costly traversal. Blobs now fill anytime the resultset moves its cursor.
  • Loading branch information
rene-ye committed Feb 22, 2018
1 parent 91bf4d3 commit 3ba5f1b
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ final void setCurrentRowType(RowType rowType) {
* occurs
*/
private Closeable activeStream;
private List<Object> streamObjects = new ArrayList<Object>();
private Blob activeBlob;

/**
* A window of fetchSize quickly accessible rows for scrollable result sets
Expand Down Expand Up @@ -436,6 +436,8 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
// can be done with it other than closing it.
if (null != rowErrorException)
throw rowErrorException;

fillBlobs();
}

public boolean isClosed() throws SQLException {
Expand Down Expand Up @@ -675,6 +677,7 @@ final Column getColumn(int columnIndex) throws SQLServerException {
// before moving to another one.
if (null != activeStream) {
try {
fillBlobs();
activeStream.close();
}
catch (IOException e) {
Expand Down Expand Up @@ -2663,7 +2666,7 @@ public Blob getBlob(int i) throws SQLServerException {
checkClosed();
Blob value = (Blob) getValue(i, JDBCType.BLOB);
loggerExternal.exiting(getClassNameLogging(), "getBlob", value);
streamObjects.add(value);
activeBlob = value;
return value;
}

Expand All @@ -2672,7 +2675,7 @@ public Blob getBlob(String colName) throws SQLServerException {
checkClosed();
Blob value = (Blob) getValue(findColumn(colName), JDBCType.BLOB);
loggerExternal.exiting(getClassNameLogging(), "getBlob", value);
streamObjects.add(value);
activeBlob = value;
return value;
}

Expand Down Expand Up @@ -6517,20 +6520,32 @@ final void doServerFetch(int fetchType,
}

/*
* Iterates through the list of objects which rely on the stream that's about to be closed, filling them with their data
* Iterates through the list of objects which rely on the stream that's about to be closed, ing them with their data
* Will skip over closed blobs, implemented in SQLServerBlob
*/
private void fillBlobs() {
for(Object o : streamObjects) {
if(o instanceof SQLServerBlob) {
try {
((SQLServerBlob) o).fillByteArray();
if (activeBlob != null && activeBlob instanceof SQLServerBlob) {
try {
((SQLServerBlob)activeBlob).fillByteArray();
} catch (SQLException e) {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(toString() + "Filling blobs before closing: " + e.getMessage());
} finally {
activeBlob = null;
}
}

/*for (int i = 0; i < streamObjects.size(); i++) {
if(streamObjects.get(i) instanceof SQLServerBlob) {
try {
((SQLServerBlob) streamObjects.get(i)).fillByteArray();
streamObjects.remove(i);
} catch (SQLException e) {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(toString() + "Filling blobs before closing: " + e.getMessage());
}
}
}
}*/
}

/**
Expand Down

0 comments on commit 3ba5f1b

Please sign in to comment.