Annotation Type Formula


  • @Target({FIELD,TYPE,ANNOTATION_TYPE})
    @Retention(RUNTIME)
    @Repeatable(List.class)
    public @interface Formula
    Assign to a property to be based on a SQL formula.

    This is typically a SQL Literal value, SQL case statement, SQL function or similar.

    Any property based on a formula becomes a read only property.

    You may also put use the Transient annotation with the Formula annotation. The effect of the Transient annotation in this case is that the formula will NOT be included in queries by default - you have to explicitly include it via Query.select() or Query.fetch(). You may want to do this if the Formula is relatively expensive and only want it included in the query when you explicitly state it.

    {@code
     // On the Order "master" bean
     // ... a formula using the Order details
     // ... sum(order_qty*unit_price)
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String select
      The SQL to be used in the SELECT part of the SQL to populate a property.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String join
      OPTIONAL - the SQL to be used in the JOIN part of the SQL to support the formula.
      Platform[] platforms  
    • Element Detail

      • select

        String select
        The SQL to be used in the SELECT part of the SQL to populate a property.
      • join

        String join
        OPTIONAL - the SQL to be used in the JOIN part of the SQL to support the formula.

        This is commonly used to join a 'dynamic view' to support aggregation such as count, sum etc.

        The join string should start with either "left join" or "join".

        You will almost certainly use the "${ta}" as a place holder for the table alias of the table you are joining back to (the "base table" of the entity bean).

        The example below is used to support a total count of topics created by a user.

        
        
         join (select user_id, count(*) as topic_count from f_topic group by user_id) as _tc on _tc.user_id = ${ta}.id
        
         
        Default:
        ""