org.apache.calcite.avatica.NoSuchStatementException Java Examples

The following examples show how to use org.apache.calcite.avatica.NoSuchStatementException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public ExecuteResult execute(StatementHandle h,
    List<TypedValue> parameterValues, int maxRowsInFirstFrame)
    throws NoSuchStatementException {
  final CalciteConnectionImpl calciteConnection = getConnection();
  CalciteServerStatement stmt = calciteConnection.server.getStatement(h);
  final Signature signature = stmt.getSignature();

  MetaResultSet metaResultSet;
  if (signature.statementType.canUpdate()) {
    final Iterable<Object> iterable =
        _createIterable(h, signature, parameterValues, null);
    final Iterator<Object> iterator = iterable.iterator();
    stmt.setResultSet(iterator);
    metaResultSet = MetaResultSet.count(h.connectionId, h.id,
        ((Number) iterator.next()).intValue());
  } else {
    // Don't populate the first frame.
    // It's not worth saving a round-trip, since we're local.
    final Meta.Frame frame =
        new Meta.Frame(0, false, Collections.emptyList());
    metaResultSet =
        MetaResultSet.create(h.connectionId, h.id, false, signature, frame);
  }

  return new ExecuteResult(ImmutableList.of(metaResultSet));
}
 
Example #2
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public StatementHandle prepare(ConnectionHandle ch, String sql,
    long maxRowCount) {
  final StatementHandle h = createStatement(ch);
  final CalciteConnectionImpl calciteConnection = getConnection();

  final CalciteServerStatement statement;
  try {
    statement = calciteConnection.server.getStatement(h);
  } catch (NoSuchStatementException e) {
    // Not possible. We just created a statement.
    throw new AssertionError("missing statement", e);
  }
  final Context context = statement.createPrepareContext();
  final CalcitePrepare.Query<Object> query = toQuery(context, sql);
  h.signature = calciteConnection.parseQuery(query, context, maxRowCount);
  statement.setSignature(h.signature);
  return h;
}
 
Example #3
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public Frame fetch(StatementHandle h, long offset,
    int fetchMaxRowCount) throws NoSuchStatementException {
  final CalciteConnectionImpl calciteConnection = getConnection();
  CalciteServerStatement stmt = calciteConnection.server.getStatement(h);
  final Signature signature = stmt.getSignature();
  final Iterator<Object> iterator;
  if (stmt.getResultSet() == null) {
    final Iterable<Object> iterable =
        _createIterable(h, signature, null, null);
    iterator = iterable.iterator();
    stmt.setResultSet(iterator);
  } else {
    iterator = stmt.getResultSet();
  }
  final List rows =
      MetaImpl.collect(signature.cursorFactory,
          LimitIterator.of(iterator, fetchMaxRowCount),
          new ArrayList<List<Object>>());
  boolean done = fetchMaxRowCount == 0 || rows.size() < fetchMaxRowCount;
  @SuppressWarnings("unchecked") List<Object> rows1 = (List<Object>) rows;
  return new Meta.Frame(offset, done, rows1);
}
 
