jxDBCon 0.9z

org.sourceforge.jxdbcon.postgresql
Class PGBlob

java.lang.Object
  |
  +--org.sourceforge.jxutil.sql.type.AbstractBLOB
        |
        +--org.sourceforge.jxdbcon.postgresql.PGBlob
All Implemented Interfaces:
Blob

public final class PGBlob
extends AbstractBLOB

The PGBlob class implements Blobs. Blobs are only available in Transactions. You need to set the connection's autoCommit feature to false. In PostgreSQL there is no real Blob type, the oid type is used for this purpose. This implementation supports both reading and writing existing blobs.

Version:
$Revision: 1.5 $
Author:
Keve Müller

Field Summary
private  Connection conn
          Our connection.
private  int handle
          The Large Object handle.
private static int INV_READ
           
private static int INV_WRITE
           
private  long objOid
          The object oid.
private  CallableStatement read
          Readily prepared call to the read function.
private  CallableStatement seek
          Readily prepared call to the seek function.
private static int SEEK_CUR
           
private static int SEEK_END
           
private static int SEEK_SET
           
private  CallableStatement write
          Readily prepared call to the write function.
 
Constructor Summary
PGBlob(Connection conn)
          Initialise the blob with the connection, create a new oid.
PGBlob(Connection conn, long objOid)
          Initialise the blob with the connection and the oid.
 
Method Summary
 void close()
          Close the LOB handle.
 byte[] getBytes(long pos, int length)
          Get a chunk of data.
 long getObjOid()
           
 long length()
          Determine Large Object's length.
 long position(Blob pattern, long start)
          Not implemented.
 long position(byte[] pattern, long start)
          Not implemented.
(package private)  void prepareCalls()
          Prepare the calls to the lo_lseek, loread and lowrite functions.
 int setBytes(long pos, byte[] data)
          Write a chunk of data.
 int setBytes(long pos, byte[] data, int spos, int len)
          Write a chunk of data.
 String toString()
          for debugging purposes.
 void truncate(long x)
          Not implemented.
 
Methods inherited from class org.sourceforge.jxutil.sql.type.AbstractBLOB
getBinaryStream, setBinaryStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

conn

private Connection conn
Our connection.


handle

private int handle
The Large Object handle.


INV_READ

private static final int INV_READ
See Also:
Constant Field Values

INV_WRITE

private static final int INV_WRITE
See Also:
Constant Field Values

objOid

private long objOid
The object oid.


read

private CallableStatement read
Readily prepared call to the read function.


seek

private CallableStatement seek
Readily prepared call to the seek function.


SEEK_CUR

private static final int SEEK_CUR
See Also:
Constant Field Values

SEEK_END

private static final int SEEK_END
See Also:
Constant Field Values

SEEK_SET

private static final int SEEK_SET
See Also:
Constant Field Values

write

private CallableStatement write
Readily prepared call to the write function.

Constructor Detail

PGBlob

public PGBlob(Connection conn)
       throws SQLException
Initialise the blob with the connection, create a new oid. This will call lo_create to create the new oid and lo_open to obtain a handle to the Large Object. Furthermore it prepares the calls to the seek/read/write functions.


PGBlob

public PGBlob(Connection conn,
              long objOid)
       throws SQLException
Initialise the blob with the connection and the oid. This will call lo_open to obtain a handle to the Large Object. Furthermore it prepares the calls to the seek/read/write functions.

Method Detail

close

public void close()
           throws SQLException
Close the LOB handle.

SQLException

getBytes

public byte[] getBytes(long pos,
                       int length)
                throws SQLException
Get a chunk of data. First seeks to the position, then reads the data.

SQLException

getObjOid

public long getObjOid()

length

public long length()
            throws SQLException
Determine Large Object's length. Seek to end, and tell the position.

SQLException

position

public long position(Blob pattern,
                     long start)
              throws SQLException
Not implemented.

SQLException

position

public long position(byte[] pattern,
                     long start)
              throws SQLException
Not implemented.

SQLException

prepareCalls

void prepareCalls()
            throws SQLException
Prepare the calls to the lo_lseek, loread and lowrite functions.

SQLException

setBytes

public int setBytes(long pos,
                    byte[] data)
             throws SQLException
Write a chunk of data. First seeks to the position, then writes the data.

Specified by:
setBytes in interface Blob
Specified by:
setBytes in class AbstractBLOB
SQLException

setBytes

public int setBytes(long pos,
                    byte[] data,
                    int spos,
                    int len)
             throws SQLException
Write a chunk of data. First seeks to the position, then writes the data.

SQLException

toString

public String toString()
for debugging purposes.

Overrides:
toString in class Object

truncate

public void truncate(long x)
              throws SQLException
Not implemented.

SQLException

jxDBCon 0.9z

Copyright © 2001,2002 Keve Müller; see LICENSE file for details.