Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package org.postgresql.pljava.example.annotation;

import org.postgresql.pljava.annotation.Function;
import org.postgresql.pljava.annotation.SQLAction;

/**
Expand Down Expand Up @@ -106,4 +107,28 @@
" current_setting('pljava.implementors'), true) " +
"END"
)
public class ConditionalDDR { }
public class ConditionalDDR
{
private ConditionalDDR() { } // do not instantiate

/**
* Tests class names in the supplied order, returning false as soon as any
* cannot be found by the class loader(s) available to the examples jar, or
* true if all can be found.
*/
@Function(variadic = true, provides = "presentOnClassPath")
public static boolean presentOnClassPath(String[] className)
{
try
{
ClassLoader myLoader = ConditionalDDR.class.getClassLoader();
for ( String cn : className )
Class.forName(cn, false, myLoader);
return true;
}
catch ( ClassNotFoundException e )
{
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020 Tada AB and other contributors, as listed below.
* Copyright (c) 2018-2025 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
Expand Down Expand Up @@ -111,6 +111,7 @@
import org.postgresql.pljava.ResultSetProvider;

import org.postgresql.pljava.annotation.Function;
import org.postgresql.pljava.annotation.SQLAction;
import org.postgresql.pljava.annotation.SQLType;
import static org.postgresql.pljava.annotation.Function.OnNullInput.CALLED;

Expand Down Expand Up @@ -288,6 +289,23 @@
* XQuery regular-expression methods provided here.
* @author Chapman Flack
*/
@SQLAction(
implementor = "postgresql_xml", // skip it all if no xml support
requires = "presentOnClassPath",
provides = "saxon9api",
install =
"SELECT CASE WHEN" +
" presentOnClassPath('net.sf.saxon.s9api.QName')" +
"THEN" +
" CAST(" +
" set_config('pljava.implementors', 'saxon9api,' || " +
" current_setting('pljava.implementors'), true)" +
" AS void" +
" )" +
"ELSE" +
" logMessage('INFO', 'Saxon examples skipped: s9api classes missing')" +
"END"
)
public class S9 implements ResultSetProvider.Large
{
private S9(
Expand Down Expand Up @@ -399,7 +417,7 @@ static class DocumentWrapUnwrap
* @param sve SQL string value to use in a text node
* @return XML content, the text node wrapped in a document node
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static SQLXML xmltext(String sve) throws SQLException
{
SQLXML rx = s_dbc.createSQLXML();
Expand Down Expand Up @@ -457,6 +475,7 @@ public static SQLXML xmltext(String sve) throws SQLException
* type to be cast to.
*/
@Function(
implementor="saxon9api",
schema="javatest",
type="pg_catalog.record",
onNullInput=CALLED,
Expand Down Expand Up @@ -615,6 +634,7 @@ public static boolean xmlcast(
* namespace.
*/
@Function(
implementor="saxon9api",
schema="javatest",
onNullInput=CALLED,
settings="IntervalStyle TO iso_8601"
Expand Down Expand Up @@ -683,6 +703,7 @@ public static SQLXML xq_ret_content(
* SQL value is null.
*/
@Function(
implementor="saxon9api",
schema="javatest",
onNullInput=CALLED,
settings="IntervalStyle TO iso_8601"
Expand Down Expand Up @@ -822,6 +843,7 @@ private static SQLXML returnContent(
* for base64 or (the default, false) hexadecimal.
*/
@Function(
implementor="saxon9api",
schema="javatest",
onNullInput=CALLED,
settings="IntervalStyle TO iso_8601"
Expand Down Expand Up @@ -2983,7 +3005,7 @@ public void onGroupEnd(int groupNumber)
* SQLFeatureNotSupportedException (0A000) if (in the current
* implementation) w3cNewlines is false or omitted.
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static boolean like_regex(
String value, //strict
String pattern, //strict
Expand Down Expand Up @@ -3036,7 +3058,7 @@ public static boolean like_regex(
* SQLFeatureNotSupportedException (0A000) if (in the current
* implementation) usingOctets is true, or w3cNewlines is false or omitted.
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static int occurrences_regex(
String pattern, //strict
@SQLType(name="\"in\"") String in, //strict
Expand Down Expand Up @@ -3115,7 +3137,7 @@ public static int occurrences_regex(
* SQLFeatureNotSupportedException (0A000) if (in the current
* implementation) usingOctets is true, or w3cNewlines is false or omitted.
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static int position_regex(
String pattern, //strict
@SQLType(name="\"in\"") String in, //strict
Expand Down Expand Up @@ -3197,7 +3219,7 @@ public static int position_regex(
* SQLFeatureNotSupportedException (0A000) if (in the current
* implementation) usingOctets is true, or w3cNewlines is false or omitted.
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static String substring_regex(
String pattern, //strict
@SQLType(name="\"in\"") String in, //strict
Expand Down Expand Up @@ -3298,7 +3320,7 @@ public static String substring_regex(
* SQLFeatureNotSupportedException (0A000) if (in the current
* implementation) usingOctets is true, or w3cNewlines is false or omitted.
*/
@Function(schema="javatest")
@Function(implementor="saxon9api", schema="javatest")
public static String translate_regex(
String pattern, //strict
@SQLType(name="\"in\"") String in, //strict
Expand Down
Loading