33
33
* Allows streaming of MySQL data.
36
* @version $Id: RowDataDynamic.java 4891 2006-02-03 19:10:02Z mmatthews $
36
* @version $Id: RowDataDynamic.java 6454 2007-06-21 17:03:53Z mmatthews $
38
38
public class RowDataDynamic implements RowData {
40
// --------------------------------------------------------
42
40
class OperationNotSupportedException extends SQLException {
43
41
OperationNotSupportedException() {
61
59
private boolean isBinaryEncoded = false;
63
private Object[] nextRow;
61
private ResultSetRow nextRow;
65
private ResultSet owner;
63
private ResultSetImpl owner;
67
65
private boolean streamerClosed = false;
67
private boolean wasEmpty = false; // we don't know until we attempt to traverse
70
// ----------------------------------------------------------------
69
private boolean useBufferRowExplicit;
73
72
* Creates a new RowDataDynamic object.
76
75
* the connection to MySQL that this data is coming from
78
* the fields that describe this data
77
* the metadata that describe this data
79
78
* @param isBinaryEncoded
80
79
* is this data in native format?
141
141
* if a database error occurs
143
143
public void close() throws SQLException {
144
// Belt and suspenders here - if we don't
145
// have a reference to the connection
146
// it's more than likely dead/gone and we
147
// won't be able to consume rows anyway
151
ConnectionImpl conn = null;
153
if (this.owner != null) {
154
conn = this.owner.connection;
157
mutex = conn.getMutex();
145
161
boolean hadMore = false;
146
162
int howMuchMore = 0;
148
// drain the rest of the records.
149
while (this.hasNext()) {
154
if (howMuchMore % 100 == 0) {
159
if (this.owner != null) {
160
Connection conn = this.owner.connection;
162
if (conn != null && conn.getUseUsageAdvisor()) {
165
ProfileEventSink eventSink = ProfileEventSink
169
.consumeEvent(new ProfilerEvent(
170
ProfilerEvent.TYPE_WARN,
172
this.owner.owningStatement == null ? "N/A" : this.owner.owningStatement.currentCatalog, //$NON-NLS-1$
173
this.owner.connectionId,
174
this.owner.owningStatement == null ? -1
175
: this.owner.owningStatement
178
System.currentTimeMillis(),
182
Messages.getString("RowDataDynamic.2") //$NON-NLS-1$
185
.getString("RowDataDynamic.3") //$NON-NLS-1$
187
.getString("RowDataDynamic.4") //$NON-NLS-1$
189
.getString("RowDataDynamic.5") //$NON-NLS-1$
191
.getString("RowDataDynamic.6") //$NON-NLS-1$
192
+ this.owner.pointOfOrigin));
164
synchronized (mutex) {
165
// drain the rest of the records.
166
while (next() != null) {
170
if (howMuchMore % 100 == 0) {
176
if (!conn.getClobberStreamingResults() &&
177
conn.getNetTimeoutForStreamingResults() > 0) {
178
String oldValue = conn
179
.getServerVariable("net_write_timeout");
181
if (oldValue == null || oldValue.length() == 0) {
182
oldValue = "60"; // the current default
185
this.io.clearInputStream();
187
java.sql.Statement stmt = null;
190
stmt = conn.createStatement();
191
stmt.executeUpdate("SET net_write_timeout=" + oldValue);
199
if (conn.getUseUsageAdvisor()) {
202
ProfileEventSink eventSink = ProfileEventSink
206
.consumeEvent(new ProfilerEvent(
207
ProfilerEvent.TYPE_WARN,
209
this.owner.owningStatement == null ? "N/A" : this.owner.owningStatement.currentCatalog, //$NON-NLS-1$
210
this.owner.connectionId,
211
this.owner.owningStatement == null ? -1
212
: this.owner.owningStatement
215
System.currentTimeMillis(),
217
Constants.MILLIS_I18N,
220
Messages.getString("RowDataDynamic.2") //$NON-NLS-1$
223
.getString("RowDataDynamic.3") //$NON-NLS-1$
225
.getString("RowDataDynamic.4") //$NON-NLS-1$
227
.getString("RowDataDynamic.5") //$NON-NLS-1$
229
.getString("RowDataDynamic.6") //$NON-NLS-1$
230
+ this.owner.pointOfOrigin));
236
this.metadata = null;
198
237
this.owner = null;
343
382
* @throws SQLException
344
383
* if a database error occurs
346
public Object[] next() throws SQLException {
347
if (this.index != Integer.MAX_VALUE) {
385
public ResultSetRow next() throws SQLException {
351
Object[] ret = this.nextRow;
390
if (this.nextRow == null && !this.streamerClosed) {
391
this.io.closeStreamer(this);
392
this.streamerClosed = true;
395
if (this.nextRow != null) {
396
if (this.index != Integer.MAX_VALUE) {
357
405
private void nextRecord() throws SQLException {
362
this.nextRow = this.io.nextRow(this.fields, this.columnCount,
409
this.nextRow = this.io.nextRow(this.metadata, this.columnCount,
363
410
this.isBinaryEncoded,
364
java.sql.ResultSet.CONCUR_READ_ONLY);
411
java.sql.ResultSet.CONCUR_READ_ONLY, true,
412
this.useBufferRowExplicit, true, null);
366
414
if (this.nextRow == null) {
367
415
this.isAtEnd = true;
417
if (this.index == -1) {
418
this.wasEmpty = true;
370
422
this.isAfterEnd = true;
372
424
} catch (SQLException sqlEx) {
425
if (sqlEx instanceof StreamingNotifiable) {
426
((StreamingNotifiable)sqlEx).setWasStreamingResults();
373
429
// don't wrap SQLExceptions
375
431
} catch (Exception ex) {