Example #1
0
 public Object get(ResultSet resultSet, int column) throws SQLException {
   switch (this) {
     case OBJECT:
       return resultSet.getObject(column + 1);
     case STRING:
       return resultSet.getString(column + 1);
     case INT:
       return resultSet.getInt(column + 1);
     case LONG:
       return resultSet.getLong(column + 1);
     case DOUBLE:
       return resultSet.getDouble(column + 1);
     default:
       throw Util.unexpected(this);
   }
 }
Example #2
0
 public List<Type> guessTypes() throws SQLException {
   final ResultSetMetaData metaData = resultSet.getMetaData();
   final int columnCount = metaData.getColumnCount();
   assert this.types == null || this.types.size() == columnCount;
   List<Type> types = new ArrayList<Type>();
   for (int i = 0; i < columnCount; i++) {
     final Type suggestedType = this.types == null ? null : this.types.get(i);
     types.add(guessType(suggestedType, metaData, i));
   }
   return types;
 }
Example #3
0
  /**
   * Closes all resources (statement, result set) held by this SqlStatement.
   *
   * <p>If any of them fails, wraps them in a {@link RuntimeException} describing the high-level
   * operation which this statement was performing. No further error-handling is required to produce
   * a descriptive stack trace, unless you want to absorb the error.
   */
  public void close() {
    if (haveSemaphore) {
      haveSemaphore = false;
      querySemaphore.leave();
    }

    // According to the JDBC spec, closing a statement automatically closes
    // its result sets, and closing a connection automatically closes its
    // statements. But let's be conservative and close everything
    // explicitly.
    Statement statement = null;
    SQLException ex = null;
    if (resultSet != null) {
      try {
        statement = resultSet.getStatement();
        resultSet.close();
      } catch (SQLException e) {
        ex = e;
      } finally {
        resultSet = null;
      }
    }
    if (statement != null) {
      try {
        statement.close();
      } catch (SQLException e) {
        if (ex != null) {
          ex = e;
        }
      }
    }
    if (jdbcConnection != null) {
      try {
        jdbcConnection.close();
      } catch (SQLException e) {
        if (ex != null) {
          ex = e;
        }
      } finally {
        jdbcConnection = null;
      }
    }

    if (ex != null) {
      throw Util.newError(ex, locus.message + "; sql=[" + sql + "]");
    }

    long endTime = System.currentTimeMillis();
    long totalMs = endTime - startTimeMillis;
    String status = ", exec+fetch " + totalMs + " ms, " + rowCount + " rows";

    locus.execution.getQueryTiming().markFull(TIMING_NAME + locus.component, totalMs);

    RolapUtil.SQL_LOGGER.debug(id + ": " + status);

    if (RolapUtil.LOGGER.isDebugEnabled()) {
      RolapUtil.LOGGER.debug(locus.component + ": done executing sql [" + sql + "]" + status);
    }

    locus
        .getServer()
        .getMonitor()
        .sendEvent(
            new SqlStatementEndEvent(endTime, id, locus, sql, getPurpose(), rowCount, false, null));
  }