/**
   * Set the Profile to query.
   *
   * @param x The Profile of the OperatingsystemProfile to query.
   * @param exact to use matches or not
   * @exception DataObjectException If a database access error occurs.
   */
  public void setQueryProfile(jobmatch.data.ProfileDO 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.ProfileDO m = DO.getProfile();
      if (null == m && null == x) {
        equals = true;
      } else if (null == m || null == x) {
        equals = false;
      } else {
        equals = (DO.getProfile().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(
          "Profile", x, "DECIMAL(19,0)", QueryBuilder.NOT_NULL, exactFlag(exact));
  }
Exemplo n.º 2
0
  /**
   * initFromResultSet initializes the data members from NewDBTable. This code was separated from
   * the ResultSet constructor so that createExisting(ResultSet) could handle VIEWs.
   */
  private void initFromResultSet(ResultSet rs)
      throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
    // Constructing a DO from a ResultSet means we definitely need the
    // DataStruct ready for the setXxx methods invoked below.
    data = new TreeLeafDataStruct();

    // writeMemberStuff uses the ResultSetExtraction.template
    // to build up the value for this tag:
    // the value is a series of calls to the DO set methods.

    setLeafNumber(rs.getInt("LeafNumber"));

    setProfile(jobmatch.data.ProfileDO.createExisting(rs.getBigDecimal("Profile", 0)));

    setMandatory(rs.getBoolean("Mandatory"));

    markClean();
  }
Exemplo n.º 3
0
  /**
   * Modifies the DO within its table. Performs recursive commit/delete on referenced DOs; all
   * operations occur within a single transaction to allow rollback in the event of error. Only the
   * creator of the transaction releases it.
   *
   * @param dbt The transaction object to use for this operation.
   * @param delete True if doing a delete, otherwise doing insert/update.
   * @exception com.lutris.appserver.server.sql.DatabaseManagerException if a Transaction can not be
   *     created.
   * @exception com.lutris.appserver.server.sql.DBRowUpdateException if a version error occurs.
   * @exception RefAssertionException thrown by okTo method.
   * @exception java.sql.SQLException if any SQL errors occur.
   */
  protected void modifyDO(DBTransaction dbt, boolean delete)
      throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException,
          DBRowUpdateException, QueryException {
    if (delete) okToDelete();
    else okToCommit();
    boolean ownTransaction = false;
    try {
      if (null == dbt) {
        DatabaseManager dbm = Enhydra.getDatabaseManager();
        dbt = dbm.createTransaction(); // create a transaction
        ownTransaction = true;
      }
      if (null == dbt)
        throw new DatabaseManagerException("DatabaseManager.createTransaction returned null.");
      if (delete) {
        // Code to perform cascading deletes is generated here
        // if cascading deletes are not supported by the database.

        // The following line keeps the compiler happy
        // when the CASCADING_DELETES tag is empty.
        if (false) throw new QueryException("XXX");
      } else {
        // commit referenced DOs.
        jobmatch.data.ProfileDO Profile_DO = getProfile();
        if (null != Profile_DO) {
          if (Profile_DO.isLoaded()) {
            okToCommitProfile(Profile_DO);
            Profile_DO.commit(dbt);
          } else {
            // since the referenced DO is not loaded,
            // it cannot be dirty, so there is no need to commit it.
          }
        } else {
          if (!false)
            throw new RefAssertionException(
                "Cannot commit TreeLeafDO ( "
                    + toString()
                    + " ) because Profile is not allowed to be null.");
        }
      }
      if (false) {
        // This throw is here to keep the compiler happy
        // in the case of a DO that does not refer to other DOs.
        // In that case, the above delete/commit code blocks will be empty
        // and throw nothing.
        throw new DataObjectException("foo");
      }
      if (delete) {
        dbt.delete(this);
      } else {
        if (isLoaded()) dbt.insert(this); // dbt.insert() handles insertions and updates
      }
      if (ownTransaction) {
        dbt.commit(); // commit the transaction
      }
    } catch (SQLException sqle) {
      StringBuffer message = new StringBuffer("Failed to insert/update DO: ");
      message.append(sqle.getMessage());

      // rollback, if necessary
      if (ownTransaction) {
        try {
          dbt.rollback();
        } catch (SQLException sqle2) {
          message.insert(0, "\n");
          message.insert(0, sqle2.getMessage());
          message.insert(0, "Rollback failed: ");
        }
      }
      throw new SQLException(message.toString());
    } finally {
      // release the transaction, if any
      if (ownTransaction) {
        dbt.release();
      }
    }
  }