Skip to content

Commit 1adf8ec

Browse files
committed
Enhance annotation option parameter validation and add new test cases for embedded properties
1 parent 91ff74a commit 1adf8ec

File tree

5 files changed

+193
-50
lines changed

5 files changed

+193
-50
lines changed

src/test/testData/src/main/java/doma/example/dao/inspection/option/AnnotationOptionTestDao.java

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package doma.example.dao.inspection.option;
2+
3+
import doma.example.entity.*;
4+
import org.seasar.doma.*;
5+
import java.util.List;
6+
7+
/**
8+
* When using this test data with [LightJavaCodeInsightFixtureTestCase],
9+
* the highlighted elements are not parsed correctly, resulting in errors.
10+
* Compare the highlights in this test data with the actual highlights in IDEA,
11+
* and visually confirm that the highlights and errors occur as expected based on the test data.
12+
*/
13+
@Dao
14+
public interface AnnotationOptionTestDao {
15+
16+
// Valid include option
17+
@Update(include = {"name", "location"})
18+
int updateWithValidInclude(Department department);
19+
20+
// Invalid include option
21+
@Update(include = {"name", "invalidField"})
22+
int updateWithInvalidInclude(Department department);
23+
24+
// Valid exclude option
25+
@Update(exclude = {"managerCount"})
26+
int updateWithValidExclude(Department department);
27+
28+
// Invalid exclude option
29+
@Update(exclude = {"salary", "location"})
30+
int updateWithInvalidExclude(Department department);
31+
32+
// Mixed valid and invalid
33+
@Update(include = {"name"}, exclude = {"bonus"})
34+
int updateWithMixedOptions(Department department);
35+
36+
// sqlFile = true should ignore include/exclude
37+
@Update(sqlFile = true, include = {"invalidField"})
38+
int updateWithSqlFile(Department department);
39+
40+
// BatchUpdate with invalid include
41+
@BatchUpdate(include = {"email"})
42+
int batchUpdateWithInvalidInclude(List<Department> departments);
43+
44+
// BatchUpdate with valid exclude
45+
@BatchUpdate(exclude = {"id", "managerCount"})
46+
int batchUpdateWithValidExclude(List<Department> departments);
47+
48+
// Non-entity parameter - no validation
49+
@Update(include = {"name"})
50+
int updateNonEntity(String name);
51+
52+
// End Embedded Property - should show error for Embeddable type needing property specification
53+
@Update(include = {"embeddableEntity"})
54+
int updateEmbedded(Department department);
55+
56+
// Valid Embedded Property specification
57+
@Update(include = {"embeddableEntity.age", "embeddableEntity.id"})
58+
int updateEmbeddedWithProperties(Department department);
59+
60+
// Valid returning options
61+
@Update(returning = @Returning(include = {"embeddableEntity.name"}))
62+
Department updateReturning(Department department);
63+
64+
@Insert(returning = @Returning(exclude = {"embeddableEntity.id"}))
65+
Department insertReturning(Department department);
66+
67+
@MultiInsert(returning = @Returning(include = {"embeddableEntity.name"},exclude = {"embeddableEntity.id"}))
68+
List<Department> multiInsertReturning(List<Department> departments);
69+
70+
// InValid returning options
71+
@Update(returning = @Returning(include = {"embeddableEntity.age"}))
72+
Department updateReturning(Department department);
73+
74+
@Insert(returning = @Returning(exclude = {"embeddableEntity"}))
75+
Department insertReturning(Department department);
76+
77+
@MultiInsert(returning = @Returning(include = {"email"},
78+
exclude = {"embeddableEntity.salary"}))
79+
List<Department> multiInsertReturning(List<Department> departments);
80+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package doma.example.dao.inspection.option;
2+
3+
import doma.example.entity.*;
4+
import org.seasar.doma.*;
5+
import java.util.List;
6+
7+
/**
8+
* When using this test data with [LightJavaCodeInsightFixtureTestCase],
9+
* the highlighted elements are not parsed correctly, resulting in errors.
10+
* Compare the highlights in this test data with the actual highlights in IDEA,
11+
* and visually confirm that the highlights and errors occur as expected based on the test data.
12+
*/
13+
@Dao
14+
public interface AnnotationOptionTestDao {
15+
16+
// Valid include option
17+
@Insert(include = {"name", "location"})
18+
int insertWithValidInclude(Department department);
19+
20+
// Invalid include option
21+
@Update(include = {"name", <error descr="Field [invalidField] specified in [include] option does not exist in \"Department\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"invalidField"</error>})
22+
int updateWithInvalidInclude(Department department);
23+
24+
// Valid exclude option
25+
@Update(exclude = {"managerCount"})
26+
int updateWithValidExclude(Department department);
27+
28+
// Invalid exclude option
29+
@Insert(exclude = {<error descr="Field [salary] specified in [exclude] option does not exist in \"Department\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"salary"</error>, "location"})
30+
int insertWithInvalidExclude(Department department);
31+
32+
// Mixed valid and invalid
33+
@Update(include = {"name"}, exclude = {<error descr="Field [bonus] specified in [exclude] option does not exist in \"Department\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"bonus"</error>})
34+
int updateWithMixedOptions(Department department);
35+
36+
// sqlFile = true should ignore include/exclude
37+
@Update(sqlFile = true, include = {"invalidField"})
38+
int updateWithSqlFile(Department department);
39+
40+
// BatchUpdate with invalid include
41+
@BatchUpdate(include = {<error descr="Field [email] specified in [include] option does not exist in \"Department\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2]">"email"</error>})
42+
int[] batchUpdateWithInvalidInclude(List<Department> departments);
43+
44+
// BatchUpdate with valid exclude
45+
@BatchInsert(exclude = {"id", "managerCount"})
46+
int[] batchInsertWithValidExclude(List<Department> departments);
47+
48+
// Non-entity parameter - no validation
49+
@Update(include = {"name"})
50+
int updateNonEntity(String name);
51+
52+
// End Embedded Property - should show error for Embeddable type needing property specification
53+
@Update(include = {<error descr="Field [embeddableEntity specified in [include] option is an Embeddable type \"ClientUser\". Must specify its properties. Available properties: [id, name, number]">"embeddableEntity"</error>})
54+
int updateEmbedded(Department department);
55+
56+
// Valid Embedded Property specification
57+
@Insert(include = {<error descr="Field [age] specified in [include] option does not exist in \"EmbeddableEntity\". Available fields: [id, name, number, childEmbedded, childEmbedded2]">"embeddableEntity.age"</error>, "embeddableEntity.id"})
58+
int insertEmbeddedWithProperties(Department department);
59+
60+
// Valid returning options
61+
@Update(returning = @Returning(include = {"embeddableEntity.name"}))
62+
Department updateReturning(Department department);
63+
64+
@Insert(returning = @Returning(exclude = {"embeddableEntity.id"}))
65+
Department insertReturning(Department department);
66+
67+
@MultiInsert(returning = @Returning(include = {"embeddableEntity.name"},exclude = {"embeddableEntity.id"}))
68+
List<Department> multiInsertReturning(List<Department> departments);
69+
70+
// InValid returning options
71+
@Update(returning = @Returning(include = {<error descr="Field [age] specified in [include] option does not exist in \"ClientUser\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"embeddableEntity.age"</error>}))
72+
Department updateReturning(Department department);
73+
74+
@Insert(returning = @Returning(exclude = {<error descr="Field [embeddableEntity] specified in [exclude] option is an Embeddable type \"ClientUser\". Must specify its properties. Available properties: [id, name, number]">"embeddableEntity"</error>}))
75+
Department insertReturning(Department department);
76+
77+
@MultiInsert(returning = @Returning(include = {<error descr="Field [email] specified in [include] option does not exist in \"Department\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"email"},
78+
exclude = {<error descr="Field [salary] specified in [exclude] option does not exist in \"ClientUser\". Available fields: [id, name, location, managerCount, embeddableEntity, embeddableEntity2] ">"embeddableEntity.salary"</error>}))
79+
List<Department> multiInsertReturning(List<Department> departments);
80+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package doma.example.domain;
2+
3+
import org.seasar.doma.Column;
4+
import org.seasar.doma.Embeddable;
5+
6+
@Embeddable
7+
public class ClientUser {
8+
9+
final Integer id;
10+
final String name;
11+
12+
@Column(name = "nmb")
13+
final Integer number;
14+
15+
final ClientUser childEmbedded;
16+
final ClientUser childEmbedded2;
17+
18+
public ClientUser(Integer id, String name, Integer number, ClientUser childEmbedded, ClientUser childEmbedded2) {
19+
this.id = id;
20+
this.name = name;
21+
this.number = number;
22+
this.childEmbedded = childEmbedded;
23+
this.childEmbedded2 = childEmbedded2;
24+
}
25+
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package doma.example.entity;
22

3-
import org.seasar.doma.Entity;
3+
import org.seasar.doma.*;
4+
import doma.example.domain.*;
45

56
@Entity
67
public class Department {
78
public Integer id;
89
public String name;
10+
@Column(updatable = false)
911
public String location;
1012
public Integer managerCount;
13+
14+
@Embedded
15+
public ClientUser embeddableEntity;
16+
@Embedded
17+
public ClientUser embeddableEntity2;
1118
}

0 commit comments

Comments
 (0)