Re: Pl/java in 8.4 bet1 sources compilation failed

From: Kris Jurka <books(at)ejurka(dot)com>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
Cc: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>, Emanuel Calvo Franco <postgres(dot)arg(at)gmail(dot)com>, postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Re: Pl/java in 8.4 bet1 sources compilation failed
Date: 2009-05-30 05:22:45
Message-ID: 4A20C2A5.9050909@ejurka.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Craig Ringer wrote:

> Perhaps a stupid question, but isn't the `-source' parameter to javac
> intended to mask new features and such for just the purpose of compiling
> older sources on a new JDK?
>

The -source argument only controls language features, not
interface/class definitions. java.sql.* provides interfaces that
drivers must implement. When they add new functions to those interfaces
you have to implement those, otherwise the compile fails saying that the
class doesn't implement the specified interface. Sometimes you can
implement new interface functions so that the code can compile in either
version, but not always. Consider the following two cases:

1) JDBC4 has added a new method to java.sql.Array named "void free()".
This can be implemented for JDBC3 and there's no problem that the JDBC3
class implements an additional method that's only required by JDBC4.
The code can be compiled against either JDK version.

2) JDBC4 has added a new interface, java.sql.SQLXML, and added methods
to java.sql.ResultSet to retrieve SQLXML objects. You can't add a
method "SQLXML getSQLXML(int)" to your JDBC3 class because it doesn't
know anything about SQLXML at all because it isn't defined by JDBC3.
For this we must add code that is only compiled if we're building with a
JDK that has JDBC4.

The JDBC driver does this by defining a hierarchy:

AbstractJdbc2ResultSet
|__Jdbc2ResultSet
|__AbstractJdbc3ResultSet
|__Jdbc3ResultSet
|__AbstractJdbc4ResultSet
|__Jdbc4ResultSet

AbstractJdbc4ResultSet will have the getSQLXML method and the
JdbcXResultSet classes will be just stubs that officially implement the
java.sql.ResultSet interface.

If we're building a JDBC3 driver we'll compile AbstractJdbc2ResultSet,
AbstractJdbc3ResultSet, and Jdbc3ResultSet and when asked for a
ResultSet instance we'll return a Jdbc3ResultSet. When building a JDBC4
driver we'll then exclude Jdbc3ResultSet and compile
AbstractJdbc4ResultSet and Jdbc4ResultSet and when asked for ResultSet
instance we'll return a Jdbc4ResultSet.

By using this inheritance we can conditionally compile entire classes
which is easy to do with ant rather than trying to implement something
like #ifdef which is ugly to do with ant's copy with filtering task.

Unfortunately pljava currently has no such infrastructure.

Kris Jurka

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-05-30 06:31:51 Re: Switching databases over JDBC/ODBC
Previous Message Craig Ringer 2009-05-30 03:27:04 Re: Pl/java in 8.4 bet1 sources compilation failed