LargeObject

This class implements the large object interface to Red Hat Database. It provides the basic methods required to run the interface plus a pair of methods that provide InputStream and OutputStream classes for this object.

Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects. Sometimes, however, lower level access to Large Objects is required beyond what is supported by the JDBC specification.

Refer to LargeObjectManager on how to gain access to LargeObject objects.

LargeObject Definition

package org.postgresql.largeobject;
public class LargeObject {
   // Constants
   public static final int SEEK_SET;
   public static final int SEEK_CUR;
   public static final int SEEK_END;
   
   // Methods
   public void close() throws SQLException;
   public int getOID();
   public byte[] read(int len) throws SQLException;
   public void read(byte buf[], int off, int len) 
      throws SQLException;
   public void write(byte buf[]) throws SQLException;
   public void write(byte buf[], int off, int len) 
      throws SQLException;
}

Constants

public static final int SEEK_SET

Indicates a seek from the beginning of a file.

public static final int SEEK_CUR

Indicates a seek from the current position.

public static final int SEEK_END

Indicates a seek from the end of a file.

public void close() throws SQLException

This method closes the object. You must not call methods of the object after this method is invoked.

public int getOID()

Returns the OID of this LargeObject.

public byte[] read(int len) throws SQLException

Read a certain amount of data from the large object, starting at the beginning, and return it as an array of bytes.

Parameters.

len

Number of bytes to read.

public void read(byte buf[], int off, int len) throws SQLException

Read a certain amount of data from the large object, starting at the given offset, into the given byte array.

Parameters.

buf

array to read bytes into

off

offset to start reading from

len

number of bytes to read

public void write(byte buf[]) throws SQLException

Write some data to the large object.

Parameters.

buf

source data

public void write(byte buf[], int off, int len) throws SQLException

Write a certain amount of data to the large object, starting at a given offset.

Parameters.

buf

source data

off

offset to start writing at

len

number of bytes to write

LargeObjectManager

This class implements the large object interface to Red Hat Database. It provides methods that allow client code to create, open, and delete large objects from the database. Opening a LOB returns an instance of org.postgresql.largeobject.LargeObject.

This class can only be created by org.postgresql.Connection. To get access to this class, use the following segment of code:

import org.postgresql.Connection;
import org.postgresql.largeobject.*;

Connection con;
LargeObjectManager lobj;
// ... code that opens a connection ...
lobj = ((org.postgresql.Connection) 
   con).getLargeObjectAPI();

LargeObjectManager Definition

package org.postgresql.largeobject;
public class LargeObjectManager {
   // Constants
   public static final int WRITE;
   public static final int READ;
   public static final int READWRITE;
   
   // Methods
   public LargeObject open(int oid) throws SQLException;
   public LargeObject open(int oid, int mode) throws SQLException;
   public int create() throws SQLException;
   public int create(int mode) throws SQLException;
   public void delete(int oid) throws SQLException;
   public void unlink(int oid) throws SQLException;
}

Constants

public static final int WRITE

This mode indicates we want to write to an object.

public static final int READ

This mode indicates we want to read an object.

public static final int READWRITE

This mode is the default. It indicates we want read and write access to a large object.

Methods

public int create() throws SQLException

Create a new LOB in the database. The access mode of the new LOB is set to READWRITE.

Returns. OID of the new LOB.

public int create(int mode) throws SQLException

Create a new LOB in the database with the given access mode.

Parameters.

mode

Access mode to use for the new LOB.

Returns. OID of the new LOB.

public void delete(int oid) throws SQLException

Delete the indicated LOB from the database.

Parameters.

oid

OID of the LOB to delete.

public LargeObject open(int oid) throws SQLException

Open the LOB indicated by the parameter oid. The access mode is set to READWRITE.

Parameters.

oid

The OID of the LOB to open.

Returns. The LargeObject object that represents the opened LOB.

public LargeObject open(int oid, int mode) throws SQLException

Parameters.

oid

The OID of the LOB to open.

mode

The access mode to use.

Returns. The LargeObject object that represents the opened LOB.

public void unlink(int oid) throws SQLException

Deletes the indicated LOB from the database. It is identical to the delete method but is supplied because the equivalent C API (libpq) uses "unlink".