How to improve the intuitivity
I am using a LINQ style way to write HQL-Queries. There are other solutions but they bring frameworks I do not like to use. Today I have a good working solution that abuse the unicode charset so the sourcecode must be at least UTF8.
My solution is working but I am not sure if this is a good solution for the general public. What to change to the syntax in order to publish it to the public accordingly?
Example: We have two Entities: eMail and eMailSubject. A eMail already exists as an hibernate-entity. The function I present is to programaticaly response to that eMail. The task is to add the "Re: "-prefix to the subject.
Code:
21 Replies
⌛
This post has been reserved for your question.
Hey @Peter Rader! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Lets break it down to the components:
The benefit is that you have full content-assist in IDEs and you need no additional dependency. The downside is that the sourcecode must be unicode in order to be used correctly.
What must be changed in order to present the solution to the public?
Why do you use special unicode characters there? Can't you just use underscores or similar?
There is already the approach of type-safe queries with the Jakarta Criteria API metamodel classes (classes that end with an
_
and are generated at compile-time)
see https://jakarta.ee/learn/docs/jakartaee-tutorial/current/persist/persistence-criteria/persistence-criteria.html#_using_the_metamodel_api_to_model_entity_classes - you might want to take inspiration from that ;)
Also how do you get from the data/entity classes to the generated classes? Are you using annotations on the entities (or however you want to call them)? Are you using an annotation processor to generate these classes?I like to use a unicode-pendant for the equals-sign (=), it is a control-character and not allowed as a method-name.
Yes at the moment. I will get rid of generating the intermediate-code due to new language improvements that did not exists before.
Example:
BiFunction<EMail, EMailSubject, EMail> subjectSetter = EMail::setSubject;
and this is what it looks like in Discord

What do you mean with didn't exist before? Method references were available in JDK 8 already...
Are you talking about code reflection? Because that would allow you to do it in a type-safe way without generating that code at compile-time
I admit that it is an old solution.
Is there an issue with it being legal method declarations that nobody will use?
You mean code-reflection like JpaRepositories?
I think I did not made this point clear. If you have a java-method like this:
public static void =(String param) {}
the compiler will mention that = is not a valid method name.Code reflection is a planned Java/JVM feature that should allow Java code to look into a method. So you could do
and then it could actually analyze that and convert it to SQL (without having to look at the bytecode)
and it would also be useful for autodifferentiation and GPU stuff
but it isn't there yet
Nice feature but its a runtime feature, right? Id like to focus on the IDE's content-assist.
Do you have a JEP at hand for that?
There's no JEP yet
just talks
and I think design documents
it's far from being done
Ok, so JDK 40+ feature then.
Like Valhalla.
Java
YouTube
Project Babylon - Code Reflection #JVMLS
Presented by Paul Sandoz - Software Architect (Java Platform Group - Oracle) during the JVM Language Summit (August 2024 - Santa Clara, CA).
_Project Babylon aims to extend the reach of Java to foreign programming models with an enhancement to Java reflection called code reflection . Code reflection expands reflective access to ...
There are relevant JEPs for that
Yeah, they are slowly adding features for that
babylon is fairly new as an OpenJDK project but it won't be as big in scope as Valhalla
https://openjdk.org/projects/babylon/
That one would be relevant to this question: https://openjdk.org/projects/babylon/articles/linq
About the code-reflection... I remember a discussion with a collegue who like to write a unit-test to make sure a constructor is a pojo-constructor and no other magic happens there, I suggested to ASM-disassemble and check the bytecode-instructions.... The discussion ended with the decision to not unit-test bytecode.
good idea
the better way to do that would probably be the AST API (since you have the source code) and probably do it at compile-time with an annotation processor or similar
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.