Example #4
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public boolean syncResults(StatementHandle sh, QueryState state, long offset)
    throws NoSuchStatementException {
  try {
    final Connection conn = getConnection(sh.connectionId);
    final StatementInfo info = statementCache.getIfPresent(sh.id);
    if (null == info) {
      throw new NoSuchStatementException(sh);
    }
    final Statement statement = info.statement;
    // Let the state recreate the necessary ResultSet on the Statement
    info.setResultSet(state.invoke(conn, statement));

    if (null != info.getResultSet()) {
      // If it is non-null, try to advance to the requested offset.
      return info.advanceResultSetToOffset(info.getResultSet(), offset);
    }

    // No results, nothing to do. Client can move on.
    return false;
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #5
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public ExecuteResult execute(StatementHandle h,
    List<TypedValue> parameterValues, int maxRowsInFirstFrame)
    throws NoSuchStatementException {
  final CalciteConnectionImpl calciteConnection = getConnection();
  CalciteServerStatement stmt = calciteConnection.server.getStatement(h);
  final Signature signature = stmt.getSignature();

  MetaResultSet metaResultSet;
  if (signature.statementType.canUpdate()) {
    final Iterable<Object> iterable =
        _createIterable(h, signature, parameterValues, null);
    final Iterator<Object> iterator = iterable.iterator();
    stmt.setResultSet(iterator);
    metaResultSet = MetaResultSet.count(h.connectionId, h.id,
        ((Number) iterator.next()).intValue());
  } else {
    // Don't populate the first frame.
    // It's not worth saving a round-trip, since we're local.
    final Meta.Frame frame =
        new Meta.Frame(0, false, Collections.emptyList());
    metaResultSet =
        MetaResultSet.create(h.connectionId, h.id, false, signature, frame);
  }

  return new ExecuteResult(ImmutableList.of(metaResultSet));
}
 
Example #6
Source File: QuicksqlRemoteMeta.java    From Quicksql with MIT License 6 votes vote down vote up
@Override public boolean syncResults(final StatementHandle h, final QueryState state,
    final long offset) throws NoSuchStatementException {
  try {
    return connection.invokeWithRetries(
        new CallableWithoutException<Boolean>() {
          public Boolean call() {
            final Service.SyncResultsResponse response =
                service.apply(
                    new Service.SyncResultsRequest(h.connectionId, h.id, state, offset));
            if (response.missingStatement) {
              throw new RuntimeException(new NoSuchStatementException(h));
            }
            return response.moreResults;
          }
        });
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof NoSuchStatementException) {
      throw (NoSuchStatementException) cause;
    }
    throw e;
  }
}
 
Example #7
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 6 votes vote down vote up
@Override
public ExecuteBatchResult prepareAndExecuteBatch(StatementHandle h,
    List<String> sqlCommands) throws NoSuchStatementException {
    try {
        // Get the statement
        final StatementInfo info = statementCache.getIfPresent(h.id);
        if (info == null) {
            throw new NoSuchStatementException(h);
        }

        // addBatch() for each sql command
        final Statement stmt = info.statement;
        for (String sqlCommand : sqlCommands) {
            stmt.addBatch(sqlCommand);
        }

        // Execute the batch and return the results
        return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(stmt));
    } catch (SQLException e) {
        throw propagate(e);
    }
}
 
Example #8
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 6 votes vote down vote up
@Override
public ExecuteBatchResult executeBatchProtobuf(StatementHandle h,
    List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException {
    try {
        final StatementInfo info = statementCache.getIfPresent(h.id);
        if (null == info) {
            throw new NoSuchStatementException(h);
        }

        final PreparedStatement preparedStmt = (PreparedStatement) info.statement;
        for (Requests.UpdateBatch update : updateBatches) {
            int i = 1;
            for (Common.TypedValue value : update.getParameterValuesList()) {
                // Use the value and then increment
                preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar));
            }
            preparedStmt.addBatch();
        }
        return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt));
    } catch (SQLException e) {
        throw propagate(e);
    }
}
 
