/**
   * selects a collection of OrdenTrabajo objects pre-filled with their Trabajador objects.
   *
   * <p>This method is protected by default in order to keep the public api reasonable. You can
   * provide public methods for those you actually need in OrdenTrabajoPeer.
   *
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  protected static List doSelectJoinTrabajador(Criteria criteria) throws TorqueException {
    setDbName(criteria);

    OrdenTrabajoPeer.addSelectColumns(criteria);
    int offset = numColumns + 1;
    TrabajadorPeer.addSelectColumns(criteria);

    criteria.addJoin(OrdenTrabajoPeer.RESPONSABLE_ID, TrabajadorPeer.ID);

    List rows = BasePeer.doSelect(criteria);
    List results = new ArrayList();

    for (int i = 0; i < rows.size(); i++) {
      Record row = (Record) rows.get(i);

      Class omClass = OrdenTrabajoPeer.getOMClass();
      OrdenTrabajo obj1 = (OrdenTrabajo) OrdenTrabajoPeer.row2Object(row, 1, omClass);
      omClass = TrabajadorPeer.getOMClass();
      Trabajador obj2 = (Trabajador) TrabajadorPeer.row2Object(row, offset, omClass);

      boolean newObject = true;
      for (int j = 0; j < results.size(); j++) {
        OrdenTrabajo temp_obj1 = (OrdenTrabajo) results.get(j);
        Trabajador temp_obj2 = (Trabajador) temp_obj1.getTrabajador();
        if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) {
          newObject = false;
          break;
        }
      }
      results.add(obj1);
    }
    return results;
  }
  /**
   * Method to do deletes. This method is to be used during a transaction, otherwise use the
   * doDelete(Criteria) method. It will take care of the connection details internally.
   *
   * @param criteria object containing data that is used DELETE from database.
   * @param con the connection to use
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static void doDelete(Criteria criteria, Connection con) throws TorqueException {

    setDbName(criteria);

    if (con == null) {
      BasePeer.doDelete(criteria);
    } else {
      BasePeer.doDelete(criteria, con);
    }
  }
  /**
   * Method to do inserts. This method is to be used during a transaction, otherwise use the
   * doInsert(Criteria) method. It will take care of the connection details internally.
   *
   * @param criteria object used to create the INSERT statement.
   * @param con the connection to use
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static ObjectKey doInsert(Criteria criteria, Connection con) throws TorqueException {

    setDbName(criteria);

    if (con == null) {
      return BasePeer.doInsert(criteria);
    } else {
      return BasePeer.doInsert(criteria, con);
    }
  }
  /**
   * Method to do updates. This method is to be used during a transaction, otherwise use the
   * doUpdate(Criteria) method. It will take care of the connection details internally.
   *
   * @param criteria object containing data that is used to create the UPDATE statement.
   * @param con the connection to use
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static void doUpdate(Criteria criteria, Connection con) throws TorqueException {
    Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
    selectCriteria.put(ID, criteria.remove(ID));

    setDbName(criteria);

    if (con == null) {
      BasePeer.doUpdate(selectCriteria, criteria);
    } else {
      BasePeer.doUpdate(selectCriteria, criteria, con);
    }
  }
  /**
   * Grabs the raw Village records to be formed into objects. This method should be used for
   * transactions
   *
   * @param criteria object used to create the SELECT statement.
   * @param con the connection to use
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static List doSelectVillageRecords(Criteria criteria, Connection con)
      throws TorqueException {
    if (criteria.getSelectColumns().size() == 0) {
      addSelectColumns(criteria);
    }

    setDbName(criteria);

    // BasePeer returns a List of Value (Village) arrays.  The array
    // order follows the order columns were placed in the Select clause.
    if (con == null) {
      return BasePeer.doSelect(criteria);
    } else {
      return BasePeer.doSelect(criteria, con);
    }
  }