View Javadoc
1   /*
2    * Copyright 2012-2025 CodeLibs Project and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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.BoostDocumentRuleDbm;
24  import org.codelibs.fess.opensearch.config.cbean.BoostDocumentRuleCB;
25  import org.codelibs.fess.opensearch.config.exentity.BoostDocumentRule;
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   * @author ESFlute (using FreeGen)
41   */
42  public abstract class BsBoostDocumentRuleBhv extends EsAbstractBehavior<BoostDocumentRule, BoostDocumentRuleCB> {
43  
44      // ===================================================================================
45      //                                                                    Control Override
46      //                                                                    ================
47      @Override
48      public String asTableDbName() {
49          return asEsIndexType();
50      }
51  
52      @Override
53      protected String asEsIndex() {
54          return "fess_config.boost_document_rule";
55      }
56  
57      @Override
58      public String asEsIndexType() {
59          return "boost_document_rule";
60      }
61  
62      @Override
63      public String asEsSearchType() {
64          return "boost_document_rule";
65      }
66  
67      @Override
68      public BoostDocumentRuleDbm asDBMeta() {
69          return BoostDocumentRuleDbm.getInstance();
70      }
71  
72      @Override
73      protected <RESULT extends BoostDocumentRule> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
74          try {
75              final RESULT result = entityType.newInstance();
76              result.setBoostExpr(DfTypeUtil.toString(source.get("boostExpr")));
77              result.setCreatedBy(DfTypeUtil.toString(source.get("createdBy")));
78              result.setCreatedTime(DfTypeUtil.toLong(source.get("createdTime")));
79              result.setSortOrder(DfTypeUtil.toInteger(source.get("sortOrder")));
80              result.setUpdatedBy(DfTypeUtil.toString(source.get("updatedBy")));
81              result.setUpdatedTime(DfTypeUtil.toLong(source.get("updatedTime")));
82              result.setUrlExpr(DfTypeUtil.toString(source.get("urlExpr")));
83              return updateEntity(source, result);
84          } catch (InstantiationException | IllegalAccessException e) {
85              final String msg = "Cannot create a new instance: " + entityType.getName();
86              throw new IllegalBehaviorStateException(msg, e);
87          }
88      }
89  
90      protected <RESULT extends BoostDocumentRule> RESULT updateEntity(Map<String, Object> source, RESULT result) {
91          return result;
92      }
93  
94      // ===================================================================================
95      //                                                                              Select
96      //                                                                              ======
97      public int selectCount(CBCall<BoostDocumentRuleCB> cbLambda) {
98          return facadeSelectCount(createCB(cbLambda));
99      }
100 
101     public OptionalEntity<BoostDocumentRule> selectEntity(CBCall<BoostDocumentRuleCB> cbLambda) {
102         return facadeSelectEntity(createCB(cbLambda));
103     }
104 
105     protected OptionalEntity<BoostDocumentRule> facadeSelectEntity(BoostDocumentRuleCB cb) {
106         return doSelectOptionalEntity(cb, typeOfSelectedEntity());
107     }
108 
109     protected <ENTITY extends BoostDocumentRule> OptionalEntity<ENTITY> doSelectOptionalEntity(BoostDocumentRuleCB cb,
110             Class<? extends ENTITY> tp) {
111         return createOptionalEntity(doSelectEntity(cb, tp), cb);
112     }
113 
114     @Override
115     public BoostDocumentRuleCB newConditionBean() {
116         return new BoostDocumentRuleCB();
117     }
118 
119     @Override
120     protected Entity doReadEntity(ConditionBean cb) {
121         return facadeSelectEntity(downcast(cb)).orElse(null);
122     }
123 
124     public BoostDocumentRule selectEntityWithDeletedCheck(CBCall<BoostDocumentRuleCB> cbLambda) {
125         return facadeSelectEntityWithDeletedCheck(createCB(cbLambda));
126     }
127 
128     public OptionalEntity<BoostDocumentRule> selectByPK(String id) {
129         return facadeSelectByPK(id);
130     }
131 
132     protected OptionalEntity<BoostDocumentRule> facadeSelectByPK(String id) {
133         return doSelectOptionalByPK(id, typeOfSelectedEntity());
134     }
135 
136     protected <ENTITY extends BoostDocumentRule> ENTITY doSelectByPK(String id, Class<? extends ENTITY> tp) {
137         return doSelectEntity(xprepareCBAsPK(id), tp);
138     }
139 
140     protected BoostDocumentRuleCB xprepareCBAsPK(String id) {
141         assertObjectNotNull("id", id);
142         return newConditionBean().acceptPK(id);
143     }
144 
145     protected <ENTITY extends BoostDocumentRule> OptionalEntity<ENTITY> doSelectOptionalByPK(String id, Class<? extends ENTITY> tp) {
146         return createOptionalEntity(doSelectByPK(id, tp), id);
147     }
148 
149     @Override
150     protected Class<? extends BoostDocumentRule> typeOfSelectedEntity() {
151         return BoostDocumentRule.class;
152     }
153 
154     @Override
155     protected Class<BoostDocumentRule> typeOfHandlingEntity() {
156         return BoostDocumentRule.class;
157     }
158 
159     @Override
160     protected Class<BoostDocumentRuleCB> typeOfHandlingConditionBean() {
161         return BoostDocumentRuleCB.class;
162     }
163 
164     public ListResultBean<BoostDocumentRule> selectList(CBCall<BoostDocumentRuleCB> cbLambda) {
165         return facadeSelectList(createCB(cbLambda));
166     }
167 
168     public PagingResultBean<BoostDocumentRule> selectPage(CBCall<BoostDocumentRuleCB> cbLambda) {
169         // #pending same?
170         return (PagingResultBean<BoostDocumentRule>) facadeSelectList(createCB(cbLambda));
171     }
172 
173     public void selectCursor(CBCall<BoostDocumentRuleCB> cbLambda, EntityRowHandler<BoostDocumentRule> entityLambda) {
174         facadeSelectCursor(createCB(cbLambda), entityLambda);
175     }
176 
177     public void selectBulk(CBCall<BoostDocumentRuleCB> cbLambda, EntityRowHandler<List<BoostDocumentRule>> entityLambda) {
178         delegateSelectBulk(createCB(cbLambda), entityLambda, typeOfSelectedEntity());
179     }
180 
181     // ===================================================================================
182     //                                                                              Update
183     //                                                                              ======
184     public void insert(BoostDocumentRule entity) {
185         doInsert(entity, null);
186     }
187 
188     public void insert(BoostDocumentRule entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
189         entity.asDocMeta().indexOption(opLambda);
190         doInsert(entity, null);
191     }
192 
193     public void update(BoostDocumentRule entity) {
194         doUpdate(entity, null);
195     }
196 
197     public void update(BoostDocumentRule entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
198         entity.asDocMeta().indexOption(opLambda);
199         doUpdate(entity, null);
200     }
201 
202     public void insertOrUpdate(BoostDocumentRule entity) {
203         doInsertOrUpdate(entity, null, null);
204     }
205 
206     public void insertOrUpdate(BoostDocumentRule entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
207         entity.asDocMeta().indexOption(opLambda);
208         doInsertOrUpdate(entity, null, null);
209     }
210 
211     public void delete(BoostDocumentRule entity) {
212         doDelete(entity, null);
213     }
214 
215     public void delete(BoostDocumentRule entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
216         entity.asDocMeta().deleteOption(opLambda);
217         doDelete(entity, null);
218     }
219 
220     public int queryDelete(CBCall<BoostDocumentRuleCB> cbLambda) {
221         return doQueryDelete(createCB(cbLambda), null);
222     }
223 
224     public int[] batchInsert(List<BoostDocumentRule> list) {
225         return batchInsert(list, null, null);
226     }
227 
228     public int[] batchInsert(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call) {
229         return batchInsert(list, call, null);
230     }
231 
232     public int[] batchInsert(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call,
233             RequestOptionCall<IndexRequestBuilder> entityCall) {
234         return doBatchInsert(new BulkList<>(list, call, entityCall), null);
235     }
236 
237     public int[] batchUpdate(List<BoostDocumentRule> list) {
238         return batchUpdate(list, null, null);
239     }
240 
241     public int[] batchUpdate(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call) {
242         return batchUpdate(list, call, null);
243     }
244 
245     public int[] batchUpdate(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call,
246             RequestOptionCall<IndexRequestBuilder> entityCall) {
247         return doBatchUpdate(new BulkList<>(list, call, entityCall), null);
248     }
249 
250     public int[] batchDelete(List<BoostDocumentRule> list) {
251         return batchDelete(list, null, null);
252     }
253 
254     public int[] batchDelete(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call) {
255         return batchDelete(list, call, null);
256     }
257 
258     public int[] batchDelete(List<BoostDocumentRule> list, RequestOptionCall<BulkRequestBuilder> call,
259             RequestOptionCall<IndexRequestBuilder> entityCall) {
260         return doBatchDelete(new BulkList<>(list, call, entityCall), null);
261     }
262 
263     // #pending create, modify, remove
264 }