Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to observe / trace class member access in Java / Scala?
    primarykey
    data
    text
    <p>I'm developing a Scala extension to an existing Java ORM (Ebean). The goal of this project is to add as much type safety as possible to the ORM. Instead of </p> <pre><code>Ebean.find(Product.class).fetch("name", "unit").findList() </code></pre> <p>I would finally like to be able to write something like </p> <pre><code>(objects of entity[Product] with attributes name and unit) getIt </code></pre> <p>(note that this is just a very first DSL approach).</p> <p>The ORM model is already defined as </p> <pre><code>@Entity public class { public String name; public String unit; } </code></pre> <p><strong>In order to achieve type safety at compile time for the attributes in the query, I would need to access them on e.g. a dummy object like <code>(new Product()).name</code>.</strong></p> <p>I think this is the best way to ensure that only such model members are used that exists on that class, but, at runtime, I need a way to recognize that this variable was accessed. Otherwise I would just call that member <code>name</code> and wouldn't know about this in my query.</p> <p>Does anybody know a way how to achieve this? <strong>Is there a possibility to trace when a variable is accessed and to give that information, at runtime, to any other object?</strong></p> <p>I already thought about hooking into getters and setters instead of using public members in the model classes, but this would either make the query or the model very ugly. Another problem is that any additional specific methods would have to be added manually for each model.</p> <p>I would be happy if anyone could suggest possible solutions. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload