Class ReturnComposite

java.lang.Object
org.postgresql.pljava.example.annotation.ReturnComposite
All Implemented Interfaces:
ResultSetProvider, ResultSetProvider.Large

@SQLAction(requires={"helloOutParams","helloTable"}, install={"SELECT CASE WHEN want IS NOT DISTINCT FROM helloOutParams() THEN javatest.logmessage(\'INFO\', \'composite return passes\') ELSE javatest.logmessage(\'WARNING\', \'composite return fails\') END FROM (SELECT \'Hello\' ::text, \'world\' ::text) AS want","WITH expected AS (VALUES (\'Hello\' ::text, \'twelve\' ::text), (\'Hello\', \'thirteen\'), (\'Hello\', \'love\') )SELECT CASE WHEN every(want IS NOT DISTINCT FROM got) THEN javatest.logmessage(\'INFO\', \'set of composite return passes\') ELSE javatest.logmessage(\'WARNING\', \'set of composite return fails\') END FROM (SELECT row_number() OVER (), * FROM expected) AS want LEFT JOIN (SELECT row_number() OVER (), * FROM hellotable()) AS got USING (row_number)"}) public class ReturnComposite extends Object implements ResultSetProvider.Large
Demonstrates @Function(out={...}) for a function that returns a non-predeclared composite type.
  • Constructor Details

  • Method Details

    • helloOutParams

      @Function(schema="javatest", out={"greeting text","addressee text"}, provides="helloOutParams") public static boolean helloOutParams(ResultSet out) throws SQLException
      Returns a two-column composite result that does not have to be a predeclared composite type, or require the calling SQL query to follow the function call with a result column definition list, as is needed for a bare RECORD return type.
      Throws:
      SQLException
    • notOutParams

      @Function(schema="javatest", type="text") public static boolean notOutParams(@SQLType("pg_catalog.record") ResultSet in) throws SQLException
      A function that does not return a composite type, despite having a similar Java form.

      Without the type= element, this would not be mistaken for composite. With the type= element (a contrived example, will cast the method's boolean result to text), PL/Java would normally match the method to the composite pattern (other than pg_catalog.RECORD, PL/Java does not pretend to know at compile time which types might be composite). The explicit SQLType annotation on the trailing ResultSet parameter forces it to be seen as an input, and the method to be seen as an ordinary method that happens to return boolean.

      Throws:
      SQLException
    • helloTable

      @Function(schema="javatest", out={"greeting text","addressee text"}, provides="helloTable") public static ResultSetProvider helloTable() throws SQLException
      Returns a two-column table result that does not have to be a predeclared composite type, or require the calling SQL query to follow the function call with a result column definition list, as is needed for a bare RECORD return type.
      Throws:
      SQLException
    • assignRowValues

      public boolean assignRowValues(ResultSet out, long currentRow) throws SQLException
      Specified by:
      assignRowValues in interface ResultSetProvider
      Specified by:
      assignRowValues in interface ResultSetProvider.Large
      Throws:
      SQLException
    • close

      public void close()
      Specified by:
      close in interface ResultSetProvider
    • helloOneOut

      @Function(schema="javatest", out="greeting text") public static String helloOneOut() throws SQLException
      Returns a result described by one out parameter.

      Such a method is written in the style of any method that returns a scalar value, rather than receiving a writable ResultSet as a parameter.

      Throws:
      SQLException
    • boolOneOut

      @Function(schema="javatest", out="exquisite boolean") public static boolean boolOneOut(@SQLType("pg_catalog.record") ResultSet in) throws SQLException
      Has a boolean result described by one out parameter.

      Because this method returns boolean and has a trailing row-typed input parameter, that parameter must have an SQLType annotation so that the method will not look like the more-than-one-OUT composite form, which would be rejected as a likely mistake.

      Throws:
      SQLException
    • helloOneOutTable

      @Function(schema="javatest", out="addressee text") public static Iterator<String> helloOneOutTable() throws SQLException
      Returns a table result described by one out parameter.

      Such a method is written in the style of any method that returns a set of some scalar value, using an Iterator rather than a ResultSetProvider or ResultSetHandle.

      Throws:
      SQLException