Skip to content

Commit 7987f29

Browse files
committed
Take advantage of new @cast annotation
1 parent 98f1a6e commit 7987f29

File tree

4 files changed

+13
-51
lines changed

4 files changed

+13
-51
lines changed

java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>org.postgresql</groupId>
4545
<artifactId>pljava-api</artifactId>
46-
<version>1.6.0</version>
46+
<version>1.6-SNAPSHOT</version>
4747
</dependency>
4848
<dependency>
4949
<groupId>junit</groupId>

java/src/main/java/com/invariantproperties/udt/sql/ComplexUDT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import java.util.ResourceBundle;
3131

3232
import org.postgresql.pljava.annotation.BaseUDT;
33+
import org.postgresql.pljava.annotation.Cast;
3334
import org.postgresql.pljava.annotation.Function;
35+
import static org.postgresql.pljava.annotation.Cast.Application.ASSIGNMENT;
3436
import static
3537
org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL;
3638
import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE;
@@ -225,6 +227,7 @@ public String toString() {
225227
*/
226228
@Function(schema="invariantproperties", name="complex_string_as_complex",
227229
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
230+
@Cast(application=ASSIGNMENT)
228231
public static ComplexUDT newInstance(String input) throws SQLException {
229232
if (input == null) {
230233
return null;
@@ -241,6 +244,7 @@ public static ComplexUDT newInstance(String input) throws SQLException {
241244
*/
242245
@Function(schema="invariantproperties", name="complex_double_as_complex",
243246
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
247+
@Cast(application=ASSIGNMENT)
244248
public static ComplexUDT newInstance(double value) throws SQLException {
245249
return new ComplexUDT(value);
246250
}
@@ -256,6 +260,7 @@ public static ComplexUDT newInstance(double value) throws SQLException {
256260
@Function(schema="invariantproperties",
257261
name="complex_bigdecimal_as_complex",
258262
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
263+
@Cast(application=ASSIGNMENT)
259264
public static ComplexUDT newInstance(BigDecimal value) throws SQLException {
260265
return new ComplexUDT(value.doubleValue());
261266
}
@@ -269,6 +274,7 @@ public static ComplexUDT newInstance(BigDecimal value) throws SQLException {
269274
*/
270275
@Function(schema="invariantproperties", name="complex_int_as_complex",
271276
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
277+
@Cast(application=ASSIGNMENT)
272278
public static ComplexUDT newInstance(int value) throws SQLException {
273279
return new ComplexUDT(value);
274280
}
@@ -282,6 +288,7 @@ public static ComplexUDT newInstance(int value) throws SQLException {
282288
*/
283289
@Function(schema="invariantproperties", name="complex_long_as_complex",
284290
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
291+
@Cast(application=ASSIGNMENT)
285292
public static ComplexUDT newInstance(long value) throws SQLException {
286293
return new ComplexUDT(value);
287294
}

java/src/main/java/com/invariantproperties/udt/sql/RationalUDT.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import java.util.ResourceBundle;
3030

3131
import org.postgresql.pljava.annotation.BaseUDT;
32+
import org.postgresql.pljava.annotation.Cast;
3233
import org.postgresql.pljava.annotation.Function;
3334
import org.postgresql.pljava.annotation.SQLAction;
3435
import org.postgresql.pljava.annotation.SQLActions;
36+
import static org.postgresql.pljava.annotation.Cast.Application.ASSIGNMENT;
3537
import static
3638
org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL;
3739
import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE;
@@ -69,28 +71,6 @@
6971
"DROP AGGREGATE max(invariantproperties.rational)",
7072
"DROP AGGREGATE min(invariantproperties.rational)"
7173
}
72-
),
73-
@SQLAction(
74-
requires={"rationalfromstring", "rationalfromint", "rationalfromlong"},
75-
install={
76-
"CREATE CAST (varchar AS invariantproperties.rational) " +
77-
"WITH FUNCTION " +
78-
"invariantproperties.rational_string_as_rational(varchar)" +
79-
"AS ASSIGNMENT",
80-
81-
"CREATE CAST (int4 AS invariantproperties.rational) " +
82-
"WITH FUNCTION invariantproperties.rational_int_as_rational(int4)" +
83-
"AS ASSIGNMENT",
84-
85-
"CREATE CAST (int8 AS invariantproperties.rational) " +
86-
"WITH FUNCTION invariantproperties.rational_long_as_rational(int8)"+
87-
"AS ASSIGNMENT"
88-
},
89-
remove={
90-
"DROP CAST (int8 AS invariantproperties.rational)",
91-
"DROP CAST (int4 AS invariantproperties.rational)",
92-
"DROP CAST (varchar AS invariantproperties.rational)"
93-
}
9474
)
9575
})
9676
public class RationalUDT implements SQLData {
@@ -441,8 +421,8 @@ public static boolean greaterThan(RationalUDT p, double q) {
441421
* @throws SQLException
442422
*/
443423
@Function(schema="invariantproperties", name="rational_string_as_rational",
444-
provides="rationalfromstring",
445424
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
425+
@Cast(application=ASSIGNMENT)
446426
public static RationalUDT newInstance(String input) throws SQLException {
447427
if (input == null) {
448428
return null;
@@ -458,8 +438,8 @@ public static RationalUDT newInstance(String input) throws SQLException {
458438
* @throws SQLException
459439
*/
460440
@Function(schema="invariantproperties", name="rational_int_as_rational",
461-
provides="rationalfromint",
462441
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
442+
@Cast(application=ASSIGNMENT)
463443
public static RationalUDT newInstance(int value) throws SQLException {
464444
return new RationalUDT(value);
465445
}
@@ -472,8 +452,8 @@ public static RationalUDT newInstance(int value) throws SQLException {
472452
* @throws SQLException
473453
*/
474454
@Function(schema="invariantproperties", name="rational_long_as_rational",
475-
provides="rationalfromlong",
476455
effects=IMMUTABLE, onNullInput=RETURNS_NULL)
456+
@Cast(application=ASSIGNMENT)
477457
public static RationalUDT newInstance(long value) throws SQLException {
478458
return new RationalUDT(value);
479459
}

java/src/main/resources/postgresql-udt.ddr

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -276,34 +276,9 @@ SQLActions[] = {
276276
);
277277
*/
278278

279-
CREATE CAST (varchar AS invariantproperties.complex)
280-
WITH FUNCTION invariantproperties.complex_string_as_complex(varchar)
281-
AS ASSIGNMENT;
282-
283-
CREATE CAST (numeric AS invariantproperties.complex)
284-
WITH FUNCTION invariantproperties.complex_bigdecimal_as_complex(numeric)
285-
AS ASSIGNMENT;
286-
287-
CREATE CAST (float8 AS invariantproperties.complex)
288-
WITH FUNCTION invariantproperties.complex_double_as_complex(float8)
289-
AS ASSIGNMENT;
290-
291-
CREATE CAST (int4 AS invariantproperties.complex)
292-
WITH FUNCTION invariantproperties.complex_int_as_complex(int4)
293-
AS ASSIGNMENT;
294-
295-
CREATE CAST (int8 AS invariantproperties.complex)
296-
WITH FUNCTION invariantproperties.complex_long_as_complex(int8)
297-
AS ASSIGNMENT;
298-
299279
END INSTALL",
300280

301281
"BEGIN REMOVE
302-
DROP CAST (int8 AS invariantproperties.complex);
303-
DROP CAST (int4 AS invariantproperties.complex);
304-
DROP CAST (float8 AS invariantproperties.complex);
305-
DROP CAST (numeric AS invariantproperties.complex);
306-
DROP CAST (varchar AS invariantproperties.complex);
307282
/* DROP OPERATOR / ( invariantproperties.complex, invariantproperties.complex ); */
308283
DROP OPERATOR * ( numeric, invariantproperties.complex );
309284
DROP OPERATOR * ( float8, invariantproperties.complex );

0 commit comments

Comments
 (0)