Example #9
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public Frame fetch(StatementHandle h, long offset, int fetchMaxRowCount) throws
    NoSuchStatementException, MissingResultsException {
  LOG.trace("fetching {} offset:{} fetchMaxRowCount:{}", h, offset, fetchMaxRowCount);
  try {
    final StatementInfo statementInfo = statementCache.getIfPresent(h.id);
    if (null == statementInfo) {
      // Statement might have expired, or never existed on this server.
      throw new NoSuchStatementException(h);
    }

    if (!statementInfo.isResultSetInitialized()) {
      // The Statement exists, but the results are missing. Need to call syncResults(...)
      throw new MissingResultsException(h);
    }
    if (statementInfo.getResultSet() == null) {
      return Frame.EMPTY;
    } else {
      return JdbcResultSet.frame(statementInfo, statementInfo.getResultSet(), offset,
          fetchMaxRowCount, calendar, Optional.<Meta.Signature>absent());
    }
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #10
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public ExecuteBatchResult prepareAndExecuteBatch(StatementHandle h,
    List<String> sqlCommands) throws NoSuchStatementException {
  try {
    // Get the statement
    final StatementInfo info = statementCache.getIfPresent(h.id);
    if (info == null) {
      throw new NoSuchStatementException(h);
    }

    // addBatch() for each sql command
    final Statement stmt = info.statement;
    for (String sqlCommand : sqlCommands) {
      stmt.addBatch(sqlCommand);
    }

    // Execute the batch and return the results
    return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(stmt));
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #11
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public ExecuteBatchResult executeBatchProtobuf(StatementHandle h,
    List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException {
  try {
    final StatementInfo info = statementCache.getIfPresent(h.id);
    if (null == info) {
      throw new NoSuchStatementException(h);
    }

    final PreparedStatement preparedStmt = (PreparedStatement) info.statement;
    for (Requests.UpdateBatch update : updateBatches) {
      int i = 1;
      for (Common.TypedValue value : update.getParameterValuesList()) {
        // Use the value and then increment
        preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar));
      }
      preparedStmt.addBatch();
    }
    return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt));
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #12
Source File: LocalService.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public ExecuteResponse apply(ExecuteRequest request) {
  try (final Context ignore = executeTimer.start()) {
    try {
      final Meta.ExecuteResult executeResult = meta.execute(request.statementHandle,
          request.parameterValues, AvaticaUtils.toSaturatedInt(request.maxRowCount));

      final List<ResultSetResponse> results = new ArrayList<>(executeResult.resultSets.size());
      for (Meta.MetaResultSet metaResultSet : executeResult.resultSets) {
        results.add(toResponse(metaResultSet));
      }
      return new ExecuteResponse(results, false, serverLevelRpcMetadata);
    } catch (NoSuchStatementException e) {
      return new ExecuteResponse(null, true, serverLevelRpcMetadata);
    }
  }
}
 
Example #13
Source File: LocalService.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public ExecuteBatchResponse apply(ExecuteBatchRequest request) {
  final Meta.StatementHandle h = new Meta.StatementHandle(request.connectionId,
      request.statementId, null);
  try {
    ExecuteBatchResult result;
    if (request.hasProtoUpdateBatches() && meta instanceof ProtobufMeta) {
      result = ((ProtobufMeta) meta).executeBatchProtobuf(h, request.getProtoUpdateBatches());
    } else {
      result = meta.executeBatch(h, request.parameterValues);
    }
    return new ExecuteBatchResponse(request.connectionId, request.statementId,
        result.updateCounts, false, serverLevelRpcMetadata);
  } catch (NoSuchStatementException e) {
    return new ExecuteBatchResponse(request.connectionId, request.statementId, null, true,
        serverLevelRpcMetadata);
  }
}
 
Example #14
Source File: QuarkMetaImpl.java    From quark with Apache License 2.0 6 votes vote down vote up
@Override
public ExecuteResult prepareAndExecute(StatementHandle statementHandle, String sql,
                                       long maxRowCount,
                                       int maxRowsInFirstFrame,
                                       PrepareCallback prepareCallback)
        throws NoSuchStatementException {
  try {
    MetaResultSet metaResultSet;
    synchronized (prepareCallback.getMonitor()) {
      prepareCallback.clear();
      ParserResult result = getConnection().parse(sql);
      metaResultSet = new PlanExecutor(statementHandle, getConnection(),
          connectionCache, maxRowCount).execute(result);
      prepareCallback.assign(metaResultSet.signature, metaResultSet.firstFrame,
          metaResultSet.updateCount);
    }
    prepareCallback.execute();
    return new ExecuteResult(ImmutableList.of(metaResultSet));
  } catch (Exception e) {
    throw propagate(e);
  }

}
 
Example #15
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public StatementHandle prepare(ConnectionHandle ch, String sql,
    long maxRowCount) {
  final StatementHandle h = createStatement(ch);
  final CalciteConnectionImpl calciteConnection = getConnection();

  final CalciteServerStatement statement;
  try {
    statement = calciteConnection.server.getStatement(h);
  } catch (NoSuchStatementException e) {
    // Not possible. We just created a statement.
    throw new AssertionError("missing statement", e);
  }
  final Context context = statement.createPrepareContext();
  final CalcitePrepare.Query<Object> query = toQuery(context, sql);
  h.signature = calciteConnection.parseQuery(query, context, maxRowCount);
  statement.setSignature(h.signature);
  return h;
}
 
Example #16
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public ExecuteBatchResult executeBatch(StatementHandle h,
    List<List<TypedValue>> parameterValueLists) throws NoSuchStatementException {
  final List<Long> updateCounts = new ArrayList<>();
  for (List<TypedValue> parameterValueList : parameterValueLists) {
    ExecuteResult executeResult = execute(h, parameterValueList, -1);
    final long updateCount =
        executeResult.resultSets.size() == 1
            ? executeResult.resultSets.get(0).updateCount
            : -1L;
    updateCounts.add(updateCount);
  }
  return new ExecuteBatchResult(Longs.toArray(updateCounts));
}
 
Example #17
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public ExecuteResult prepareAndExecute(StatementHandle h,
    String sql, long maxRowCount, int maxRowsInFirstFrame,
    PrepareCallback callback) throws NoSuchStatementException {
  final CalcitePrepare.CalciteSignature<Object> signature;
  try {
    final int updateCount;
    synchronized (callback.getMonitor()) {
      callback.clear();
      final CalciteConnectionImpl calciteConnection = getConnection();
      final CalciteServerStatement statement =
          calciteConnection.server.getStatement(h);
      final Context context = statement.createPrepareContext();
      final CalcitePrepare.Query<Object> query = toQuery(context, sql);
      signature = calciteConnection.parseQuery(query, context, maxRowCount);
      statement.setSignature(signature);
      switch (signature.statementType) {
      case CREATE:
      case DROP:
      case ALTER:
      case OTHER_DDL:
        updateCount = 0; // DDL produces no result set
        break;
      default:
        updateCount = -1; // SELECT and DML produces result set
        break;
      }
      callback.assign(signature, null, updateCount);
    }
    callback.execute();
    final MetaResultSet metaResultSet =
        MetaResultSet.create(h.connectionId, h.id, false, signature, null, updateCount);
    return new ExecuteResult(ImmutableList.of(metaResultSet));
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }
  // TODO: share code with prepare and createIterable
}
 
Example #18
Source File: CalciteStatement.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public <T> T unwrap(Class<T> iface) throws SQLException {
  if (iface == CalciteServerStatement.class) {
    final CalciteServerStatement statement;
    try {
      statement = getConnection().server.getStatement(handle);
    } catch (NoSuchStatementException e) {
      throw new AssertionError("invalid statement", e);
    }
    return iface.cast(statement);
  }
  return super.unwrap(iface);
}
 
Example #19
Source File: RemoteMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Override public ExecuteResult execute(final StatementHandle h,
    final List<TypedValue> parameterValues, final int maxRowsInFirstFrame)
    throws NoSuchStatementException {
  try {
    return connection.invokeWithRetries(
        new CallableWithoutException<ExecuteResult>() {
          public ExecuteResult call() {
            final Service.ExecuteResponse response = service.apply(
                new Service.ExecuteRequest(h, parameterValues, maxRowsInFirstFrame));

            if (response.missingStatement) {
              throw new RuntimeException(new NoSuchStatementException(h));
            }

            List<MetaResultSet> metaResultSets = new ArrayList<>();
            for (Service.ResultSetResponse result : response.results) {
              metaResultSets.add(toResultSet(null, result));
            }

            return new ExecuteResult(metaResultSets);
          }
        });
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof NoSuchStatementException) {
      throw (NoSuchStatementException) cause;
    }
    throw e;
  }
}
 
Example #20
Source File: RemoteMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Override public Frame fetch(final StatementHandle h, final long offset,
    final int fetchMaxRowCount) throws NoSuchStatementException, MissingResultsException {
  try {
    return connection.invokeWithRetries(
        new CallableWithoutException<Frame>() {
          public Frame call() {
            final Service.FetchResponse response =
                service.apply(
                    new Service.FetchRequest(h.connectionId, h.id, offset, fetchMaxRowCount));
            if (response.missingStatement) {
              throw new RuntimeException(new NoSuchStatementException(h));
            }
            if (response.missingResults) {
              throw new RuntimeException(new MissingResultsException(h));
            }
            return response.frame;
          }
        });
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof NoSuchStatementException) {
      throw (NoSuchStatementException) cause;
    } else if (cause instanceof MissingResultsException) {
      throw (MissingResultsException) cause;
    }
    throw e;
  }
}
 
