db-set
Creates DbUnit dataset for specified table and applies it to database
Overview
e:db-set
<e:db-set caption="optional caption" operation="clean_insert" table="ANDROIDS_TABLE" cols="id, name" separator=","> <e:row>1, Adam</e:row> <e:row>2, Bob</e:row> </e:db-set>
Usage
1. Configure a connection to database via DbPlugin.
2. Use e:db-set
tag in specification:
<e:db-set caption="optional caption" operation="clean_insert" table="ANDROIDS_TABLE" cols="id, name" separator=",">
<e:row>1, Adam</e:row>
<e:row>2, Bob</e:row>
</e:db-set>
Attributes
attribute | desc | example |
---|---|---|
table |
Table name | Required. Default: -
|
cols |
List of comma-separated column names with optionally provided values to include in dataset | Optional. Default: -
|
operation |
DbUnit operation to apply | Optional. Default: clean_insert other options: insert, update, refresh, delete, delete_all, truncate_table, truncate_insert |
separator |
Value separator in e:row |
Optional. Default: ,
|
ds |
Datasource to which dataset will be applied. By default only 1 datasource with name default exists, other may be added by DbPlugin configuration. | Optional. Default: default
|
caption |
Caption to display instead of table name in report | Optional. Default: -
|
Each dataset record will be zipped from cols and rows declarations (hence order of cols and order of values inside rows should match).
Given
Empty table:
EMPTY |
When
<e:db-set table="ANDROIDS_TABLE" cols="id, name, height, manufactured">
<e:row>1, Adam, 170, {{now}}</e:row>
<e:row>2, Bob, 200, {{now}}</e:row>
</e:db-set>
will be rendered as:id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 15:26:17.732 |
2 | Bob | 200 | 2022-03-12 15:26:17.733 |
Then
Table will have the following records after applying the following dataset:
ID | NAME | HEIGHT | WEIGHT | MANUFACTURED |
---|---|---|---|---|
1 | Adam | 1.7E+2 | (null) | 2022-03-12 15:26:17.721 |
2 | Bob | 2E+2 | (null) | 2022-03-12 15:26:17.729 |
If all rows should have the same value declaration for specific column, then value assignment may be inlined
with column declaration. Values declaration for such columns should be omitted in e:row
tag.
The next example produces the same result as the previous one:
Given
Empty table:
EMPTY |
When
<e:db-set table="ANDROIDS_TABLE" cols="id=1..10, name, height, manufactured={{now}}">
<e:row>Adam, 170</e:row>
<e:row> Bob, 200</e:row>
</e:db-set>
will be rendered as:id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 15:26:17.755 |
2 | Bob | 200 | 2022-03-12 15:26:17.756 |
Then
Table will have the following records after applying the following dataset:
ID | NAME | HEIGHT | WEIGHT | MANUFACTURED |
---|---|---|---|---|
1 | Adam | 1.7E+2 | (null) | 2022-03-12 15:26:17.752 |
2 | Bob | 2E+2 | (null) | 2022-03-12 15:26:17.754 |
Examples
Value declaration
Value can be declared as simple text, Handlebar helpers invocation or ranges.
Given
Empty table:
EMPTY |
When
id
value is declared as range and will be assigned from 1 to 10 in circlename
andweight
values are declared as simple text values (value will be casted to column type be DbUnit)manufactured
value is declared as Handlebar helpers invocation and will be assigned to result of invocation (which will be casted to column type by DbUnit)
<e:db-set table="ANDROIDS_TABLE" cols="id=1..10, name, weight, height=180, manufactured={{now minus='1 d'}}">
<e:row>Adam, 70</e:row>
<e:row>Bob , 90</e:row>
</e:db-set>
will be rendered as:id | name | weight | height | manufactured |
---|---|---|---|---|
1 | Adam | 70 | 180 | 2022-03-11 15:26:17.766 |
2 | Bob | 90 | 180 | 2022-03-11 15:26:17.767 |
Then
Table will have the following records after applying the following dataset:
ID | NAME | HEIGHT | WEIGHT | MANUFACTURED |
---|---|---|---|---|
1 | Adam | 1.8E+2 | 7E+1 | 2022-03-11 15:26:17.763 |
2 | Bob | 1.8E+2 | 9E+1 | 2022-03-11 15:26:17.765 |
Trimmed spaces
Values declarations a trimmed by default, if there is a need to preserve spaces, then declaration should be
surrounded by '
Given
Empty table:
EMPTY |
When
First
name
equals to A
(surrounded by spaces).Second
name
equals to just A
.
<e:db-set table="ANDROIDS_TABLE" cols="id=1..10, name, weight">
<e:row> ' A ' , 70</e:row>
<e:row> A , 90</e:row>
</e:db-set>
will be rendered as:id | name | weight |
---|---|---|
1 | A | 70 |
2 | A | 90 |
Then
Table will have the following records after applying the following dataset:
ID | NAME | HEIGHT | WEIGHT | MANUFACTURED |
---|---|---|---|---|
1 | A | (null) | 7E+1 | (null) |
2 | A | (null) | 9E+1 | (null) |
Values with commas
Comma is used as default values separator, so using it as part as the value declaration will break parsing.
To workaround this custom value separator may be set by separator
attribute.
Given
Empty table:
EMPTY |
When
name
equals to a , b
:
<e:db-set table="ANDROIDS_TABLE" cols="id=1..10, name, weight" separator="|">
<e:row> a , b | 70</e:row>
</e:db-set>
will be rendered as:id | name | weight |
---|---|---|
1 | a , b | 70 |
Then
Table will have the following records after applying the following dataset:
ID | NAME | HEIGHT | WEIGHT | MANUFACTURED |
---|---|---|---|---|
1 | a , b | (null) | 7E+1 | (null) |