Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 85584B886FB for ; Fri, 3 Jun 2011 17:05:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 87929-03 for ; Fri, 3 Jun 2011 20:05:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 35427B6F035 for ; Fri, 3 Jun 2011 17:05:01 -0300 (ADT) Received: by pvg12 with SMTP id 12so1027333pvg.19 for ; Fri, 03 Jun 2011 13:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:content-type:content-transfer-encoding :subject:date:message-id:to:mime-version:x-mailer; bh=wYPVL1F5+CNtiHrN9avyn3JFCxCrSW/5uZM2Gq6ksIw=; b=gQpyp8t7kwzPrd6WMwhO+WSbQf61PiB8Zccho+HkkUtiO/mxSSQXxZVZejnZLRuy2x hc5s/SeUj3hMClyShVe5owOx+pHSXfV8sybyc21CRaeZxGYb9yrvEYTRmvV3GJ8aIh/F bV8Ja8oxMfszLW4YMB4MFG5jnC8F6SW57AHto= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:content-type:content-transfer-encoding:subject:date:message-id :to:mime-version:x-mailer; b=I29QFEI2oTqjIf+KH7GTx/iGybwLgQMRaW5n+DdUPOjXv2j1nPi8CG+oDIBszornqt e8PHco0CtkGTf5Q+ZagAYhmXc2Jpuf8Ve74ktWqhe0AVBlwsJ9FXh+s6LI1xM140ayht vhXHRFSBaVSwKi+XPrrVUZVQlQrFQZ7Eqn6w0= Received: by 10.142.242.16 with SMTP id p16mr327167wfh.424.1307131500486; Fri, 03 Jun 2011 13:05:00 -0700 (PDT) Received: from sexy.pa.trumpet.io (c-76-21-5-154.hsd1.ca.comcast.net [76.21.5.154]) by mx.google.com with ESMTPS id n1sm1687243pbi.31.2011.06.03.13.04.59 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 03 Jun 2011 13:04:59 -0700 (PDT) From: Steven Schlansker Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: Accepting Object[] as an acceptable input to setObject with Types.ARRAY? Date: Fri, 3 Jun 2011 13:04:58 -0700 Message-Id: To: pgsql-jdbc@postgresql.org Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201106/5 X-Sequence-Number: 21929 Hi all, First off, the environment -=20 PostgreSQL 9.0, driver 9.0-801.jdbc4 C3P0 0.9.1.2 H2 1.3.154 Here's my dilemma. I am attempting to use SQL Arrays (a JDBC 4 feature) = but all the JDBC pools I have had good success with (to date, only C3P0) = do not support JDBC 4. Specifically, if you try to call = Connection.createArrayOf, the pool intercepts it and fails with an = AbstractMethodError as the Connection did not specify that interface = method when C3P0 was compiled (against the JDBC 2 API). It is possible = to break through this barrier with reflective magic, but I don't like = this as a long term solution. This means that it is not possible to create the java.sql.Array instance = that would be required to call setArray to set an array argument on a = prepared statement in a portable way. H2 (http://www.h2database.com) supports a nifty workaround - if you call = setObject with a Object[] it will "do the right thing" and internally = convert this into the SQL Array. This means that the driver does the = work so client code does not have to hack around the lack of = createArrayOf. (ref: http://www.h2database.com/html/datatypes.html#array_type ) It looks like adding support for such a fix to the Postgres driver would = be extremely easy. In particular looking around = AbstractJdbc2Statement.java:1732 case Types.ARRAY: if (in instanceof Array) setArray(parameterIndex, (Array)in); else throw new PSQLException(GT.tr("Cannot cast an = instance of {0} to type {1}", new = Object[]{in.getClass().getName(),"Types.ARRAY"}), = PSQLState.INVALID_PARAMETER_TYPE); break; it could check if in is an array type and if so synthesize the Array = object necessary. Does this sound like a reasonable feature request? Did I miss an easier = way to do this? It is probably outside of the JDBC spec but it at least = has some traction with H2... If this is a reasonable approach I would be happy to contribute a patch, = although I am sure an actual PG JDBC developer could do it much faster = than I. Thanks much for any input, Steven