Class WurbletArgument

java.lang.Object
org.tentackle.wurblet.WurbletArgument
All Implemented Interfaces:
WurbletArgumentOperand

public class WurbletArgument extends Object implements WurbletArgumentOperand
A wurblet argument.

There are 4 WurbletArgumentTypes:

  • property condition: refers to an Entity's Attribute that must meet a condition.
  • property update: defines an Entity's Attribute that will be updated.
  • property sorting: define the sorting according to an Entity's Attribute.
  • load join: describes a Relation that will be eagerly loaded.

An argument is of the form:

[*|+|-][Relation|.Entity[.Relation...]][Attribute[#column][[name]]][:relop[:value|#value]]

  • argument type:
    • default (missing): attribute as a condition or for update
    • + or -: sorting criteria (+ for ascending, - for descending)
    • *: load join
  • relation-path: list of relations.
    Optional for conditions, required for load joins. Illegal for updates and sorting.
    If the current entity is a root-entity, the path starts with a dot and is followed by the name of a pointsToComponent, the pointsToComponent is replaced by its relation path, if there is only one path.
    For joins, the dots between the relations can be replaced by asterisks.
  • attribute: a property of an entity.
    Required for conditions, updates, sorting. Illegal for joins.
  • column: the optional column suffix or getter name for multi-column types. If missing and the multi-column type defines a default column, this column is taken. A * will explicitly select all columns.
  • name: optional name of the method argument.
    Only allowed for conditions and updates.
  • relop-expression: optional relop.
    Only allowed for conditions.
    Defaults to '='.
    The special relop ':null' will be translated to " IS NULL" and ':notnull' translated to " IS NOT NULL".
    ':like' will translated to " LIKE ". ':notlike' will be translated to " NOT LIKE ".
    ':in', ':notin' or if the relop ends with 'any' or 'all', it will be translated to IN(?), NOT IN(?), ANY(?) or ALL(?) operators with its argument being an array instead of a simple value. Notice that backends may not support array operators at all or only a subset. This is verified by the wurblets.
    The optional ':value' will be set as a '?'-parameter of the generated prepared statement. As an alternative, the value may be given as '#value' which will include the value literally in the SQL-string.
 Examples:
          poolId                      -> attribute=poolId, arg=poolId, relop="="
          poolId[from]:>=             -> attribute=poolId, arg=from, relop=">="
          code:=:"Hurrz"              -> attribute=code, relop="=", value="Hurz"
          code:=#"Hurrz"              -> attribute=code, relop="=", value="Hurz", literally=true

          +poolId -kurzname           -> ORDER BY pool_id ASC, kurzname DESC

          invoice.lines.currencyId    -> SQL WHERE condition for currency_id
          .InvoiceLine.currencyId     -> equivalent to the above

          *invoice.lines              -> joins the invoice pointsToComponent together with its lines
          *invoice*lines              -> equivalent to the above

          blahId:=ANY                 -> attribute blahId as an array, SQL relop is =ANY(?)

 
Author:
harald
  • Constructor Details

    • WurbletArgument

      public WurbletArgument(Entity entity, int index, String text, boolean expressionFinished, boolean argumentGroupingEnabled) throws org.wurbelizer.wurbel.WurbelException
      Constructs a wurblet argument.

      Parameters:
      entity - the entity the wurblet is applied to
      index - the position among all arguments
      text - the wurblet arg
      expressionFinished - true if expression is finished
      argumentGroupingEnabled - true if argument grouping is enabled
      Throws:
      org.wurbelizer.wurbel.WurbelException - if parsing failed
  • Method Details

    • getEntity

      public Entity getEntity()
      Gets the entity the wurblet is applied to.
      Returns:
      the entity
    • getIndex

      public int getIndex()
      Gets the index within the wurblet anchor.
      Returns:
      the index, lower comes first
    • getText

      public String getText()
      Gets the original text.
      Returns:
      the text
    • getArgumentType

      public WurbletArgumentType getArgumentType()
      Gets the argument type.
      Returns:
      the type, never null
    • getAttribute

      public Attribute getAttribute()
      Gets the model attribute.
      Returns:
      the attribute
    • getDataType

      public org.tentackle.sql.DataType<?> getDataType()
      Gets the effective datatype of the attribute.
      Returns:
      the datatype
    • getColumnIndex

      public Integer getColumnIndex()
      Gets the datatype column index.
      Returns:
      the index if column specified, else null
    • getRelations

      public List<Relation> getRelations()
      Gets the relation path.

      If the path starts with a component, the relations start there.

      Returns:
      the relations, null if refers directly to the wurblet's entity
    • getExistsRelations

      public Set<Relation> getExistsRelations()
      Sets the relations used within the current SQL EXISTS clause.
      Returns:
      the relations, null if argument has no relations or already covered by EXISTS-clause
    • setExistsRelations

      public void setExistsRelations(Set<Relation> existsRelations)
      Sets the relations used within the current SQL EXISTS clause.
      Parameters:
      existsRelations - the effective relations
    • getExistsComponents

      public Set<Entity> getExistsComponents()
      Gets the components for the current SQL EXISTS clause.
      Returns:
      the components, null if argument has no relations or already covered by EXISTS-clause
    • setExistsComponents

      public void setExistsComponents(Set<Entity> existsComponents)
      Sets the components for the current SQL EXISTS clause.
      Parameters:
      existsComponents - the components
    • isEndOfExistsClause

      public boolean isEndOfExistsClause()
      Returns whether this is the last argument of the current SQL EXISTS clause.
      Returns:
      true if finish clause
    • setEndOfExistsClause

      public void setEndOfExistsClause(boolean endOfExistsClause)
      Sets whether this is the last argument of the current SQL EXISTS clause.
      Parameters:
      endOfExistsClause - true if finish clause
    • getExpressionRelations

      public List<Relation> getExpressionRelations()
      Gets the compacted relation path starting with the last component relation in chain, if any.
      Returns:
      the relation path to be used in expressions, null if refers directly to the wurblet's entity
    • getComponent

      public Entity getComponent()
      Gets the component that prepends the relation path.
      Returns:
      the component, null if path does not start with a component
    • isPath

      public boolean isPath()
      Returns whether argument points to another entity.
      Returns:
      true if argument describes a path to another entity
    • getSortType

      public SortType getSortType()
      Gets the sorting type if this a sorting criteria argument.
      Returns:
      ASC or DESC, null if not a sorting argument
    • getName

      public String getName()
      Gets the optional name of the method argument.
      Returns:
      the argument name, null if default attribute name
    • isMethodArgument

      public boolean isMethodArgument()
      Returns whether this is a method argument.
      Returns:
      true if attribute set and value is null
    • getMethodArgumentName

      public String getMethodArgumentName() throws org.wurbelizer.wurbel.WurbelException
      Gets the effective name of the method argument.
      This is ether the optionally defined [name] or the name of the Attribute.
      Returns:
      the method argument name, never null
      Throws:
      org.wurbelizer.wurbel.WurbelException - if arhument type provides no argument name
    • getJdbcValue

      public String getJdbcValue() throws org.wurbelizer.wurbel.WurbelException, ModelException
      Gets the value to be used in JDBC prepared statements.
      Returns:
      the JDBC value
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
      ModelException
    • getRelop

      public String getRelop()
      Gets the relational operator.
      Returns:
      the relop
    • getValue

      public String getValue()
      Gets the predefined value.
      Returns:
      the value
    • isValueLiterally

      public boolean isValueLiterally()
      fixed value (directly put into sql-statement).
      Returns:
      the fixed
    • isArray

      public boolean isArray()
      Returns whether argument must be treated as an array.
      Returns:
      true if IN, ANY or ALL operators used
    • getArrayOperator

      public String getArrayOperator()
      Returns the array operator.
      Returns:
      IN, ANY or ALL, null if no array relop
    • toString

      public String toString()
      Overrides:
      toString in class Object