Support building/using PL/Java on Java 26 - #547
Merged
Conversation
These examples preserve a snapshot of how PL/Java's existing, ancient, Blob support can (and can't) be used.
These examples preserve a snapshot of how PL/Java's existing, ancient, Clob support can (and can't, mostly can't) be used.
BlobValue was implemented as a subclass of InputStream, which cannot be
compiled under Java 26 because JDBC 4.5 makes Blob AutoCloseable with
incompatible exception typing for close().
It was a quite incomplete implementation anyway: limited to 2GB and with
several methods unimplemented. The offline SerialBlob found in the
javax.sql.rowset.serial package is also limited to 2GB and with some
methods unusable (at least when instantiated from a byte[], as here),
but it is more complete than BlobValue.
The C code was depending on an internal getContents method of BlobValue,
Now it uses the documented interface methods, so should be able to use
objects of any class that (correctly) implements Blob (provided, still,
that the length doesn't exceed 2GB).
This is not an effort to improve the java.sql.Blob support significantly,
but just to make it no worse and also compatible with Java 26. This
implementation remains essentially a veneer that doesn't do anything
better than using the {get,update,set,read,write}Bytes methods, and
probably has never seen much use for exactly that reason.
ClobValue was implemented as a subclass of Reader, which cannot be
compiled under Java 26 because JDBC 4.5 makes Clob AutoCloseable with
incompatible exception typing for close().
It was a badly incomplete implementation anyway: limited to 2Gchars and
with several methods unimplemented. The offline SerialClob found in the
javax.sql.rowset.serial package is also limited to 2Gchars and with some
methods unusable (at least when instantiated from a char[], as here),
but it is more complete than ClobValue.
Even the partial work that was done to integrate BlobValue into PL/Java's
legacy type system had not been done for ClobValue; compared to the working
tests in the LegacyBlob example, several of the corresponding tests in
the LegacyClob example did not work.
Some still don't, but a few more do work now, thanks to having the
AsciiStream and CharacterStream methods no longer going through Clob now
at all. That's good enough for now: this is not an effort to improve the
java.sql.Clob support significantly, but just to make it no worse and also
compatible with Java 26. This implementation remains essentially a veneer
that doesn't do anything better than using the {get,update,set,read,write}
String methods, and probably has never seen much use for exactly
that reason.
Those examples that do work after this refactoring, including ones that didn't before, are now run with SQLAction in the deployment descriptor so that at least the current state of limited utility can be preserved.
No issues observed in compiling manually (without the Maven directive specifying an earlier --release) on Oracle JDK 25 GA. cd pljava-api/src/main/java /var/tmp/jdk-26.0.1/bin/javac -d ../../../target/classes/ \ -Xlint:unchecked -Xlint:-removal --module-version 1.6-SNAPSHOT \ $(find . -name '*.java') cd ../../.. /var/tmp/jdk-26.0.1/bin/jar cf target/pljava-api-1.6-SNAPSHOT.jar \ -C target/classes . cd ../pljava/src/main/java /var/tmp/jdk-26.0.1/bin/javac --module-version 1.6-SNAPSHOT \ -d ../../../target/classes/ \ -h ../../../target/javah-include \ --module-path ../../../../pljava-api/target/pljava-api-1.6-SNAPSHOT.jar \ --processor-module-path \ ../../../../pljava-api/target/pljava-api-1.6-SNAPSHOT.jar \ -Xlint:unchecked -Xlint:-removal $(find . -name '*.java') cd ../../../ /var/tmp/jdk-26.0.1/bin/jar cf target/pljava-1.6-SNAPSHOT.jar \ -C target/classes . cd ../pljava-examples/src/main/java /var/tmp/jdk-26.0.1/bin/javac -d ../../../target/classes/ \ --module-path ../../../../pljava-api/target/pljava-api-1.6-SNAPSHOT.jar \ --processor-module-path \ ../../../../pljava-api/target/pljava-api-1.6-SNAPSHOT.jar \ --class-path \ ~/.m2/repository/net/sf/saxon/Saxon-HE/10.9/Saxon-HE-10.9.jar: \ -Xlint:unchecked -Xlint:-removal \ --add-modules org.postgresql.pljava $(find . -name '*.java') cd ../../../target/classes cp -r ../../src/main/resources/* . zip -r ../pljava-examples-1.6-SNAPSHOT.jar * # zip because jar m doesn't preserve order of manifest entries cd ../../../ # with dir of intended pg_config version on PATH: mvn clean install --projects pljava-pgxs,pljava-so,pljava-packaging
PostgreSQL adopted the inttypes.h format macros in 18, but continues to define the older ..._FORMAT macros, so those are what should be used for compatibility across versions.
Aliases for subqueries in a FROM clause became optional in PG 16 (postgres/postgres@bcedd8f, as an extension to the standard), but are strictly required in earlier versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enables PL/Java to build and run with Java 26, but does not bring any PL/Java API changes corresponding to any new features in the JDK 26 release notes. Some new features brought by Java 26's inclusion of the JDBC 4.5 maintenance release could merit future work:
?parameter placeholder should not take place between{\and\}(spelled in a Java string literal as{\\and\\}, respectively), and that\\in such a region (\\\\in a Java literal) represents a literal backslash.?character, which has become more common with recent additions to the language. However:??represents a literal?.nativeSQLmethod that it would be difficult to add this feature without risk of changing behavior, be it even already-broken behavior, that is being relied on. A future major release that revamps the JDBC layer would be a better target for this change.??convention, PL/Java does provide a way to include?in SQL when needed. It is a consequence of the failure of PL/Java'snativeSQLmethod to understand comments, while it does understand quoting. The string/*'*/?/*'*/will therefore be seen by PL/Java as containing a?that should be left alone because inside quotes, while PostgreSQL will recognize it as a?surrounded by comments. This should be covered in PL/Java's documentation./* ... */comments (and also//comments, even though those aren't a thing), which would seem to make the/*'*/?/*'*/technique unusable. But because this method only recognizes comments that follow whitespace, the technique can still be used as long as no whitespace precedes it.DECFLOATandJSON.java.sql.Typesandjava.sql.JDBCTypewill be present when running on Java 26 or later, but PL/Java has no new behavior tied to those types.AutoCloseableimplemented by several JDBC interfaces.BlobandClob, so those implementations are now different internally.BlobandClobimplementations completely with versions that actually manipulate PostgreSQL large objects. That would bring the behavior in line with PGJDBC.Naturally, no patch will begin using Java 26 features within PL/Java itself until a future major release adopts a newer minimum build version.