當前位置: 首頁>>代碼示例>>Java>>正文


Java DBCursor.sort方法代碼示例

本文整理匯總了Java中com.mongodb.DBCursor.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCursor.sort方法的具體用法?Java DBCursor.sort怎麽用?Java DBCursor.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.DBCursor的用法示例。


在下文中一共展示了DBCursor.sort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRetrieveAllAssetsWithSearchAndFilter

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 * Test that a non empty list of filters and a simple search string result in a database query
 * with a sort condition, followed by a sort.
 *
 */
@Test
public void testRetrieveAllAssetsWithSearchAndFilter(final @Mocked DBCollection collection, final @Mocked DBCursor cursor) {
    final BasicDBObject sortObject = new BasicDBObject("score", new BasicDBObject("$meta", "textScore"));

    new Expectations() {
        {
            collection.find((DBObject) withNotNull(), sortObject);
            cursor.sort(sortObject);
        }
    };

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("key1", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "value1") })));
    createTestBean().retrieveAllAssets(filters, "foo", null, null);
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:21,代碼來源:PersistenceBeanBasicSearchTest.java

示例2: getChatMessages

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 * @param channelId The Unique ID of the channel.
 * @param limit     The Integer limit of ChatMessages to load.
 * @return Returns a List of ChatMessages for the ChatChannel.
 */
private List<ChatMessage> getChatMessages(UUID channelId, int limit) {
    List<ChatMessage> listChatMessages = new LinkedList<>();
    // Grab all the messages with the channel_id set to the one provided.
    DBObject query = new BasicDBObject("channel_id", channelId);
    DBCursor cursor = collectionMessages.find(query);
    // Sort the list by timestamp so that the last messages appear first.
    cursor.sort(new BasicDBObject("timestamp", -1));
    cursor.limit(limit);
    if(cursor.size() > 0) {
        List<DBObject> listObjects = cursor.toArray();
        Collections.reverse(listObjects);
        for(DBObject object : listObjects) {
            // Create the MongoDocument.
            MongoChatMessage mongoChatMessage = new MongoChatMessage(collectionMessages, object);
            // Create the container for the document.
            ChatMessage chatMessage = new ChatMessage(mongoChatMessage);
            // Add this to the list to return.
            listChatMessages.add(chatMessage);
        }
    }
    // Close the cursor to release resources.
    cursor.close();
    // Return the result list of messages for the channel.
    return listChatMessages;
}
 
開發者ID:JabJabJab,項目名稱:Sledgehammer,代碼行數:31,代碼來源:ModuleChat.java

示例3: testRetrieveAllAssetsSorted

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 * Test that providing a SortOptions object results in the correct sort() method being called on
 * the result cursor
 */
public void testRetrieveAllAssetsSorted(final @Mocked DBCollection collection, final @Injectable DBCursor cursor) {
    final DBObject sortObject = new BasicDBObject("key2", -1);
    new Expectations() {
        {
            collection.find((DBObject) withNotNull(), (DBObject) withNull());
            result = cursor;
            cursor.sort(sortObject);
        }
    };

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("key1", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "value1") })));
    SortOptions sortOptions = new SortOptions("key2", SortOrder.DESCENDING);
    createTestBean().retrieveAllAssets(filters, null, null, sortOptions);
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:20,代碼來源:PersistenceBeanBasicSearchTest.java

示例4: testRetrieveAllAssetsWithSearch

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 * Test that an empty list of filters and a simple search string result in a database query with
 * a sort condition, and then a sort.
 *
 */
@Test
public void testRetrieveAllAssetsWithSearch(final @Mocked DBCollection collection, final @Mocked DBCursor cursor) {
    BasicDBList list = new BasicDBList();
    list.add(new BasicDBObject("$text", new BasicDBObject("$search", "foo")));
    final BasicDBObject searchObject = new BasicDBObject("$and", list);
    final BasicDBObject sortObject = new BasicDBObject("score", new BasicDBObject("$meta", "textScore"));
    new Expectations() {
        {
            collection.find(searchObject, sortObject);
            cursor.sort(sortObject);
        }
    };

    createTestBean().retrieveAllAssets(Collections.<AssetFilter> emptySet(), "foo", null, null);
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:21,代碼來源:PersistenceBeanBasicSearchTest.java

示例5: testRetrieveAllAssetsWithSearchAndSort

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 * Test that a searchTerm and SortingOptions result in a database query with no projection
 * object and a correct sort.
 */
@Test
public void testRetrieveAllAssetsWithSearchAndSort(final @Mocked DBCollection collection, final @Mocked DBCursor cursor) {
    final BasicDBObject sortObject = new BasicDBObject("key2", -1);

    new Expectations() {
        {
            collection.find((DBObject) withNotNull(), (DBObject) withNull());
            cursor.sort(sortObject);
        }
    };

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("key1", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "value1") })));
    SortOptions sortOptions = new SortOptions("key2", SortOrder.DESCENDING);
    createTestBean().retrieveAllAssets(filters, "foo", null, sortOptions);
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:21,代碼來源:PersistenceBeanBasicSearchTest.java