Example #21
Source File: RemoteMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount,
    PrepareCallback callback) throws NoSuchStatementException {
  // The old semantics were that maxRowCount was also treated as the maximum number of
  // elements in the first Frame of results. A value of -1 would also preserve this, but an
  // explicit (positive) number is easier to follow, IMO.
  return prepareAndExecute(h, sql, maxRowCount, AvaticaUtils.toSaturatedInt(maxRowCount),
      callback);
}
 
Example #22
Source File: MetaImpl.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
public ExecuteBatchResult executeBatch(StatementHandle h,
                                       List<List<TypedValue>> parameterValueLists) throws NoSuchStatementException {
    begin();
    try {
        return super.executeBatch(h, parameterValueLists);
    } finally {
        if (isAutoCommit()) {
            commit(connection.handle);
        }
    }
}
 
Example #23
Source File: LocalService.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public ExecuteBatchResponse apply(PrepareAndExecuteBatchRequest request) {
  final Meta.StatementHandle h = new Meta.StatementHandle(request.connectionId,
      request.statementId, null);
  try {
    ExecuteBatchResult result = meta.prepareAndExecuteBatch(h, request.sqlCommands);
    return new ExecuteBatchResponse(request.connectionId, request.statementId,
        result.updateCounts, false, serverLevelRpcMetadata);
  } catch (NoSuchStatementException e) {
    return new ExecuteBatchResponse(request.connectionId, request.statementId, null, true,
        serverLevelRpcMetadata);
  }
}
 
