pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedOT: easiest way to create a custom PreparedStatement class
4+ messages / 4 participants
[nested] [flat]
* OT: easiest way to create a custom PreparedStatement class
@ 2005-06-28 18:55 Kevin Murphy <murphy@genome.chop.edu>
0 siblings, 2 replies; 4+ messages in thread
From: Kevin Murphy @ 2005-06-28 18:55 UTC (permalink / raw)
To: pgsql-jdbc
I am modifying some existing data loading code (that only makes use of 4
or 5 methods from PreparedStatement) to optionally be able to *not*
connect to a database but instead dump either the generated SQL code or
the raw insert data to files on the file system.
It would be great if I could just overload PreparedStatement with my own
classes, but unfortunately it is an interface, so I presumably need to
implement stubs for the umpty-ump methods defined by PreparedStatement?
Is this true, and if so, what is the easiest/fastest way to do this (if
it is even possible)?
I am a java newbie, by the way. Don't flame me too hard. I did say
"OT", after all ;-)
Thanks,
Kevin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: OT: easiest way to create a custom PreparedStatement class
@ 2005-06-28 19:42 Craig Servin <cservin@cdhps.com>
parent: Kevin Murphy <murphy@genome.chop.edu>
1 sibling, 0 replies; 4+ messages in thread
From: Craig Servin @ 2005-06-28 19:42 UTC (permalink / raw)
To: pgsql-jdbc; murphy@genome.chop.edu
Or you could use:
java.lang.reflect.Proxy
On Tuesday 28 June 2005 01:55 pm, Kevin Murphy wrote:
> I am modifying some existing data loading code (that only makes use of 4
> or 5 methods from PreparedStatement) to optionally be able to *not*
> connect to a database but instead dump either the generated SQL code or
> the raw insert data to files on the file system.
>
> It would be great if I could just overload PreparedStatement with my own
> classes, but unfortunately it is an interface, so I presumably need to
> implement stubs for the umpty-ump methods defined by PreparedStatement?
>
> Is this true, and if so, what is the easiest/fastest way to do this (if
> it is even possible)?
>
> I am a java newbie, by the way. Don't flame me too hard. I did say
> "OT", after all ;-)
>
> Thanks,
> Kevin
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: OT: easiest way to create a custom PreparedStatement class
@ 2005-06-28 19:55 Craig Servin <cservin@cromagnon.com>
parent: Kevin Murphy <murphy@genome.chop.edu>
1 sibling, 1 reply; 4+ messages in thread
From: Craig Servin @ 2005-06-28 19:55 UTC (permalink / raw)
To: Kevin Murphy <murphy@genome.chop.edu>; pgsql-jdbc
Or you could use:
java.lang.reflect.Proxy
On Tuesday 28 June 2005 01:55 pm, Kevin Murphy wrote:
> I am modifying some existing data loading code (that only makes use of 4
> or 5 methods from PreparedStatement) to optionally be able to *not*
> connect to a database but instead dump either the generated SQL code or
> the raw insert data to files on the file system.
>
> It would be great if I could just overload PreparedStatement with my own
> classes, but unfortunately it is an interface, so I presumably need to
> implement stubs for the umpty-ump methods defined by PreparedStatement?
>
> Is this true, and if so, what is the easiest/fastest way to do this (if
> it is even possible)?
>
> I am a java newbie, by the way. Don't flame me too hard. I did say
> "OT", after all ;-)
>
> Thanks,
> Kevin
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: OT: easiest way to create a custom PreparedStatement
@ 2005-06-28 20:29 Mark Lewis <mark.lewis@mir3.com>
parent: Craig Servin <cservin@cromagnon.com>
0 siblings, 0 replies; 4+ messages in thread
From: Mark Lewis @ 2005-06-28 20:29 UTC (permalink / raw)
To: Kevin Murphy <murphy@genome.chop.edu>; +Cc: pgsql-jdbc
We use java.lang.reflect.Proxy in our production systems to do things
like log SQL statements, do a little bookkeeping for application-level
replication, log timings and the like. Works great.
Here's a snippet that we use to wrap a PreparedStatement with a proxy to
do some logging every time somebody calls any method on it.
-- Mark Lewis
final PreparedStatement realStatement = xxx;
PreparedStatement debugWrapped =
(PreparedStatement)Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{PreparedStatement.class}, new InvocationHandler() {
public Object invoke(Object instance, Method method, Object
[] params) throws Throwable {
StringBuffer buf = new StringBuffer();
buf.append("Called ").append(method.getName());
buf.append('(');
if(params != null) {
for(int i=0; i<params.length; i++) {
if(i > 0) buf.append(',');
buf.append(String.valueOf(params[i]));
}
}
buf.append(')');
log.debug(buf);
try {
return method.invoke(realStatement, params);
}
catch(InvocationTargetException ex) {
throw ex.getCause();
}
}
});
On Tue, 2005-06-28 at 14:55 -0500, Craig Servin wrote:
> Or you could use:
>
> java.lang.reflect.Proxy
>
>
> On Tuesday 28 June 2005 01:55 pm, Kevin Murphy wrote:
> > I am modifying some existing data loading code (that only makes use of 4
> > or 5 methods from PreparedStatement) to optionally be able to *not*
> > connect to a database but instead dump either the generated SQL code or
> > the raw insert data to files on the file system.
> >
> > It would be great if I could just overload PreparedStatement with my own
> > classes, but unfortunately it is an interface, so I presumably need to
> > implement stubs for the umpty-ump methods defined by PreparedStatement?
> >
> > Is this true, and if so, what is the easiest/fastest way to do this (if
> > it is even possible)?
> >
> > I am a java newbie, by the way. Don't flame me too hard. I did say
> > "OT", after all ;-)
> >
> > Thanks,
> > Kevin
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2005-06-28 20:29 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-28 18:55 OT: easiest way to create a custom PreparedStatement class Kevin Murphy <murphy@genome.chop.edu>
2005-06-28 19:42 ` Craig Servin <cservin@cdhps.com>
2005-06-28 19:55 ` Craig Servin <cservin@cromagnon.com>
2005-06-28 20:29 ` Re: OT: easiest way to create a custom PreparedStatement Mark Lewis <mark.lewis@mir3.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox