Esempio n. 1
0
 /**
  * Remove (delete) a CompanyBDO object whose CompanyDO refers to the DO held by this BDO.
  *
  * @param r CompanyBDO to be deleted.
  * @param tran The transaction to be used for the commit. If null, a new transaction is created.
  * @exception DatabaseManagerException if could not create a transaction
  * @exception java.sql.SQLException if any SQL errors occur.
  * @exception DataObjectException If object is not found in the database.
  */
 public void removeCompanyBDO(jobmatch.data.CompanyBDO rbdo, DBTransaction tran)
     throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException,
         DBRowUpdateException, QueryException {
   IndustryDO rdo = rbdo.getIndustry();
   String rdoHandle = rdo.getHandle();
   String mydoHandle = DO.getHandle();
   if (null == rdoHandle || null == mydoHandle || (!rdoHandle.equals(mydoHandle))) {
     throw new DataObjectException(
         "Object " + rdo + " does not refer to object " + DO + ", cannot be removed this way.");
   }
   rbdo.delete(tran);
 }
Esempio n. 2
0
 /**
  * Set Description of the IndustryDO
  *
  * @param Description of the IndustryDO
  * @exception DataObjectException If the object is not found in the database.
  */
 public void setDescription(String Description) throws DataObjectException {
   try {
     // business actions/assertions prior to data assignment
     beforeAnySet();
   } catch (Exception e) {
     throw new DataObjectException("beforeAnySet: " + e.getMessage());
   }
   DO.setDescription(Description);
   afterAnySet(); // business actions/assertions after data assignment
 }
Esempio 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 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 {
    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.

        {
          // perform cascading delete on referring table
          jobmatch.data.CompanyBDO[] a = getCompanyBDOArray();
          for (int i = 0; i < a.length; i++) {
            a[i].delete(dbt);
          }
        }

        // The following line keeps the compiler happy
        // when the CASCADING_DELETES tag is empty.
        if (false) throw new QueryException("XXX");
      } else {
        // commit referenced DOs.

      }
      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(DO);
      } else {
        if (DO.isLoaded()) dbt.insert(DO); // dbt.insert() handles insertions and updates
      }
      if (ownTransaction) {
        dbt.commit(); // commit the transaction
      }
    } catch (DataObjectException doe) {
      throw doe;
    } 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();
      }
    }
  }
Esempio n. 4
0
 /**
  * Get Description of the IndustryDO
  *
  * @return Description of the IndustryDO
  * @exception DataObjectException If the object is not found in the database.
  */
 public String getDescription() throws DataObjectException {
   beforeAnyGet(); // business actions/assertions prior to data return
   return DO.getDescription();
 }
Esempio n. 5
0
 /** for debugging */
 public String toString() {
   if (null == DO) return "NULL";
   return DO.toString();
 }
Esempio n. 6
0
 /**
  * @param handle <CODE>String</CODE> representation of the id for this BDO
  * @return boolean True if the string version of the id of this DO matches passed handle
  * @see getHandle
  */
 public boolean hasMatchingHandle(String handle) {
   return DO.hasMatchingHandle(handle);
 }
Esempio n. 7
0
 /**
  * The methods <CODE>
  *     getHandle
  *     hasMatchingHandle
  * </CODE> are used by Presentation Objects that need to populate
  * HTML select lists with <CODE>IndustryBDO</CODE> objects as options.
  *
  * The <CODE>getHandle()</CODE> method is used
  * to set the value for each option,
  * and the <CODE>hasMatchingHandle()<CODE>
  * methods are used to lookup the Data Object when the selection has
  * been made.
  *
  * This IndustryBDO object holds a reference to a IndustryDO object.
  * The id of this IndustryBDO is the id of its IndustryDO.
  * @exception DatabaseManagerException
  *   If a connection to the database cannot be established, etc.
  * @return id of this BDO as a string
  *   If an object id can't be allocated for this object.
  */
 public String getHandle() throws DatabaseManagerException {
   return DO.getHandle();
 }
Esempio n. 8
0
 // beforeAnySet throws plain Exception to allow overriding implementations
 // to throw any flavor needed.
 protected void beforeAnySet() throws Exception {
   if (DO.isReadOnly()) throw new DataObjectException(DO + " is read-only.");
 }
Esempio n. 9
0
 /** Constructor required by <CODE>IndustryBDO.create</CODE> methods. */
 public IndustryBDO() throws Exception {
   this.DO = IndustryDO.createVirgin();
 }