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