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