Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for native Database functions #23

Closed
oberien opened this issue May 31, 2016 · 2 comments
Closed

Support for native Database functions #23

oberien opened this issue May 31, 2016 · 2 comments

Comments

@oberien
Copy link

oberien commented May 31, 2016

Can you please add support for calling database functions with Jinq?

In JPA 2.1 Support for calling database functions was added. It can be reviewed in the JPA 2.1 Specification on Page 193:

4.6.17.3 Invocation of Predefined and User-defined Database Functions
The invocation of functions other than the built-in functions of the Java Persistence query language is supported by means of the function_invocation syntax. This includes the invocation of predefined database functions and user-defined database functions.

In eclipselink it is implemented since version 2.4, i don't know about hibernate though.

I would have the following suggestions:

Add .function(...)

I imagine this to be the simpler one to implement but rather hard and inflexible to use

Let users add java-method-references with their database-function-string to JinqJPAStreamProvider

For example Math.ceil() could be added and translated like this:

streams.addNativeFunction(Math::ceil, "CEIL")
streams.streamAll(em, Book.class)
    .select(b -> new Pair(b.getName(), Math.ceil(b.getPrice())))

could get translated into

SELECT b.name, FUNCTION("CEIL", b.price) FROM Book b

How would this work for non-static methods? If I have the instance of an object and mapped one of this object's methods, could this case still be analyzed?

@my2iu
Copy link
Owner

my2iu commented Jun 1, 2016

Yes, I've been thinking of this. It isn't a big change. But as an open-source project, Jinq doesn't make any money, so I haven't had the cycles to look at doing this. Unless someone absolutely needs this functionality, I probably won't get around to looking at this until December at the earliest.

@my2iu
Copy link
Owner

my2iu commented Nov 8, 2018

v1.8.25 of Jinq now has experimental support for custom SQL functions.

@my2iu my2iu closed this as completed Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants