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