package org.okip.service.dbc.api;



/*
   Copyright (c) 2002 Massachusetts Institute of Technology

   This work, including any software, documents, or other related items
   (the "Work"), is being provided by the copyright holder(s) subject to
   the terms of the MIT OKI(TM) API Definition License. By obtaining,
   using and/or copying this Work, you agree that you have read,
   understand, and will comply with the following terms and conditions of
   the MIT OKI(TM) API Definition License:

   You may use, copy, and distribute unmodified versions of this Work for
   any purpose, without fee or royalty, provided that you include the
   following on ALL copies of the Work that you make or distribute:

    *  The full text of the MIT OKI(TM) API Definition License in a
       location viewable to users of the redistributed Work.

    *  Any pre-existing intellectual property disclaimers, notices, or
       terms and conditions. If none exist, a short notice similar to the
       following should be used within the body of any redistributed
       Work: "Copyright (c) 2002 Massachusetts Institute of Technology. All
       Rights Reserved."

   You may modify or create Derivatives of this Work only for your
   internal purposes. You shall not distribute or transfer any such
   Derivative of this Work to any location or any other third party. For
   purposes of this license, "Derivative" shall mean any derivative of
   the Work as defined in the United States Copyright Act of 1976, such
   as a translation or modification.

   THIS WORK PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE WORK
   OR THE USE OR OTHER DEALINGS IN THE WORK.

   The name and trademarks of copyright holder(s) and/or MIT may NOT be
   used in advertising or publicity pertaining to the Work without
   specific, written prior permission. Title to copyright in the Work and
   any associated documentation will at all times remain with the
   copyright holders.

*/

/*
 * $Source: /cvs/oki/tech/src/org/okip/service/dbc/api/Blob.java,v $
 */

/**
 * The mapping in the OKI DBC API programming language for the SQL
 * BLOB value. An SQL BLOB is a built-in type that stores a Binary
 * Large Object as a column value in a row of a database table. By
 * default drivers implement a Blob object using an SQL locator(BLOB),
 * which means that a Blob object contains a logical pointer to the
 * SQL BLOB data rather than the data itself. A Blob object is valid
 * for the duration of the transaction in which it was created.
 * <p>
 * Methods in the interfaces ResultSet, CallableStatement, and
 * PreparedStatement, such as getBlob and setBlob allow a programmer
 * to access an SQL BLOB value. The Blob interface provides methods
 * for getting the length of an SQL BLOB (Binary Large Object) value,
 * for materializing a BLOB value on the client, and for determining
 * the position of a pattern of bytes within a BLOB value. In
 * addition, this interface has methods for updating a BLOB value.
 * <p>
 * Licensed under the {@link org.okip.service.ApiLicense MIT OKI&#153; API Definition License}.
 *
 * @version $Name:  $ / $Revision: 1.7 $ / $Date: 2002/07/29 18:42:42 $
 */
public interface Blob
extends java.io.Serializable {

  /* methods which are in Blob in 1.4 but not in this interface:
     getBinaryStream
     setBinaryStream
   */

  /**
   * Retrieves all or part of the BLOB value that
   * this Blob object represents, as an array of bytes.
   *
   * @param pos
   * @param len
   *
   * @return byte[]
   *
   * @throws DbcException
   *
   */
  byte[] getBytes(long pos, int len)
  throws DbcException;

  /**
   * Returns the number of bytes in the BLOB value
   * designated by this Blob object.
   *
   * @return long
   *
   * @throws DbcException
   *
   */
  long length()
  throws DbcException;

  /**
   * Retrieves the byte position in the BLOB value
   * designated by this Blob object at which pattern
   * begins.
   *
   * @param pattern
   * @param start
   *
   * @return long
   *
   * @throws DbcException
   *
   */
  long position(Blob pattern, long start)
  throws DbcException;

  /**
   * Retrieves the byte position at which the
   * specified byte array pattern begins within
   * the BLOB value that this Blob object represents.
   *
   * @param pattern
   * @param start
   *
   * @return long
   *
   * @throws DbcException
   *
   */
  long position(byte[] pattern, long start)
  throws DbcException;

  /**
   * Writes the given array of bytes to the BLOB
   * value that this Blob object represents,
   * starting at position pos, and returns the
   * number of bytes written.
   *
   * @param pos
   * @param bytes
   *
   * @return int
   *
   * @throws DbcException
   *
   */
  int setBytes(long pos, byte[] bytes)
  throws DbcException;

  /**
   * Writes all or part of the given byte array
   * to the BLOB value that this Blob object
   * represents and returns the number of bytes
   * written.
   *
   * @param pos
   * @param bytes
   * @param offset
   * @param len
   *
   * @return int
   *
   * @throws DbcException
   *
   */
  int setBytes(long pos, byte[] bytes, int offset, int len)
  throws DbcException;

  /**
   * Truncates the BLOB value that this Blob
   * object represents to be len bytes in length.
   *
   * @param len
   *
   * @throws DbcException
   *
   */
  void truncate(long len)
  throws DbcException;

}
