Class Point
- java.lang.Object
-
- org.postgresql.pljava.example.annotation.Point
-
- All Implemented Interfaces:
SQLData
@SQLAction(requires={"point mirror type","point assertHasValues"}, install="SELECT javatest.assertHasValues(CAST(\'(1,2)\' AS point), 1, 2)") @MappedUDT(name="point", provides="point mirror type") public class Point extends Object implements SQLData
Example of a "mirrored UDT": a user-defined type that exposes to Java the internal representation of an existing (but not SQL-standard) PostgreSQL type. Naturally, the author of this type has to know (from the PostgreSQL source) that aPoint
is stored as twofloat8
s,x
first and theny
.
-
-
Constructor Summary
Constructors Constructor Description Point()
-
Method Summary
Modifier and Type Method Description static void
assertHasValues(Point pt, double x, double y)
Assert a 'point' has given x and y values, to test that its representation in Java corresponds to what PostgreSQL sees.String
getSQLTypeName()
static Point
logAndReturn(Point pt)
Return the same 'point' passed in, logging its contents at level INFO.void
readSQL(SQLInput stream, String typeName)
String
toString()
void
writeSQL(SQLOutput stream)
-
-
-
Constructor Detail
-
Point
public Point()
-
-
Method Detail
-
logAndReturn
@Function(schema="javatest", requires="point mirror type", effects=IMMUTABLE, onNullInput=RETURNS_NULL) public static Point logAndReturn(Point pt)
Return the same 'point' passed in, logging its contents at level INFO.- Parameters:
pt
- any instance of the type this UDT mirrors- Returns:
- the same instance passed in
-
assertHasValues
@Function(schema="javatest", requires="point mirror type", provides="point assertHasValues", effects=IMMUTABLE, onNullInput=RETURNS_NULL) public static void assertHasValues(Point pt, double x, double y) throws SQLException
Assert a 'point' has given x and y values, to test that its representation in Java corresponds to what PostgreSQL sees.- Parameters:
pt
- an instance of this UDTx
- the x value it should havey
- the y value it should have- Throws:
SQLException
- if the values do not match
-
getSQLTypeName
public String getSQLTypeName()
- Specified by:
getSQLTypeName
in interfaceSQLData
-
readSQL
public void readSQL(SQLInput stream, String typeName) throws SQLException
- Specified by:
readSQL
in interfaceSQLData
- Throws:
SQLException
-
writeSQL
public void writeSQL(SQLOutput stream) throws SQLException
- Specified by:
writeSQL
in interfaceSQLData
- Throws:
SQLException
-
-