提交 370bf811 authored 作者: Thomas Mueller's avatar Thomas Mueller

User defined functions can now have parameters of any class. Values of type…

User defined functions can now have parameters of any class. Values of type OTHER (or OBJECT or JAVA_OBJECT) are automatically de-serialized in that case.
上级 bdc005e0
......@@ -1047,6 +1047,12 @@ public class DataType {
} else if (paramClass == Clob.class) {
return new JdbcClob(conn, v, 0);
}
if (v.getType() == Value.JAVA_OBJECT) {
Object o = Utils.deserialize(v.getBytes());
if (paramClass.isAssignableFrom(o.getClass())) {
return o;
}
}
throw DbException.getUnsupportedException(paramClass.getName());
}
......
......@@ -70,6 +70,23 @@ public class Function {
System.out.println(rs.getInt(1) + "/" + rs.getInt(2));
}
prep.close();
// Creating functions with source code
// in this case the JDK classes must be in the classpath
// where the database is running
stat.execute("create alias make_point as $$ " +
"java.awt.Point newPoint(int x, int y) { " +
"return new java.awt.Point(x, y); } $$");
// parameters of type OTHER (or OBJECT or JAVA_OBJECT)
// are de-serialized to match the type
stat.execute("create alias get_x as $$ " +
"int pointX(java.awt.geom.Point2D p) { " +
"return (int) p.getX(); } $$");
rs = stat.executeQuery("call get_x(make_point(10, 20))");
while (rs.next()) {
System.out.println(rs.getString(1));
}
stat.close();
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论