Package org.tentackle.wurblet
Class WurbletArgument
java.lang.Object
org.tentackle.wurblet.WurbletArgument
- All Implemented Interfaces:
WurbletArgumentOperand
A wurblet argument.
There are 4 WurbletArgumentTypes:
- property condition: refers to an
Entity'sAttributethat must meet a condition. - property update: defines an
Entity'sAttributethat will be updated. - property sorting: define the sorting according to an
Entity'sAttribute. - load join: describes a
Relationthat 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 Summary
ConstructorsConstructorDescriptionWurbletArgument(Entity entity, int index, String text, boolean expressionFinished, boolean argumentGroupingEnabled) Constructs a wurblet argument. -
Method Summary
Modifier and TypeMethodDescriptionGets the argument type.Returns the array operator.Gets the model attribute.Gets the datatype column index.Gets the component that prepends the relation path.org.tentackle.sql.DataType<?> Gets the effective datatype of the attribute.Gets the column prefix for nested embedded relations.Gets the getter prefix for nested embedded relations.Gets the embedding relation path to the attribute.
Starts at the embedding entity.intGets the embedding prefix count.
The embedding prefixes are only necessary for chained embedding relations, i.e.Gets the entity the wurblet is applied to.Gets the components for the current SQL EXISTS clause.Sets the relations used within the current SQL EXISTS clause.Gets the compacted relation path starting with the last component relation in chain, if any.intgetIndex()Gets the index within the wurblet anchor.Gets the value to be used in JDBC prepared statements.Gets the effective name of the method argument.
This is ether the optionally defined[name]or the name of theAttribute.getName()Gets the optional name of the method argument.Gets the relation path.getRelop()Gets the relational operator.Gets the sorting type if this a sorting criteria argument.getText()Gets the original text.getValue()Gets the predefined value.booleanisArray()Returns whether argument must be treated as an array.booleanReturns whether this is the last argument of the current SQL EXISTS clause.booleanReturns whether this is a method argument.booleanisPath()Returns whether argument points to another entity.booleanfixed value (directly put into sql-statement).voidsetEndOfExistsClause(boolean endOfExistsClause) Sets whether this is the last argument of the current SQL EXISTS clause.voidsetExistsComponents(Set<Entity> existsComponents) Sets the components for the current SQL EXISTS clause.voidsetExistsRelations(Set<Relation> existsRelations) Sets the relations used within the current SQL EXISTS clause.toString()
-
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 toindex- the position among all argumentstext- the wurblet argexpressionFinished- true if expression is finishedargumentGroupingEnabled- true if argument grouping is enabled- Throws:
org.wurbelizer.wurbel.WurbelException- if parsing failed
-
-
Method Details
-
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
Gets the original text.- Returns:
- the text
-
getArgumentType
Gets the argument type.- Returns:
- the type, never null
-
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
Gets the datatype column index.- Returns:
- the index if column specified, else null
-
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
-
getEmbeddingPath
Gets the embedding relation path to the attribute.
Starts at the embedding entity.- Returns:
- the relation path, if attribute is embedded, empty list if not
-
getEmbeddingPrefixCount
public int getEmbeddingPrefixCount()Gets the embedding prefix count.
The embedding prefixes are only necessary for chained embedding relations, i.e. relations from within an embedded entity which is embedded in at least one other embedded entity. This is used in wurblet joins (and fetch joins) only.- Returns:
- the embedding count, 0 if no prefixing necessary.
-
getEmbeddingColumnPrefix
Gets the column prefix for nested embedded relations.- Returns:
- the column prefix, empty string if none
- See Also:
-
getEmbeddingGetterPrefix
Gets the getter prefix for nested embedded relations.- Returns:
- the getter prefix, empty string if none
- See Also:
-
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
Sets the relations used within the current SQL EXISTS clause.- Parameters:
existsRelations- the effective relations
-
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
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
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
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
Gets the sorting type if this a sorting criteria argument.- Returns:
- ASC or DESC, null if not a sorting argument
-
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
Gets the effective name of the method argument.
This is ether the optionally defined[name]or the name of theAttribute.- Returns:
- the method argument name, never null
- Throws:
org.wurbelizer.wurbel.WurbelException- if argument type provides no argument name
-
getJdbcValue
Gets the value to be used in JDBC prepared statements.- Returns:
- the JDBC value
- Throws:
org.wurbelizer.wurbel.WurbelException- if failedModelException
-
getRelop
Gets the relational operator.- Returns:
- the relop
-
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
Returns the array operator.- Returns:
- IN, ANY or ALL, null if no array relop
-
toString
-