示例6: selectSet

import com.mongodb.DBCursor; //導入方法依賴的package包/類
public DBCursor selectSet(DBCollection collection) {
	DBObject fields = getFields();
	DBObject query = getQuery();
	DBObject orderByObject = getOrderByObject();
	DBCursor cursor = null;

	// 日誌
	log(fields, query, orderByObject);

	if (null != query && null == fields) {
		cursor = collection.find(query);
	} else if (null == query && null != fields) {
		cursor = collection.find(new BasicDBObject(), fields);
	} else if (null != fields && null != query) {
		cursor = collection.find(query, fields);
	} else {
		cursor = collection.find();
	}

	if (null != orderByObject) {
		cursor.sort(orderByObject);
	}
	if (null != this.limit) {
		if (null == this.limit.getOffset()) {
			cursor.limit(this.limit.getRowCount());
		} else {
			cursor.limit(this.limit.getRowCount());
			cursor.skip(this.limit.getOffset());
		}
	}
	return cursor;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:33,代碼來源:SelectVo.java

示例7: getDataCursor

import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
protected DBCursor getDataCursor(Map<String, ?> ranges, int start, int count, ColumnDescriptor[] columnDescriptors, Map<String, INDEXTYPE> indexTypes) {
    DBCursor cursor = super.getDataCursor(ranges, start, count, columnDescriptors, indexTypes);

    //TODO use indexes on filters ; check http://emptysqua.re/blog/optimizing-mongodb-compound-indexes/
    // example : {horizon:1,datetime:1,CHOO17GROUP_1_NGU_SM_P:1}

    return cursor.sort(new BasicDBObject("datetime", 1));
}
 
開發者ID:itesla,項目名稱:ipst,代碼行數:10,代碼來源:ITeslaDatasource.java

示例8: find

import com.mongodb.DBCursor; //導入方法依賴的package包/類
private static ModulesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
  DBCollection collection = MongoFactory.getDB().getCollection(collectionName);
  List<Module> list = new ArrayList<Module>();
  DBCursor cursor;
  
  if (limit != null) {
    page = (page != null && page > 0) ? ((page-1)*limit) : 0;
  } else {
    page = null;
  }

  if (query == null) {
    cursor = collection.find();
  } else {
    cursor = collection.find(query);
  }

  int totalModules = cursor.count();
  
  if (orderBy != null) {
    cursor = cursor.sort(orderBy);
  }
  
  if (page != null && page > 0) {
    cursor.skip(page);
  }
  
  if (limit != null) {
    cursor = cursor.limit(limit);
  }

  for (DBObject dbObject : cursor) {
    list.add(new Module(dbObject));
  }

  return new ModulesContainer(list, totalModules);
}
 
開發者ID:telefonicaid,項目名稱:fiware-sinfonier,代碼行數:38,代碼來源:Module.java

示例9: find

import com.mongodb.DBCursor; //導入方法依賴的package包/類
private static TopologiesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
  DBCollection collection = MongoFactory.getDB().getCollection(getCollectionName());
  List<Topology> list = new ArrayList<Topology>();
  DBCursor cursor;

  if (limit != null) {
    page = (page != null && page > 0) ? ((page-1)*limit) : 0;
  } else {
    page = null;
  }
  
  if (query == null) {
    cursor = collection.find();
  } else {
    cursor = collection.find(query);
  }
  
  int totalTopologies = cursor.count();

  if (orderBy != null) {
    cursor = cursor.sort(orderBy);
  }

  if (page != null && page > 0) {
    cursor.skip(page);
  }
  
  if (limit != null) {
    cursor = cursor.limit(limit);
  }

  for (DBObject dbObject : cursor) {
    list.add(new Topology(dbObject));
  }

  return new TopologiesContainer(list, totalTopologies);
}
 
開發者ID:telefonicaid,項目名稱:fiware-sinfonier,代碼行數:38,代碼來源:Topology.java

示例10: getFeatures

import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
 *
 * @param queryObject
 * @param limit Limitation on the number of results returned. Setting to 0 is equivalent to unlimited
 * @return
 * @throws IOException
 */
