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