Package org.tentackle.wurblet
Class WurbletArgument
- java.lang.Object
-
- org.tentackle.wurblet.WurbletArgument
-
- All Implemented Interfaces:
WurbletArgumentOperand
public class WurbletArgument extends java.lang.Object implements 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 ".
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- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description WurbletArgument(org.tentackle.model.Entity entity, int index, java.lang.String text, boolean expressionFinished, boolean argumentGroupingEnabled)Constructs a wurblet argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WurbletArgumentTypegetArgumentType()Gets the argument type.org.tentackle.model.AttributegetAttribute()Gets the model attribute.java.lang.IntegergetColumnIndex()Gets the datatype column index.org.tentackle.model.EntitygetComponent()Gets the component that prepends the relation path.org.tentackle.sql.DataType<?>getDataType()Gets the effective datatype of the attribute.org.tentackle.model.EntitygetEntity()Gets the entity the wurblet is applied to.java.util.Set<org.tentackle.model.Entity>getExistsComponents()Gets the components for the current SQL EXISTS clause.java.util.Set<org.tentackle.model.Relation>getExistsRelations()Sets the relations used within the current SQL EXISTS clause.java.util.List<org.tentackle.model.Relation>getExpressionRelations()Gets the compacted relation path starting with the last component relation in chain, if any.intgetIndex()Gets the index within the wurblet anchor.java.lang.StringgetJdbcValue()Gets the value to be used in JDBC prepared statements.java.lang.StringgetMethodArgumentName()Gets the effective name of the method argument.
This is ether the optionally defined[name]or the name of theAttribute.java.lang.StringgetName()Gets the optional name of the method argument.java.util.List<org.tentackle.model.Relation>getRelations()Gets the relation path.java.lang.StringgetRelop()Gets the relational operator.org.tentackle.model.SortTypegetSortType()Gets the sorting type if this a sorting criteria argument.java.lang.StringgetText()Gets the original text.java.lang.StringgetValue()Gets the predefined value.booleanisEndOfExistsClause()Returns whether this is the last argument of the current SQL EXISTS clause.booleanisMethodArgument()Returns whether this is a method argument.booleanisPath()Returns whether argument points to another entity.booleanisValueLiterally()fixed value (directly put into sql-statement).voidsetEndOfExistsClause(boolean endOfExistsClause)Sets whether this is the last argument of the current SQL EXISTS clause.voidsetExistsComponents(java.util.Set<org.tentackle.model.Entity> existsComponents)Sets the components for the current SQL EXISTS clause.voidsetExistsRelations(java.util.Set<org.tentackle.model.Relation> existsRelations)Sets the relations used within the current SQL EXISTS clause.java.lang.StringtoString()
-
-
-
Constructor Detail
-
WurbletArgument
public WurbletArgument(org.tentackle.model.Entity entity, int index, java.lang.String text, boolean expressionFinished, boolean argumentGroupingEnabled) throws org.wurbelizer.wurbel.WurbelExceptionConstructs 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 Detail
-
getEntity
public org.tentackle.model.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 java.lang.String getText()
Gets the original text.- Returns:
- the text
-
getArgumentType
public WurbletArgumentType getArgumentType()
Gets the argument type.- Returns:
- the type, never null
-
getAttribute
public org.tentackle.model.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 java.lang.Integer getColumnIndex()
Gets the datatype column index.- Returns:
- the index if column specified, else null
-
getRelations
public java.util.List<org.tentackle.model.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 java.util.Set<org.tentackle.model.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(java.util.Set<org.tentackle.model.Relation> existsRelations)
Sets the relations used within the current SQL EXISTS clause.- Parameters:
existsRelations- the effective relations
-
getExistsComponents
public java.util.Set<org.tentackle.model.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(java.util.Set<org.tentackle.model.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 java.util.List<org.tentackle.model.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 org.tentackle.model.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 org.tentackle.model.SortType getSortType()
Gets the sorting type if this a sorting criteria argument.- Returns:
- ASC or DESC, null if not a sorting argument
-
getName
public java.lang.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 java.lang.String getMethodArgumentName() throws org.wurbelizer.wurbel.WurbelExceptionGets 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 arhument type provides no argument name
-
getJdbcValue
public java.lang.String getJdbcValue() throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelExceptionGets the value to be used in JDBC prepared statements.- Returns:
- the JDBC value
- Throws:
org.wurbelizer.wurbel.WurbelException- if failedorg.tentackle.model.ModelException
-
getRelop
public java.lang.String getRelop()
Gets the relational operator.- Returns:
- the relop
-
getValue
public java.lang.String getValue()
Gets the predefined value.- Returns:
- the value
-
isValueLiterally
public boolean isValueLiterally()
fixed value (directly put into sql-statement).- Returns:
- the fixed
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-