1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.opensearch.config.bsbhv;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.codelibs.fess.opensearch.config.allcommon.EsAbstractBehavior;
22 import org.codelibs.fess.opensearch.config.allcommon.EsAbstractEntity.RequestOptionCall;
23 import org.codelibs.fess.opensearch.config.bsentity.dbmeta.PathMappingDbm;
24 import org.codelibs.fess.opensearch.config.cbean.PathMappingCB;
25 import org.codelibs.fess.opensearch.config.exentity.PathMapping;
26 import org.dbflute.Entity;
27 import org.dbflute.bhv.readable.CBCall;
28 import org.dbflute.bhv.readable.EntityRowHandler;
29 import org.dbflute.cbean.ConditionBean;
30 import org.dbflute.cbean.result.ListResultBean;
31 import org.dbflute.cbean.result.PagingResultBean;
32 import org.dbflute.exception.IllegalBehaviorStateException;
33 import org.dbflute.optional.OptionalEntity;
34 import org.dbflute.util.DfTypeUtil;
35 import org.opensearch.action.bulk.BulkRequestBuilder;
36 import org.opensearch.action.delete.DeleteRequestBuilder;
37 import org.opensearch.action.index.IndexRequestBuilder;
38
39
40
41
42 public abstract class BsPathMappingBhv extends EsAbstractBehavior<PathMapping, PathMappingCB> {
43
44
45
46
47 @Override
48 public String asTableDbName() {
49 return asEsIndexType();
50 }
51
52 @Override
53 protected String asEsIndex() {
54 return "fess_config.path_mapping";
55 }
56
57 @Override
58 public String asEsIndexType() {
59 return "path_mapping";
60 }
61
62 @Override
63 public String asEsSearchType() {
64 return "path_mapping";
65 }
66
67 @Override
68 public PathMappingDbm asDBMeta() {
69 return PathMappingDbm.getInstance();
70 }
71
72 @Override
73 protected <RESULT extends PathMapping> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
74 try {
75 final RESULT result = entityType.newInstance();
76 result.setCreatedBy(DfTypeUtil.toString(source.get("createdBy")));
77 result.setCreatedTime(DfTypeUtil.toLong(source.get("createdTime")));
78 result.setProcessType(DfTypeUtil.toString(source.get("processType")));
79 result.setRegex(DfTypeUtil.toString(source.get("regex")));
80 result.setReplacement(DfTypeUtil.toString(source.get("replacement")));
81 result.setSortOrder(DfTypeUtil.toInteger(source.get("sortOrder")));
82 result.setUpdatedBy(DfTypeUtil.toString(source.get("updatedBy")));
83 result.setUpdatedTime(DfTypeUtil.toLong(source.get("updatedTime")));
84 result.setUserAgent(DfTypeUtil.toString(source.get("userAgent")));
85 return updateEntity(source, result);
86 } catch (InstantiationException | IllegalAccessException e) {
87 final String msg = "Cannot create a new instance: " + entityType.getName();
88 throw new IllegalBehaviorStateException(msg, e);
89 }
90 }
91
92 protected <RESULT extends PathMapping> RESULT updateEntity(Map<String, Object> source, RESULT result) {
93 return result;
94 }
95
96
97
98
99 public int selectCount(CBCall<PathMappingCB> cbLambda) {
100 return facadeSelectCount(createCB(cbLambda));
101 }
102
103 public OptionalEntity<PathMapping> selectEntity(CBCall<PathMappingCB> cbLambda) {
104 return facadeSelectEntity(createCB(cbLambda));
105 }
106
107 protected OptionalEntity<PathMapping> facadeSelectEntity(PathMappingCB cb) {
108 return doSelectOptionalEntity(cb, typeOfSelectedEntity());
109 }
110
111 protected <ENTITY extends PathMapping> OptionalEntity<ENTITY> doSelectOptionalEntity(PathMappingCB cb, Class<? extends ENTITY> tp) {
112 return createOptionalEntity(doSelectEntity(cb, tp), cb);
113 }
114
115 @Override
116 public PathMappingCB newConditionBean() {
117 return new PathMappingCB();
118 }
119
120 @Override
121 protected Entity doReadEntity(ConditionBean cb) {
122 return facadeSelectEntity(downcast(cb)).orElse(null);
123 }
124
125 public PathMapping selectEntityWithDeletedCheck(CBCall<PathMappingCB> cbLambda) {
126 return facadeSelectEntityWithDeletedCheck(createCB(cbLambda));
127 }
128
129 public OptionalEntity<PathMapping> selectByPK(String id) {
130 return facadeSelectByPK(id);
131 }
132
133 protected OptionalEntity<PathMapping> facadeSelectByPK(String id) {
134 return doSelectOptionalByPK(id, typeOfSelectedEntity());
135 }
136
137 protected <ENTITY extends PathMapping> ENTITY doSelectByPK(String id, Class<? extends ENTITY> tp) {
138 return doSelectEntity(xprepareCBAsPK(id), tp);
139 }
140
141 protected PathMappingCB xprepareCBAsPK(String id) {
142 assertObjectNotNull("id", id);
143 return newConditionBean().acceptPK(id);
144 }
145
146 protected <ENTITY extends PathMapping> OptionalEntity<ENTITY> doSelectOptionalByPK(String id, Class<? extends ENTITY> tp) {
147 return createOptionalEntity(doSelectByPK(id, tp), id);
148 }
149
150 @Override
151 protected Class<? extends PathMapping> typeOfSelectedEntity() {
152 return PathMapping.class;
153 }
154
155 @Override
156 protected Class<PathMapping> typeOfHandlingEntity() {
157 return PathMapping.class;
158 }
159
160 @Override
161 protected Class<PathMappingCB> typeOfHandlingConditionBean() {
162 return PathMappingCB.class;
163 }
164
165 public ListResultBean<PathMapping> selectList(CBCall<PathMappingCB> cbLambda) {
166 return facadeSelectList(createCB(cbLambda));
167 }
168
169 public PagingResultBean<PathMapping> selectPage(CBCall<PathMappingCB> cbLambda) {
170
171 return (PagingResultBean<PathMapping>) facadeSelectList(createCB(cbLambda));
172 }
173
174 public void selectCursor(CBCall<PathMappingCB> cbLambda, EntityRowHandler<PathMapping> entityLambda) {
175 facadeSelectCursor(createCB(cbLambda), entityLambda);
176 }
177
178 public void selectBulk(CBCall<PathMappingCB> cbLambda, EntityRowHandler<List<PathMapping>> entityLambda) {
179 delegateSelectBulk(createCB(cbLambda), entityLambda, typeOfSelectedEntity());
180 }
181
182
183
184
185 public void insert(PathMapping entity) {
186 doInsert(entity, null);
187 }
188
189 public void insert(PathMapping entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
190 entity.asDocMeta().indexOption(opLambda);
191 doInsert(entity, null);
192 }
193
194 public void update(PathMapping entity) {
195 doUpdate(entity, null);
196 }
197
198 public void update(PathMapping entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
199 entity.asDocMeta().indexOption(opLambda);
200 doUpdate(entity, null);
201 }
202
203 public void insertOrUpdate(PathMapping entity) {
204 doInsertOrUpdate(entity, null, null);
205 }
206
207 public void insertOrUpdate(PathMapping entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
208 entity.asDocMeta().indexOption(opLambda);
209 doInsertOrUpdate(entity, null, null);
210 }
211
212 public void delete(PathMapping entity) {
213 doDelete(entity, null);
214 }
215
216 public void delete(PathMapping entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
217 entity.asDocMeta().deleteOption(opLambda);
218 doDelete(entity, null);
219 }
220
221 public int queryDelete(CBCall<PathMappingCB> cbLambda) {
222 return doQueryDelete(createCB(cbLambda), null);
223 }
224
225 public int[] batchInsert(List<PathMapping> list) {
226 return batchInsert(list, null, null);
227 }
228
229 public int[] batchInsert(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call) {
230 return batchInsert(list, call, null);
231 }
232
233 public int[] batchInsert(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call,
234 RequestOptionCall<IndexRequestBuilder> entityCall) {
235 return doBatchInsert(new BulkList<>(list, call, entityCall), null);
236 }
237
238 public int[] batchUpdate(List<PathMapping> list) {
239 return batchUpdate(list, null, null);
240 }
241
242 public int[] batchUpdate(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call) {
243 return batchUpdate(list, call, null);
244 }
245
246 public int[] batchUpdate(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call,
247 RequestOptionCall<IndexRequestBuilder> entityCall) {
248 return doBatchUpdate(new BulkList<>(list, call, entityCall), null);
249 }
250
251 public int[] batchDelete(List<PathMapping> list) {
252 return batchDelete(list, null, null);
253 }
254
255 public int[] batchDelete(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call) {
256 return batchDelete(list, call, null);
257 }
258
259 public int[] batchDelete(List<PathMapping> list, RequestOptionCall<BulkRequestBuilder> call,
260 RequestOptionCall<IndexRequestBuilder> entityCall) {
261 return doBatchDelete(new BulkList<>(list, call, entityCall), null);
262 }
263
264
265 }