Exemple #1
0
  protected ResultSet createResultSet(MockPreparedStatement stmt) {
    MockResultSet rs = new MockResultSet(stmt);

    String sql = stmt.getSql();

    if ("SELECT 1".equalsIgnoreCase(sql)) {
      rs.getRows().add(new Object[] {1});
    } else if ("SELECT NOW()".equalsIgnoreCase(sql)) {
      rs.getRows().add(new Object[] {new java.sql.Timestamp(System.currentTimeMillis())});
    } else if ("SELECT ?".equalsIgnoreCase(sql)) {
      rs.getRows().add(new Object[] {stmt.getParameters().get(0)});
    }

    return rs;
  }
Exemple #2
0
  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);
  }