当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.clear方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:69,代码来源:SnapshotFileExportRunner.java


注:本文中的org.json.simple.JSONObject.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。