[英]How to fix generating proper value type for INPUT parameter in jOOQ for generated user-defined PL/pgSQL function using <forcedType> tag?
I'm having an issue with resolving issue with <forcedType>
for stored function written in PL/pgSQL in my generated Routines.我在解决
<forcedType>
问题时遇到了问题,用于在我生成的例程中以 PL/pgSQL 编写的存储 function。 This question is more specific for solving problem I had already asked in this question and answer is partially provided in this Q&A.这个问题更具体地解决了我在这个问题中已经提出的问题,并且在这个问答中部分提供了答案。
This is ONE of my user-defined functions in PL/pgSQL which I'm having issue with (I'm displaying only one since both functions have same RETURN TYPE and INPUT parameter ):这是我在 PL/pgSQL 中遇到问题的用户定义函数之一(我只显示一个,因为两个函数具有相同的RETURN TYPE和INPUT 参数):
create or replace function public.get_order_by_order_id(o_id bigint) returns json as
$BODY$
DECLARE
finalJson json;
BEGIN
return finalJson;
END;
&BODY&
LANGUAGE 'plpgsql';
Since I'm using Maven these is my pom.xml forced types I've used to performed conversion (like in above linked Q&A ):由于我使用的是 Maven 这些是我的 pom.xml 强制类型,我曾经执行过转换(如上面链接的问答):
<forcedType>
<userType>java.lang.String</userType>
<converter>
org.jooq.Converter.ofNullable(org.jooq.JSON.class, String.class, Object::toString, org.jooq.JSON::valueOf)
</converter>
<includeExpression>(?i:get_book_by_book_id|return_value)</includeExpression>
</forcedType>
<forcedType>
<userType>java.lang.Long</userType>
<converter>
org.jooq.Converter.ofNullable(Long.class, String.class, Object::toString, java.lang.Long::valueOf)
</converter>
<includeExpression>(?i:get_book_by_book_id\.b_id)</includeExpression>
</forcedType>
<forcedType>
<userType>java.lang.String</userType>
<converter>
org.jooq.Converter.ofNullable(org.jooq.JSON.class, String.class, Object::toString, org.jooq.JSON::valueOf)
</converter>
<includeExpression>(?i:get_order_by_order_id|return_value)</includeExpression>
</forcedType>
<forcedType>
<userType>java.lang.Long</userType>
<converter>
org.jooq.Converter.ofNullable(Long.class, String.class, Object::toString, java.lang.Long::valueOf)
</converter>
<includeExpression>(?i:get_order_by_order_id\.o_id)</includeExpression>
</forcedType>
When I perform right click on my project in Project Exporer>Maven>Update Project and check "Force Update.." checkbox I get two following errors:当我在Project Exporer>Maven>Update Project中右键单击我的项目并选中“强制更新..”复选框时,我收到以下两个错误:
Type mismatch: cannot convert from Parameter < String > to Parameter < Long >
类型不匹配:无法从 Parameter < String > 转换为 Parameter < Long >
...and this is how generated GetBookByBookId.java class code I get looks like: ...这就是生成GetBookByBookId.java class 代码的方式:
// This class is generated by jOOQ.
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class GetBookByBookId extends AbstractRoutine<String> {
private static final long serialVersionUID = 1276724822;
// The parameter <code>public.get_book_by_book_id.RETURN_VALUE</code>.
public static final Parameter<String> RETURN_VALUE = Internal.createParameter("RETURN_VALUE", org.jooq.impl.SQLDataType.JSON, false, false, org.jooq.Converter.ofNullable(org.jooq.JSON.class, String.class, Object::toString, org.jooq.JSON::valueOf));
// The parameter <code>public.get_book_by_book_id.b_id</code>.
// Error is occuring AT NEXT LINE of code for value of "B_ID" variable !!!!!!!!!!
public static final Parameter<Long> B_ID = Internal.createParameter("b_id", org.jooq.impl.SQLDataType.BIGINT, false, false, org.jooq.Converter.ofNullable(Long.class, String.class, Object::toString, java.lang.Long::valueOf));
// Create a new routine call instance
public GetBookByBookId() {
super("get_book_by_book_id", Public.PUBLIC, org.jooq.impl.SQLDataType.JSON, org.jooq.Converter.ofNullable(org.jooq.JSON.class, String.class, Object::toString, org.jooq.JSON::valueOf));
setReturnParameter(RETURN_VALUE);
addInParameter(B_ID);
}
// Set the <code>b_id</code> parameter IN value to the routine
public void setBId(Long value) {
setValue(B_ID, value);
}
// Set the <code>b_id</code> parameter to the function to be used with a {@link org.jooq.Select} statement
public GetBookByBookId setBId(Field<Long> field) {
setField(B_ID, field);
return this;
}
}
Passing String value strParam to Long.valueOf( strParam ) should work, but here in jOOQ it doesn't work for some reason.将字符串值strParam传递给Long.valueOf( strParam )应该可以工作,但是在 jOOQ 中由于某种原因它不起作用。 Shouldn't Java compiler be able to infer it from
org.jooq.Converter.ofNullable(Long.class, String.class, Object::toString, java.lang.Long::valueOf)
code passed in <converter>
...is there something I'm missing and what exactly? Shouldn't Java compiler be able to infer it from
org.jooq.Converter.ofNullable(Long.class, String.class, Object::toString, java.lang.Long::valueOf)
code passed in <converter>
...有什么我想念的吗?到底是什么?
Any kind of help or suggestion is greatly appreciated.非常感谢任何形式的帮助或建议。
You did this twice:你这样做了两次:
<forcedType>
<userType>java.lang.Long</userType>
<converter>
org.jooq.Converter.ofNullable(
Long.class, String.class, Object::toString, java.lang.Long::valueOf
)
</converter>
<includeExpression>...</includeExpression>
</forcedType>
Look at the signature of Converter.ofNullable()
.查看
Converter.ofNullable()
的签名。 It's:它的:
static <T, U> Converter<T, U> ofNullable(
Class<T> fromType,
Class<U> toType,
Function<? super T, ? extends U> from,
Function<? super U, ? extends T> to
) { ... }
Where <T>
is the database / JDBC type, and <U>
is the user type.其中
<T>
是数据库/JDBC类型, <U>
是用户类型。 You're just mixing up the two types.你只是混淆了这两种类型。 The parameter is already of type
Long
, and you're trying to convert it to String
.该参数已经是
Long
类型,您正在尝试将其转换为String
。 So declare a String
as your user type:因此,将
String
声明为您的用户类型:
<forcedType>
<userType>java.lang.String</userType>
...
</forcedType>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.