|
From: Roman R. <rro...@us...> - 2003-07-02 21:26:41
|
Update of /cvsroot/firebird/client-java/src/main/org/firebirdsql/jdbc
In directory sc8-pr-cvs1:/tmp/cvs-serv8509/jdbc
Modified Files:
FBBlob.java FirebirdBlob.java
Log Message:
added blob seek modes
Index: FBBlob.java
===================================================================
RCS file: /cvsroot/firebird/client-java/src/main/org/firebirdsql/jdbc/FBBlob.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -U3 -r1.14 -r1.15
--- FBBlob.java 27 Jun 2003 20:43:14 -0000 1.14
+++ FBBlob.java 2 Jul 2003 21:26:38 -0000 1.15
@@ -148,13 +148,16 @@
*
* @return array of bytes containing information about this Blob.
*
- * @throws GDSException if something went wrong.
+ * @throws SQLException if something went wrong.
*/
- public byte[] getInfo(byte[] items, int buffer_length) throws GDSException {
+ public byte[] getInfo(byte[] items, int buffer_length) throws SQLException {
Object syncObject = getSynchronizationObject();
synchronized(syncObject) {
+ try {
+ c.ensureInTransaction();
+
isc_blob_handle blob = c.openBlobHandle(blob_id, SEGMENTED);
try {
GDS gds = c.getInternalAPIHandler();
@@ -162,6 +165,13 @@
} finally {
c.closeBlob(blob);
}
+
+ } catch(GDSException ex) {
+ throw new FBSQLException(ex);
+ } finally {
+ if (c.willEndTransaction())
+ c.checkEndTransaction();
+ }
}
}
@@ -175,15 +185,10 @@
* @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
*/
public long length() throws SQLException {
- try {
byte[] info = getInfo(
new byte[]{ISCConstants.isc_info_blob_total_length}, 20);
return interpretLength(info, 0);
-
- } catch(GDSException ex) {
- throw new FBSQLException(ex);
- }
}
/**
@@ -217,7 +222,6 @@
* @throws SQLException if something went wrong.
*/
public boolean isSegmented() throws SQLException {
- try {
byte[] info = getInfo(
new byte[] {ISCConstants.isc_info_blob_type}, 20);
@@ -231,9 +235,6 @@
info, 3, dataLength);
return type == ISCConstants.isc_bpb_type_segmented;
- } catch(GDSException ex) {
- throw new FBSQLException(ex);
- }
}
/**
@@ -275,7 +276,37 @@
* @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
*/
public byte[] getBytes(long pos, int length) throws SQLException{
- throw new SQLException("Not yet implemented");
+
+ if (pos > Integer.MAX_VALUE)
+ throw new SQLException("Blob position is limited to 2^31 - 1 " +
+ "due to isc_seek_blob limitations.");
+
+ Object syncObject = getSynchronizationObject();
+ synchronized(syncObject) {
+ c.ensureInTransaction();
+
+ try {
+ FirebirdBlob.BlobInputStream in =
+ (FirebirdBlob.BlobInputStream)getBinaryStream();
+
+ try {
+ byte[] result = new byte[length];
+
+ in.seek((int)pos - 1);
+ in.readFully(result);
+
+ return result;
+ } finally {
+ in.close();
+ }
+
+ } catch(IOException ex) {
+ throw new FBSQLException(ex);
+ } finally {
+ if (c.willEndTransaction())
+ c.checkEndTransaction();
+ }
+ }
}
@@ -500,12 +531,16 @@
}
public void seek(int position) throws IOException {
+ seek(position, SEEK_MODE_ABSOLUTE);
+ }
+
+ public void seek(int position, int seekMode) throws IOException {
Object syncObject = getSynchronizationObject();
synchronized(syncObject) {
try {
- c.getInternalAPIHandler().isc_seek_blob(blob, position);
+ c.getInternalAPIHandler().isc_seek_blob(blob, position, seekMode);
} catch (GDSException ex) {
/** @todo fix this */
throw new IOException(ex.getMessage());
@@ -653,9 +688,9 @@
}
}
- public void seek(int position) throws SQLException {
+ public void seek(int position, int seekMode) throws SQLException {
try {
- c.getInternalAPIHandler().isc_seek_blob(blob, position);
+ c.getInternalAPIHandler().isc_seek_blob(blob, position, seekMode);
} catch(GDSException ex) {
throw new FBSQLException(ex);
}
Index: FirebirdBlob.java
===================================================================
RCS file: /cvsroot/firebird/client-java/src/main/org/firebirdsql/jdbc/FirebirdBlob.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -U3 -r1.1 -r1.2
--- FirebirdBlob.java 22 Jun 2003 22:40:26 -0000 1.1
+++ FirebirdBlob.java 2 Jul 2003 21:26:38 -0000 1.2
@@ -39,6 +39,10 @@
*/
interface BlobInputStream {
+ int SEEK_MODE_ABSOLUTE = 0;
+ int SEEK_MODE_RELATIVE = 1;
+ int SEEK_MODE_FROM_TAIL = 2;
+
/**
* Get instance of {@link FirebirdBlob} to which this stream belongs to.
* <p>
@@ -132,13 +136,34 @@
void readFully(byte[] buffer) throws IOException;
/**
- * Move current position in the Blob stream.
+ * Move current position in the Blob stream. This is a shortcut method
+ * to {@link #seek(int, int)} passing {@link #SEEK_MODE_ABSOLUTE} as
+ * seek mode.
*
- * @param position absolute position in the stream.
+ * @param position absolute position to seek, starting position is
+ * 0 (note, in {@link Blob#getBytes(long, int)} starting position is 1).
*
- * @throws IOException if I/O erro occurs.
+ * @throws IOException if I/O error occurs.
*/
void seek(int position) throws IOException;
+
+ /**
+ * Move current position in the Blob stream. Depending on the specified
+ * seek mode, position can be either positive or negative.
+ * <p>
+ * Note, this method allows to move position in the Blob stream only
+ * forward. If you need to read data before the current position, new
+ * stream must be opened.
+ *
+ * @param position position in the stream, starting position is
+ * 0 (note, in {@link Blob#getBytes(long, int)} starting position is 1).
+ *
+ * @param seekMode mode of seek operation, one of {@link #SEEK_MODE_ABSOLUTE},
+ * {@link #SEEK_MODE_RELATIVE} or {@link #SEEK_MODE_FROM_TAIL}.
+ *
+ * @throws IOException if I/O erro occurs.
+ */
+ void seek(int position, int seekMode) throws IOException;
}
/**
|