Package org.sonar.core.profiling

Examples of org.sonar.core.profiling.StopWatch


      if (staticResourceDirs.contains(rootDir)) {
        // Static resource, not profiled
        chain.doFilter(request, response);
      } else {
        StopWatch watch = getProfiling().start("http", Level.BASIC);
        try {
          chain.doFilter(request, response);
        } finally {
          String queryString = httpRequest.getQueryString();
          watch.stop(queryString == null ? MESSAGE_WITHOUT_QUERY : MESSAGE_WITH_QUERY, httpRequest.getMethod(), requestUri, queryString);
        }
      }
    } else {
      // Not an HTTP request, not profiled
      chain.doFilter(request, response);
View Full Code Here


    return copyTableColumns(source, dest, table, selectQuery, null);
  }

  public DbTemplate copyTableColumns(DataSource source, DataSource dest, String table, String selectQuery, @Nullable String[] columnNames) {
    LOG.debug("Copy table {}", table);
    StopWatch watch = profiling.start("previewdb", Level.BASIC);

    truncate(dest, table);

    Connection sourceConnection = null;
    Statement sourceStatement = null;
    ResultSet sourceResultSet = null;
    Connection destConnection = null;
    ResultSet destResultSet = null;
    PreparedStatement destStatement = null;
    int count = 0;
    try {
      sourceConnection = source.getConnection();
      sourceStatement = sourceConnection.createStatement();
      sourceResultSet = sourceStatement.executeQuery(selectQuery);

      if (sourceResultSet.next()) {
        if (columnNames == null) {
          // Copy all columns
          columnNames = columnNames(sourceResultSet);
        }
        int[] columnTypes = columnTypes(sourceResultSet);

        destConnection = dest.getConnection();
        destConnection.setAutoCommit(false);

        String insertSql = new StringBuilder().append("INSERT INTO ").append(table).append("(").append(Joiner.on(",").join(columnNames))
          .append(") VALUES(").append(StringUtils.repeat("?", ",", columnNames.length)).append(")").toString();
        destStatement = destConnection.prepareStatement(insertSql);

        do {
          copyColumns(sourceResultSet, destStatement, columnNames, columnTypes);
          count++;
          destStatement.addBatch();
          if (count % BatchSession.MAX_BATCH_SIZE == 0) {
            destStatement.executeBatch();
            destConnection.commit();

          }
        } while (sourceResultSet.next());

        destStatement.executeBatch();
        destConnection.commit();
      }
    } catch (SQLException e) {
      LOG.error("Fail to copy table " + table, e);
      throw new IllegalStateException("Fail to copy table " + table, e);
    } finally {
      watch.stop("  " + count + " rows of " + table + " copied");
      DbUtils.closeQuietly(destStatement);
      DbUtils.closeQuietly(destResultSet);
      DbUtils.closeQuietly(destConnection);
      DbUtils.closeQuietly(sourceResultSet);
      DbUtils.closeQuietly(sourceStatement);
View Full Code Here

    this.database = database;
    this.profiling = profiling;
  }

  public File createNewDatabaseForDryRun(Long projectId, File destFolder, String dbFileName) {
    StopWatch watch = profiling.start("previewdb", Level.BASIC);

    String h2Name = destFolder.getAbsolutePath() + File.separator + dbFileName;

    try {
      DataSource source = database.getDataSource();
      BasicDataSource destination = create(DIALECT, DRIVER, USER, PASSWORD, URL + h2Name + ";LOG=0;CACHE_SIZE=65536;LOCK_MODE=0;UNDO_LOG=0");

      copy(source, destination, projectId);
      close(destination);

      File dbFile = new File(h2Name + H2_FILE_SUFFIX);

      long size = dbFile.length();
      String message = "";
      if (projectId == null) {
        message = "Preview Database created, size is " + size + " bytes";
      } else {
        message = "Preview Database for project " + projectId + " created, size is " + size + " bytes";
      }
      watch.stop(message);

      return dbFile;

    } catch (SQLException e) {
      throw new SonarException("Unable to create database for DryRun", e);
View Full Code Here

TOP

Related Classes of org.sonar.core.profiling.StopWatch

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.