Example #24
Source File: LocalService.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public SyncResultsResponse apply(SyncResultsRequest request) {
  final Meta.StatementHandle h = new Meta.StatementHandle(
      request.connectionId, request.statementId, null);
  SyncResultsResponse response;
  try {
    // Set success on the cached statement
    response = new SyncResultsResponse(meta.syncResults(h, request.state, request.offset), false,
        serverLevelRpcMetadata);
  } catch (NoSuchStatementException e) {
    // Tried to sync results on a statement which wasn't cached
    response = new SyncResultsResponse(false, true, serverLevelRpcMetadata);
  }

  return response;
}
 
Example #25
Source File: MetaImpl.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
public ExecuteBatchResult prepareAndExecuteBatch(
    final StatementHandle h,
    List<String> sqlCommands) throws NoSuchStatementException {
    begin();
    try {
        return super.prepareAndExecuteBatch(h, sqlCommands);
    } finally {
        if (isAutoCommit()) {
            commit(connection.handle);
        }
    }
}
 
Example #26
Source File: LocalService.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public ExecuteResponse apply(PrepareAndExecuteRequest request) {
  try (final Context ignore = prepareAndExecuteTimer.start()) {
    final Meta.StatementHandle sh =
        new Meta.StatementHandle(request.connectionId, request.statementId, null);
    try {
      final Meta.ExecuteResult executeResult =
          meta.prepareAndExecute(sh, request.sql, request.maxRowCount,
              request.maxRowsInFirstFrame, new Meta.PrepareCallback() {
                @Override public Object getMonitor() {
                  return LocalService.class;
                }

                @Override public void clear() {
                }

                @Override public void assign(Meta.Signature signature,
                    Meta.Frame firstFrame, long updateCount) {
                }

                @Override public void execute() {
                }
              });
      final List<ResultSetResponse> results = new ArrayList<>();
      for (Meta.MetaResultSet metaResultSet : executeResult.resultSets) {
        results.add(toResponse(metaResultSet));
      }
      return new ExecuteResponse(results, false, serverLevelRpcMetadata);
    } catch (NoSuchStatementException e) {
      // The Statement doesn't exist anymore, bubble up this information
      return new ExecuteResponse(null, true, serverLevelRpcMetadata);
    }
  }
}
 
