X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 78D15D1C50B for ; Mon, 21 Jul 2003 14:24:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 61953-02 for ; Mon, 21 Jul 2003 14:24:08 +0000 (GMT) Received: from exchange.hq.openratings.com (unknown [141.149.165.226]) by svr1.postgresql.org (Postfix) with ESMTP id 17801D1C4E3 for ; Mon, 21 Jul 2003 11:24:12 -0300 (ADT) Received: from openratings.com (cancun.hq.openratings.com [10.0.0.225]) by exchange.hq.openratings.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 38QMVWT7; Mon, 21 Jul 2003 10:24:08 -0400 Message-ID: <3F1BF78F.4040604@openratings.com> Date: Mon, 21 Jul 2003 10:24:15 -0400 From: Dmitry Tkach User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Oliver Jowett Cc: pgsql-jdbc-list Subject: Re: Prepared Statements References: <3F183004.4010508@openratings.com> <3F1830F6.3020203@openratings.com> <1058550328.19657.168.camel@topanga.toronto.redhat.com> <3F183423.9030900@openratings.com> <1058551402.20165.177.camel@topanga.toronto.redhat.com> <3F183AE0.8060204@openratings.com> <20030719012555.GA20158@opencloud.com> <3F1AC5D1.4010307@openratings.com> <20030721000241.GB665@opencloud.com> <3F1B51C5.4080108@openratings.com> <20030721030157.GE665@opencloud.com> In-Reply-To: <20030721030157.GE665@opencloud.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/199 X-Sequence-Number: 7583 > > >Um, so you don't want to depend on the JDBC postgresql driver at all, but >don't mind having postgresql-specific behaviour elsewhere so long >as you can do it purely through the JDBC interface? That seems a bit >inconsistent. > > I don't see anything "inconsistent" about it. I am just choosing the lesser of two evils. At least, I don't need to know what database I am going to be working with when I compile the code. >Note that using setObject() to set IN clauses is no less postgresql-specific >than using setArray() would be .. I know of at least one DB where you really >can only set data values in a prepared statement as the prepared SQL is >compiled down to a form of bytecode for DB-side execution, there *is* no >textual substitution that goes on. > Right. I do need a scheme like what you suggest below to set up database-specific logic. The difference is - I do not need all the possible jdbc drivers to be installed just to compile my application. And I do not need to know which driver a particular customer is using to send him my application. And I don't need to force my customers to have to request a new app from me if they decide to switch to another database. With your suggestion, the only way I can have the above is to pack all the possible jdbc drivers into every build of the app... Dima > >What I was suggesting was a scheme like: > > interface JDBCExtensions { > void initStatement(PreparedStatement stmt); > void setInClause(PreparedStatement stmt, int index, int[] values); > } > > class PostgresqlJDBCExceptions implements JDBCExtensions { > public void initStatement(PreparedStatement stmt) { > ((org.postgresql.PGStatement)stmt).setUseServerPrepare(true); > } > > public void setInClause(PreparedStatement stmt, int index, int[] values) { > stmt.setArray(index, new org.postgresql.jdbc2.WrappedArray(values, Types.INTEGER)); > } > } > > class FooJDBCExceptions implements JDBCExtensions { > // implementation for FooDB > } > > // ... > > Class datasourceClass = Class.forName(configuredDatasourceClass); > Class extensionsClass = Class.forName(configuredExtensionsClass); > JDBCExtensions extensions = extensionsClass.newInstance(); > > // ... > > PreparedStatement stmt = connection.prepareStatement(...); > extensions.initStatement(stmt); > extensions.setInClause(stmt, 4, new int[] { 1,2,3,4 }); > >Then conditionalize compilation of implementations of JDBCExceptions on the >presence of the appropriate driver. When built, you get extension support >for all the drivers present on the build system. When running from a built >jar, only the configured extension class is loaded (and presumably the >end-user has the corresponding JDBC driver available, or they can't talk to >the DB anyway!) > >What prevents you from taking this approach? > >-O > >