Skip to content

Commit 00b369b

Browse files
committed
feature: 扩展查询JAVA API,用于支持不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
1 parent 31602b0 commit 00b369b

File tree

8 files changed

+486
-1
lines changed

8 files changed

+486
-1
lines changed

src/main/java/com/github/myoss/phoenix/mybatis/mapper/template/CrudMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.github.myoss.phoenix.mybatis.mapper.annotation.RegisterMapper;
2121
import com.github.myoss.phoenix.mybatis.mapper.template.delete.DeleteMapper;
2222
import com.github.myoss.phoenix.mybatis.mapper.template.insert.CreateMapper;
23+
import com.github.myoss.phoenix.mybatis.mapper.template.select.RetrieveIncludeLogicDeleteMapper;
2324
import com.github.myoss.phoenix.mybatis.mapper.template.select.RetrieveMapper;
2425
import com.github.myoss.phoenix.mybatis.mapper.template.update.UpdateMapper;
2526

@@ -30,5 +31,6 @@
3031
* @since 2018年4月29日 下午4:58:48
3132
*/
3233
@RegisterMapper
33-
public interface CrudMapper<T> extends CreateMapper<T>, RetrieveMapper<T>, UpdateMapper<T>, DeleteMapper<T> {
34+
public interface CrudMapper<T> extends CreateMapper<T>, RetrieveMapper<T>, RetrieveIncludeLogicDeleteMapper<T>,
35+
UpdateMapper<T>, DeleteMapper<T> {
3436
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2018-2018 https://github.com/myoss
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+
* http://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+
*/
17+
18+
package com.github.myoss.phoenix.mybatis.mapper.template.select;
19+
20+
import com.github.myoss.phoenix.mybatis.mapper.annotation.RegisterMapper;
21+
import com.github.myoss.phoenix.mybatis.table.annotation.Column;
22+
23+
/**
24+
* 读取(Retrieve)操作,通用 Mapper 接口,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
25+
*
26+
* @author Jerry.Chen
27+
* @since 2018年4月29日 下午5:14:41
28+
*/
29+
@RegisterMapper
30+
public interface RetrieveIncludeLogicDeleteMapper<T> extends SelectOneIncludeLogicDeleteMapper<T>,
31+
SelectListIncludeLogicDeleteMapper<T>, SelectCountIncludeLogicDeleteMapper<T>,
32+
SelectPageIncludeLogicDeleteMapper<T>, SelectByPrimaryKeyIncludeLogicDeleteMapper<T> {
33+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2018-2018 https://github.com/myoss
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+
* http://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+
*/
17+
18+
package com.github.myoss.phoenix.mybatis.mapper.template.select;
19+
20+
import java.io.Serializable;
21+
22+
import org.apache.ibatis.annotations.SelectProvider;
23+
24+
import com.github.myoss.phoenix.mybatis.mapper.annotation.RegisterMapper;
25+
import com.github.myoss.phoenix.mybatis.mapper.template.select.impl.SelectIncludeLogicDeleteMapperTemplate;
26+
import com.github.myoss.phoenix.mybatis.table.annotation.Column;
27+
28+
/**
29+
* 查询记录通用 Mapper 接口,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
30+
*
31+
* @author Jerry.Chen
32+
* @since 2018年6月11日 下午11:02:45
33+
*/
34+
@RegisterMapper
35+
public interface SelectByPrimaryKeyIncludeLogicDeleteMapper<T> {
36+
/**
37+
* 根据主键id查询实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
38+
*
39+
* @param id 主键id
40+
* @return 对应的实体对象
41+
* @see SelectIncludeLogicDeleteMapperTemplate#selectByPrimaryKeyIncludeLogicDelete
42+
*/
43+
@SelectProvider(type = SelectIncludeLogicDeleteMapperTemplate.class, method = "dynamicSql")
44+
T selectByPrimaryKeyIncludeLogicDelete(Serializable id);
45+
46+
/**
47+
* 根据主键字段查询实体对象,可以支持多主键字段的表,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
48+
*
49+
* @param condition 匹配的条件,主键有值的实体对象
50+
* @return 对应的实体对象
51+
* @see SelectIncludeLogicDeleteMapperTemplate#selectWithPrimaryKeyIncludeLogicDelete
52+
*/
53+
@SelectProvider(type = SelectIncludeLogicDeleteMapperTemplate.class, method = "dynamicSql")
54+
T selectWithPrimaryKeyIncludeLogicDelete(T condition);
55+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2018-2018 https://github.com/myoss
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+
* http://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+
*/
17+
18+
package com.github.myoss.phoenix.mybatis.mapper.template.select;
19+
20+
import java.util.Map;
21+
22+
import org.apache.ibatis.annotations.Param;
23+
import org.apache.ibatis.annotations.SelectProvider;
24+
25+
import com.github.myoss.phoenix.mybatis.mapper.annotation.RegisterMapper;
26+
import com.github.myoss.phoenix.mybatis.mapper.template.select.impl.SelectIncludeLogicDeleteMapperTemplate;
27+
import com.github.myoss.phoenix.mybatis.table.annotation.Column;
28+
29+
/**
30+
* 查询记录通用 Mapper 接口,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
31+
*
32+
* @author Jerry.Chen
33+
* @since 2018年6月11日 下午10:54:56
34+
*/
35+
@RegisterMapper
36+
public interface SelectCountIncludeLogicDeleteMapper<T> {
37+
/**
38+
* 根据条件查询匹配的实体对象总记录数,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
39+
*
40+
* @param condition 匹配的条件
41+
* @return 匹配的实体对象
42+
* @see SelectIncludeLogicDeleteMapperTemplate#selectCountIncludeLogicDelete
43+
*/
44+
@SelectProvider(type = SelectIncludeLogicDeleteMapperTemplate.class, method = "dynamicSql")
45+
int selectCountIncludeLogicDelete(T condition);
46+
47+
/**
48+
* 根据条件查询匹配的实体对象总记录数,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
49+
*
50+
* @param condition 匹配的条件
51+
* @param extraCondition 扩展可选查询条件,需要自定义
52+
* @return 匹配的实体对象
53+
* @see SelectIncludeLogicDeleteMapperTemplate#selectCountIncludeLogicDelete2
54+
*/
55+
@SelectProvider(type = SelectIncludeLogicDeleteMapperTemplate.class, method = "dynamicSql")
56+
int selectCountIncludeLogicDelete2(@Param("condition") T condition,
57+
@Param("extraCondition") Map<String, Object> extraCondition);
58+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2018-2018 https://github.com/myoss
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+
* http://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+
*/
17+
18+
package com.github.myoss.phoenix.mybatis.mapper.template.select;
19+
20+
import org.apache.ibatis.annotations.SelectProvider;
21+
22+
import com.github.myoss.phoenix.mybatis.mapper.annotation.RegisterMapper;
23+
import com.github.myoss.phoenix.mybatis.mapper.template.select.impl.SelectIncludeLogicDeleteMapperTemplate;
24+
import com.github.myoss.phoenix.mybatis.table.annotation.Column;
25+
26+
/**
27+
* 查询记录通用 Mapper 接口,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
28+
*
29+
* @author Jerry.Chen
30+
* @since 2018年6月11日 下午11:01:23
31+
*/
32+
@RegisterMapper
33+
public interface SelectOneIncludeLogicDeleteMapper<T> {
34+
/**
35+
* 根据条件查询匹配的实体对象,只能有一条查询结果记录,有多条查询结果则会抛出异常,不会过滤掉已经被标记为逻辑删除(
36+
* {@link Column#logicDelete})的数据
37+
*
38+
* @param condition 匹配的条件
39+
* @return 匹配的实体对象
40+
* @see SelectIncludeLogicDeleteMapperTemplate#selectOneIncludeLogicDelete
41+
*/
42+
@SelectProvider(type = SelectIncludeLogicDeleteMapperTemplate.class, method = "dynamicSql")
43+
T selectOneIncludeLogicDelete(T condition);
44+
}

src/main/java/com/github/myoss/phoenix/mybatis/mapper/template/select/impl/SelectIncludeLogicDeleteMapperTemplate.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.github.myoss.phoenix.mybatis.mapper.template.select.impl;
1919

20+
import java.io.Serializable;
2021
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.Map;
@@ -31,7 +32,10 @@
3132
import org.apache.ibatis.session.Configuration;
3233

3334
import com.github.myoss.phoenix.mybatis.mapper.template.AbstractMapperTemplate;
35+
import com.github.myoss.phoenix.mybatis.mapper.template.select.SelectByPrimaryKeyIncludeLogicDeleteMapper;
36+
import com.github.myoss.phoenix.mybatis.mapper.template.select.SelectCountIncludeLogicDeleteMapper;
3437
import com.github.myoss.phoenix.mybatis.mapper.template.select.SelectListIncludeLogicDeleteMapper;
38+
import com.github.myoss.phoenix.mybatis.mapper.template.select.SelectOneIncludeLogicDeleteMapper;
3539
import com.github.myoss.phoenix.mybatis.mapper.template.select.SelectPageIncludeLogicDeleteMapper;
3640
import com.github.myoss.phoenix.mybatis.table.TableInfo;
3741
import com.github.myoss.phoenix.mybatis.table.TableMetaObject;
@@ -62,6 +66,7 @@ public class SelectIncludeLogicDeleteMapperTemplate extends AbstractMapperTempla
6266
* @param tableInfo 数据库表结构信息
6367
* @param ms sql语句节点信息,会将生成的sql语句替换掉原有的 {@link MappedStatement#sqlSource}
6468
* @return 生成的sql语句
69+
* @see SelectOneIncludeLogicDeleteMapper#selectOneIncludeLogicDelete(Object)
6570
*/
6671
public String selectOneIncludeLogicDelete(TableInfo tableInfo, MappedStatement ms) {
6772
MetaObject metaObject = SystemMetaObject.forObject(ms);
@@ -125,6 +130,7 @@ public String selectListIncludeLogicDelete(TableInfo tableInfo, MappedStatement
125130
* @param tableInfo 数据库表结构信息
126131
* @param ms sql语句节点信息,会将生成的sql语句替换掉原有的 {@link MappedStatement#sqlSource}
127132
* @return 生成的sql语句
133+
* @see SelectCountIncludeLogicDeleteMapper#selectCountIncludeLogicDelete(Object)
128134
*/
129135
public String selectCountIncludeLogicDelete(TableInfo tableInfo, MappedStatement ms) {
130136
MetaObject metaObject = SystemMetaObject.forObject(ms);
@@ -165,6 +171,8 @@ public String selectCountIncludeLogicDelete(TableInfo tableInfo, MappedStatement
165171
* @param tableInfo 数据库表结构信息
166172
* @param ms sql语句节点信息,会将生成的sql语句替换掉原有的 {@link MappedStatement#sqlSource}
167173
* @return 生成的sql语句
174+
* @see SelectCountIncludeLogicDeleteMapper#selectCountIncludeLogicDelete2(Object,
175+
* Map)
168176
*/
169177
public String selectCountIncludeLogicDelete2(TableInfo tableInfo, MappedStatement ms) {
170178
MetaObject metaObject = SystemMetaObject.forObject(ms);
@@ -322,6 +330,7 @@ public String selectPageIncludeLogicDelete2(TableInfo tableInfo, MappedStatement
322330
* @param tableInfo 数据库表结构信息
323331
* @param ms sql语句节点信息,会将生成的sql语句替换掉原有的 {@link MappedStatement#sqlSource}
324332
* @return 生成的sql语句
333+
* @see SelectByPrimaryKeyIncludeLogicDeleteMapper#selectByPrimaryKeyIncludeLogicDelete(Serializable)
325334
*/
326335
public String selectByPrimaryKeyIncludeLogicDelete(TableInfo tableInfo, MappedStatement ms) {
327336
MetaObject metaObject = SystemMetaObject.forObject(ms);
@@ -360,6 +369,7 @@ public String selectByPrimaryKeyIncludeLogicDelete(TableInfo tableInfo, MappedSt
360369
* @param tableInfo 数据库表结构信息
361370
* @param ms sql语句节点信息,会将生成的sql语句替换掉原有的 {@link MappedStatement#sqlSource}
362371
* @return 生成的sql语句
372+
* @see SelectByPrimaryKeyIncludeLogicDeleteMapper#selectWithPrimaryKeyIncludeLogicDelete(Object)
363373
*/
364374
public String selectWithPrimaryKeyIncludeLogicDelete(TableInfo tableInfo, MappedStatement ms) {
365375
return selectByPrimaryKeyIncludeLogicDelete(tableInfo, ms);
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2018-2018 https://github.com/myoss
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+
* http://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+
*/
17+
18+
package com.github.myoss.phoenix.mybatis.repository.service;
19+
20+
import java.io.Serializable;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import com.github.myoss.phoenix.core.lang.dto.Page;
25+
import com.github.myoss.phoenix.core.lang.dto.Result;
26+
import com.github.myoss.phoenix.mybatis.table.annotation.Column;
27+
28+
/**
29+
* 封装数据库查询常用操作,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
30+
*
31+
* @author Jerry.Chen
32+
* @since 2018年6月12日 上午12:10:29
33+
*/
34+
public interface RetrieveIncludeLogicDeleteService<T> {
35+
/**
36+
* 根据主键查询实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
37+
*
38+
* @param id 主键
39+
* @return 对应的实体对象
40+
*/
41+
Result<T> findByPrimaryKeyIncludeLogicDelete(Serializable id);
42+
43+
/**
44+
* 根据主键查询实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
45+
*
46+
* @param condition 匹配的条件,主键有值的实体对象
47+
* @return 对应的实体对象
48+
*/
49+
Result<T> findByPrimaryKeyIncludeLogicDelete(T condition);
50+
51+
/**
52+
* 根据条件查询匹配的实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
53+
*
54+
* @param condition 匹配的条件
55+
* @return 匹配的实体对象
56+
*/
57+
Result<T> findOneIncludeLogicDelete(T condition);
58+
59+
/**
60+
* 根据条件查询匹配的实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
61+
*
62+
* @param condition 匹配的条件
63+
* @return 匹配的实体对象
64+
*/
65+
Result<List<T>> findListIncludeLogicDelete(T condition);
66+
67+
/**
68+
* 根据条件查询匹配的实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据,并支持字段排序
69+
*
70+
* @param condition 匹配的条件和排序字段
71+
* @return 匹配的实体对象
72+
*/
73+
Result<List<T>> findListWithSortIncludeLogicDelete(Page<T> condition);
74+
75+
/**
76+
* 根据条件查询匹配的实体对象总记录数,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
77+
*
78+
* @param condition 匹配的条件
79+
* @return 匹配的实体对象总记录数
80+
*/
81+
Result<Integer> findCountIncludeLogicDelete(T condition);
82+
83+
/**
84+
* 根据条件查询匹配的实体对象总记录数,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据
85+
*
86+
* @param condition 匹配的条件
87+
* @param extraCondition 扩展查询条件,需要自定义
88+
* @return 匹配的实体对象总记录数
89+
*/
90+
Result<Integer> findCountIncludeLogicDelete(T condition, Map<String, Object> extraCondition);
91+
92+
/**
93+
* 根据条件查询匹配的实体对象,不会过滤掉已经被标记为逻辑删除({@link Column#logicDelete})的数据,并进行分页
94+
*
95+
* @param condition 匹配的条件
96+
* @return 匹配的实体对象
97+
*/
98+
Page<T> findPageIncludeLogicDelete(Page<T> condition);
99+
}

0 commit comments

Comments
 (0)