コード例 #1
0
  /**
   * Maps attributes of an SQL structured type that are not serialized to a serialized form, using
   * the given type map for custom mapping when appropriate. The following types in the Java
   * programming language are mapped to their serialized forms: <code>Struct</code>, <code>SQLData
   * </code>, <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, and <code>Array</code>.
   *
   * <p>This method is called internally and is not used by an application programmer.
   *
   * @param map a <code>java.util.Map</code> object in which each entry consists of 1) a <code>
   *     String</code> object giving the fully qualified name of a UDT and 2) the <code>Class</code>
   *     object for the <code>SQLData</code> implementation that defines how the UDT is to be mapped
   * @throws SerialException if an error occurs
   */
  private void mapToSerial(Map map) throws SerialException {

    try {

      for (int i = 0; i < attribs.length; i++) {
        if (attribs[i] instanceof Struct) {
          attribs[i] = new SerialStruct((Struct) attribs[i], map);
        } else if (attribs[i] instanceof SQLData) {
          attribs[i] = new SerialStruct((SQLData) attribs[i], map);
        } else if (attribs[i] instanceof Blob) {
          attribs[i] = new SerialBlob((Blob) attribs[i]);
        } else if (attribs[i] instanceof Clob) {
          attribs[i] = new SerialClob((Clob) attribs[i]);
        } else if (attribs[i] instanceof Ref) {
          attribs[i] = new SerialRef((Ref) attribs[i]);
        } else if (attribs[i] instanceof java.sql.Array) {
          attribs[i] = new SerialArray((java.sql.Array) attribs[i], map);
        }
      }

    } catch (SQLException e) {
      throw new SerialException(e.getMessage());
    }
    return;
  }
コード例 #2
0
  /**
   * Constructs a <code>SerialStruct</code> object from the given <code>SQLData</code> object, using
   * the given type map to custom map it to a class in the Java programming language. The type map
   * gives the SQL type and the class to which it is mapped. The <code>SQLData</code> object defines
   * the class to which the SQL type will be mapped.
   *
   * @param in an instance of the <code>SQLData</code> class that defines the mapping of the SQL
   *     structured type to one or more objects in the Java programming language
   * @param map a <code>java.util.Map</code> object in which each entry consists of 1) a <code>
   *     String</code> object giving the fully qualified name of a UDT and 2) the <code>Class</code>
   *     object for the <code>SQLData</code> implementation that defines how the UDT is to be mapped
   * @throws SerialException if an error occurs
   */
  public SerialStruct(SQLData in, Map<String, Class<?>> map) throws SerialException {

    try {

      // set the type name
      SQLTypeName = new String(in.getSQLTypeName());

      Vector tmp = new Vector();
      in.writeSQL(new SQLOutputImpl(tmp, map));
      attribs = tmp.toArray();

    } catch (SQLException e) {
      throw new SerialException(e.getMessage());
    }
  }
コード例 #3
0
  /**
   * Constructs a <code>SerialStruct</code> object from the given <code>Struct</code> object, using
   * the given <code>java.util.Map</code> object for custom mapping the SQL structured type or any
   * of its attributes that are SQL structured types.
   *
   * @param map a <code>java.util.Map</code> object in which each entry consists of 1) a <code>
   *     String</code> object giving the fully qualified name of a UDT and 2) the <code>Class</code>
   *     object for the <code>SQLData</code> implementation that defines how the UDT is to be mapped
   * @throws SerialException if an error occurs
   * @see java.sql.Struct
   */
  public SerialStruct(Struct in, Map<String, Class<?>> map) throws SerialException {

    try {

      // get the type name
      SQLTypeName = new String(in.getSQLTypeName());
      System.out.println("SQLTypeName: " + SQLTypeName);

      // get the attributes of the struct
      attribs = in.getAttributes(map);

      /*
       * the array may contain further Structs
       * and/or classes that have been mapped,
       * other types that we have to serialize
       */
      mapToSerial(map);

    } catch (SQLException e) {
      throw new SerialException(e.getMessage());
    }
  }
コード例 #4
0
ファイル: TreeLeafDO.java プロジェクト: mlocher-sf/jobmatch
  /**
   * 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();
      }
    }
  }