Class DbModelWurblet

    • Field Summary

      • Fields inherited from class org.wurbelizer.wurblet.AbstractWurblet

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

      Constructors 
      Constructor Description
      DbModelWurblet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String aas​(java.lang.String str)
      Utility method to generate argument list.
      java.lang.String acs​(java.lang.String str, java.lang.String appendStr)
      Adds a string to a comma separated list.
      java.lang.String as​(java.lang.String str)
      Utility method to always get a non-null string.
      void assertEntityIsPersistable()
      Asserts that SQL statements can be executed for that entity.
      java.lang.String buildInvocationParameters()
      Builds the string of invocation parameters.
      java.lang.String buildInvocationParameters​(boolean limit, boolean offset)
      Builds the string of invocation parameters.
      java.lang.String buildMethodParameters()
      Builds the string of method parameters.
      java.lang.String buildMethodParameters​(boolean limit, boolean offset)
      Builds the string of method parameters.
      java.lang.String createJdbcGetterName​(org.tentackle.model.Attribute attribute)
      Creates the "getXXXX" method name for ResultSetWrapper.
      java.lang.String createJdbcSetterName​(org.tentackle.sql.DataType<?> dataType)
      Creates the "setXXXX" method name for PreparedStatementWrapper.
      java.lang.String createJoins()
      Creates the java code for JoinedSelects.
      java.lang.String createJoinSetPars()
      Creates optional JDBC-set paramaters code for joins with extra arguments.
      java.lang.String createOrderBy()
      Creates the order by clause.
      java.lang.String createOrderBy​(java.util.List<org.tentackle.wurblet.WurbletArgument> sortKeys)
      Creates the order by clause.
      java.lang.String createRelationArgString​(org.tentackle.model.Relation relation)
      Creates the argument string for select- or delete statement of a relation.
      java.lang.String createRelationDeleteCode​(org.tentackle.model.Relation relation)
      Creates the java code to delete a relation.
      java.lang.String createRelationLinkCode​(org.tentackle.model.Relation relation)
      Creates the java code to set the link of a relation.
      java.lang.String createRelationSelectCode​(org.tentackle.model.Relation relation)
      Creates the java code to select a relation.
      java.lang.String createRelationSetFirstArgMethodName​(org.tentackle.model.Relation relation)
      Creates the set-first-arg method name (useful only in object relations).
      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()".
      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.
      java.lang.String createRelationWurbletArgString​(org.tentackle.model.Relation relation)
      Creates the wurblet argument string for select- or delete statement of a relation.
      java.lang.String createRelopCode​(org.tentackle.wurblet.WurbletArgument arg)
      Creates the relop code for prepared statements.
      The code assumes a StringBuilder and begins with ".append(".
      java.lang.String createStatementId()
      Creates the name of a statement id.
      Because statement ids are final, the name is in uppercase.
      java.lang.String createWhereSetPars​(org.tentackle.model.Attribute attr, java.lang.String argument)
      Creates the java code to set a single-column parameter in a PreparedStatementWrapper.
      java.lang.String createWhereSetPars​(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.Attribute getContextAttribute()
      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.WurbletArgumentExpression getExpression()
      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.String getJdbcCode​(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.String getModelCode​(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.
      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.
      boolean isAttracked()
      Returns whether the entity is attracked or fulltracked.
      boolean isClassIdRequiredInWhereClause()
      Returns whether the classid needs to be inluded in the WHERE-clause.
      boolean isClassIdRequiredInWhereClause​(org.tentackle.model.Entity entity)
      Returns whether the classid needs to be inluded in the WHERE-clause.
      boolean isEntityPersistable()
      Returns whether SQL statements can be executed for that entity.
      boolean isFullTracked()
      Returns whether the entity is fulltracked.
      boolean isPathAllowed()
      Returns whether expression arguments may contain paths to other entities.
      boolean isPdoProvidingArguments()
      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 isTracked()
      Returns whether the entity is tracked.
      boolean isWithDefaultSorting()
      Returns whether default sorting is configured for the entity.
      boolean isWithJoins()
      Returns whether there are load joins.
      boolean isWithSorting()
      Returns whether sorting is configured for this wurblet.
      java.lang.String pcs​(java.lang.String str, java.lang.String prependStr)
      Prepends a string to a comma separated list.
      void run()  
      • 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
      • 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 Detail

      • DbModelWurblet

        public DbModelWurblet()
    • 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:
        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
      • 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.WurbelException
        Asserts 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.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 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.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 java.lang.String createOrderBy​(java.util.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 java.lang.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 java.lang.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 java.lang.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 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 java.lang.String createWhereSetPars​(org.tentackle.model.Attribute attr,
                                                   java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String acs​(java.lang.String str,
                                    java.lang.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 java.lang.String pcs​(java.lang.String str,
                                    java.lang.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 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.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 java.lang.String getModelCode​(org.tentackle.model.Attribute attribute,
                                             java.lang.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 java.lang.String getJdbcCode​(org.tentackle.model.Attribute attribute,
                                            java.lang.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 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 relation
        pdo - the PDO name
        blunt - 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.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 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