^ Tag <dto-class...
1
<dto-class name="Product" ref="products"/>     <!-- DTO -->

<dto-class name="sa-Product" ref="products"/>  <!-- Model -->
The value of 'ref' specifies the name of data table or view.
2
<dto-class name="ProductDetails" ref="product_details.sql"/>

<dto-class name="ProductDetails" ref="select * from product_details(?)"/>
The value of 'ref' specifies SQL statement that returns ResultSet.
3
<dto-class name="Pair" ref="">
    <field type="int64" column="id"/>
    <field type="string" column="name"/>
</dto-class>
The value of 'ref' is empty. All the fields must be defined manually.

Notes for (1) and (2):

  • Code generator obtains information about DTO fields from JDBC metadata.
  • This is how to redefine auto-detected field types:

    <dto-class name="Order" ref="get_orders.sql">
        <field type="int64" column="positions_count"/>
    </dto-class>
  • This is how to add more fields to auto-detected set:

    <dto-class name="Product" ref="products">
        <field type="int64" column="amount_of_sales"/>
        <field type="float64" column="sum_of_sales"/>
    </dto-class>
  • Use type="-" to exclude fields from auto-detected set:

    <dto-class name="sa-TaskLI" ref="tasks">
        <field column="t_comments" type="-"/>
    </dto-class>

Attributes "pk" and "auto" are used for "extreme" cases of CRUD scenario: 1) a lack of primary key (PK) in data table 2) auto-generated/auto-incremented/serial columns cannot be not detected.

<dto-class name="Group" ref="groups" pk="g_id" auto="g_id"/>
  • The value '*' for 'pk' instructs the code generator to detect PK using JDBC. If it doesn't work, you may need pk="g_id".
  • The value '*' for 'auto' instructs the code generator to detect auto-columns using JDBC. If it doesn't work, you may need auto="g_id".
  • Defaults are '*' for 'pk' and '*' for 'auto'.
  • Auto-columns are not included in SQL statement INSERT. If 'groups' consists of ['id', 'no', 'name'], and 'id' is auto-column, generated SQL is 'insert (no, name) into groups (?, ?)'.
  • Empty value for 'auto' instructs the code generator to ignore auto-columns while building SQL. With auto="", generated SQL is 'insert (id, no, name) into groups (?, ?, ?)'.

Try to use plug-in GUI > tab 'DTO' > local toolbar > 'Fields Definition Assistant'.

This is how to specify comments/code-docs/options for entire DTO class:

<dto-class name="sa-TaskLI" ref="tasks">
    <header><![CDATA[    """
    Task list item
    """
    __table_args__ = {'extend_existing': True}]]></header>
</dto-class>
class TaskLi(Base):
    """
    Task list item
    """
        __table_args__ = {'extend_existing': True}
    __tablename__ = 'tasks'

    t_id = Column('t_id', Integer, primary_key=True, autoincrement=True)
    p_id = Column('p_id', Integer)
    t_date = Column('t_date', DateTime)
    t_subject = Column('t_subject', String(256))
    t_priority = Column('t_priority', Integer)
^ Tag <custom...

(Golang only so far)

<dto-class name="gorm-Department" ref="departments" auto="id">
    <custom>
        {base} app/dbal/thread:thread.BaseModel
        ID // PK
        InstitutionID // FK column
        Institution Institution `gorm:"foreignKey:InstitutionID"` // FK
    </custom>
</dto-class>
import (
    "github.com/google/uuid"
    "app/dbal/thread"
)

type Department struct {
    thread.BaseModel
    ID            uuid.UUID   `json:"id" gorm:"column:id;primary_key;type:uuid;default:gen_random_uuid()"` // PK
    Name          string      `json:"name" gorm:"column:name"`
    InstitutionID uuid.UUID   `json:"institution_id" gorm:"column:institution_id;type:uuid"` // FK column
    Institution   Institution `gorm:"foreignKey:InstitutionID"`                              // FK
}

^ Top