protected long realCreate(AttrSetter attrSetter, String insertStatement)
      throws IOException {
    int retryCount = 0;

    PreparedStatement stmt = null;
    ResultSet generatedKeys = null;
    while (true) {
      try {
        stmt = conn.getPreparedStatement(insertStatement, Statement.RETURN_GENERATED_KEYS);
        attrSetter.set(stmt);
        stmt.execute();
        generatedKeys = stmt.getGeneratedKeys();
        generatedKeys.next();
        long newId = generatedKeys.getLong(1);
        return newId;
      } catch (SQLRecoverableException e) {
        conn.resetConnection(e);
        if (++retryCount > MAX_CONNECTION_RETRIES) {
          throw new IOException(e);
        }
      } catch (SQLException e) {
        throw new IOException(e);
      } finally {
        closeQuery(generatedKeys, stmt);
      }
    }
  }