use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.
the class FessEsClient method deleteByQuery.
public int deleteByQuery(final String index, final String type, final QueryBuilder queryBuilder) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
SearchResponse response = client.prepareSearch(index).setTypes(type).setScroll(scrollForDelete).setSize(sizeForDelete).setFetchSource(new String[] { fessConfig.getIndexFieldId() }, null).setQuery(queryBuilder).setPreference(Constants.SEARCH_PREFERENCE_PRIMARY).execute().actionGet(fessConfig.getIndexScrollSearchTimeoutTimeout());
int count = 0;
String scrollId = response.getScrollId();
while (scrollId != null) {
final SearchHits searchHits = response.getHits();
final SearchHit[] hits = searchHits.getHits();
if (hits.length == 0) {
scrollId = null;
break;
}
final BulkRequestBuilder bulkRequest = client.prepareBulk();
for (final SearchHit hit : hits) {
bulkRequest.add(client.prepareDelete(index, type, hit.getId()));
}
count += hits.length;
final BulkResponse bulkResponse = bulkRequest.execute().actionGet(fessConfig.getIndexBulkTimeout());
if (bulkResponse.hasFailures()) {
throw new IllegalBehaviorStateException(bulkResponse.buildFailureMessage());
}
response = client.prepareSearchScroll(scrollId).setScroll(scrollForDelete).execute().actionGet(fessConfig.getIndexBulkTimeout());
scrollId = response.getScrollId();
}
return count;
}
use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.
the class BsFileConfigToLabelBhv method createEntity.
@Override
protected <RESULT extends FileConfigToLabel> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
try {
final RESULT result = entityType.newInstance();
result.setFileConfigId(DfTypeUtil.toString(source.get("fileConfigId")));
result.setLabelTypeId(DfTypeUtil.toString(source.get("labelTypeId")));
return updateEntity(source, result);
} catch (InstantiationException | IllegalAccessException e) {
final String msg = "Cannot create a new instance: " + entityType.getName();
throw new IllegalBehaviorStateException(msg, e);
}
}
use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.
the class BsWebConfigToRoleBhv method createEntity.
@Override
protected <RESULT extends WebConfigToRole> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
try {
final RESULT result = entityType.newInstance();
result.setRoleTypeId(DfTypeUtil.toString(source.get("roleTypeId")));
result.setWebConfigId(DfTypeUtil.toString(source.get("webConfigId")));
return updateEntity(source, result);
} catch (InstantiationException | IllegalAccessException e) {
final String msg = "Cannot create a new instance: " + entityType.getName();
throw new IllegalBehaviorStateException(msg, e);
}
}
use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.
the class BsSearchFieldLogBhv method createEntity.
@Override
protected <RESULT extends SearchFieldLog> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
try {
final RESULT result = entityType.newInstance();
result.setName(DfTypeUtil.toString(source.get("name")));
result.setSearchLogId(DfTypeUtil.toString(source.get("searchLogId")));
result.setValue(DfTypeUtil.toString(source.get("value")));
return updateEntity(source, result);
} catch (InstantiationException | IllegalAccessException e) {
final String msg = "Cannot create a new instance: " + entityType.getName();
throw new IllegalBehaviorStateException(msg, e);
}
}
use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.
the class EsAbstractBehavior method delegateQueryDelete.
@Override
protected int delegateQueryDelete(final ConditionBean cb, final DeleteOption<? extends ConditionBean> option) {
final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()).setScroll(scrollForDelete).setSize(sizeForDelete);
final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
if (esCb.getPreference() != null) {
esCb.setPreference(esCb.getPreference());
}
esCb.request().build(builder);
SearchResponse response = esCb.build(builder).execute().actionGet(scrollSearchTimeout);
String scrollId = response.getScrollId();
int count = 0;
try {
while (scrollId != null) {
final SearchHits searchHits = getSearchHits(response);
final SearchHit[] hits = searchHits.getHits();
if (hits.length == 0) {
break;
}
final BulkRequestBuilder bulkRequest = client.prepareBulk();
for (final SearchHit hit : hits) {
bulkRequest.add(client.prepareDelete().setIndex(asEsIndex()).setId(hit.getId()));
}
count += hits.length;
final BulkResponse bulkResponse = bulkRequest.execute().actionGet(bulkTimeout);
if (bulkResponse.hasFailures()) {
throw new IllegalBehaviorStateException(bulkResponse.buildFailureMessage());
}
response = client.prepareSearchScroll(scrollId).setScroll(scrollForDelete).execute().actionGet(scrollSearchTimeout);
if (!scrollId.equals(response.getScrollId())) {
deleteScrollContext(scrollId);
}
}
} finally {
deleteScrollContext(scrollId);
}
return count;
}
Aggregations