Package org.tentackle.persist.wurblet
Class DbModelWurblet
- java.lang.Object
-
- org.wurbelizer.wurblet.AbstractWurblet
-
- org.wurbelizer.wurblet.AbstractJavaWurblet
-
- org.tentackle.wurblet.ModelWurblet
-
- org.tentackle.persist.wurblet.DbModelWurblet
-
- All Implemented Interfaces:
org.wurbelizer.wurblet.Wurblet
- Direct Known Subclasses:
AssertRemote,ClassVariables,DbDeleteBy,DbIsReferencing,DbSelectList,DbSelectUnique,DbUpdateBy,Declare,MethodsImpl,PdoCache,PdoDeleteBy,PdoIsReferencing,PdoRelations,PdoSelectList,PdoSelectUnique,PdoUpdateBy,RemoteMethod
public class DbModelWurblet extends org.tentackle.wurblet.ModelWurbletBase class for persistence wurblets.The following wurblet options are supported:
- --context=<key>: defines the context id (--context= turns off default context).
- --tracked: return a TrackedList instead of List (useful if [TRACKED] not given in model).
- --attracked: same as --tracked but generate is...Modified per attribute.
- --fulltracked: same as --attracked but keep last persisted values as well.
- --untracked: disable [TRACKED, ATTRACKED or FULLTRACKED] from model.
ModelWurblet.- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description DbModelWurblet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringaas(java.lang.String str)Utility method to generate argument list.java.lang.Stringacs(java.lang.String str, java.lang.String appendStr)Adds a string to a comma separated list.java.lang.Stringas(java.lang.String str)Utility method to always get a non-null string.voidassertEntityIsPersistable()Asserts that SQL statements can be executed for that entity.java.lang.StringbuildInvocationParameters()Builds the string of invocation parameters.java.lang.StringbuildInvocationParameters(boolean limit, boolean offset)Builds the string of invocation parameters.java.lang.StringbuildMethodParameters()Builds the string of method parameters.java.lang.StringbuildMethodParameters(boolean limit, boolean offset)Builds the string of method parameters.java.lang.StringcreateJdbcGetterName(org.tentackle.model.Attribute attribute)Creates the "getXXXX" method name for ResultSetWrapper.java.lang.StringcreateJdbcSetterName(org.tentackle.sql.DataType<?> dataType)Creates the "setXXXX" method name for PreparedStatementWrapper.java.lang.StringcreateJoins()Creates the java code forJoinedSelects.java.lang.StringcreateJoinSetPars()Creates optional JDBC-set paramaters code for joins with extra arguments.java.lang.StringcreateOrderBy()Creates the order by clause.java.lang.StringcreateOrderBy(java.util.List<org.tentackle.wurblet.WurbletArgument> sortKeys)Creates the order by clause.java.lang.StringcreateRelationArgString(org.tentackle.model.Relation relation)Creates the argument string for select- or delete statement of a relation.java.lang.StringcreateRelationDeleteCode(org.tentackle.model.Relation relation)Creates the java code to delete a relation.java.lang.StringcreateRelationLinkCode(org.tentackle.model.Relation relation)Creates the java code to set the link of a relation.java.lang.StringcreateRelationSelectCode(org.tentackle.model.Relation relation)Creates the java code to select a relation.java.lang.StringcreateRelationSetFirstArgMethodName(org.tentackle.model.Relation relation)Creates the set-first-arg method name (useful only in object relations).java.lang.StringcreateRelationUpdateReferenceCode(org.tentackle.model.Relation relation)Creates the java code to update the reference of a relation.
The pdo name is fixed"me()".java.lang.StringcreateRelationUpdateReferenceCode(org.tentackle.model.Relation relation, java.lang.String pdo, boolean blunt)Creates the java code to update the reference of a relation.java.lang.StringcreateRelationWurbletArgString(org.tentackle.model.Relation relation)Creates the wurblet argument string for select- or delete statement of a relation.java.lang.StringcreateRelopCode(org.tentackle.wurblet.WurbletArgument arg)Creates the relop code for prepared statements.
The code assumes a StringBuilder and begins with".append(".java.lang.StringcreateStatementId()Creates the name of a statement id.
Because statement ids are final, the name is in uppercase.java.lang.StringcreateWhereSetPars(org.tentackle.model.Attribute attr, java.lang.String argument)Creates the java code to set a single-column parameter in a PreparedStatementWrapper.java.lang.StringcreateWhereSetPars(org.tentackle.wurblet.WurbletArgument arg)Creates the java code to set a parameter in a PreparedStatementWrapper.
Works for single- and multicolumn datatypes.org.tentackle.model.AttributegetContextAttribute()Gets the context attribute.java.util.List<org.tentackle.model.AttributeSorting>getDefaultSorting()Goes up the inheritance tree until a default sorting is found.java.util.List<org.tentackle.wurblet.WurbletArgument>getDefaultSortKeys()Gets the default sorting keys.java.util.List<org.tentackle.model.Relation>getEagerRelations()The TT persistence layer provides an optimized select for a single eager relations via a LeftJoin.org.tentackle.wurblet.WurbletArgumentExpressiongetExpression()Gets the select/where expression.java.util.List<org.tentackle.wurblet.WurbletArgument>getExpressionArguments()Gets the expression arguments.java.util.List<org.tentackle.wurblet.WurbletArgument>getExtraArguments()Gets the extra arguments.
Those are not part of the expression and not sorting arguments.java.lang.StringgetJdbcCode(org.tentackle.model.Attribute attribute, java.lang.String modelCode)Creates java code applicable to the JDBC layer from model variable access code.
Applies .toExternal() if attribute is an application specific type.java.util.List<org.tentackle.wurblet.JoinPath>getJoinPaths()Gets the consolidated relation paths for the join arguments.java.util.List<org.tentackle.wurblet.WurbletArgument>getMethodArguments()Gets the method arguments.java.lang.StringgetModelCode(org.tentackle.model.Attribute attribute, java.lang.String jdbcCode)Creates java code applicable to the application model from JDBC variable access code.
Applies .toInternal() if attribute is an application specific type.java.util.List<org.tentackle.wurblet.WurbletArgument>getSortingArguments()Gets the sorting arguments.booleanisArgumentGroupingEnabled()Returns whether argument grouping is enabled.
By default, the grouping separator '|' just improves readability.
Some wurblet, however, need extra arguments separated from the main expression.booleanisAttracked()Returns whether the entity is attracked or fulltracked.booleanisClassIdRequiredInWhereClause()Returns whether the classid needs to be inluded in the WHERE-clause.booleanisClassIdRequiredInWhereClause(org.tentackle.model.Entity entity)Returns whether the classid needs to be inluded in the WHERE-clause.booleanisEntityPersistable()Returns whether SQL statements can be executed for that entity.booleanisFullTracked()Returns whether the entity is fulltracked.booleanisPathAllowed()Returns whether expression arguments may contain paths to other entities.booleanisPdoProvidingArguments()Determines whether one the wurblet arguments refer to a value returned by a PDO's method.booleanisRelationTransient(org.tentackle.model.Relation relation)Returns whether the relation is transient.booleanisTracked()Returns whether the entity is tracked.booleanisWithDefaultSorting()Returns whether default sorting is configured for the entity.booleanisWithJoins()Returns whether there are load joins.booleanisWithSorting()Returns whether sorting is configured for this wurblet.java.lang.Stringpcs(java.lang.String str, java.lang.String prependStr)Prepends a string to a comma separated list.voidrun()-
Methods inherited from class org.tentackle.wurblet.ModelWurblet
appendCommaSeparated, assertSupportedByBackends, createComponentInfo, createDeclaredArgsForSelectOrDeleteMethod, createListRelationDeleteMethodName, createRelationSelectMethodName, deriveClassNameForEntity, getArgs, getBackends, getColumnName, getColumnNameConstant, getEffectiveDataType, getEntity, getMethodName, getModelDefaults, getModelDirName, getModelName, getOption, getOptionArgs, getPdoClassName, getWurbletArgs, isAttributeDerived, isGenerified, isIdAttribute, isIdOrSerialAttribute, isInterface, isPartOfInheritanceHierarchy, isPdo, isRemote, isSerialAttribute, orderByInheritanceLevelAndClassId, prependCommaSeparated, setRemote
-
Methods inherited from class org.wurbelizer.wurblet.AbstractJavaWurblet
getClassName, getPackageName, getSuperClassName, isAbstract, isFinal, isPrivate, isProtected, isPublic, toString
-
-
-
-
Method Detail
-
isArgumentGroupingEnabled
public boolean isArgumentGroupingEnabled()
Returns whether argument grouping is enabled.
By default, the grouping separator '|' just improves readability.
Some wurblet, however, need extra arguments separated from the main expression. This is true for the PdoUpdateBy or DbUpdateBy wurblets, for example. Grouping is turned on via the wurblet option "groupArgs".- Returns:
- true if grouping enabled
-
isPathAllowed
public boolean isPathAllowed()
Returns whether expression arguments may contain paths to other entities.- Returns:
- true if allowed, false if not
-
run
public void run() throws org.wurbelizer.wurbel.WurbelException- Specified by:
runin interfaceorg.wurbelizer.wurblet.Wurblet- Overrides:
runin classorg.tentackle.wurblet.ModelWurblet- Throws:
org.wurbelizer.wurbel.WurbelException
-
isTracked
public boolean isTracked()
Returns whether the entity is tracked.- Returns:
- true if tracked (TRACKED, ATTRACKED or FULLTRACKED)
-
isAttracked
public boolean isAttracked()
Returns whether the entity is attracked or fulltracked.- Returns:
- true if attracked (ATTRACKED or FULLTRACKED)
-
isFullTracked
public boolean isFullTracked()
Returns whether the entity is fulltracked.- Returns:
- true if FULLTRACKED
-
getContextAttribute
public org.tentackle.model.Attribute getContextAttribute()
Gets the context attribute.- Returns:
- the context attribute, null if none
-
isClassIdRequiredInWhereClause
public boolean isClassIdRequiredInWhereClause(org.tentackle.model.Entity entity)
Returns whether the classid needs to be inluded in the WHERE-clause.- Parameters:
entity- the entity- Returns:
- true if include classid
-
isClassIdRequiredInWhereClause
public boolean isClassIdRequiredInWhereClause()
Returns whether the classid needs to be inluded in the WHERE-clause.- Returns:
- true if include classid
-
isEntityPersistable
public boolean isEntityPersistable()
Returns whether SQL statements can be executed for that entity.- Returns:
- true if persistable
-
assertEntityIsPersistable
public void assertEntityIsPersistable() throws org.wurbelizer.wurbel.WurbelExceptionAsserts that SQL statements can be executed for that entity.- Throws:
org.wurbelizer.wurbel.WurbelException- if not
-
getMethodArguments
public java.util.List<org.tentackle.wurblet.WurbletArgument> getMethodArguments()
Gets the method arguments.- Returns:
- the method arguments
-
getExpressionArguments
public java.util.List<org.tentackle.wurblet.WurbletArgument> getExpressionArguments()
Gets the expression arguments.- Returns:
- the arguments used within the expression
-
getExtraArguments
public java.util.List<org.tentackle.wurblet.WurbletArgument> getExtraArguments()
Gets the extra arguments.
Those are not part of the expression and not sorting arguments.- Returns:
- the extra arguments
-
getExpression
public org.tentackle.wurblet.WurbletArgumentExpression getExpression()
Gets the select/where expression.- Returns:
- the expression
-
getSortingArguments
public java.util.List<org.tentackle.wurblet.WurbletArgument> getSortingArguments()
Gets the sorting arguments.- Returns:
- the sorting arguments, empty if no "order by"
-
isWithSorting
public boolean isWithSorting()
Returns whether sorting is configured for this wurblet.- Returns:
- true if sorting defined in args
-
getDefaultSorting
public java.util.List<org.tentackle.model.AttributeSorting> getDefaultSorting()
Goes up the inheritance tree until a default sorting is found.- Returns:
- the sorting, null if none
-
getDefaultSortKeys
public java.util.List<org.tentackle.wurblet.WurbletArgument> getDefaultSortKeys() throws org.wurbelizer.wurbel.WurbelExceptionGets the default sorting keys.- Returns:
- the sorting keys, empty if no "order by"
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
isWithDefaultSorting
public boolean isWithDefaultSorting()
Returns whether default sorting is configured for the entity.- Returns:
- true if sorting enabled
-
getJoinPaths
public java.util.List<org.tentackle.wurblet.JoinPath> getJoinPaths()
Gets the consolidated relation paths for the join arguments.- Returns:
- the join paths
-
isWithJoins
public boolean isWithJoins()
Returns whether there are load joins.- Returns:
- true if with load joins
-
createRelopCode
public java.lang.String createRelopCode(org.tentackle.wurblet.WurbletArgument arg) throws org.wurbelizer.wurbel.WurbelExceptionCreates the relop code for prepared statements.
The code assumes a StringBuilder and begins with".append(".- Parameters:
arg- the wurblet argument- Returns:
- the java code
- Throws:
org.wurbelizer.wurbel.WurbelException
-
createOrderBy
public java.lang.String createOrderBy(java.util.List<org.tentackle.wurblet.WurbletArgument> sortKeys) throws org.wurbelizer.wurbel.WurbelExceptionCreates the order by clause.- Parameters:
sortKeys- the sorting keys- Returns:
- the order by clause, null if unsorted
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createOrderBy
public java.lang.String createOrderBy() throws org.wurbelizer.wurbel.WurbelExceptionCreates the order by clause.- Returns:
- the order by clause, null if unsorted
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createJoins
public java.lang.String createJoins() throws org.wurbelizer.wurbel.WurbelExceptionCreates the java code forJoinedSelects.- Returns:
- the generated java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createWhereSetPars
public java.lang.String createWhereSetPars(org.tentackle.wurblet.WurbletArgument arg) throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelExceptionCreates the java code to set a parameter in a PreparedStatementWrapper.
Works for single- and multicolumn datatypes.- Parameters:
arg- the wurblet argument- Returns:
- the java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if malformed or illegal wurblet argumentorg.tentackle.model.ModelException- if getting the jdbc java code failed
-
createWhereSetPars
public java.lang.String createWhereSetPars(org.tentackle.model.Attribute attr, java.lang.String argument) throws org.wurbelizer.wurbel.WurbelExceptionCreates the java code to set a single-column parameter in a PreparedStatementWrapper.- Parameters:
attr- the model attributeargument- the argument string- Returns:
- the created java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createJoinSetPars
public java.lang.String createJoinSetPars() throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelExceptionCreates optional JDBC-set paramaters code for joins with extra arguments.- Returns:
- the optional code, empty if none
- Throws:
org.wurbelizer.wurbel.WurbelException- if failedorg.tentackle.model.ModelException
-
createStatementId
public java.lang.String createStatementId() throws org.wurbelizer.wurbel.WurbelExceptionCreates the name of a statement id.
Because statement ids are final, the name is in uppercase.- Returns:
- the id string
- Throws:
org.wurbelizer.wurbel.WurbelException- if guardname could not be determined
-
buildMethodParameters
public java.lang.String buildMethodParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelExceptionBuilds the string of method parameters.- Parameters:
limit- optional limit rowsoffset- optional skip rows- Returns:
- the method parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
buildMethodParameters
public java.lang.String buildMethodParameters() throws org.wurbelizer.wurbel.WurbelExceptionBuilds the string of method parameters.- Returns:
- the method parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failef
-
buildInvocationParameters
public java.lang.String buildInvocationParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelExceptionBuilds the string of invocation parameters.- Parameters:
limit- optional limit rowsoffset- optional skip rows- Returns:
- the invocation parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
isPdoProvidingArguments
public boolean isPdoProvidingArguments()
Determines whether one the wurblet arguments refer to a value returned by a PDO's method.- Returns:
- true if at least one argument is something like "getBlah()"
-
buildInvocationParameters
public java.lang.String buildInvocationParameters() throws org.wurbelizer.wurbel.WurbelExceptionBuilds the string of invocation parameters.- Returns:
- the invocation parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
acs
public java.lang.String acs(java.lang.String str, java.lang.String appendStr)Adds a string to a comma separated list.- Parameters:
str- the stringappendStr- the string to append- Returns:
- the new string
-
pcs
public java.lang.String pcs(java.lang.String str, java.lang.String prependStr)Prepends a string to a comma separated list.- Parameters:
str- the string builderprependStr- the string to prepend- Returns:
- the new string
-
aas
public java.lang.String aas(java.lang.String str)
Utility method to generate argument list.- Parameters:
str- the argument string- Returns:
- comma + str if str not empty or null, the empty string otherwise
-
as
public java.lang.String as(java.lang.String str)
Utility method to always get a non-null string.- Parameters:
str- the source string- Returns:
- the string or the empty string if str is null
-
createJdbcSetterName
public java.lang.String createJdbcSetterName(org.tentackle.sql.DataType<?> dataType)
Creates the "setXXXX" method name for PreparedStatementWrapper.- Parameters:
dataType- the datatype- Returns:
- the method name
-
createJdbcGetterName
public java.lang.String createJdbcGetterName(org.tentackle.model.Attribute attribute) throws org.wurbelizer.wurbel.WurbelExceptionCreates the "getXXXX" method name for ResultSetWrapper.- Parameters:
attribute- the model attribute- Returns:
- the method name
- Throws:
org.wurbelizer.wurbel.WurbelException- if type is misconfigured
-
getModelCode
public java.lang.String getModelCode(org.tentackle.model.Attribute attribute, java.lang.String jdbcCode) throws org.wurbelizer.wurbel.WurbelExceptionCreates java code applicable to the application model from JDBC variable access code.
Applies .toInternal() if attribute is an application specific type. Otherwise jdbcCode is returned unchanged.- Parameters:
attribute- the attributejdbcCode- the jdbc code- Returns:
- the code the model code
- Throws:
org.wurbelizer.wurbel.WurbelException- if some model error
-
getJdbcCode
public java.lang.String getJdbcCode(org.tentackle.model.Attribute attribute, java.lang.String modelCode) throws org.wurbelizer.wurbel.WurbelExceptionCreates java code applicable to the JDBC layer from model variable access code.
Applies .toExternal() if attribute is an application specific type. Otherwise modelCode is returned unchanged.- Parameters:
attribute- the attributemodelCode- the jdbc code- Returns:
- the code the model code
- Throws:
org.wurbelizer.wurbel.WurbelException- if some model error
-
isRelationTransient
public boolean isRelationTransient(org.tentackle.model.Relation relation)
Returns whether the relation is transient.- Parameters:
relation- the relation- Returns:
- true if transient modifier required
-
createRelationArgString
public java.lang.String createRelationArgString(org.tentackle.model.Relation relation)
Creates the argument string for select- or delete statement of a relation.- Parameters:
relation- the relation.- Returns:
- the arg string
-
createRelationWurbletArgString
public java.lang.String createRelationWurbletArgString(org.tentackle.model.Relation relation)
Creates the wurblet argument string for select- or delete statement of a relation.- Parameters:
relation- the relation.- Returns:
- the arg string
-
createRelationSelectCode
public java.lang.String createRelationSelectCode(org.tentackle.model.Relation relation)
Creates the java code to select a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationUpdateReferenceCode
public java.lang.String createRelationUpdateReferenceCode(org.tentackle.model.Relation relation, java.lang.String pdo, boolean blunt)Creates the java code to update the reference of a relation.- Parameters:
relation- the relationpdo- the PDO nameblunt- use the blunt setter method, if provided- Returns:
- the java code
-
createRelationUpdateReferenceCode
public java.lang.String createRelationUpdateReferenceCode(org.tentackle.model.Relation relation)
Creates the java code to update the reference of a relation.
The pdo name is fixed"me()".- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationSetFirstArgMethodName
public java.lang.String createRelationSetFirstArgMethodName(org.tentackle.model.Relation relation) throws org.wurbelizer.wurbel.WurbelExceptionCreates the set-first-arg method name (useful only in object relations).- Parameters:
relation- the relation- Returns:
- the set-method name
- Throws:
org.wurbelizer.wurbel.WurbelException- if unexpected method args
-
createRelationDeleteCode
public java.lang.String createRelationDeleteCode(org.tentackle.model.Relation relation)
Creates the java code to delete a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationLinkCode
public java.lang.String createRelationLinkCode(org.tentackle.model.Relation relation)
Creates the java code to set the link of a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
getEagerRelations
public java.util.List<org.tentackle.model.Relation> getEagerRelations()
The TT persistence layer provides an optimized select for a single eager relations via a LeftJoin.- Returns:
- the eager relations, empty list if no optimization possible or no eagers at all
-
-