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