private Collection<DBFeature.IGVFeat> getFeatures(DBObject queryObject, int limit) throws IOException{
    DBCursor cursor = this.collection.find(queryObject);
    cursor.limit(limit >= 0 ? limit : 0);

    //Sort by increasing start value
    //Only do this if we have an index, otherwise might be too memory intensive
    if(hasLocusIndex){
        cursor.sort(new BasicDBObject("Start", 1));
    }
    boolean isSorted = true;
    int lastStart = -1;

    List<DBFeature.IGVFeat> features = new ArrayList<DBFeature.IGVFeat>();
    while (cursor.hasNext()) {
        DBObject obj = cursor.next();
        DBFeature feat = (DBFeature) obj;
        features.add(feat.createIGVFeature());
        isSorted &= feat.getStart() >= lastStart;
        lastStart = feat.getStart();
    }

    if(!isSorted){
        FeatureUtils.sortFeatureList(features);
    }

    return features;
}
 
開發者ID:hyounesy,項目名稱:ALEA,代碼行數:35,代碼來源:MongoFeatureSource.java

示例11: findAll

import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<GridFSDBFile> findAll(OrderBy orderBy, Page page) {
    DBCursor _cursor = __dbCollection.find();
    if (orderBy != null) {
        _cursor.sort(orderBy.toBson());
    }
    if (page != null && page.page() > 0 && page.pageSize() > 0) {
        _cursor.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize());
    }
    List<GridFSDBFile> _results = new ArrayList<GridFSDBFile>();
    while (_cursor.hasNext()) {
        _results.add((GridFSDBFile) _cursor.next());
    }
    _cursor.close();
    return _results;
}
 
開發者ID:suninformation,項目名稱:ymate-platform-v2,代碼行數:16,代碼來源:MongoGridFSSession.java

示例12: find

import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<GridFSDBFile> find(Query query, OrderBy orderBy, Page page) {
    DBCursor _cursor = __dbCollection.find(query.toBson());
    if (orderBy != null) {
        _cursor.sort(orderBy.toBson());
    }
    if (page != null && page.page() > 0 && page.pageSize() > 0) {
        _cursor.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize());
    }
    List<GridFSDBFile> _results = new ArrayList<GridFSDBFile>();
    while (_cursor.hasNext()) {
        _results.add((GridFSDBFile) _cursor.next());
    }
    _cursor.close();
    return _results;
}
 
開發者ID:suninformation,項目名稱:ymate-platform-v2,代碼行數:16,代碼來源:MongoGridFSSession.java

示例13: query

import com.mongodb.DBCursor; //導入方法依賴的package包/類
private AssetCursor query(DBObject filterObject, DBObject sortObject, DBObject projectionObject, PaginationOptions pagination) {

        if (logger.isLoggable(Level.FINE)) {
            logger.fine("query: Querying database with query object " + filterObject);
            logger.fine("query: sort object " + sortObject);
            logger.fine("query: projection object " + projectionObject);
            logger.fine("query: pagination object " + pagination);
        }

        DBCursor cursor = getAssetCollection().find(filterObject, projectionObject);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("query: found " + cursor.count() + " assets.");
        }

        if (pagination != null) {
            cursor.skip(pagination.getOffset());
            cursor.limit(pagination.getLimit());
        }

        if (sortObject != null) {
            cursor.sort(sortObject);
        }

        AssetCursor result = new MongoAssetCursor(cursor);
        result.addOperation(CONVERT_OID_TO_HEX);

        return result;
    }
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:29,代碼來源:PersistenceBean.java

示例14: addOptionsOn

import com.mongodb.DBCursor; //導入方法依賴的package包/類
private void addOptionsOn(DBCursor cursor) {
    if (limit != null) {
        cursor.limit(limit);
    }
    if (skip != null) {
        cursor.skip(skip);
    }
    if (sort != null) {
        cursor.sort(sort.toDBObject());
    }
    if (hint != null) {
        cursor.hint(hint.toDBObject());
    }
}
 
開發者ID:CIDARLAB,項目名稱:clotho3crud,代碼行數:15,代碼來源:RefFind.java

示例15: applyCursorConfigs

import com.mongodb.DBCursor; //導入方法依賴的package包/類
public void applyCursorConfigs(DBCursor dbCursor) {
  if (skip!=null || limit!=null) {
    log.debug("Applying page to cursor: skip="+skip+", limit="+limit);
    if (skip!=null) {
      dbCursor.skip(skip);
    }
    if (limit!=null) {
      dbCursor.limit(limit);
    }
  }
  if (orderBy!=null) {
    log.debug("Applying sort to cursor: "+orderBy);
    dbCursor.sort(orderBy);
  }
}
 
開發者ID:effektif,項目名稱:effektif,代碼行數:16,代碼來源:Query.java


注:本文中的com.mongodb.DBCursor.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。