[Pljava-dev] How to read LargeObject with pljava?

Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2009-06-18 이후 토토 사이트 추천Dev 17:52
From: olegvvasylenko at gmail(dot)com (Oleg Vasylenko)
To:
Subject: [Pljava-dev] How to read LargeObject with pljava?
Date: 2009-06-13 09:43:17
Message-ID: 4A3374B5.7020100@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

Hi everybody!

Have some code to read LargeObject from db and create digest message for
the it content. The code generate an error attemtting to read a portion
of LO.

Could anybody give an example how to read LO from database?

I'm using jre1.6.0.13, pljava1.4.0, postgresql8.3.7.

Thanks.

import java.io.FileOutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;

public class ServerDigestCreator {

public static String
anotherCreateStrDigest(org.postgresql.pljava.internal.Oid lObjectId)
throws SQLException,NoSuchAlgorithmException
{
String digest = null;
java.sql.Savepoint sp = null;
if(lObjectId==null) return null;
java.sql.Connection aConnection =
DriverManager.getConnection("jdbc:default:connection");
try{
sp = aConnection.setSavepoint();
org.postgresql.pljava.internal.LargeObject lo =
org.postgresql.pljava.internal.LargeObject.open(lObjectId,
org.postgresql.pljava.internal.LargeObject.INV_READ);
MessageDigest aDigest = MessageDigest.getInstance("md5");
if(lo==null) {
aConnection.releaseSavepoint(sp);
return digest;
}
byte buf[] = new byte[2048];
int s=0;
while((s = lo.read(buf))!=0)
<---------------------- Error occurs here
=============================================================
aDigest.update(buf); byte[] digestByteArray
= aDigest.digest();
BigInteger tempBI = new BigInteger(digestByteArray);
digest = tempBI.toString(); lo.close();
aConnection.releaseSavepoint(sp);
}
catch(SQLException ex)
{ if(sp!=null)
aConnection.rollback(sp);
Logger.getAnonymousLogger().info("ERROR: " + ex.getMessage()
+ "\n");
throw new SQLException(ex.getMessage());
}
return digest;
}


From: olegvvasylenko at gmail(dot)com (Oleg Vasylenko)
To:
Subject: [Pljava-dev] How to read LargeObject with pljava?
Date: 2009-06-17 13:12:49
Message-ID: 4A38EBD1.2000604@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

Does org.postgresql.pljava.internal.LargeObject object and methods
read/write/open/close still being experimental or methods have to work
correctly in PLJava 1.4.0?


From: books at ejurka(dot)com (Kris Jurka)
To:
Subject: [Pljava-dev] How to read LargeObject with pljava?
Date: 2009-06-18 17:52:14
Message-ID: alpine.BSO.2.00.0906181310440.17688@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2009-06-18 이후 토토 사이트 추천Dev 17:52

On Wed, 17 Jun 2009, Oleg Vasylenko wrote:

> Does org.postgresql.pljava.internal.LargeObject object and methods
> read/write/open/close still being experimental or methods have to work
> correctly in PLJava 1.4.0?

Looking at the source code, it doesn't work at all. With the attached
patch it mostly works. LargeObject.create still doesn't work and you will
get warnings about relcache reference leaks, but these are harmless and
can be ignored.

Kris Jurka
-------------- next part --------------
Index: src/C/pljava/type/LargeObject.c
===================================================================
RCS file: /cvsroot/pljava/org.postgresql.pljava/src/C/pljava/type/LargeObject.c,v
retrieving revision 1.14
diff -c -r1.14 LargeObject.c
*** src/C/pljava/type/LargeObject.c 28 May 2006 22:01:48 -0000 1.14
--- src/C/pljava/type/LargeObject.c 18 Jun 2009 17:07:49 -0000
***************
*** 23,38 ****
*/
jobject LargeObject_create(LargeObjectDesc* lo)
{
- jobject jlo;
- Ptr2Long loH;
-
if(lo == 0)
return 0;

! loH.longVal = 0L; /* ensure that the rest is zeroed out */
! loH.ptrVal = lo;
! jlo = JNI_newObject(s_LargeObject_class, s_LargeObject_init, loH.longVal);
! return jlo;
}

extern void LargeObject_initialize(void);
--- 23,32 ----
*/
jobject LargeObject_create(LargeObjectDesc* lo)
{
if(lo == 0)
return 0;

! return JNI_newObject(s_LargeObject_class, s_LargeObject_init, Invocation_createLocalWrapper(lo));
}

extern void LargeObject_initialize(void);