private MetaResultSet s(String s) { try { logger.debug("Running {}", s); AvaticaStatement statement = connection.createStatement(); return MetaResultSet.create(connection.id, statement.getId(), true, newSignature(s), null); } catch (Exception e) { // Wrap in RuntimeException because Avatica's abstract method declarations // didn't allow for SQLException! throw new DrillRuntimeException("Failure while attempting to get DatabaseMetadata.", e); } }
DrillResultSetImpl(AvaticaStatement statement, QueryState state, Meta.Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame) throws SQLException { super(statement, state, signature, resultSetMetaData, timeZone, firstFrame); connection = (DrillConnectionImpl) statement.getConnection(); }
@Override public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException { checkOpen(); return super.executeLargeUpdate(sql, columnIndexes); }
/** * Throws AlreadyClosedSqlException if the associated ResultSet is closed. * * @throws AlreadyClosedSqlException if ResultSet is closed * @throws SQLException if error in checking ResultSet's status */ private void checkOpen() throws AlreadyClosedSqlException, SQLException { // Statement.isClosed() call is to avoid exception from getResultSet(). if (statement.isClosed() || (statement.getResultSet() != null // result set doesn't exist for prepared statement cases && statement.getResultSet().isClosed())) { throw new AlreadyClosedSqlException( "ResultSetMetaData's ResultSet is already closed." ); } }
/** * Called by each child result set when it is closed. * * @param resultSet Result set or cell set */ void onResultSetClose(ResultSet resultSet) { if (closeOnCompletion) { close_(); } }
public AvaticaResultSet(AvaticaStatement statement, QueryState state, Meta.Signature signature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, Meta.Frame firstFrame) { this.statement = statement; this.state = state; this.signature = signature; this.firstFrame = firstFrame; this.columnMetaDataList = signature.columns; this.type = statement.resultSetType; this.concurrency = statement.resultSetConcurrency; this.holdability = statement.resultSetHoldability; this.fetchSize = statement.getFetchSize(); this.fetchDirection = statement.getFetchDirection(); this.resultSetMetaData = resultSetMetaData; this.localCalendar = Calendar.getInstance(timeZone); }
@Test public void testGetMoreResults() throws SQLException { AvaticaResultSet resultSet = mock(AvaticaResultSet.class); statement.openResultSet = resultSet; doCallRealMethod().when(statement).onResultSetClose(any(ResultSet.class)); when(statement.getMoreResults()).thenCallRealMethod(); when(statement.getMoreResults(anyInt())).thenCallRealMethod(); assertFalse(statement.getMoreResults()); verify(resultSet).close(); } }
@Test public void testUpdateCounts() throws SQLException { long[] longValues = new long[] {-1, -3, 1, 5, ((long) Integer.MAX_VALUE) + 1}; int[] intValues = new int[] {-1, -3, 1, 5, Integer.MAX_VALUE}; when(statement.executeBatch()).thenCallRealMethod(); when(statement.executeLargeBatch()).thenCallRealMethod(); when(statement.executeBatchInternal()).thenReturn(longValues); assertArrayEquals(intValues, statement.executeBatch()); assertArrayEquals(longValues, statement.executeLargeBatch()); }
@Override public boolean getMoreResults(int current) throws SQLException { try { return super.getMoreResults(current); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public boolean isClosed() { try { return super.isClosed(); } catch ( SQLException e ) { // Currently can't happen, since AvaticaStatement.isClosed() never throws // SQLException. throw new DrillRuntimeException( "Unexpected exception from " + getClass().getSuperclass() + ".isClosed(): " + e, e ); } }
if (statement.isWrapperFor(AvaticaPreparedStatement.class)) { final AvaticaPreparedStatement pstmt = (AvaticaPreparedStatement) statement; final Meta.ExecuteResult executeResult = meta.execute(pstmt.handle, pstmt.getParameterValues(), statement.getFetchSize()); final MetaResultSet metaResultSet = executeResult.resultSets.get(0); frame = metaResultSet.firstFrame;
public long[] executeLargeBatch() throws SQLException { checkOpen(); try { return executeBatchInternal(); } finally { // If we failed to send this batch, that's a problem for the user to handle, not us. // Make sure we always clear the statements we collected to submit in one RPC. clearBatch(); } }
public boolean getMoreResults() throws SQLException { checkOpen(); return getMoreResults(CLOSE_CURRENT_RESULT); }
@Override protected Statement newInstance() throws Exception { UnregisteredDriver driver = new TestDriver(); AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(), "jdbc:avatica", new Properties()) { }; StatementHandle handle = mock(StatementHandle.class); AvaticaStatement statement = new AvaticaStatement(connection, handle, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT) { }; statement.close(); assertTrue("Statement is not closed", statement.isClosed()); return statement; } }
@Override public int[] executeBatch() throws SQLException { checkOpen(); try { return super.executeBatch(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void clearBatch() throws SQLException { try { super.clearBatch(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public int getFetchDirection() { try { throwIfClosed(); } catch (SQLException e) { // Can't throw any SQLException because AvaticaConnection's // getFetchDirection() is missing "throws SQLException". throw new RuntimeException(e.getMessage(), e); } return super.getFetchDirection(); }
@Override public int getFetchSize() { try { throwIfClosed(); } catch (SQLException e) { // Can't throw any SQLException because AvaticaConnection's // getFetchSize() is missing "throws SQLException". throw new RuntimeException(e.getMessage(), e); } return super.getFetchSize(); }
/** * Called by each child result set when it is closed. * * @param resultSet Result set or cell set */ void onResultSetClose(ResultSet resultSet) { if (closeOnCompletion) { close_(); } }
/** * Throws AlreadyClosedSqlException if the associated ResultSet is closed. * * @throws AlreadyClosedSqlException if ResultSet is closed * @throws SQLException if error in checking ResultSet's status */ private void checkOpen() throws AlreadyClosedSqlException, SQLException { // Statement.isClosed() call is to avoid exception from getResultSet(). if (statement.isClosed() || (statement.getResultSet() != null // result set doesn't exist for prepared statement cases && statement.getResultSet().isClosed())) { throw new AlreadyClosedSqlException( "ResultSetMetaData's ResultSet is already closed." ); } }