/**
   * Set the OperatingSystem to query.
   *
   * @param x The OperatingSystem of the OperatingsystemProfile to query.
   * @param exact to use matches or not
   * @exception DataObjectException If a database access error occurs.
   */
  public void setQueryOperatingSystem(jobmatch.data.OperatingsystemDO x, boolean exact)
      throws DataObjectException, QueryException {
    // Remove from cacheHits any DOs that do not meet this
    // setQuery requirement.
    for (int i = 0; i < cacheHits.size() && !hitDb; i++) {
      OperatingsystemProfileDO DO = (OperatingsystemProfileDO) cacheHits.elementAt(i);
      if (null == DO) continue;
      boolean equals = true;

      // DOs are compared by their handles..
      jobmatch.data.OperatingsystemDO m = DO.getOperatingSystem();
      if (null == m && null == x) {
        equals = true;
      } else if (null == m || null == x) {
        equals = false;
      } else {
        equals = (DO.getOperatingSystem().getOId().toString().equals(x.getOId().toString()));
        if (equals && m != x) {
          System.err.println("\n----------------------------------------------------------");
          System.err.println("m =" + m);
          System.err.println("x =" + x);
        }
      }

      if (!equals) cacheHits.removeElementAt(i--);
    }

    // Also prepare the SQL needed to query the database
    // in case there is no cache, or the query involves other tables.
    if (partialCache || hitDb)
      builder.addWhereClause(
          "OperatingSystem", x, "DECIMAL(19,0)", QueryBuilder.NOT_NULL, exactFlag(exact));
  }
  /**
   * Set the OID to query. WARNING! This method assumes that table <CODE>OperatingsystemProfile
   * </CODE> has a column named <CODE>"oid"</CODE>. This method is called from the DO classes to
   * retrieve an object by id.
   *
   * @param oid The object id to query.
   */
  public void setQueryOId(ObjectId oid) {
    // Remove from cacheHits any DOs that do not meet this
    // setQuery requirement.
    if (null == oid) return;
    requireUniqueInstance();
    for (int i = 0; i < cacheHits.size(); i++) {
      OperatingsystemProfileDO DO = (OperatingsystemProfileDO) cacheHits.elementAt(i);
      if (null == DO) continue;
      boolean equals = true;
      ObjectId id = DO.getOId();
      if (null == id || !id.equals(oid)) cacheHits.removeElementAt(i--);
    }

    // Also prepare the SQL needed to query the database
    // in case there is no cache, or the query involves other tables.
    builder.addWhereClause("oid", oid.toBigDecimal(), QueryBuilder.NOT_NULL);
  }
  /**
   * Set the LeafNumber to query.
   *
   * @param x The LeafNumber of the OperatingsystemProfile to query.
   * @param exact to use matches or not
   * @exception DataObjectException If a database access error occurs.
   */
  public void setQueryLeafNumber(int x, boolean exact) throws DataObjectException, QueryException {
    // Remove from cacheHits any DOs that do not meet this
    // setQuery requirement.
    for (int i = 0; i < cacheHits.size() && !hitDb; i++) {
      OperatingsystemProfileDO DO = (OperatingsystemProfileDO) cacheHits.elementAt(i);
      if (null == DO) continue;
      boolean equals = true;

      // primitive types are compared using the == operator.
      equals = (DO.getLeafNumber() == x);

      if (!equals) cacheHits.removeElementAt(i--);
    }

    // Also prepare the SQL needed to query the database
    // in case there is no cache, or the query involves other tables.
    if (partialCache || hitDb)
      builder.addWhereClause("LeafNumber", x, "INTEGER", QueryBuilder.NULL_OK, exactFlag(exact));
  }
  /**
   * Perform the query on the database, and prepare the array of returned DO objects.
   *
   * @exception DataObjectException If a database access error occurs.
   * @exception NonUniqueQueryException If too many rows were found.
   */
  private void runQuery() throws DataObjectException, NonUniqueQueryException {
    needToRun = false;
    arrayIndex = -1;

    DBQuery dbQuery = null;
    try {
      Vector results;
      /*
         if ( cacheHits.size() > 0 ) {
      // The setQuery methods build up the cacheHits.
      // If the cache had our desired objects,
      // we don't query the database, so we have no ResultSet.
      results = cacheHits;	 // executeQuery saw cache hits
         } else {
      // If the cache doesn't exist, or could not handle the query,
      // then we actually query the database.
      dbQuery = Enhydra.getDatabaseManager().createQuery();
      dbQuery.query( this );    // invokes executeQuery
             results = new Vector();
             while ( resultSet.next() ) {
          results.addElement( new OperatingsystemProfileDO ( resultSet ) );
             }
         }
         */
      if (/* partialCache && */ 0 == cacheHits.size()) hitDb = true;
      if (hitDb) {
        dbQuery = Enhydra.getDatabaseManager().createQuery();
        dbQuery.query(this); // invokes executeQuery
        results = new Vector();
        while (resultSet.next()) {
          //		    results.addElement( new OperatingsystemProfileDO ( resultSet ) );
          results.addElement(OperatingsystemProfileDO.createExisting(resultSet));
        }
      } else {
        results = cacheHits; // executeQuery saw cache hits
      }

      if (results.size() > 1 && uniqueInstance)
        throw new NonUniqueQueryException("Too many rows returned from database");
      DOs = new OperatingsystemProfileDO[results.size()];
      for (int i = 0; i < results.size(); i++) {
        DOs[i] = (OperatingsystemProfileDO) results.elementAt(i);
      }
      arrayIndex = 0;
    } catch (SQLException se) {
      if (null == se.getSQLState()) {
        throw new DataObjectException("Unknown SQLException", se);
      }
      if (se.getSQLState().startsWith("02") && se.getErrorCode() == 100) {
        throw new DataObjectException("Update or delete DO is out of synch", se);
      } else if (se.getSQLState().equals("S1000") && se.getErrorCode() == -268) {
        throw new DataObjectException("Integrity constraint violation", se);
      } else {
        throw new DataObjectException("Data Object Error", se);
      }
    } catch (ObjectIdException oe) {
      throw new DataObjectException("Object ID Error", oe);
    } catch (DatabaseManagerException de) {
      throw new DataObjectException("Database connection Error", de);
    } finally {
      if (null != dbQuery) dbQuery.release();
    }
  }