<commit_before>/*
 * Copyright (c) 2011-2014 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 *     The Eclipse Public License is available at
 *     http://www.eclipse.org/legal/epl-v10.html
 *
 *     The Apache License v2.0 is available at
 *     http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */

package io.vertx.ext.jdbc.impl.actions;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractJDBCAction<T> {

  private static final Logger log = LoggerFactory.getLogger(AbstractJDBCAction.class);

  protected final Vertx vertx;
  protected final Connection conn;
  protected final Context context;

  protected AbstractJDBCAction(Vertx vertx, Connection conn, Context context) {
    this.vertx = vertx;
    this.conn = conn;
    this.context = context;
  }

  public void handle(Future<T> future, long timerID) {
    try {
      T result = execute(conn);
      if (!future.isComplete()) {
        vertx.cancelTimer(timerID);
        future.complete(result);
      }
    } catch (SQLException e) {
      if (!future.isComplete()) {
        vertx.cancelTimer(timerID);
        future.fail(e);
      }
    }
  }

  public void execute(Handler<AsyncResult<T>> resultHandler) {
    Future<T> f = Future.future();
    long timerID = vertx.setTimer(5000, id -> {
      if (!f.isComplete()) {
        f.fail(new TimeoutException());
      }
    });
    Context callbackContext = vertx.getOrCreateContext();
    context.runOnContext(v -> {
      f.setHandler(ar -> {
        callbackContext.runOnContext(v2 -> {
          resultHandler.handle(ar);
        });
      });
      handle(f, timerID);
    });
  }

  protected abstract T execute(Connection conn) throws SQLException;

  protected abstract String name();
}<commit_msg>remove timer<commit_after>/*
 * Copyright (c) 2011-2014 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 *     The Eclipse Public License is available at
 *     http://www.eclipse.org/legal/epl-v10.html
 *
 *     The Apache License v2.0 is available at
 *     http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */

package io.vertx.ext.jdbc.impl.actions;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractJDBCAction<T> {

  private static final Logger log = LoggerFactory.getLogger(AbstractJDBCAction.class);

  protected final Vertx vertx;
  protected final Connection conn;
  protected final Context context;

  protected AbstractJDBCAction(Vertx vertx, Connection conn, Context context) {
    this.vertx = vertx;
    this.conn = conn;
    this.context = context;
  }

  public void handle(Future<T> future) {
    try {
      T result = execute(conn);
      future.complete(result);
    } catch (SQLException e) {
      future.fail(e);
    }
  }

  public void execute(Handler<AsyncResult<T>> resultHandler) {
    Future<T> f = Future.future();
    Context callbackContext = vertx.getOrCreateContext();
    context.runOnContext(v -> {
      f.setHandler(ar -> {
        callbackContext.runOnContext(v2 -> {
          resultHandler.handle(ar);
        });
      });
      handle(f);
    });
  }

  protected abstract T execute(Connection conn) throws SQLException;

  protected abstract String name();
}
{'fraction_non_alphanumeric': 0.13224909052000855, 'fraction_numerical': 0.008987802268350097, 'mean_word_length': 3.0537727666955767, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6817043', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1345, 'n_words': 356}