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 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
  • 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 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
    • getMethodArguments

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

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

      public List<WurbletArgument> getExtraArguments()
      Gets the extra arguments.
      Those are not part of the expression and not sorting arguments.
      Returns:
      the extra arguments
    • getExpression

      public WurbletArgumentExpression getExpression()
      Gets the select/where expression.
      Returns:
      the expression
    • getSortingArguments

      public List<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<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<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(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<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
    • 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(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 multicolumn datatypes.
      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 paramaters 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 failef
    • 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.wurbelizer.wurbel.WurbelException
      Creates 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 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()
      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