Class ReturnComposite
- java.lang.Object
-
- org.postgresql.pljava.example.annotation.ReturnComposite
-
- All Implemented Interfaces:
org.postgresql.pljava.ResultSetProvider
,org.postgresql.pljava.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 org.postgresql.pljava.ResultSetProvider.Large
Demonstrates@Function(out={...})
for a function that returns a non-predeclared composite type.
-
-
Constructor Summary
Constructors Constructor Description ReturnComposite()
-
Method Summary
Modifier and Type Method Description boolean
assignRowValues(ResultSet out, long currentRow)
static boolean
boolOneOut(ResultSet in)
Has a boolean result described by oneout
parameter.void
close()
static String
helloOneOut()
Returns a result described by oneout
parameter.static Iterator<String>
helloOneOutTable()
Returns a table result described by oneout
parameter.static boolean
helloOutParams(ResultSet out)
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 bareRECORD
return type.static org.postgresql.pljava.ResultSetProvider
helloTable()
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 bareRECORD
return type.static boolean
notOutParams(ResultSet in)
A function that does not return a composite type, despite having a similar Java form.
-
-
-
Constructor Detail
-
ReturnComposite
public ReturnComposite()
-
-
Method Detail
-
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 bareRECORD
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 thetype=
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 thanpg_catalog.RECORD
, PL/Java does not pretend to know at compile time which types might be composite). The explicitSQLType
annotation on the trailingResultSet
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 org.postgresql.pljava.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 bareRECORD
return type.- Throws:
SQLException
-
assignRowValues
public boolean assignRowValues(ResultSet out, long currentRow) throws SQLException
- Specified by:
assignRowValues
in interfaceorg.postgresql.pljava.ResultSetProvider
- Specified by:
assignRowValues
in interfaceorg.postgresql.pljava.ResultSetProvider.Large
- Throws:
SQLException
-
close
public void close()
- Specified by:
close
in interfaceorg.postgresql.pljava.ResultSetProvider
-
helloOneOut
@Function(schema="javatest", out="greeting text") public static String helloOneOut() throws SQLException
Returns a result described by oneout
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 oneout
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 oneout
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 aResultSetProvider
orResultSetHandle
.- Throws:
SQLException
-
-