コード例 #1
0
ファイル: MockDriver.java プロジェクト: bilxio/druid
  protected void afterConnectionClose(MockConnection conn) {
    connectionCloseCount.incrementAndGet();

    connections.remove(conn);

    if (LOG.isDebugEnabled()) {
      LOG.debug("conn-" + conn.getId() + " close");
    }
  }
コード例 #2
0
ファイル: MockDriver.java プロジェクト: bilxio/druid
  @Override
  public Connection connect(String url, Properties info) throws SQLException {
    if (!acceptsURL(url)) {
      return null;
    }

    if (info != null) {
      Object val = info.get("connectSleep");
      if (val != null) {
        long millis = Long.parseLong(val.toString());
        try {
          Thread.sleep(millis);
        } catch (InterruptedException e) {
          // skip
        }
      }
    }

    MockConnection conn = new MockConnection(this, url, info);

    if (LOG.isDebugEnabled()) {
      LOG.debug("connect, url " + url + ", id " + conn.getId());
    }

    if (url == null) {
      connectCount.incrementAndGet();
      connections.add(conn);
      return conn;
    }

    if (url.startsWith(prefix)) {
      String catalog = url.substring(prefix.length());
      conn.setCatalog(catalog);

      connectCount.incrementAndGet();
      connections.add(conn);
      return conn;
    }

    if (url.startsWith(mockPrefix)) {
      String catalog = url.substring(mockPrefix.length());
      conn.setCatalog(catalog);

      connectCount.incrementAndGet();
      connections.add(conn);
      return conn;
    }

    return null;
  }
コード例 #3
0
ファイル: MockDriver.java プロジェクト: bilxio/druid
  protected ResultSet executeQuery(MockStatement stmt, String sql) throws SQLException {
    if (logExecuteQueryEnable && LOG.isDebugEnabled()) {
      LOG.debug("executeQuery " + sql);
    }

    MockConnection conn = stmt.getMockConnection();

    long idleTimeMillis = System.currentTimeMillis() - conn.getLastActiveTimeMillis();
    if (idleTimeMillis >= this.idleTimeCount) {
      throw new SQLException("connection is idle time count");
    }

    conn.setLastActiveTimeMillis(System.currentTimeMillis());

    if (conn != null) {
      if (conn.getConnectProperties() != null) {
        Object propertyValue = conn.getConnectProperties().get("executeSleep");

        if (propertyValue != null) {
          long millis = Long.parseLong(propertyValue.toString());
          try {
            Thread.sleep(millis);
          } catch (InterruptedException e) {
            // skip
          }
        }
      }
    }

    if ("SELECT value FROM _int_1000_".equalsIgnoreCase(sql)) {
      MockResultSet rs = new MockResultSet(stmt);

      for (int i = 0; i < 1000; ++i) {
        rs.getRows().add(new Object[] {i});
      }

      return rs;
    }

    return this.executeHandler.executeQuery(stmt, sql);
  }