3.4 Multiple Properties
Query Dynamic Entities
- Java
- Kotlin
TreeNodeTable table = TreeNodeTable.$;
TreeNode treeNode = sqlClient
.findById(
TreeNodeFetcher.$
.allScalarFields()
.recursiveParent() ❶
.recursiveChildNodes() ❷,
10L
);
val treeNode = sqlClient
.findById(
newFetcher(TreeNode::class).by {
allScalarFields()
`parent*`() ❶
`childNodes*`() ❷
},
10L
)
The result is
{
"id":10,
"name":"Woman",
"parent":{ ❶
"id":9,
"name":"Clothing",
"parent":{ ❶
"id":1,
"name":"Home",
"parent":null ❶
}
},
"childNodes":[ ❷
{
"id":11,
"name":"Casual wear",
"childNodes":[ ❷
{
"id":12,
"name":"Dress",
"childNodes":[] ❷
},
{
"id":13,
"name":"Miniskirt",
"childNodes":[] ❷
},
{
"id":14,
"name":"Jeans",
"childNodes":[] ❷
}
]
},
{
"id":15,
"name":"Formal wear",
"childNodes":[ ❷
{
"id":16,
"name":"Suit",
"childNodes":[] ❷
},
{
"id":17,
"name":"Shirt",
"childNodes":[] ❷
}
]
}
]
}
Query Static DTO
Create any file with the dto
extension under the src/main/dto
folder, and edit the code as follows:
export com.yourcompany.yourproject.model.TreeNode
-> package com.yourcompany.yourproject.model.dto
RecursiveTreeNodeView {
#allScalars(this)
parent* ❶
childNodes* ❷
}
Compile the project, a java/kotlin class named RecursiveTreeNodeView
will be automatically generated.
- Java
- Kotlin
TreeNodeTable table = TreeNodeTable.$;
RecursiveTreeNodeView treeNode = sqlClient
.findById(
RecursiveTreeNodeView.class,
10L
);
val treeNode = sqlClient
.findById(
RecursiveTreeNodeView::class,
10L
)
The result is
RecursiveTreeNodeView(
id=10,
name=Woman,
parent=RecursiveTreeNodeView.TargetOf_parent( ❶
id=9,
name=Clothing,
parent=RecursiveTreeNodeView.TargetOf_parent( ❶
id=1,
name=Home,
parent=null ❶
)
),
childNodes=[ ❷
RecursiveTreeNodeView.TargetOf_childNodes(
id=11,
name=Casual wear,
childNodes=[ ❷
RecursiveTreeNodeView.TargetOf_childNodes(
id=12,
name=Dress,
childNodes=[] ❷
),
RecursiveTreeNodeView.TargetOf_childNodes(
id=13,
name=Miniskirt,
childNodes=[] ❷
),
RecursiveTreeNodeView.TargetOf_childNodes(
id=14,
name=Jeans,
childNodes=[] ❷
)
]
),
RecursiveTreeNodeView.TargetOf_childNodes(
id=15,
name=Formal wear,
childNodes=[ ❷
RecursiveTreeNodeView.TargetOf_childNodes(
id=16,
name=Suit,
childNodes=[] ❷
),
RecursiveTreeNodeView.TargetOf_childNodes(
id=17,
name=Shirt,
childNodes=[] ❷
)
]
)
]
)