/*
* Copyright 2012-2017 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.es.user.bsbhv;
import java.util.List;
import java.util.Map;
import org.codelibs.fess.es.user.allcommon.EsAbstractBehavior;
import org.codelibs.fess.es.user.allcommon.EsAbstractEntity.RequestOptionCall;
import org.codelibs.fess.es.user.bsentity.dbmeta.GroupDbm;
import org.codelibs.fess.es.user.cbean.GroupCB;
import org.codelibs.fess.es.user.exentity.Group;
import org.dbflute.Entity;
import org.dbflute.bhv.readable.CBCall;
import org.dbflute.bhv.readable.EntityRowHandler;
import org.dbflute.cbean.ConditionBean;
import org.dbflute.cbean.result.ListResultBean;
import org.dbflute.cbean.result.PagingResultBean;
import org.dbflute.exception.IllegalBehaviorStateException;
import org.dbflute.optional.OptionalEntity;
import org.dbflute.util.DfTypeUtil;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.delete.DeleteRequestBuilder;
import org.elasticsearch.action.index.IndexRequestBuilder;
/**
* @author ESFlute (using FreeGen)
*/
public abstract class BsGroupBhv extends EsAbstractBehavior<Group, GroupCB> {
// ===================================================================================
// Control Override
// ================
@Override
public String asTableDbName() {
return asEsIndexType();
}
@Override
protected String asEsIndex() {
return ".fess_user";
}
@Override
public String asEsIndexType() {
return "group";
}
@Override
public String asEsSearchType() {
return "group";
}
@Override
public GroupDbm asDBMeta() {
return GroupDbm.getInstance();
}
@Override
protected <RESULT extends Group> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
try {
final RESULT result = entityType.newInstance();
result.setName(DfTypeUtil.toString(source.get("name")));
result.setGidNumber(DfTypeUtil.toLong(source.get("gidNumber")));
return updateEntity(source, result);
} catch (InstantiationException | IllegalAccessException e) {
final String msg = "Cannot create a new instance: " + entityType.getName();
throw new IllegalBehaviorStateException(msg, e);
}
}
protected <RESULT extends Group> RESULT updateEntity(Map<String, Object> source, RESULT result) {
return result;
}
// ===================================================================================
// Select
// ======
public int selectCount(CBCall<GroupCB> cbLambda) {
return facadeSelectCount(createCB(cbLambda));
}
public OptionalEntity<Group> selectEntity(CBCall<GroupCB> cbLambda) {
return facadeSelectEntity(createCB(cbLambda));
}
protected OptionalEntity<Group> facadeSelectEntity(GroupCB cb) {
return doSelectOptionalEntity(cb, typeOfSelectedEntity());
}
protected <ENTITY extends Group> OptionalEntity<ENTITY> doSelectOptionalEntity(GroupCB cb, Class<? extends ENTITY> tp) {
return createOptionalEntity(doSelectEntity(cb, tp), cb);
}
@Override
public GroupCB newConditionBean() {
return new GroupCB();
}
@Override
protected Entity doReadEntity(ConditionBean cb) {
return facadeSelectEntity(downcast(cb)).orElse(null);
}
public Group selectEntityWithDeletedCheck(CBCall<GroupCB> cbLambda) {
return facadeSelectEntityWithDeletedCheck(createCB(cbLambda));
}
public OptionalEntity<Group> selectByPK(String id) {
return facadeSelectByPK(id);
}
protected OptionalEntity<Group> facadeSelectByPK(String id) {
return doSelectOptionalByPK(id, typeOfSelectedEntity());
}
protected <ENTITY extends Group> ENTITY doSelectByPK(String id, Class<? extends ENTITY> tp) {
return doSelectEntity(xprepareCBAsPK(id), tp);
}
protected GroupCB xprepareCBAsPK(String id) {
assertObjectNotNull("id", id);
return newConditionBean().acceptPK(id);
}
protected <ENTITY extends Group> OptionalEntity<ENTITY> doSelectOptionalByPK(String id, Class<? extends ENTITY> tp) {
return createOptionalEntity(doSelectByPK(id, tp), id);
}
@Override
protected Class<? extends Group> typeOfSelectedEntity() {
return Group.class;
}
@Override
protected Class<Group> typeOfHandlingEntity() {
return Group.class;
}
@Override
protected Class<GroupCB> typeOfHandlingConditionBean() {
return GroupCB.class;
}
public ListResultBean<Group> selectList(CBCall<GroupCB> cbLambda) {
return facadeSelectList(createCB(cbLambda));
}
public PagingResultBean<Group> selectPage(CBCall<GroupCB> cbLambda) {
// #pending same?
return (PagingResultBean<Group>) facadeSelectList(createCB(cbLambda));
}
public void selectCursor(CBCall<GroupCB> cbLambda, EntityRowHandler<Group> entityLambda) {
facadeSelectCursor(createCB(cbLambda), entityLambda);
}
public void selectBulk(CBCall<GroupCB> cbLambda, EntityRowHandler<List<Group>> entityLambda) {
delegateSelectBulk(createCB(cbLambda), entityLambda, typeOfSelectedEntity());
}
// ===================================================================================
// Update
// ======
public void insert(Group entity) {
doInsert(entity, null);
}
public void insert(Group entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
entity.asDocMeta().indexOption(opLambda);
doInsert(entity, null);
}
public void update(Group entity) {
doUpdate(entity, null);
}
public void update(Group entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
entity.asDocMeta().indexOption(opLambda);
doUpdate(entity, null);
}
public void insertOrUpdate(Group entity) {
doInsertOrUpdate(entity, null, null);
}
public void insertOrUpdate(Group entity, RequestOptionCall<IndexRequestBuilder> opLambda) {
entity.asDocMeta().indexOption(opLambda);
doInsertOrUpdate(entity, null, null);
}
public void delete(Group entity) {
doDelete(entity, null);
}
public void delete(Group entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
entity.asDocMeta().deleteOption(opLambda);
doDelete(entity, null);
}
public int queryDelete(CBCall<GroupCB> cbLambda) {
return doQueryDelete(createCB(cbLambda), null);
}
public int[] batchInsert(List<Group> list) {
return batchInsert(list, null, null);
}
public int[] batchInsert(List<Group> list, RequestOptionCall<BulkRequestBuilder> call) {
return batchInsert(list, call, null);
}
public int[] batchInsert(List<Group> list, RequestOptionCall<BulkRequestBuilder> call, RequestOptionCall<IndexRequestBuilder> entityCall) {
return doBatchInsert(new BulkList<>(list, call, entityCall), null);
}
public int[] batchUpdate(List<Group> list) {
return batchUpdate(list, null, null);
}
public int[] batchUpdate(List<Group> list, RequestOptionCall<BulkRequestBuilder> call) {
return batchUpdate(list, call, null);
}
public int[] batchUpdate(List<Group> list, RequestOptionCall<BulkRequestBuilder> call, RequestOptionCall<IndexRequestBuilder> entityCall) {
return doBatchUpdate(new BulkList<>(list, call, entityCall), null);
}
public int[] batchDelete(List<Group> list) {
return batchDelete(list, null, null);
}
public int[] batchDelete(List<Group> list, RequestOptionCall<BulkRequestBuilder> call) {
return batchDelete(list, call, null);
}
public int[] batchDelete(List<Group> list, RequestOptionCall<BulkRequestBuilder> call, RequestOptionCall<IndexRequestBuilder> entityCall) {
return doBatchDelete(new BulkList<>(list, call, entityCall), null);
}
// #pending create, modify, remove
}