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