Example #27
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 5 votes vote down vote up
@Override public void closeStatement(StatementHandle h) {
  final CalciteConnectionImpl calciteConnection = getConnection();
  final CalciteServerStatement stmt;
  try {
    stmt = calciteConnection.server.getStatement(h);
  } catch (NoSuchStatementException e) {
    // statement is not valid; nothing to do
    return;
  }
  // stmt.close(); // TODO: implement
  calciteConnection.server.removeStatement(h);
}
 
Example #28
Source File: MetaImpl.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
public ExecuteResult prepareAndExecute(StatementHandle h,
                                       String sql, long maxRowCount, int maxRowsInFirstFrame,
                                       PrepareCallback callback) throws NoSuchStatementException {
    begin();
    try {
        return super.prepareAndExecute(h, sql, maxRowCount, maxRowsInFirstFrame, callback);
    } finally {
        if (isAutoCommit()) {
            commit(connection.handle);
        }
    }
}
 
Example #29
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount,
    int maxRowsInFirstFrame, PrepareCallback callback) throws NoSuchStatementException {
  try {
    final StatementInfo info = getStatementCache().getIfPresent(h.id);
    if (info == null) {
      throw new NoSuchStatementException(h);
    }
    final Statement statement = info.statement;
    // Make sure that we limit the number of rows for the query
    setMaxRows(statement, maxRowCount);
    boolean ret = statement.execute(sql);
    info.setResultSet(statement.getResultSet());
    // Either execute(sql) returned true or the resultSet was null
    assert ret || null == info.getResultSet();
    final List<MetaResultSet> resultSets = new ArrayList<>();
    if (null == info.getResultSet()) {
      // Create a special result set that just carries update count
      resultSets.add(
          JdbcResultSet.count(h.connectionId, h.id,
              AvaticaUtils.getLargeUpdateCount(statement)));
    } else {
      resultSets.add(
          JdbcResultSet.create(h.connectionId, h.id, info.getResultSet(), maxRowsInFirstFrame));
    }
    LOG.trace("prepAndExec statement {}", h);
    // TODO: review client to ensure statementId is updated when appropriate
    return new ExecuteResult(resultSets);
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
Example #30
Source File: RemoteMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Override public ExecuteBatchResult prepareAndExecuteBatch(final StatementHandle h,
    final List<String> sqlCommands) throws NoSuchStatementException {
  return connection.invokeWithRetries(new CallableWithoutException<ExecuteBatchResult>() {
    @Override public ExecuteBatchResult call() {
      Service.ExecuteBatchResponse response =
          service.apply(
              new Service.PrepareAndExecuteBatchRequest(h.connectionId, h.id, sqlCommands));
      return new ExecuteBatchResult(response.updateCounts);
    }
  });
}