コード例 #1
0
  /**
   * Execute queries.
   *
   * @param queries queries list
   * @param streaming is streaming flag
   * @param isRewritable is rewritable flag
   * @param rewriteOffset rewriteoffset
   * @return queryResult
   * @throws QueryException exception
   */
  public AbstractQueryResult executeBatch(
      final List<Query> queries, boolean streaming, boolean isRewritable, int rewriteOffset)
      throws QueryException {
    for (Query query : queries) {
      query.validate();
    }

    this.moreResults = false;
    final SendTextQueryPacket packet =
        new SendTextQueryPacket(queries, isRewritable, rewriteOffset);
    try {
      packet.send(writer);
    } catch (MaxAllowedPacketException e) {
      if (e.isMustReconnect()) {
        connect();
      }
      throw new QueryException(
          "Could not send query: " + e.getMessage(),
          -1,
          ExceptionMapper.SqlStates.INTERRUPTED_EXCEPTION.getSqlState(),
          e);
    } catch (IOException e) {
      throw new QueryException(
          "Could not send query: " + e.getMessage(),
          -1,
          ExceptionMapper.SqlStates.CONNECTION_EXCEPTION.getSqlState(),
          e);
    }

    try {
      return getResult(queries, streaming, false);
    } catch (QueryException qex) {
      if (qex.getCause() instanceof SocketTimeoutException) {
        throw new QueryException(
            "Connection timed out",
            -1,
            ExceptionMapper.SqlStates.CONNECTION_EXCEPTION.getSqlState(),
            qex);
      } else {
        throw qex;
      }
    }
  }
コード例 #2
0
 private int sendQuery(SendTextQueryPacket packet) throws QueryException {
   try {
     return packet.send(writer);
   } catch (MaxAllowedPacketException e) {
     if (e.isMustReconnect()) {
       connect();
     }
     throw new QueryException(
         "Could not send query: " + e.getMessage(),
         -1,
         ExceptionMapper.SqlStates.INTERRUPTED_EXCEPTION.getSqlState(),
         e);
   } catch (IOException e) {
     throw new QueryException(
         "Could not send query: " + e.getMessage(),
         -1,
         ExceptionMapper.SqlStates.CONNECTION_EXCEPTION.getSqlState(),
         e);
   }
 }