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.LabelTypeDbm;
24 import org.codelibs.fess.opensearch.config.cbean.LabelTypeCB;
25 import org.codelibs.fess.opensearch.config.exentity.LabelType;
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 BsLabelTypeBhv extends EsAbstractBehavior<LabelType, LabelTypeCB> {
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.label_type";
55 }
56
57 @Override
58 public String asEsIndexType() {
59 return "label_type";
60 }
61
62 @Override
63 public String asEsSearchType() {
64 return "label_type";
65 }
66
67 @Override
68 public LabelTypeDbm asDBMeta() {
69 return LabelTypeDbm.getInstance();
70 }
71
72 @Override
73 protected <RESULT extends LabelType> 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.setExcludedPaths(DfTypeUtil.toString(source.get("excludedPaths")));
79 result.setIncludedPaths(DfTypeUtil.toString(source.get("includedPaths")));
80 result.setName(DfTypeUtil.toString(source.get("name")));
81 result.setPermissions(toStringArray(source.get("permissions")));
82 result.setSortOrder(DfTypeUtil.toInteger(source.get("sortOrder")));
83 result.setUpdatedBy(DfTypeUtil.toString(source.get("updatedBy")));
84 result.setUpdatedTime(DfTypeUtil.toLong(source.get("updatedTime")));
85 result.setValue(DfTypeUtil.toString(source.get("value")));
86 result.setVirtualHost(DfTypeUtil.toString(source.get("virtualHost")));
87 return updateEntity(source, result);
88 } catch (InstantiationException | IllegalAccessException e) {
89 final String msg = "Cannot create a new instance: " + entityType.getName();
90 throw new IllegalBehaviorStateException(msg, e);
91 }
92 }
93
94 protected <RESULT extends LabelType> RESULT updateEntity(Map<String, Object> source, RESULT result) {
95 return result;
96 }
97
98
99
100
101 public int selectCount(CBCall<LabelTypeCB> cbLambda) {
102 return facadeSelectCount(createCB(cbLambda));
103 }
104
105 public OptionalEntity<LabelType> selectEntity(CBCall<LabelTypeCB> cbLambda) {
106 return facadeSelectEntity(createCB(cbLambda));
107 }
108
109 protected OptionalEntity<LabelType> facadeSelectEntity(LabelTypeCB cb) {
110 return doSelectOptionalEntity(cb, typeOfSelectedEntity());
111 }
112
113 protected <ENTITY extends LabelType> OptionalEntity<ENTITY> doSelectOptionalEntity(LabelTypeCB cb, Class<? extends ENTITY> tp) {
114 return createOptionalEntity(doSelectEntity(cb, tp), cb);
115 }
116
117 @Override
118 public LabelTypeCB newConditionBean() {
119 return new LabelTypeCB();
120 }
121
122 @Override
123 protected Entity doReadEntity(ConditionBean cb) {
124 return facadeSelectEntity(downcast(cb)).orElse(null);
125 }
126
127 public LabelType selectEntityWithDeletedCheck(CBCall<LabelTypeCB> cbLambda) {
128 return facadeSelectEntityWithDeletedCheck(createCB(cbLambda));
129 }
130
131 public OptionalEntity<LabelType> selectByPK(String id) {
132 return facadeSelectByPK(id);
133 }
134
135 protected OptionalEntity<LabelType> facadeSelectByPK(String id) {
136 return doSelectOptionalByPK(id, typeOfSelectedEntity());
137 }
138
139 protected <ENTITY extends LabelType> ENTITY doSelectByPK(String id, Class<? extends ENTITY> tp) {
140 return doSelectEntity(xprepareCBAsPK(id), tp);
141 }
142
143 protected LabelTypeCB xprepareCBAsPK(String id) {
144 assertObjectNotNull("id", id);
145 return newConditionBean().acceptPK(id);
146 }
147
148 protected <ENTITY extends LabelType> OptionalEntity<ENTITY> doSelectOptionalByPK(String id, Class<? extends ENTITY> tp) {
149 return createOptionalEntity(doSelectByPK(id, tp), id);
150 }
151
152 @Override
153 protected Class<? extends LabelType> typeOfSelectedEntity() {
154 return LabelType.class;
155 }
156
157 @Override
158 protected Class<LabelType> typeOfHandlingEntity() {
159 return LabelType.class;
160 }
161
162 @Override
163 protected Class<LabelTypeCB> typeOfHandlingConditionBean() {
164 return LabelTypeCB.class;
165 }
166
167 public ListResultBean<LabelType> selectList(CBCall<LabelTypeCB> cbLambda) {
168 return facadeSelectList(createCB(cbLambda));
169 }
170
171 public PagingResultBean<LabelType> selectPage(CBCall<LabelTypeCB> cbLambda) {
172
173 return (PagingResultBean<LabelType>) facadeSelectList(createCB(cbLambda));
174 }
175
176 public void selectCursor(CBCall<LabelTypeCB> cbLambda, EntityRowHandler<LabelType> entityLambda) {
177 facadeSelectCursor(createCB(cbLambda), entityLambda);
178 }
179
180 public void selectBulk(CBCall<LabelTypeCB> cbLambda, EntityRowHandler<List<LabelType>> entityLambda) {
181 delegateSelectBulk(createCB(cbLambda), entityLambda, typeOfSelectedEntity());
182 }
183
184
185
186
187 public void insert(LabelType entity) {
188 doInsert(entity, null);
189 }
190
191 public void insert(LabelType entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
192 entity.asDocMeta().indexOption(opLambda);
193 doInsert(entity, null);
194 }
195
196 public void update(LabelType entity) {
197 doUpdate(entity, null);
198 }
199
200 public void update(LabelType entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
201 entity.asDocMeta().indexOption(opLambda);
202 doUpdate(entity, null);
203 }
204
205 public void insertOrUpdate(LabelType entity) {
206 doInsertOrUpdate(entity, null, null);
207 }
208
209 public void insertOrUpdate(LabelType entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
210 entity.asDocMeta().indexOption(opLambda);
211 doInsertOrUpdate(entity, null, null);
212 }
213
214 public void delete(LabelType entity) {
215 doDelete(entity, null);
216 }
217
218 public void delete(LabelType entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
219 entity.asDocMeta().deleteOption(opLambda);
220 doDelete(entity, null);
221 }
222
223 public int queryDelete(CBCall<LabelTypeCB> cbLambda) {
224 return doQueryDelete(createCB(cbLambda), null);
225 }
226
227 public int[] batchInsert(List<LabelType> list) {
228 return batchInsert(list, null, null);
229 }
230
231 public int[] batchInsert(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call) {
232 return batchInsert(list, call, null);
233 }
234
235 public int[] batchInsert(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call,
236 RequestOptionCall<IndexRequestBuilder> entityCall) {
237 return doBatchInsert(new BulkList<>(list, call, entityCall), null);
238 }
239
240 public int[] batchUpdate(List<LabelType> list) {
241 return batchUpdate(list, null, null);
242 }
243
244 public int[] batchUpdate(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call) {
245 return batchUpdate(list, call, null);
246 }
247
248 public int[] batchUpdate(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call,
249 RequestOptionCall<IndexRequestBuilder> entityCall) {
250 return doBatchUpdate(new BulkList<>(list, call, entityCall), null);
251 }
252
253 public int[] batchDelete(List<LabelType> list) {
254 return batchDelete(list, null, null);
255 }
256
257 public int[] batchDelete(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call) {
258 return batchDelete(list, call, null);
259 }
260
261 public int[] batchDelete(List<LabelType> list, RequestOptionCall<BulkRequestBuilder> call,
262 RequestOptionCall<IndexRequestBuilder> entityCall) {
263 return doBatchDelete(new BulkList<>(list, call, entityCall), null);
264 }
265
266
267 }