View Javadoc
1   /*
2    * Copyright 2012-2021 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.es.config.bsbhv;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.codelibs.fesen.action.bulk.BulkRequestBuilder;
22  import org.codelibs.fesen.action.delete.DeleteRequestBuilder;
23  import org.codelibs.fesen.action.index.IndexRequestBuilder;
24  import org.codelibs.fess.es.config.allcommon.EsAbstractBehavior;
25  import org.codelibs.fess.es.config.allcommon.EsAbstractEntity.RequestOptionCall;
26  import org.codelibs.fess.es.config.bsentity.dbmeta.FileConfigDbm;
27  import org.codelibs.fess.es.config.cbean.FileConfigCB;
28  import org.codelibs.fess.es.config.exentity.FileConfig;
29  import org.dbflute.Entity;
30  import org.dbflute.bhv.readable.CBCall;
31  import org.dbflute.bhv.readable.EntityRowHandler;
32  import org.dbflute.cbean.ConditionBean;
33  import org.dbflute.cbean.result.ListResultBean;
34  import org.dbflute.cbean.result.PagingResultBean;
35  import org.dbflute.exception.IllegalBehaviorStateException;
36  import org.dbflute.optional.OptionalEntity;
37  import org.dbflute.util.DfTypeUtil;
38  
39  /**
40   * @author ESFlute (using FreeGen)
41   */
42  public abstract class BsFileConfigBhv extends EsAbstractBehavior<FileConfig, FileConfigCB> {
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.file_config";
55      }
56  
57      @Override
58      public String asEsIndexType() {
59          return "file_config";
60      }
61  
62      @Override
63      public String asEsSearchType() {
64          return "file_config";
65      }
66  
67      @Override
68      public FileConfigDbm asDBMeta() {
69          return FileConfigDbm.getInstance();
70      }
71  
72      @Override
73      protected <RESULT extends FileConfig> 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.setConfigParameter(DfTypeUtil.toString(source.get("configParameter")));
79              result.setCreatedBy(DfTypeUtil.toString(source.get("createdBy")));
80              result.setCreatedTime(DfTypeUtil.toLong(source.get("createdTime")));
81              result.setDepth(DfTypeUtil.toInteger(source.get("depth")));
82              result.setDescription(DfTypeUtil.toString(source.get("description")));
83              result.setExcludedDocPaths(DfTypeUtil.toString(source.get("excludedDocPaths")));
84              result.setExcludedPaths(DfTypeUtil.toString(source.get("excludedPaths")));
85              result.setIncludedDocPaths(DfTypeUtil.toString(source.get("includedDocPaths")));
86              result.setIncludedPaths(DfTypeUtil.toString(source.get("includedPaths")));
87              result.setIntervalTime(DfTypeUtil.toInteger(source.get("intervalTime")));
88              result.setMaxAccessCount(DfTypeUtil.toLong(source.get("maxAccessCount")));
89              result.setName(DfTypeUtil.toString(source.get("name")));
90              result.setNumOfThread(DfTypeUtil.toInteger(source.get("numOfThread")));
91              result.setPaths(DfTypeUtil.toString(source.get("paths")));
92              result.setPermissions(toStringArray(source.get("permissions")));
93              result.setSortOrder(DfTypeUtil.toInteger(source.get("sortOrder")));
94              result.setTimeToLive(DfTypeUtil.toInteger(source.get("timeToLive")));
95              result.setUpdatedBy(DfTypeUtil.toString(source.get("updatedBy")));
96              result.setUpdatedTime(DfTypeUtil.toLong(source.get("updatedTime")));
97              result.setVirtualHosts(toStringArray(source.get("virtualHosts")));
98              return updateEntity(source, result);
99          } catch (InstantiationException | IllegalAccessException e) {
100             final String msg = "Cannot create a new instance: " + entityType.getName();
101             throw new IllegalBehaviorStateException(msg, e);
102         }
103     }
104 
105     protected <RESULT extends FileConfig> RESULT updateEntity(Map<String, Object> source, RESULT result) {
106         return result;
107     }
108 
109     // ===================================================================================
110     //                                                                              Select
111     //                                                                              ======
112     public int selectCount(CBCall<FileConfigCB> cbLambda) {
113         return facadeSelectCount(createCB(cbLambda));
114     }
115 
116     public OptionalEntity<FileConfig> selectEntity(CBCall<FileConfigCB> cbLambda) {
117         return facadeSelectEntity(createCB(cbLambda));
118     }
119 
120     protected OptionalEntity<FileConfig> facadeSelectEntity(FileConfigCB cb) {
121         return doSelectOptionalEntity(cb, typeOfSelectedEntity());
122     }
123 
124     protected <ENTITY extends FileConfig> OptionalEntity<ENTITY> doSelectOptionalEntity(FileConfigCB cb, Class<? extends ENTITY> tp) {
125         return createOptionalEntity(doSelectEntity(cb, tp), cb);
126     }
127 
128     @Override
129     public FileConfigCB newConditionBean() {
130         return new FileConfigCB();
131     }
132 
133     @Override
134     protected Entity doReadEntity(ConditionBean cb) {
135         return facadeSelectEntity(downcast(cb)).orElse(null);
136     }
137 
138     public FileConfig selectEntityWithDeletedCheck(CBCall<FileConfigCB> cbLambda) {
139         return facadeSelectEntityWithDeletedCheck(createCB(cbLambda));
140     }
141 
142     public OptionalEntity<FileConfig> selectByPK(String id) {
143         return facadeSelectByPK(id);
144     }
145 
146     protected OptionalEntity<FileConfig> facadeSelectByPK(String id) {
147         return doSelectOptionalByPK(id, typeOfSelectedEntity());
148     }
149 
150     protected <ENTITY extends FileConfig> ENTITY doSelectByPK(String id, Class<? extends ENTITY> tp) {
151         return doSelectEntity(xprepareCBAsPK(id), tp);
152     }
153 
154     protected FileConfigCB xprepareCBAsPK(String id) {
155         assertObjectNotNull("id", id);
156         return newConditionBean().acceptPK(id);
157     }
158 
159     protected <ENTITY extends FileConfig> OptionalEntity<ENTITY> doSelectOptionalByPK(String id, Class<? extends ENTITY> tp) {
160         return createOptionalEntity(doSelectByPK(id, tp), id);
161     }
162 
163     @Override
164     protected Class<? extends FileConfig> typeOfSelectedEntity() {
165         return FileConfig.class;
166     }
167 
168     @Override
169     protected Class<FileConfig> typeOfHandlingEntity() {
170         return FileConfig.class;
171     }
172 
173     @Override
174     protected Class<FileConfigCB> typeOfHandlingConditionBean() {
175         return FileConfigCB.class;
176     }
177 
178     public ListResultBean<FileConfig> selectList(CBCall<FileConfigCB> cbLambda) {
179         return facadeSelectList(createCB(cbLambda));
180     }
181 
182     public PagingResultBean<FileConfig> selectPage(CBCall<FileConfigCB> cbLambda) {
183         // #pending same?
184         return (PagingResultBean<FileConfig>) facadeSelectList(createCB(cbLambda));
185     }
186 
187     public void selectCursor(CBCall<FileConfigCB> cbLambda, EntityRowHandler<FileConfig> entityLambda) {
188         facadeSelectCursor(createCB(cbLambda), entityLambda);
189     }
190 
191     public void selectBulk(CBCall<FileConfigCB> cbLambda, EntityRowHandler<List<FileConfig>> entityLambda) {
192         delegateSelectBulk(createCB(cbLambda), entityLambda, typeOfSelectedEntity());
193     }
194 
195     // ===================================================================================
196     //                                                                              Update
197     //                                                                              ======
198     public void insert(FileConfig entity) {
199         doInsert(entity, null);
200     }
201 
202     public void insert(FileConfig entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
203         entity.asDocMeta().indexOption(opLambda);
204         doInsert(entity, null);
205     }
206 
207     public void update(FileConfig entity) {
208         doUpdate(entity, null);
209     }
210 
211     public void update(FileConfig entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
212         entity.asDocMeta().indexOption(opLambda);
213         doUpdate(entity, null);
214     }
215 
216     public void insertOrUpdate(FileConfig entity) {
217         doInsertOrUpdate(entity, null, null);
218     }
219 
220     public void insertOrUpdate(FileConfig entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
221         entity.asDocMeta().indexOption(opLambda);
222         doInsertOrUpdate(entity, null, null);
223     }
224 
225     public void delete(FileConfig entity) {
226         doDelete(entity, null);
227     }
228 
229     public void delete(FileConfig entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
230         entity.asDocMeta().deleteOption(opLambda);
231         doDelete(entity, null);
232     }
233 
234     public int queryDelete(CBCall<FileConfigCB> cbLambda) {
235         return doQueryDelete(createCB(cbLambda), null);
236     }
237 
238     public int[] batchInsert(List<FileConfig> list) {
239         return batchInsert(list, null, null);
240     }
241 
242     public int[] batchInsert(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call) {
243         return batchInsert(list, call, null);
244     }
245 
246     public int[] batchInsert(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call,
247             RequestOptionCall<IndexRequestBuilder> entityCall) {
248         return doBatchInsert(new BulkList<>(list, call, entityCall), null);
249     }
250 
251     public int[] batchUpdate(List<FileConfig> list) {
252         return batchUpdate(list, null, null);
253     }
254 
255     public int[] batchUpdate(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call) {
256         return batchUpdate(list, call, null);
257     }
258 
259     public int[] batchUpdate(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call,
260             RequestOptionCall<IndexRequestBuilder> entityCall) {
261         return doBatchUpdate(new BulkList<>(list, call, entityCall), null);
262     }
263 
264     public int[] batchDelete(List<FileConfig> list) {
265         return batchDelete(list, null, null);
266     }
267 
268     public int[] batchDelete(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call) {
269         return batchDelete(list, call, null);
270     }
271 
272     public int[] batchDelete(List<FileConfig> list, RequestOptionCall<BulkRequestBuilder> call,
273             RequestOptionCall<IndexRequestBuilder> entityCall) {
274         return doBatchDelete(new BulkList<>(list, call, entityCall), null);
275     }
276 
277     // #pending create, modify, remove
278 }