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