Re: about monitoring the input stream

From: Marc Herbert <Marc(dot)Herbert(at)continuent(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: about monitoring the input stream
Date: 2006-09-14 10:08:09
Message-ID: khj4pvayd4m.fsf@meije.emic.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Albert Cardona <acardona(at)ini(dot)phys(dot)ethz(dot)ch> writes:

> The idea is not to modify the driver one bit in benefit of uncontroversial
> deployment of my application (TrakEM2 at
> http://www.ini.unizh.ch/~acardona/trackem2.html ). If java was lisp I would
> simply alter the register to replace the InputStream, but it isn't and/or I
> don't know how to use reflection to that extent

Thanks to its reflection API, java is actually lisp. Just a bit less
convenient. This should do the trick:

pg_input_field = PGStream.class.getDeclaredField("pg_input");

pg_input_field.setAccessible(true);

InputStream orig_stream = (InputStream) pg_input_field.get(pg_stream_to_hack);

InputStream counting_stream = new CountingInputStream(orig_stream);

pg_input_field.set(pg_stream_to_hack, counting_stream);

> (I don't know what would happen was I to replace the InputStream
> using reflection once a connection has been created).

As far as I understand the driver you _have to_ replace it after the
connection has been created. Just avoid using it before replace.

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Christopher Bruhn 2006-09-14 17:12:01 Problem with Java-SQL connection, postgresql.conf file
Previous Message Mark Lewis 2006-09-13 19:55:59 FAQ update patch