Package pt.opensoft.util

Examples of pt.opensoft.util.Timer


   * query; never null
   * @exception SQLException if a database-access error occurs.
   */

  public ResultSet executeQuery () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    ResultSet results = null;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("query");
    try {
      results = ((PreparedStatement) _stmt).executeQuery();
    } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
      if (tooLong) logger.push("too long");
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return results;
  }
View Full Code Here


   * for SQL statements that return nothing
   * @exception SQLException if a database-access error occurs.
   */

  public int executeUpdate () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    if(_doQueryTimeout)
    _stmt.setQueryTimeout(_queryTimeout);
    int count = 0;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("update");
    try {
      count = ((PreparedStatement) _stmt).executeUpdate();
    } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
            _dbc.setDbChanged(true);
            logger.push(count + " ROWS");
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return count;
  }
View Full Code Here

   * @exception SQLException if a database-access error occurs.
   * @see Statement#executeQuery(java.lang.String)
   * @see Statement#executeUpdate(java.lang.String)
   */
  public boolean execute () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    boolean result = false;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("execute");
    try {
      result = ((PreparedStatement) _stmt).execute();
    } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
            _dbc.setDbChanged(true);
      logger.push(String.valueOf(result));
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return result;
  }
View Full Code Here

    /**
     * Submits a batch of commands to the database for execution and
     * if all commands execute successfully, returns an array of update counts.
     */
  public int[] executeBatch() throws SQLException {
      Timer timer = new Timer();
        timer.start();
        int[] results = null;
        Exception ex = null;
        Logger logger = _dbc.getLogger();
        logger.push("BATCH");
        try {
            results = _stmt.executeBatch();
        } catch (SQLException e) {
            ex = e;
            throw e;
        } finally {
            timer.stop();
            boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
            if (tooLong) logger.push("too long");
            if (ex != null) {
                logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
            } else if (tooLong) {
                logger.warning(timer.ellapsed(), getSQLString());
            } else {
                logger.debug(timer.ellapsed(), getSQLString());
            }
        }
        return results;
    }
View Full Code Here

        this(DEFAULT_APP_NAME, name);
    }

    public Transaction(String app, String name) {
        super(name, true);
        processTimer = new Timer();
        logger = Logger.getDefault().getWrapper();
        if (app != null) {
            application = app;
        } else {
            application = DEFAULT_APP_NAME;
View Full Code Here

TOP

Related Classes of pt.opensoft.util.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.