Skip to content

Commit 39935c1

Browse files
committed
Add test code
1 parent 8fc3c6a commit 39935c1

File tree

10 files changed

+405
-80
lines changed

10 files changed

+405
-80
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Doma Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.seasar.doma.it.dao;
17+
18+
import org.seasar.doma.Dao;
19+
import org.seasar.doma.Delete;
20+
import org.seasar.doma.Returning;
21+
import org.seasar.doma.Select;
22+
import org.seasar.doma.Sql;
23+
import org.seasar.doma.it.entity.Employee;
24+
25+
@Dao
26+
public interface DeleteReturningDao {
27+
28+
@Sql("select * from EMPLOYEE where EMPLOYEE_ID = /* id */0")
29+
@Select
30+
Employee selectById(Integer id);
31+
32+
@Delete(returning = @Returning)
33+
Employee deleteThenReturnAll(Employee employee);
34+
35+
@Delete(returning = @Returning(include = "employeeId"))
36+
Employee deleteThenReturnOnlyId(Employee employee);
37+
38+
@Delete(returning = @Returning(exclude = "version"))
39+
Employee deleteThenReturnExceptVersion(Employee employee);
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Doma Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.seasar.doma.it.dao;
17+
18+
import org.seasar.doma.Dao;
19+
import org.seasar.doma.Insert;
20+
import org.seasar.doma.Returning;
21+
import org.seasar.doma.it.entity.IdentityStrategy;
22+
23+
@Dao
24+
public interface InsertReturningDao {
25+
26+
@Insert(returning = @Returning)
27+
IdentityStrategy insertThenReturnAll(IdentityStrategy identityStrategy);
28+
29+
@Insert(returning = @Returning(include = "id"))
30+
IdentityStrategy insertThenReturnOnlyId(IdentityStrategy identityStrategy);
31+
32+
@Insert(returning = @Returning(exclude = "value"))
33+
IdentityStrategy insertThenReturnExceptValue(IdentityStrategy identityStrategy);
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Doma Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.seasar.doma.it.dao;
17+
18+
import java.util.List;
19+
import org.seasar.doma.Dao;
20+
import org.seasar.doma.MultiInsert;
21+
import org.seasar.doma.Returning;
22+
import org.seasar.doma.it.entity.Address;
23+
24+
@Dao
25+
public interface MultiInsertReturningDao {
26+
27+
@MultiInsert(returning = @Returning)
28+
List<Address> insertThenReturnAll(List<Address> addresses);
29+
30+
@MultiInsert(returning = @Returning(include = "addressId"))
31+
List<Address> insertThenReturnOnlyId(List<Address> addresses);
32+
33+
@MultiInsert(returning = @Returning(exclude = "version"))
34+
List<Address> insertThenReturnExceptVersion(List<Address> addresses);
35+
}

integration-test-java/src/main/java/org/seasar/doma/it/dao/ReturningDao.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright Doma Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.seasar.doma.it.dao;
17+
18+
import org.seasar.doma.Dao;
19+
import org.seasar.doma.Returning;
20+
import org.seasar.doma.Select;
21+
import org.seasar.doma.Sql;
22+
import org.seasar.doma.Update;
23+
import org.seasar.doma.it.entity.Employee;
24+
import org.seasar.doma.it.entity.Staff;
25+
26+
@Dao
27+
public interface UpdateReturningDao {
28+
29+
@Sql("select * from EMPLOYEE where EMPLOYEE_ID = /* id */0")
30+
@Select
31+
Employee selectById(Integer id);
32+
33+
@Update(returning = @Returning)
34+
Employee updateThenReturnAll(Employee employee);
35+
36+
@Update(returning = @Returning(include = "employeeId"))
37+
Employee updateThenReturnOnlyId(Employee employee);
38+
39+
@Update(returning = @Returning(exclude = "version"))
40+
Employee updateThenReturnExceptVersion(Employee employee);
41+
42+
@Sql("select * from EMPLOYEE where EMPLOYEE_ID = /* id */0")
43+
@Select
44+
Staff selectStaffById(Integer id);
45+
46+
@Update(returning = @Returning(include = {"staffInfo.managerId", "staffInfo.salary"}))
47+
Staff updateStaffThenReturnManagerAndSalary(Staff staff);
48+
49+
@Update(returning = @Returning(exclude = "staffInfo.salary"))
50+
Staff updateStaffThenReturnExceptSalary(Staff staff);
51+
}

integration-test-java/src/main/java/org/seasar/doma/it/entity/Address.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
import org.seasar.doma.Entity;
1919
import org.seasar.doma.Id;
20+
import org.seasar.doma.Version;
2021
import org.seasar.doma.it.criteria.Street;
2122

2223
@Entity
2324
public class Address {
2425

2526
@Id private Integer addressId;
2627
private Street street;
27-
private Integer version;
28+
@Version private Integer version;
2829

2930
public Integer getAddressId() {
3031
return addressId;

integration-test-java/src/test/java/org/seasar/doma/it/auto/AutoDeleteTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
import java.util.OptionalInt;
2424
import org.junit.jupiter.api.Test;
2525
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.seasar.doma.it.Dbms;
2627
import org.seasar.doma.it.IntegrationTestEnvironment;
28+
import org.seasar.doma.it.Run;
2729
import org.seasar.doma.it.dao.BusinessmanDao;
2830
import org.seasar.doma.it.dao.BusinessmanDaoImpl;
2931
import org.seasar.doma.it.dao.CompKeyEmployeeDao;
3032
import org.seasar.doma.it.dao.CompKeyEmployeeDaoImpl;
33+
import org.seasar.doma.it.dao.DeleteReturningDao;
34+
import org.seasar.doma.it.dao.DeleteReturningDaoImpl;
3135
import org.seasar.doma.it.dao.EmployeeDao;
3236
import org.seasar.doma.it.dao.EmployeeDaoImpl;
3337
import org.seasar.doma.it.dao.NoIdDao;
@@ -203,4 +207,43 @@ public void testTenantId(Config config) {
203207
salesman.departmentId = tenantId;
204208
dao.delete(salesman);
205209
}
210+
211+
@Test
212+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
213+
public void returning(Config config) {
214+
DeleteReturningDao dao = new DeleteReturningDaoImpl(config);
215+
216+
var entity = dao.selectById(1);
217+
var result = dao.deleteThenReturnAll(entity);
218+
219+
assertEquals(1, entity.getAddressId());
220+
assertEquals("SMITH", result.getEmployeeName());
221+
assertEquals(1, result.getVersion());
222+
}
223+
224+
@Test
225+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
226+
public void returning_include(Config config) {
227+
DeleteReturningDao dao = new DeleteReturningDaoImpl(config);
228+
229+
var entity = dao.selectById(1);
230+
var result = dao.deleteThenReturnOnlyId(entity);
231+
232+
assertEquals(1, entity.getAddressId());
233+
assertNull(result.getEmployeeName());
234+
assertNull(result.getVersion());
235+
}
236+
237+
@Test
238+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
239+
public void returning_exclude(Config config) {
240+
DeleteReturningDao dao = new DeleteReturningDaoImpl(config);
241+
242+
var entity = dao.selectById(1);
243+
var result = dao.deleteThenReturnExceptVersion(entity);
244+
245+
assertEquals(1, entity.getAddressId());
246+
assertEquals("SMITH", result.getEmployeeName());
247+
assertNull(result.getVersion());
248+
}
206249
}

integration-test-java/src/test/java/org/seasar/doma/it/auto/AutoInsertTest.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
import org.seasar.doma.it.dao.IdentityStrategy2DaoImpl;
5151
import org.seasar.doma.it.dao.IdentityStrategyDao;
5252
import org.seasar.doma.it.dao.IdentityStrategyDaoImpl;
53+
import org.seasar.doma.it.dao.InsertReturningDao;
54+
import org.seasar.doma.it.dao.InsertReturningDaoImpl;
5355
import org.seasar.doma.it.dao.NoIdDao;
5456
import org.seasar.doma.it.dao.NoIdDaoImpl;
5557
import org.seasar.doma.it.dao.OptionalIdentityStrategyDao;
5658
import org.seasar.doma.it.dao.OptionalIdentityStrategyDaoImpl;
5759
import org.seasar.doma.it.dao.PrimitiveIdentityStrategyDao;
5860
import org.seasar.doma.it.dao.PrimitiveIdentityStrategyDaoImpl;
59-
import org.seasar.doma.it.dao.ReturningDao;
60-
import org.seasar.doma.it.dao.ReturningDaoImpl;
6161
import org.seasar.doma.it.dao.SequenceStrategyDao;
6262
import org.seasar.doma.it.dao.SequenceStrategyDaoImpl;
6363
import org.seasar.doma.it.dao.StaffDao;
@@ -723,7 +723,41 @@ public void insert_DuplicateKeyType_UPDATE_identityTable_duplicated(Config confi
723723
}
724724

725725
@Test
726+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
726727
public void returning(Config config) {
727-
ReturningDao dao = new ReturningDaoImpl(config);
728+
InsertReturningDao dao = new InsertReturningDaoImpl(config);
729+
730+
var entity = new IdentityStrategy();
731+
entity.setValue(10);
732+
733+
var result = dao.insertThenReturnAll(entity);
734+
assertEquals(1, result.getId());
735+
assertEquals(10, result.getValue());
736+
}
737+
738+
@Test
739+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
740+
public void returning_include(Config config) {
741+
InsertReturningDao dao = new InsertReturningDaoImpl(config);
742+
743+
var entity = new IdentityStrategy();
744+
entity.setValue(10);
745+
746+
var result = dao.insertThenReturnOnlyId(entity);
747+
assertEquals(1, result.getId());
748+
assertNull(result.getValue());
749+
}
750+
751+
@Test
752+
@Run(unless = {Dbms.MYSQL, Dbms.MYSQL8, Dbms.ORACLE})
753+
public void returning_exclude(Config config) {
754+
InsertReturningDao dao = new InsertReturningDaoImpl(config);
755+
756+
var entity = new IdentityStrategy();
757+
entity.setValue(10);
758+
759+
var result = dao.insertThenReturnExceptValue(entity);
760+
assertEquals(1, result.getId());
761+
assertNull(result.getValue());
728762
}
729763
}

0 commit comments

Comments
 (0)