@SuppressWarnings("unchecked")
  static <T> T executeWithArray(Query query, Object[] params, String sql, int limit) throws MetaException {
    try {
      if (limit >= 0)
        query.setRange(0, limit);
      return (T)((params == null) ? query.execute() : query.executeWithArray(params));
    } catch (Exception ex) {
      StringBuilder errorBuilder = new StringBuilder("Failed to execute [" + sql + "] with parameters [");
      if (params != null) {
        boolean isFirst = true;
        for (Object param : params) {
          errorBuilder.append((isFirst ? "" : ", ") + param);
          isFirst = false;
        }
      }
      LOG.warn(errorBuilder.toString() + "]", ex);
      // We just logged an exception with (in case of JDO) a humongous callstack. Make a new one.
      throw new MetaException("See previous errors; " + ex.getMessage() + errorBuilder.toString() + "]");
    }
  }
Helper utilities used by DirectSQL code in HiveMetastore.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java