com.pivotal.gemfirexd.internal.client.net.SingleHopResultSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snappydata-store-client Show documentation
Show all versions of snappydata-store-client Show documentation
SnappyData store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.internal.client.net;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import com.pivotal.gemfirexd.internal.client.am.PreparedStatement;
import com.pivotal.gemfirexd.internal.client.net.NetConnection.DSConnectionInfo;
import com.pivotal.gemfirexd.internal.shared.common.error.ExceptionSeverity;
import com.pivotal.gemfirexd.internal.shared.common.reference.SQLState;
import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager;
/**
*
* @author kneeraj
*
*/
public abstract class SingleHopResultSet implements java.sql.ResultSet {
private int currRSIndex;
private PreparedStatement[] prepStmntArray;
private int totalNumOfResults;
protected java.sql.ResultSet currentResultSet;
FinalizeSingleHopResultSet finalizer;
// arg1 is corresponding the first result set
public SingleHopResultSet(java.sql.ResultSet nrs0,
PreparedStatement[] psarray, DSConnectionInfo dsConnInfo) {
this.currRSIndex = 0;
this.prepStmntArray = psarray;
this.totalNumOfResults = psarray.length;
this.currentResultSet = nrs0;
if (psarray != null
&& psarray.length != 0
&& psarray[0].sqlMode_ == com.pivotal.gemfirexd.internal.client.am.Statement.isQuery__) {
this.finalizer = new FinalizeSingleHopResultSet(this, dsConnInfo);
}
}
public FinalizeSingleHopResultSet getFinalizer() {
return this.finalizer;
}
public PreparedStatement[] getPreparedStatements() {
return this.prepStmntArray;
}
private void returnConnection(String op) throws SQLException {
final FinalizeSingleHopResultSet finalizer = this.finalizer;
if (finalizer != null) {
try {
finalizer.doFinalize();
this.finalizer = null;
} catch (Exception e) {
SQLException sqle = new SQLException(e.getMessage(),
SQLState.JAVA_EXCEPTION, ExceptionSeverity.STATEMENT_SEVERITY);
sqle.initCause(e);
throw sqle;
}
}
}
public boolean next() throws SQLException {
boolean gotException = false;
try {
for (;;) {
final boolean ret = this.currentResultSet.next();
if (ret) {
return true;
}
if (this.currRSIndex == (this.totalNumOfResults - 1)) {
// all ResultSets consumed; check if FORWARD_ONLY then return connection
// to pool
if (this.currentResultSet.getType() == TYPE_FORWARD_ONLY) {
returnConnection("implicitClose");
}
return false;
}
this.currRSIndex++;
this.currentResultSet = this.prepStmntArray[this.currRSIndex]
.getSuperResultSet();
}
} catch (SQLException ex) {
gotException = true;
throw ex;
} finally {
if (gotException) {
resetAndDoFinalize();
}
}
}
private void resetAndDoFinalize() {
final FinalizeSingleHopResultSet finalizer = this.finalizer;
if (finalizer != null) {
finalizer.resetAndDoFinalize();
}
}
public void close() throws SQLException {
for (int i = 0; i < this.totalNumOfResults; i++) {
this.prepStmntArray[i].getSuperResultSet().close();
}
this.currRSIndex = 0;
this.totalNumOfResults = 0;
this.prepStmntArray = null;
returnConnection("close");
}
public boolean wasNull() throws SQLException {
return this.currentResultSet.wasNull();
}
public String getString(int columnIndex) throws SQLException {
return this.currentResultSet.getString(columnIndex);
}
public boolean getBoolean(int columnIndex) throws SQLException {
return this.currentResultSet.getBoolean(columnIndex);
}
public byte getByte(int columnIndex) throws SQLException {
return this.currentResultSet.getByte(columnIndex);
}
///
public short getShort(int columnIndex) throws SQLException {
return this.currentResultSet.getShort(columnIndex);
}
public int getInt(int columnIndex) throws SQLException {
return this.currentResultSet.getInt(columnIndex);
}
public long getLong(int columnIndex) throws SQLException {
return this.currentResultSet.getLong(columnIndex);
}
public float getFloat(int columnIndex) throws SQLException {
return this.currentResultSet.getFloat(columnIndex);
}
public double getDouble(int columnIndex) throws SQLException {
return this.currentResultSet.getDouble(columnIndex);
}
public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException {
return this.currentResultSet.getBigDecimal(columnIndex);
}
public byte[] getBytes(int columnIndex) throws SQLException {
return this.currentResultSet.getBytes(columnIndex);
}
public Date getDate(int columnIndex) throws SQLException {
return this.currentResultSet.getDate(columnIndex);
}
public Time getTime(int columnIndex) throws SQLException {
return this.currentResultSet.getTime(columnIndex);
}
public Timestamp getTimestamp(int columnIndex) throws SQLException {
return this.currentResultSet.getTimestamp(columnIndex);
}
public InputStream getAsciiStream(int columnIndex) throws SQLException {
return this.currentResultSet.getAsciiStream(columnIndex);
}
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
return this.currentResultSet.getUnicodeStream(columnIndex);
}
public InputStream getBinaryStream(int columnIndex) throws SQLException {
return this.currentResultSet.getBinaryStream(columnIndex);
}
public String getString(String columnLabel) throws SQLException {
return this.currentResultSet.getString(columnLabel);
}
public boolean getBoolean(String columnLabel) throws SQLException {
return this.currentResultSet.getBoolean(columnLabel);
}
public byte getByte(String columnLabel) throws SQLException {
return this.currentResultSet.getByte(columnLabel);
}
public short getShort(String columnLabel) throws SQLException {
return this.currentResultSet.getShort(columnLabel);
}
public int getInt(String columnLabel) throws SQLException {
return this.currentResultSet.getInt(columnLabel);
}
public long getLong(String columnLabel) throws SQLException {
return this.currentResultSet.getLong(columnLabel);
}
public float getFloat(String columnLabel) throws SQLException {
return this.currentResultSet.getFloat(columnLabel);
}
public double getDouble(String columnLabel) throws SQLException {
return this.currentResultSet.getDouble(columnLabel);
}
public BigDecimal getBigDecimal(String columnLabel, int scale)
throws SQLException {
return this.currentResultSet.getBigDecimal(columnLabel, scale);
}
public byte[] getBytes(String columnLabel) throws SQLException {
return this.currentResultSet.getBytes(columnLabel);
}
public Date getDate(String columnLabel) throws SQLException {
return this.currentResultSet.getDate(columnLabel);
}
public Time getTime(String columnLabel) throws SQLException {
return this.currentResultSet.getTime(columnLabel);
}
public Timestamp getTimestamp(String columnLabel) throws SQLException {
return this.currentResultSet.getTimestamp(columnLabel);
}
public InputStream getAsciiStream(String columnLabel) throws SQLException {
return this.currentResultSet.getAsciiStream(columnLabel);
}
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
return this.currentResultSet.getUnicodeStream(columnLabel);
}
public InputStream getBinaryStream(String columnLabel) throws SQLException {
return this.currentResultSet.getBinaryStream(columnLabel);
}
public SQLWarning getWarnings() throws SQLException {
SQLWarning allwarnings = null;
for (int i=0; i