本文整理匯總了Java中org.json.simple.JSONObject.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.clear方法的具體用法?Java JSONObject.clear怎麽用?Java JSONObject.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.simple.JSONObject
的用法示例。
在下文中一共展示了JSONObject.clear方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addDataToZip
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Extract data other than cells from OData and add it to the zip file.
* @param snapshotFile snapshot file
*/
@SuppressWarnings("unchecked")
private void addDataToZip(SnapshotFile snapshotFile) {
// Specifying filter
Map<String, Object> filter = new HashMap<String, Object>();
filter = QueryMapFactory.termQuery(OEntityDocHandler.KEY_CELL_ID, targetCell.getId());
Map<String, Object> filtered = new HashMap<String, Object>();
filtered = QueryMapFactory.filteredQuery(null, filter);
// Specifying sort
List<Map<String, Object>> sortList = new ArrayList<Map<String, Object>>();
sortList.add(QueryMapFactory.sortQuery("_type", EsQueryHandler.SORT_ASC));
sortList.add(QueryMapFactory.sortQuery(OEntityDocHandler.KEY_BOX_ID, EsQueryHandler.SORT_ASC));
sortList.add(QueryMapFactory.sortQuery(OEntityDocHandler.KEY_NODE_ID, EsQueryHandler.SORT_ASC));
sortList.add(QueryMapFactory.sortQuery(OEntityDocHandler.KEY_ENTITY_ID, EsQueryHandler.SORT_ASC));
sortList.add(QueryMapFactory.sortQuery("_uid", EsQueryHandler.SORT_ASC));
// Generate query
long queryFrom = 0L;
Map<String, Object> query = QueryMapFactory.query(filtered);
query.put("sort", sortList);
query.put("from", queryFrom);
query.put("size", SEARCH_LIMIT);
// Get index accessor of Es
String indexName = targetCell.getDataBundleName();
DataSourceAccessor dataSourceAccessor = EsModel.getDataSourceAccessorFromIndexName(indexName);
// At least create an empty file.
snapshotFile.createDataPJson();
while (true) {
// Search Es
PersoniumSearchResponse response = dataSourceAccessor.searchForIndex(
targetCell.getId(), query);
if (response.getHits().getCount() == 0) {
break;
}
JSONObject resultJson = new JSONObject();
StringBuilder builder = new StringBuilder();
for (PersoniumSearchHit hit : response.getHits().getHits()) {
resultJson.put("_index", hit.getIndex());
resultJson.put("_type", hit.getType());
resultJson.put("_id", hit.getId());
resultJson.put("_source", hit.getSource());
builder.append(resultJson.toJSONString());
builder.append(System.lineSeparator());
resultJson.clear();
}
snapshotFile.writeDataPJson(builder.toString());
progressInfo.addDelta(response.getHits().getCount());
progressInfo.writeToCache();
// If the search result is smaller than LIMIT, the processing is terminated
if (SEARCH_LIMIT > response.getHits().getCount()) {
break;
}
// If the search result is LIMIT, search again from the following
queryFrom += SEARCH_LIMIT;
query.put("from", queryFrom);
}
}