Class ModelWurblet

  • All Implemented Interfaces:
    org.wurbelizer.wurblet.Wurblet
    Direct Known Subclasses:
    AttributeNames, ColumnLengths, ColumnNames, DomainMethods, Methods, ModelComment, Relations, UniqueDomainKey

    public class ModelWurblet
    extends org.wurbelizer.wurblet.AbstractJavaWurblet
    Extended AbstractJavaWurblet providing basic functionality for the persistent object model.

    The following wurblet options are parsed:

    • --method=<method-name>: optional name of the generated method. Defaults to the wurblet tag.
    • --model=<mapping>: optional model mapping. Derived from source file, if missing.
    • --remote: force generating remote code. Taken from model-defaults, if missing.
    • --noremote: don't generate remote code. Taken from model-defaults, if missing.
    For the general form of a wurblet-anchor, see AbstractWurblet.
    Author:
    harald
    • Field Summary

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

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

      Constructors 
      Constructor Description
      ModelWurblet()
      Creates a wurblet.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendCommaSeparated​(java.lang.StringBuilder builder, java.lang.String appendStr)
      Adds a string to a comma separated list.
      java.lang.String createDeclaredArgsForSelectOrDeleteMethod​(org.tentackle.model.Relation relation)
      Creates the method argument declaration for the select or delete method.
      java.lang.String createListRelationDeleteMethodName​(org.tentackle.model.Relation relation)
      Creates the method name to select a relation.
      java.lang.String createRelationSelectMethodName​(org.tentackle.model.Relation relation)
      Creates the method name to select a relation.
      java.lang.String deriveClassNameForEntity​(org.tentackle.model.Entity otherEntity)
      Applies the semantics of AbstractJavaWurblet.getClassName() to another entity.
      Example:
      java.util.List<java.lang.String> getArgs()
      Gets the wurblet arguments.
      org.tentackle.model.Entity getEntity()
      Gets the model entity.
      java.lang.String getMethodName()
      Gets the methodname.
      From the guardname or from arg "--method=<.....>" if present.
      org.tentackle.model.ModelDefaults getModelDefaults()
      Gets the optional model defaults.
      java.lang.String getModelDirName()
      Gets the name of the model directory.
      java.lang.String getModelName()
      Gets the name of the modelfile.
      java.lang.String getOption​(java.lang.String option)
      Gets the option if set.
      Options come in two flavours: without a value.
      java.util.List<java.lang.String> getOptionArgs()
      Gets the wurblet options.
      The options got the leading '--' removed.
      java.lang.String getPdoClassName()
      Gets the pdo class from the source.
      Looks for annotations @DomainObjectService, @PersistentObjectService and interface extensions.
      java.util.List<java.lang.String> getWurbletArgs()
      Gets the wurblet arguments.
      All arguments except the options.
      boolean isAttributeDerived​(org.tentackle.model.Attribute attribute)
      Checks whether attribute is derived from a superclass.
      boolean isGenerified()
      Returns whether the class is defined using java generics.
      boolean isIdAttribute​(org.tentackle.model.Attribute attribute)
      Checks whether attribute is the pdo ID.
      boolean isIdOrSerialAttribute​(org.tentackle.model.Attribute attribute)
      Checks whether attribute is the pdo ID or serial.
      boolean isInterface()
      Returns whether wurblet is defined within an interface.
      Only valid if isPdo() returns non-null.
      boolean isPartOfInheritanceHierarchy()
      Returns whether the entity is part of an inheritance tree.
      boolean isPdo()
      Returns whether this is a pdo.
      boolean isRemote()
      Returns true if --remote option set.
      boolean isSerialAttribute​(org.tentackle.model.Attribute attribute)
      Checks whether attribute is the pdo serial.
      java.util.List<org.tentackle.model.Entity> orderByInheritanceLevelAndClassId​(java.util.List<org.tentackle.model.Entity> entities)
      Sorts the given list of entities by inheritance level plus classid.
      void prependCommaSeparated​(java.lang.StringBuilder builder, java.lang.String prependStr)
      Prepends a string to a comma separated list.
      void run()
      void setRemote​(boolean remote)
      Sets the remote option explicitly.
      • 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

      • ModelWurblet

        public ModelWurblet()
        Creates a wurblet.
    • Method Detail

      • getModelDirName

        public java.lang.String getModelDirName()
        Gets the name of the model directory.
        Returns:
        the model dir name
      • getModelDefaults

        public org.tentackle.model.ModelDefaults getModelDefaults()
        Gets the optional model defaults.
        Returns:
        the defaults, null if none
      • getPdoClassName

        public java.lang.String getPdoClassName()
                                         throws org.wurbelizer.wurbel.WurbelException
        Gets the pdo class from the source.
        Looks for annotations @DomainObjectService, @PersistentObjectService and interface extensions.
        Returns:
        the pdo name
        Throws:
        org.wurbelizer.wurbel.WurbelException - if pdo class cannot be determined from the source file
      • isPdo

        public boolean isPdo()
        Returns whether this is a pdo.
        Returns:
        true if pdo
      • isInterface

        public boolean isInterface()
        Returns whether wurblet is defined within an interface.
        Only valid if isPdo() returns non-null.
        Returns:
        true if interface
      • isRemote

        public boolean isRemote()
        Returns true if --remote option set.
        Returns:
        true if remote
      • setRemote

        public void setRemote​(boolean remote)
        Sets the remote option explicitly.
        Parameters:
        remote - true if remoting enabled
      • isPartOfInheritanceHierarchy

        public boolean isPartOfInheritanceHierarchy()
        Returns whether the entity is part of an inheritance tree.
        Returns:
        truf if part of an inheritance tree
      • isGenerified

        public boolean isGenerified()
        Returns whether the class is defined using java generics.

        Generics are used in abstract inheritable classes. Final concrete PDO classes must not use generics. Otherwise the generated wurblet code will not compile.

        Returns:
        true if class is generified
      • getMethodName

        public java.lang.String getMethodName()
                                       throws org.wurbelizer.wurbel.WurbelException
        Gets the methodname.
        From the guardname or from arg "--method=<.....>" if present.
        Returns:
        the method name
        Throws:
        org.wurbelizer.wurbel.WurbelException - if no guardname
      • getModelName

        public java.lang.String getModelName()
                                      throws org.wurbelizer.wurbel.WurbelException
        Gets the name of the modelfile.
        Returns:
        the name
        Throws:
        org.wurbelizer.wurbel.WurbelException - if model could not be determined
      • deriveClassNameForEntity

        public java.lang.String deriveClassNameForEntity​(org.tentackle.model.Entity otherEntity)
                                                  throws org.wurbelizer.wurbel.WurbelException
        Applies the semantics of AbstractJavaWurblet.getClassName() to another entity.
        Example:
         getEntity() -> Firma
         getClassName() -> "MyFirmaPersistenceImpl"
         Assumed that otherEntity = Kontakt (which is a superclass of Firma, for example), then:
         deriveClassNameForEntity(otherEntity) -> "MyKontaktPersistenceImpl"
         
        Parameters:
        otherEntity - the other entity
        Returns:
        the derived classname
        Throws:
        org.wurbelizer.wurbel.WurbelException - if this classname does not contain the entity name as a substring
      • orderByInheritanceLevelAndClassId

        public java.util.List<org.tentackle.model.Entity> orderByInheritanceLevelAndClassId​(java.util.List<org.tentackle.model.Entity> entities)
        Sorts the given list of entities by inheritance level plus classid.
        Parameters:
        entities - the entities
        Returns:
        the sorted entities (same reference as argument)
      • getEntity

        public org.tentackle.model.Entity getEntity()
        Gets the model entity.
        Returns:
        the entity
      • getArgs

        public java.util.List<java.lang.String> getArgs()
        Gets the wurblet arguments.
        Returns:
        the wurblet args
      • getOptionArgs

        public java.util.List<java.lang.String> getOptionArgs()
        Gets the wurblet options.
        The options got the leading '--' removed.
        Returns:
        the option args
      • getOption

        public java.lang.String getOption​(java.lang.String option)
        Gets the option if set.
        Options come in two flavours:
        1. without a value. Example: --remote
        2. with a value. Example: --model=modlog.map
        Parameters:
        option - the option
        Returns:
        the empty string (case 1), the value (case 2) or null if option not set
      • getWurbletArgs

        public java.util.List<java.lang.String> getWurbletArgs()
        Gets the wurblet arguments.
        All arguments except the options.
        Returns:
        the wurblet args
      • createRelationSelectMethodName

        public java.lang.String createRelationSelectMethodName​(org.tentackle.model.Relation relation)
        Creates the method name to select a relation.
        Parameters:
        relation - the relation
        Returns:
        the method name
      • createListRelationDeleteMethodName

        public java.lang.String createListRelationDeleteMethodName​(org.tentackle.model.Relation relation)
        Creates the method name to select a relation.
        Parameters:
        relation - the relation
        Returns:
        the method name
      • createDeclaredArgsForSelectOrDeleteMethod

        public java.lang.String createDeclaredArgsForSelectOrDeleteMethod​(org.tentackle.model.Relation relation)
                                                                   throws org.tentackle.model.ModelException
        Creates the method argument declaration for the select or delete method.
        Parameters:
        relation - the relation
        Returns:
        the argument declaration
        Throws:
        org.tentackle.model.ModelException - if failed
      • run

        public void run()
                 throws org.wurbelizer.wurbel.WurbelException

        Overridden to load the map file.

        Specified by:
        run in interface org.wurbelizer.wurblet.Wurblet
        Overrides:
        run in class org.wurbelizer.wurblet.AbstractWurblet
        Throws:
        org.wurbelizer.wurbel.WurbelException - if running the wurblet failed
      • isIdAttribute

        public boolean isIdAttribute​(org.tentackle.model.Attribute attribute)
        Checks whether attribute is the pdo ID.
        Parameters:
        attribute - the attribute
        Returns:
        true if pdo id
      • isSerialAttribute

        public boolean isSerialAttribute​(org.tentackle.model.Attribute attribute)
        Checks whether attribute is the pdo serial.
        Parameters:
        attribute - the attribute
        Returns:
        true if pdo serial
      • isIdOrSerialAttribute

        public boolean isIdOrSerialAttribute​(org.tentackle.model.Attribute attribute)
        Checks whether attribute is the pdo ID or serial.
        Parameters:
        attribute - the attribute
        Returns:
        true if pdo id or serial
      • isAttributeDerived

        public boolean isAttributeDerived​(org.tentackle.model.Attribute attribute)
        Checks whether attribute is derived from a superclass.
        Parameters:
        attribute - the attribute
        Returns:
        true if derived from superclass
      • appendCommaSeparated

        public void appendCommaSeparated​(java.lang.StringBuilder builder,
                                         java.lang.String appendStr)
        Adds a string to a comma separated list.
        Parameters:
        builder - the string builder
        appendStr - the string to append
      • prependCommaSeparated

        public void prependCommaSeparated​(java.lang.StringBuilder builder,
                                          java.lang.String prependStr)
        Prepends a string to a comma separated list.
        Parameters:
        builder - the string builder
        prependStr - the string to prepend