Class DTO

java.lang.Object
org.wurbelizer.wurblet.AbstractWurblet
org.wurbelizer.wurblet.AbstractJavaWurblet
org.tentackle.wurblet.DTOWurblet
org.tentackle.wurblet.DTO
All Implemented Interfaces:
org.wurbelizer.wurblet.Wurblet

public class DTO extends DTOWurblet
(@wurblet) DTO creates code for a data transfer object.

usage:
@wurblet <tag> DTO [options] <filename>

  • --builder: generate code according to the builder pattern.
  • --equals: generate the equals method.
  • --hashCode: generate the hashCode method.
  • --validate[=<code>]: perform validation after construction. Requires that the DTO implements Validateable. If the optional <code> is missing, the default "ValidationUtilities.getInstance().validate(this)" will be used.
  • --names: generate the name constants for all properties.
  • --from: only if --builder set: generate method to create a builder from instance. This will automatically happen if the '+' option is set for at least one property.
  • --with: same as --from, but the generated methods are prefixed by "with" instead of "from". In TT, the default is to use "frommers" instead of "withers", since builder implementations exist in the wild that use withers for builder methods (which return the builder and not the object to be built!). This may be confusing. TT supports both, though.
  • --nott: generate generic code that does not need any Tentackle dependency (such as TentackleRuntimeException)
  • filename: the file holding the DTO model. Obsolete if the class is a java record.
For more options, see AbstractWurblet.

The model is usually stored in a heap-file such as ".$filename" created as a here-document within the leading comment block of the DTO-file.
Each line describes a property.
Example:

 String  name    the object's name
 int     count   the counter
 
If the line is prefixed by "^", the property is passed to the super entity within the constructor.
In builder pattern mode, standard java inheritance must be used instead.
Example:
 ^String name   the name
 
If the line is prefixed by "=" or "~", the property is mutable and a setter is generated. "~" marks the property transient as well.
In builder pattern mode, no builder method is generated for this property.
Examples:
 =String name   the name
 
Only for builder mode: lines prefixed by "!" are considered as required and a (Tentackle)RuntimeException is thrown by the build-method, if a required attribute was not configured. Notice that a required attribute is always immutable.
 !String name   the name
 
For lines prefixed by "+" a from-Method is generated that creates a new DTO from the current one by replacing the given property. If the option --with is set, the methods are prefixed by with (a.k.a. "withers").
 +String name   the name
 
This would create an instance method "fromName(String name)" that returns a new DTO instance.

The comment may contain optional annotations or access scope enclosed in square brackets.

 String name   the name [@Bindable(MAXCOL=20)] [@MyAnno] [protected]
 
Can also be written as:
 String name   the name [@Bindable(MAXCOL=20), @MyAnno, protected]
 

Valid access scopes are: public (default), protected, package, private.

Global annotations are defined in a single line above the properties, enclosed in square brackets. Annotations not belonging to a property are applied to all properties, if not already defined in the comment. Global annotations can be removed from a property with a leading dash or exclamation mark.

 [@Bindable]
 String blah   the blah
 String blue   the blue not bindable [-@Bindable]
 ...
 

If the builder pattern is used and the class extends a superclass, the builder is created as an extension of the superclass'es builder.

Important: if --equals or --hashCode is given in a subclass, all superclasses must get those options as well!


The wurblet can also be used for the new java record type to generate additional "from" methods and/or a builder. The record declaration must be annotated with @RecordDTO to get the record components from the analyze build phase instead of a DTO model (which is not necessary in that case). Example:

 @RecordDTO
 public record Position3D(@Bindable(options="AUTOSELECT") int x,
                          @Bindable(options="AUTOSELECT") int y,
                          @Bindable(options="AUTOSELECT") int z) {
   ...
   // @wurblet dto DTO --builder --from
 
  • Constructor Details

    • DTO

      public DTO()
  • Method Details

    • run

      public void run() throws org.wurbelizer.wurbel.WurbelException
      Specified by:
      run in interface org.wurbelizer.wurblet.Wurblet
      Overrides:
      run in class DTOWurblet
      Throws:
      org.wurbelizer.wurbel.WurbelException