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