@Override public AvaticaStatement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return super.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); }
@Override public PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { checkOpen(); try { return super.prepareStatement(sql, columnIndexes); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override protected ExecuteResult prepareAndExecuteInternal(AvaticaStatement statement, String sql, long maxRowCount) throws SQLException, NoSuchStatementException { try { return super.prepareAndExecuteInternal(statement, sql, maxRowCount); } catch (RuntimeException e) { Throwables.throwIfInstanceOf(e.getCause(), SQLException.class); throw e; } } /**
public Statement createStatement( int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); //noinspection MagicConstant return createStatement(resultSetType, resultSetConcurrency, holdability); }
@Override protected ResultSet createResultSet(MetaResultSet metaResultSet, QueryState state) throws SQLException { return super.createResultSet(metaResultSet, state); }
public PreparedStatement prepareStatement(String sql) throws SQLException { checkOpen(); //noinspection MagicConstant return prepareStatement( sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, holdability); }
this.maxRetriesPerExecute = getNumStatementRetries(info);
protected ResultSet createResultSet(Meta.MetaResultSet metaResultSet, QueryState state) throws SQLException { final Meta.StatementHandle h = new Meta.StatementHandle( metaResultSet.connectionId, metaResultSet.statementId, null); final AvaticaStatement statement = lookupStatement(h); ResultSet resultSet = executeQueryInternal(statement, metaResultSet.signature.sanitize(), metaResultSet.firstFrame, state); if (metaResultSet.ownStatement) { resultSet.getStatement().closeOnCompletion(); } return resultSet; }
@Test public void testIsValid() throws SQLException { AvaticaConnection connection = Mockito.mock(AvaticaConnection.class, Mockito.CALLS_REAL_METHODS); try { connection.isValid(-1); Assert.fail("Connection isValid should throw SQLException on negative timeout"); } catch (SQLException expected) { Assert.assertEquals("timeout is less than 0", expected.getMessage()); } Mockito.when(connection.isClosed()).thenReturn(false); Assert.assertTrue(connection.isValid(0)); Mockito.when(connection.isClosed()).thenReturn(true); Assert.assertFalse(connection.isValid(0)); }
@Override public boolean isClosed() { try { return super.isClosed(); } catch (SQLException e) { // Currently can't happen, since AvaticaConnection.isClosed() never throws // SQLException. throw new DrillRuntimeException( "Unexpected exception from " + getClass().getSuperclass() + ".isClosed(): " + e, e ); } }
@Override protected Connection newInstance() throws Exception { UnregisteredDriver driver = new TestDriver(); AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(), "jdbc:avatica", new Properties()) { }; connection.close(); assertTrue("Connection is not closed", connection.isClosed()); return connection; } }
@Override protected AvaticaStatement lookupStatement(StatementHandle h) throws SQLException { return super.lookupStatement(h); }
@Override public boolean isValid(int timeout) throws SQLException { checkOpen(); return super.isValid(timeout); }
@Override public String getCatalog() { // Can't throw any SQLException because AvaticaConnection's getCatalog() is // missing "throws SQLException". try { throwIfClosed(); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } return super.getCatalog(); }
public Statement createStatement( int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); //noinspection MagicConstant return createStatement(resultSetType, resultSetConcurrency, holdability); }
public ResultSet call() { try { return connection.createResultSet(connection.meta.getCatalogs(connection.handle), new QueryState(MetaDataOperation.GET_CATALOGS)); } catch (SQLException e) { throw new RuntimeException(e); } } });
public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); //noinspection MagicConstant return prepareStatement( sql, resultSetType, resultSetConcurrency, holdability); }
/** * Creates an AvaticaConnection. * * <p>Not public; method is called only from the driver or a derived * class.</p> * * @param driver Driver * @param factory Factory for JDBC objects * @param url Server URL * @param info Other connection properties */ protected AvaticaConnection(UnregisteredDriver driver, AvaticaFactory factory, String url, Properties info) { this.id = UUID.randomUUID().toString(); this.handle = new Meta.ConnectionHandle(this.id); this.driver = driver; this.factory = factory; this.url = url; this.info = info; this.meta = driver.createMeta(this); this.metaData = factory.newDatabaseMetaData(this); this.holdability = metaData.getResultSetHoldability(); this.maxRetriesPerExecute = getNumStatementRetries(info); }
protected ResultSet createResultSet(Meta.MetaResultSet metaResultSet, QueryState state) throws SQLException { final Meta.StatementHandle h = new Meta.StatementHandle( metaResultSet.connectionId, metaResultSet.statementId, null); final AvaticaStatement statement = lookupStatement(h); // These are all the metadata operations, no updates ResultSet resultSet = executeQueryInternal(statement, metaResultSet.signature.sanitize(), metaResultSet.firstFrame, state, false); if (metaResultSet.ownStatement) { resultSet.getStatement().closeOnCompletion(); } return resultSet; }
@Test public void testIsValid() throws SQLException { AvaticaConnection connection = Mockito.mock(AvaticaConnection.class, Mockito.CALLS_REAL_METHODS); try { connection.isValid(-1); Assert.fail("Connection isValid should throw SQLException on negative timeout"); } catch (SQLException expected) { Assert.assertEquals("timeout is less than 0", expected.getMessage()); } Mockito.when(connection.isClosed()).thenReturn(false); Assert.assertTrue(connection.isValid(0)); Mockito.when(connection.isClosed()).thenReturn(true); Assert.assertFalse(connection.isValid(0)); }