Class IntWithMod
- java.lang.Object
-
- org.postgresql.pljava.example.annotation.IntWithMod
-
- All Implemented Interfaces:
SQLData
@SQLAction(requires="IntWithMod modCast", install="SELECT CAST(\'42\' AS javatest.IntWithMod(even))") @BaseUDT(schema="javatest", provides="IntWithMod type", typeModifierInput="javatest.intwithmod_typmodin", typeModifierOutput="javatest.intwithmod_typmodout", like="pg_catalog.int4") public class IntWithMod extends Object implements SQLData
An integer-like data type accepting a type modifier: IntWithMod(even) or IntWithMod(odd).Support for type modifiers in PL/Java is only partial so far. It does not yet honor typmods passed to the input/receive functions ... but it may be that only COPY operations require that. Most uses of types with modifiers seem to pass -1 when first constructing the value, then use a typmod- application cast, and all of that can be done in PL/Java already.
Serving suggestion:
CREATE TABLE evod ( ev javatest.IntWithMod(even), od javatest.IntWithMod(odd) ); INSERT INTO evod ( ev, od ) VALUES ( '4', '7' );
Of course this example more or less duplicates what you could do in two lines with CREATE DOMAIN. But it is enough to illustrate the process.
-
-
Constructor Summary
Constructors Constructor Description IntWithMod()
-
Method Summary
Modifier and Type Method Description String
getSQLTypeName()
static IntWithMod
modApply(IntWithMod iwm, int mod, boolean explicit)
Function backing the type-modifier application cast for IntWithMod type.static int
modIn(String[] toks)
Type modifier input function for IntWithMod type: accepts "even" or "odd".static String
modOut(int mod)
Type modifier output function for IntWithMod type.static IntWithMod
parse(String input, String typeName)
void
readSQL(SQLInput stream, String typeName)
String
toString()
void
writeSQL(SQLOutput stream)
-
-
-
Constructor Detail
-
IntWithMod
public IntWithMod()
-
-
Method Detail
-
parse
@Function(effects=IMMUTABLE, onNullInput=RETURNS_NULL) public static IntWithMod parse(String input, String typeName) throws SQLException
- Throws:
SQLException
-
getSQLTypeName
public String getSQLTypeName()
- Specified by:
getSQLTypeName
in interfaceSQLData
-
readSQL
@Function(effects=IMMUTABLE, onNullInput=RETURNS_NULL) public void readSQL(SQLInput stream, String typeName) throws SQLException
- Specified by:
readSQL
in interfaceSQLData
- Throws:
SQLException
-
writeSQL
@Function(effects=IMMUTABLE, onNullInput=RETURNS_NULL) public void writeSQL(SQLOutput stream) throws SQLException
- Specified by:
writeSQL
in interfaceSQLData
- Throws:
SQLException
-
modIn
@Function(schema="javatest", name="intwithmod_typmodin", effects=IMMUTABLE, onNullInput=RETURNS_NULL) public static int modIn(@SQLType("pg_catalog.cstring[]") String[] toks) throws SQLException
Type modifier input function for IntWithMod type: accepts "even" or "odd". The modifier value is 0 for even or 1 for odd.- Throws:
SQLException
-
modOut
@Function(schema="javatest", name="intwithmod_typmodout", type="pg_catalog.cstring", effects=IMMUTABLE, onNullInput=RETURNS_NULL) public static String modOut(int mod) throws SQLException
Type modifier output function for IntWithMod type.- Throws:
SQLException
-
modApply
@Function(schema="javatest", name="intwithmod_typmodapply", effects=IMMUTABLE, onNullInput=RETURNS_NULL) @Cast(comment="Cast that applies/verifies the type modifier on an IntWithMod.", provides="IntWithMod modCast") public static IntWithMod modApply(IntWithMod iwm, int mod, boolean explicit) throws SQLException
Function backing the type-modifier application cast for IntWithMod type.- Throws:
SQLException
-
-