Skip to main content

3.4 Multiple Properties

Query Dynamic Entities

TreeNodeTable table = TreeNodeTable.$;

TreeNode treeNode = sqlClient
.findById(
TreeNodeFetcher.$
.allScalarFields()
.recursiveParent()
.recursiveChildNodes(),
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.

TreeNodeTable table = TreeNodeTable.$;

RecursiveTreeNodeView 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=[]
)
]
)
]
)