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, MethodCache, MethodsImpl, PdoCache, PdoDeleteBy, PdoIsReferencing, PdoRelations, PdoSelectList, PdoSelectUnique, PdoUpdateBy, RemoteMethod

public class DbModelWurblet extends org.tentackle.wurblet.ModelWurblet
Base 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.
For more options, see ModelWurblet.
Author:
harald
  • Field Summary

    Fields inherited from class org.wurbelizer.wurblet.AbstractWurblet

    configuration, container, out, phase, source
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    aas(String str)
    Utility method to generate argument list.
    acs(String str, String appendStr)
    Adds a string to a comma separated list.
    as(String str)
    Utility method to always get a non-null string.
    void
    Asserts that SQL statements can be executed for that entity.
    void
    Asserts that entity can be selected from the database.
    Builds the string of invocation parameters.
    buildInvocationParameters(boolean limit, boolean offset)
    Builds the string of invocation parameters.
    Builds the string of method parameters.
    buildMethodParameters(boolean limit, boolean offset)
    Builds the string of method parameters.
    createJdbcGetterName(org.tentackle.model.Attribute attribute)
    Creates the "getXXXX" method name for ResultSetWrapper.
    createJdbcSetterName(org.tentackle.sql.DataType<?> dataType)
    Creates the "setXXXX" method name for PreparedStatementWrapper.
    Creates the java code for JoinedSelects.
    Creates optional JDBC-set parameters code for joins with extra arguments.
    Creates the order by clause.
    createOrderBy(List<org.tentackle.wurblet.WurbletArgument> sortKeys)
    Creates the order by clause.
    createRelationArgString(org.tentackle.model.Relation relation)
    Creates the argument string for select or delete statement of a relation.
    createRelationDeleteCode(org.tentackle.model.Relation relation)
    Creates the java code to delete a relation.
    createRelationLinkCode(org.tentackle.model.Relation relation)
    Creates the java code to set the link of a relation.
    createRelationSelectCode(org.tentackle.model.Relation relation)
    Creates the java code to select a relation.
    createRelationSetFirstArgMethodName(org.tentackle.model.Relation relation)
    Creates the set-first-arg method name (useful only in object relations).
    createRelationUpdateReferenceCode(org.tentackle.model.Relation relation)
    Creates the java code to update the reference of a relation.
    The pdo name is fixed "me()".
    createRelationUpdateReferenceCode(org.tentackle.model.Relation relation, String pdo, boolean blunt)
    Creates the java code to update the reference of a relation.
    createRelationWurbletArgString(org.tentackle.model.Relation relation)
    Creates the wurblet argument string for select or delete statement of a relation.
    createRelopCode(org.tentackle.wurblet.WurbletArgument arg)
    Creates the relop code for prepared statements.
    The code assumes a StringBuilder and begins with ".append(".
    Creates the name of a statement id.
    Because statement ids are final, the name is in uppercase.
    createWhereSetPars(org.tentackle.model.Attribute attr, String argument)
    Creates the java code to set a single-column parameter in a PreparedStatementWrapper.
    createWhereSetPars(org.tentackle.wurblet.WurbletArgument arg)
    Creates the java code to set a parameter in a PreparedStatementWrapper.
    Works for single- and multi-column data types.
    org.tentackle.model.Attribute
    Gets the context attribute.
    List<org.tentackle.model.AttributeSorting>
    Goes up the inheritance tree until a default sorting is found.
    List<org.tentackle.wurblet.WurbletArgument>
    Gets the default sorting keys.
    List<org.tentackle.model.Relation>
    The TT persistence layer provides an optimized select for a single eager relations via a LeftJoin.
    org.tentackle.wurblet.WurbletArgumentExpression
    Gets the select/where expression.
    List<org.tentackle.wurblet.WurbletArgument>
    Gets the expression arguments.
    List<org.tentackle.wurblet.WurbletArgument>
    Gets the extra arguments.
    Those are not part of the expression and not sorting arguments.
    org.tentackle.model.Attribute
    getFirstMethodAttribute(org.tentackle.model.Relation relation)
    Gets the method attribute for a relation.
    getJdbcCode(org.tentackle.model.Attribute attribute, String modelCode)
    Creates java code applicable to the JDBC layer from model variable access code.
    Applies .toExternal() if attribute is an application specific type.
    List<org.tentackle.wurblet.JoinPath>
    Gets the consolidated relation paths for the join arguments.
    List<org.tentackle.wurblet.WurbletArgument>
    Gets the method arguments.
    getModelCode(org.tentackle.model.Attribute attribute, String jdbcCode)
    Creates java code applicable to the application model from JDBC variable access code.
    Applies .toInternal() if attribute is an application specific type.
    List<org.tentackle.wurblet.WurbletArgument>
    Gets the sorting arguments.
    boolean
    isAbstractJoinPath(List<org.tentackle.wurblet.JoinPath> paths)
    Returns whether joins with delegates of abstract classes are used.
    The casts of such joins are "unchecked" and need a SuppressWarnings to avoid Xlint warnings.
    boolean
    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.
    boolean
    Returns whether the entity is attracked or fulltracked.
    boolean
    Returns whether SQL statements can be executed for that entity.
    boolean
    Returns whether the entity is fulltracked.
    boolean
    Returns whether expression arguments may contain paths to other entities.
    boolean
    Determines whether one the wurblet arguments refer to a value returned by a PDO's method.
    boolean
    isRelationTransient(org.tentackle.model.Relation relation)
    Returns whether the relation is transient.
    boolean
    Returns whether the entity is tracked.
    boolean
    Returns whether default sorting is configured for the entity.
    boolean
    Returns whether there are load joins.
    boolean
    Returns whether sorting is configured for this wurblet.
    pcs(String str, String prependStr)
    Prepends a string to a comma separated list.
    void
    run()
     

    Methods inherited from class org.tentackle.wurblet.ModelWurblet

    appendCommaSeparated, assertSupportedByBackends, createAccessorCode, createComponentInfo, createDeclaredArgsForSelectOrDeleteMethod, createListRelationDeleteMethodName, createRelationSelectMethodName, deriveClassNameForEntity, getAnnotationOptions, getArgs, getBackends, getColumnName, getColumnNameConstant, getEffectiveDataType, getEmbeddedTableAttributes, getEntity, getMethodName, getModelDefaults, getModelDirName, getModelName, getNonPrimitiveJavaType, getOption, getOptionArgs, getPdoClassName, getWurbletArgs, isAttributeDerived, isGenerified, isIdAttribute, isIdOrSerialAttribute, isInterface, isMuteOptionSet, isPartOfInheritanceHierarchy, isPdo, isRemote, isSerialAttribute, orderByInheritanceLevelAndClassId, prependCommaSeparated, setRemote

    Methods inherited from class org.wurbelizer.wurblet.AbstractJavaWurblet

    getClassName, getPackageName, getSuperClassName, isAbstract, isClass, isFinal, isPrivate, isProtected, isPublic, isRecord, toString

    Methods inherited from class org.wurbelizer.wurblet.AbstractWurblet

    cleanup, getConfiguration, getContainer, getGuardName, getPhase, process, setConfiguration, setContainer, setPhase

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DbModelWurblet

      public DbModelWurblet()
  • Method Details

    • 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:
      run in interface org.wurbelizer.wurblet.Wurblet
      Overrides:
      run in class org.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
    • 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.WurbelException
      Asserts that SQL statements can be executed for that entity.
      Throws:
      org.wurbelizer.wurbel.WurbelException - if not
    • assertEntityNotEmbedded

      public void assertEntityNotEmbedded() throws org.wurbelizer.wurbel.WurbelException
      Asserts that entity can be selected from the database.
      Throws:
      org.wurbelizer.wurbel.WurbelException - if not
    • getMethodArguments

      public List<org.tentackle.wurblet.WurbletArgument> getMethodArguments()
      Gets the method arguments.
      Returns:
      the method arguments
    • getExpressionArguments

      public List<org.tentackle.wurblet.WurbletArgument> getExpressionArguments()
      Gets the expression arguments.
      Returns:
      the arguments used within the expression
    • getExtraArguments

      public 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 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 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 List<org.tentackle.wurblet.WurbletArgument> getDefaultSortKeys() throws org.wurbelizer.wurbel.WurbelException
      Gets 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 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 String createRelopCode(org.tentackle.wurblet.WurbletArgument arg) throws org.wurbelizer.wurbel.WurbelException
      Creates 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 String createOrderBy(List<org.tentackle.wurblet.WurbletArgument> sortKeys) throws org.wurbelizer.wurbel.WurbelException
      Creates 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 String createOrderBy() throws org.wurbelizer.wurbel.WurbelException
      Creates the order by clause.
      Returns:
      the order by clause, null if unsorted
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • isAbstractJoinPath

      public boolean isAbstractJoinPath(List<org.tentackle.wurblet.JoinPath> paths) throws org.wurbelizer.wurbel.WurbelException
      Returns whether joins with delegates of abstract classes are used.
      The casts of such joins are "unchecked" and need a SuppressWarnings to avoid Xlint warnings.
      Returns:
      true if join paths involve delegates of abstract classes
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • createJoins

      public String createJoins() throws org.wurbelizer.wurbel.WurbelException
      Creates the java code for JoinedSelects.
      Returns:
      the generated java code
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • createWhereSetPars

      public String createWhereSetPars(org.tentackle.wurblet.WurbletArgument arg) throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelException
      Creates the java code to set a parameter in a PreparedStatementWrapper.
      Works for single- and multi-column data types.
      Parameters:
      arg - the wurblet argument
      Returns:
      the java code
      Throws:
      org.wurbelizer.wurbel.WurbelException - if malformed or illegal wurblet argument
      org.tentackle.model.ModelException - if getting the jdbc java code failed
    • createWhereSetPars

      public String createWhereSetPars(org.tentackle.model.Attribute attr, String argument) throws org.wurbelizer.wurbel.WurbelException
      Creates the java code to set a single-column parameter in a PreparedStatementWrapper.
      Parameters:
      attr - the model attribute
      argument - the argument string
      Returns:
      the created java code
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • createJoinSetPars

      public String createJoinSetPars() throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelException
      Creates optional JDBC-set parameters code for joins with extra arguments.
      Returns:
      the optional code, empty if none
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
      org.tentackle.model.ModelException
    • createStatementId

      public String createStatementId() throws org.wurbelizer.wurbel.WurbelException
      Creates 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 String buildMethodParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelException
      Builds the string of method parameters.
      Parameters:
      limit - optional limit rows
      offset - optional skip rows
      Returns:
      the method parameters
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • buildMethodParameters

      public String buildMethodParameters() throws org.wurbelizer.wurbel.WurbelException
      Builds the string of method parameters.
      Returns:
      the method parameters
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • buildInvocationParameters

      public String buildInvocationParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelException
      Builds the string of invocation parameters.
      Parameters:
      limit - optional limit rows
      offset - 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 String buildInvocationParameters() throws org.wurbelizer.wurbel.WurbelException
      Builds the string of invocation parameters.
      Returns:
      the invocation parameters
      Throws:
      org.wurbelizer.wurbel.WurbelException - if failed
    • acs

      public String acs(String str, String appendStr)
      Adds a string to a comma separated list.
      Parameters:
      str - the string
      appendStr - the string to append
      Returns:
      the new string
    • pcs

      public String pcs(String str, String prependStr)
      Prepends a string to a comma separated list.
      Parameters:
      str - the string builder
      prependStr - the string to prepend
      Returns:
      the new string
    • aas

      public String aas(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 String as(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 String createJdbcSetterName(org.tentackle.sql.DataType<?> dataType)
      Creates the "setXXXX" method name for PreparedStatementWrapper.
      Parameters:
      dataType - the datatype
      Returns:
      the method name
    • createJdbcGetterName

      public String createJdbcGetterName(org.tentackle.model.Attribute attribute) throws org.wurbelizer.wurbel.WurbelException
      Creates 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 String getModelCode(org.tentackle.model.Attribute attribute, String jdbcCode) throws org.wurbelizer.wurbel.WurbelException
      Creates 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 attribute
      jdbcCode - the jdbc code
      Returns:
      the code the model code
      Throws:
      org.wurbelizer.wurbel.WurbelException - if some model error
    • getJdbcCode

      public String getJdbcCode(org.tentackle.model.Attribute attribute, String modelCode) throws org.wurbelizer.wurbel.WurbelException
      Creates 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 attribute
      modelCode - 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 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 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 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 String createRelationUpdateReferenceCode(org.tentackle.model.Relation relation, String pdo, boolean blunt)
      Creates the java code to update the reference of a relation.
      Parameters:
      relation - the relation
      pdo - the PDO name
      blunt - use the blunt setter method, if provided
      Returns:
      the java code
    • createRelationUpdateReferenceCode

      public 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 String createRelationSetFirstArgMethodName(org.tentackle.model.Relation relation) throws org.tentackle.model.ModelException
      Creates the set-first-arg method name (useful only in object relations).
      Parameters:
      relation - the relation
      Returns:
      the set-method name
      Throws:
      org.tentackle.model.ModelException - if unexpected method args
    • getFirstMethodAttribute

      public org.tentackle.model.Attribute getFirstMethodAttribute(org.tentackle.model.Relation relation) throws org.tentackle.model.ModelException
      Gets the method attribute for a relation.
      Parameters:
      relation - the relation
      Returns:
      the attribute
      Throws:
      org.tentackle.model.ModelException - if no method args found or missing attribute
    • createRelationDeleteCode

      public 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 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 List<org.tentackle.model.Relation> getEagerRelations() throws org.tentackle.model.ModelException
      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 eager relations at all
      Throws:
      org.tentackle.model.ModelException