/**
     * Returns the reults as an ArrayList of Record objects. The Result set is closed within this
     * call
     *
     * @param maxRows if the result set contains more than this param then an exception is thrown
     */
    public ArrayList<DataPoint> getArrayList(int maxRows) {
      ArrayList<DataPoint> results = new ArrayList<DataPoint>();
      int count = 0;

      try {
        if (m_onFirstResult) {
          count++;
          results.add(factory.newDataPoint(m_resultSet));
        }

        while (m_resultSet.next() && (count < maxRows)) {
          count++;
          results.add(factory.newDataPoint(m_resultSet));
        }

        if (m_resultSet.next())
          throw new GenOrmException(
              "Bound of " + maxRows + " is too small for query [" + m_query + "]");
      } catch (java.sql.SQLException sqle) {
        sqle.printStackTrace();
        throw new GenOrmException(sqle);
      }

      close();
      return (results);
    }
    /**
     * Find the record with the specified primary keys
     *
     * @return DataPoint or null if no record is found
     */
    public DataPoint find(int id) {
      DataPoint rec = new DataPoint();

      // Create temp object and look in cache for it
      ((DataPoint_base) rec).initialize(id);
      rec = (DataPoint) GenOrmDataSource.getGenOrmConnection().getCachedRecord(rec.getRecordKey());

      java.sql.PreparedStatement genorm_statement = null;
      java.sql.ResultSet genorm_rs = null;

      if (rec == null) {
        try {
          // No cached object so look in db
          genorm_statement = GenOrmDataSource.prepareStatement(SELECT + FROM + KEY_WHERE);
          genorm_statement.setInt(1, id);

          s_logger.debug(genorm_statement.toString());

          genorm_rs = genorm_statement.executeQuery();
          if (genorm_rs.next()) rec = newDataPoint(genorm_rs);
        } catch (java.sql.SQLException sqle) {
          throw new GenOrmException(sqle);
        } finally {
          try {
            if (genorm_rs != null) genorm_rs.close();

            if (genorm_statement != null) genorm_statement.close();
          } catch (java.sql.SQLException sqle2) {
            throw new GenOrmException(sqle2);
          }
        }
      }

      return (rec);
    }
    /**
     * This call expects only one record in the result set. If multiple records are found an
     * excpetion is thrown. The ResultSet object is automatically closed by this call.
     */
    public DataPoint getOnlyRecord() {
      DataPoint ret = null;

      try {
        if (m_resultSet.next()) ret = factory.newDataPoint(m_resultSet);

        if (m_resultSet.next())
          throw new GenOrmException("Multiple rows returned in call from DataPoint.getOnlyRecord");
      } catch (java.sql.SQLException sqle) {
        throw new GenOrmException(sqle);
      }

      close();
      return (ret);
    }
 /**
  * Closes any underlying java.sql.Result set and java.sql.Statement that was used to create this
  * results set.
  */
 public void close() {
   try {
     m_resultSet.close();
     m_statement.close();
   } catch (java.sql.SQLException sqle) {
     throw new GenOrmException(sqle);
   }
 }
  // ---------------------------------------------------------------------------
  protected void initialize(java.sql.ResultSet rs) {
    try {
      if (s_logger.isDebug()) {
        java.sql.ResultSetMetaData meta = rs.getMetaData();
        for (int I = 1; I <= meta.getColumnCount(); I++) {
          s_logger.debug("Reading - " + meta.getColumnName(I) + " : " + rs.getString(I));
        }
      }
      m_id.setValue(rs, 1);
      m_metricId.setValue(rs, 2);
      m_timestamp.setValue(rs, 3);
      m_longValue.setValue(rs, 4);
      m_doubleValue.setValue(rs, 5);

    } catch (java.sql.SQLException sqle) {
      throw new GenOrmException(sqle);
    }
  }
    /** Returns true if there is another record in the result set. */
    public boolean next() {
      boolean ret = false;
      m_onFirstResult = true;
      try {
        ret = m_resultSet.next();
      } catch (java.sql.SQLException sqle) {
        throw new GenOrmException(sqle);
      }

      return (ret);
    }
    /**
     * This resets the key generator from the values in the database Usefull if the generated key
     * has been modified via some other means Connection must be open before calling this
     */
    public synchronized void reset() {
      m_nextKey = 0;
      java.sql.Statement stmnt = null;
      java.sql.ResultSet rs = null;
      try {
        stmnt = GenOrmDataSource.createStatement();
        rs = stmnt.executeQuery(MAX_QUERY);

        if (rs.next()) m_nextKey = rs.getInt(1);
      } catch (java.sql.SQLException sqle) {
        // The exception may occur if the table does not yet exist
        if (WARNINGS) System.out.println(sqle);
      } finally {
        try {
          if (rs != null) rs.close();

          if (stmnt != null) stmnt.close();
        } catch (java.sql.SQLException sqle2) {
          throw new GenOrmException(sqle2);
        }
      }
    }
    public DataPointKeyGenerator(javax.sql.DataSource ds) {
      m_nextKey = 0;
      java.sql.Connection con = null;
      java.sql.Statement stmnt = null;
      try {
        con = ds.getConnection();
        con.setAutoCommit(true);
        stmnt = con.createStatement();
        java.sql.ResultSet rs = stmnt.executeQuery(MAX_QUERY);
        if (rs.next()) m_nextKey = rs.getInt(1);

        rs.close();
      } catch (java.sql.SQLException sqle) {
        // The exception may occur if the table does not yet exist
        if (WARNINGS) System.out.println(sqle);
      } finally {
        try {
          if (stmnt != null) stmnt.close();

          if (con != null) con.close();
        } catch (java.sql.SQLException sqle) {
        }
      }
    }
    /**
     * Returns the reults as an ArrayList of Record objects. The Result set is closed within this
     * call
     */
    public ArrayList<DataPoint> getArrayList() {
      ArrayList<DataPoint> results = new ArrayList<DataPoint>();

      try {
        if (m_onFirstResult) results.add(factory.newDataPoint(m_resultSet));

        while (m_resultSet.next()) results.add(factory.newDataPoint(m_resultSet));
      } catch (java.sql.SQLException sqle) {
        sqle.printStackTrace();
        throw new GenOrmException(sqle);
      }

      close();
      return (results);
    }