本文整理汇总了Java中org.springframework.data.mongodb.core.query.BasicQuery类的典型用法代码示例。如果您正苦于以下问题:Java BasicQuery类的具体用法?Java BasicQuery怎么用?Java BasicQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicQuery类属于org.springframework.data.mongodb.core.query包,在下文中一共展示了BasicQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isImportProcessLockedSpentTheTime
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void isImportProcessLockedSpentTheTime() throws Exception{
String idApplication = "1";
String strQuery = "{ '_id':'" + idApplication + "'}";
String strNow = DateTime.now().toString();
//Fixture
Query query=Mockito.mock(Query.class);
PowerMockito.whenNew(BasicQuery.class).withArguments(strQuery).thenReturn(basicQuery);
Mockito.when(mongoTemplate.find(query, LockImport.class, collectionLock)).thenReturn(lockImportList);
Mockito.when(mongoTemplate.collectionExists(collectionLock)).thenReturn(true);
Mockito.when(mongoTemplate.getCollection(collectionLock)).thenReturn(dbCollection);
PowerMockito.whenNew(LockImport.class).withNoArguments().thenReturn(lockImport);
PowerMockito.mockStatic(DateTime.class);
Mockito.when(DateTime.now()).thenReturn(now);
Mockito.when(now.toString()).thenReturn(strNow);
//Experimentation
importRepositoryCustom.isImportProcessLocked(idApplication);
//Expectations
}
示例2: saveCrawlStatus
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
/**
* save crawl status to db
* <p>
*
* @author chen.chen.9, 2013-8-26
* @param crawlStatus
* {@link CrawlStatus}
*/
protected void saveCrawlStatus(CrawlStatus crawlStatus) {
String code = crawlStatus.getCode();
Query query = new BasicQuery(new BasicDBObject("code", code));
CrawlStatus crawlStatusInDb = getMongoTemplate().findOne(query, CrawlStatus.class);
// if exists, update it
if (crawlStatusInDb != null) {
crawlStatus.set_id(crawlStatusInDb.get_id());
getMongoTemplate().save(crawlStatus);
}
// if not exists, insert it
else {
getMongoTemplate().insert(crawlStatus);
}
// XXX {@link WriteResult}#getLastError() to return isSuccess
getLOGGER().info("The status of the crawl {} job has gone step to {}", code, crawlStatus.getStatus());
}
示例3: findByServiceIdAndJSONQuery
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Override
public List<GenericResource> findByServiceIdAndJSONQuery(String serviceId, String jsonQuery) {
// First parse query document and prepare a list of key to rename then remove.
Document query = Document.parse(jsonQuery);
ArrayList<String> keysToRemove = new ArrayList<>();
// Collect the keys of document that should be updated.
for (String key : query.keySet()) {
keysToRemove.add(key);
}
// Prefix all keys by payload. that is the nested document where we put resource in
// and remove all modified keys.
for (String keyToRemove : keysToRemove) {
query.append("payload." + keyToRemove, query.get(keyToRemove));
query.remove(keyToRemove);
}
// Finally, append serviceId criterion before launching selection.
query.append("serviceId", serviceId);
return template.find(new BasicQuery(query.toJson()), GenericResource.class);
}
示例4: findByIDAppAndQueryTest
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void findByIDAppAndQueryTest() throws Exception{
String idApplication = "1";
String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";
Integer pageIndex=5;
Integer pageSize= 20;
int skipElementsValue = pageIndex*pageSize;
//Fixture
Query querySkip=Mockito.mock(Query.class);
Query queryLimit=Mockito.mock(Query.class);
PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);
Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);
Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionMap+idApplication)).thenReturn(features);
//Experimentation
Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
//Expectations
Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionMap+idApplication);
Assert.assertEquals("Features must be equals", featuresResponse, features);
}
示例5: findByIDAppAndQueryErrorQueryTesTest
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test(expected=QueryException.class)
public void findByIDAppAndQueryErrorQueryTesTest() throws Exception{
String idApplication = "1";
String queryJSON = "{ geometry:{ $geoWithin: $centerSphere:[ [20.05,20.01] , 0.05]} } }";
Integer pageIndex=5;
Integer pageSize= 20;
//Fixture
PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenThrow(Exception.class);
//Experimentation
mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
//Expectations
}
示例6: deleteLockImportProcess
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void deleteLockImportProcess() throws Exception{
String idApplication = "1";
String strQuery = "{ '_id':'" + idApplication + "'}";
//Fixture
PowerMockito.whenNew(BasicQuery.class).withArguments(strQuery).thenReturn(basicQuery);
Mockito.when(mongoTemplate.collectionExists(collectionLock)).thenReturn(true);
//Experimentation
importRepositoryCustom.deleteLockImportProcess(idApplication);
//Expectations
verify(mongoTemplate).collectionExists(collectionLock);
verify(mongoTemplate).remove(basicQuery,collectionLock);
}
示例7: loopContent
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
/**
*
* @Description: 查询未读消息
* @param
* @return List<PageData>
* @throws Exception
* @Data: 2017/3/2 下午4:47
*
*/
private List<PageData> loopContent(PageData pd){
BasicDBObject fieldsObject=new BasicDBObject();
//指定返回的字段
fieldsObject.put("CONTENT", true);
fieldsObject.put("MESSAGETYPE", true);
fieldsObject.put("CREATE_TIME", true);
fieldsObject.put("IMAGE_PATH", true);
fieldsObject.put("_id", false);
// Criteria criteria = new Criteria();
// criteria.orOperator(Criteria.where("TITLE_ID").is(pd.get("TITLE_ID")),
// Criteria.where("CHANGE_TIME").gt(pd.get("STARTTIME")),
// Criteria.where("CHANGE_TIME").lte(pd.get("EMDTIME")),
// Criteria.where("TITLE_TYPE").is(pd.get("TITLE_TYPE")));
// System.out.print(criteria.toString());
//查询条件
DBObject dbObject = new BasicDBObject();
dbObject.put("TITLE_ID",pd.get("TITLE_ID"));
if(StringUtils.isNotBlank(pd.getString("TITLE_TYPE"))){
dbObject.put("TITLE_TYPE",pd.get("TITLE_TYPE"));
}
dbObject.put("CHANGE_TIME",new BasicDBObject("$lt", pd.get("EMDTIME")));
dbObject.put("CHANGE_TIME",new BasicDBObject("$gte", pd.get("STARTTIME")));
Query query = new BasicQuery(dbObject,fieldsObject);
//排序
query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "CHANGE_TIME")));
List<PageData> allContent=mongoTemplate.find(query,PageData.class,"IM_CONTENT");
return allContent;
}
示例8: findTitleList
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Override
public List<Blog> findTitleList() {
BasicDBObject basicDBObject = new BasicDBObject();
basicDBObject.put("id", 1);
basicDBObject.put("title", 1);
basicDBObject.put("type", 1);
basicDBObject.put("currentDate", 1);
QueryBuilder builder = new QueryBuilder();
return mongoTemplate.find(new BasicQuery(builder.get(), basicDBObject), Blog.class);
}
示例9: main
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
System.out.println(find.size());
find.forEach(System.out::println);
}
示例10: main
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
System.out.println(find.size());
find.forEach(System.out::println);
// Projection Expressions
System.err.println("Projection Expressions");
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.project("apply_id", "apply_type"));
AggregationResults<OutputType> aggregate = mongoTemplate.aggregate(aggregation, "fk_qc_apply", OutputType.class);
aggregate.forEach(System.out::println);
}
示例11: main
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/mongoDBConfig/spring-mongoDB.xml");
MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
BasicQuery basicQuery = new BasicQuery("{apply_id:{$gt:800}}");
List<FkApply> find = mongoTemplate.find(basicQuery, FkApply.class);
System.out.println(find.size());
find.forEach(System.out::println);
}
示例12: basicQuery
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
/**
* {@inheritDoc} TODO: remove when not needed anymore
*/
@Override
public List<ClientRequestCollector> basicQuery() {
List<ClientRequestCollector> result = mongoTemplate
.find(
new BasicQuery(
"[{ '$match' : { 'procedure.annotations.name': { $regex: '.*MicroserviceClientRequest' }, 'procedure.annotations.members.caller' : 'eu.cloudwave.samples.services.currency'}},{ $project : { 'startTimeGrouping' : { '$subtract' : [ { $divide : ['$startTime', 3600 ]}, { $mod : [{ $divide : ['$startTime', 3600 ]},1] } ] },'caller': '$procedure.annotations.members.caller','callee': '$procedure.annotations.members.callee'} }]"),
ClientRequestCollector.class);
return result;
}
示例13: findByIDAppAndQueryWithOrderTest
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
String idApplication = "1";
String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";
Integer pageIndex=5;
Integer pageSize= 20;
int skipElementsValue = pageIndex*pageSize;
String orderField = "_id";
String order = "ASC";
//Fixture
Query querySkip=Mockito.mock(Query.class);
Query queryLimit=Mockito.mock(Query.class);
Query query=Mockito.mock(Query.class);
Sort sort = Mockito.mock(Sort.class);
PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);
Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);
PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
Mockito.when(queryLimit.with(sort)).thenReturn(query);
Mockito.when(mongoTemplate.find(query, Feature.class, collectionMap+idApplication)).thenReturn(features);
//Experimentation
Collection<Feature> featuresResponse=mapRepositoryCustomImpl.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
//Expectations
Mockito.verify(mongoTemplate).find(query, Feature.class, collectionMap+idApplication);
Assert.assertEquals("Features must be equals", featuresResponse, features);
}
示例14: findByIDAppAndQueryTest
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void findByIDAppAndQueryTest() throws Exception{
String idApplication = "1";
String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";
Integer pageIndex=5;
Integer pageSize= 20;
int skipElementsValue = pageIndex*pageSize;
//Fixture
Query querySkip=Mockito.mock(Query.class);
Query queryLimit=Mockito.mock(Query.class);
PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);
Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);
Mockito.when(mongoTemplate.find(queryLimit, Feature.class, collectionName+idApplication)).thenReturn(features);
//Experimentation
Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize);
//Expectations
Mockito.verify(mongoTemplate).find(queryLimit, Feature.class, collectionName+idApplication);
Assert.assertEquals("Features must be equals", featuresResponse, features);
}
示例15: findByIDAppAndQueryWithOrderTest
import org.springframework.data.mongodb.core.query.BasicQuery; //导入依赖的package包/类
@Test
public void findByIDAppAndQueryWithOrderTest() throws Exception{
String idApplication = "1";
String queryJSON = "{ geometry:{ $geoWithin:{ $centerSphere:[ [20.05,20.01] , 0.05]} } }";
Integer pageIndex=5;
Integer pageSize= 20;
int skipElementsValue = pageIndex*pageSize;
String orderField = "_id";
String order = "ASC";
//Fixture
Query querySkip=Mockito.mock(Query.class);
Query queryLimit=Mockito.mock(Query.class);
Query query=Mockito.mock(Query.class);
Sort sort = Mockito.mock(Sort.class);
PowerMockito.whenNew(BasicQuery.class).withArguments(queryJSON).thenReturn(basicQuery);
Mockito.when(basicQuery.skip(skipElementsValue)).thenReturn(querySkip);
Mockito.when(querySkip.limit(pageSize)).thenReturn(queryLimit);
PowerMockito.whenNew(Sort.class).withArguments(Sort.Direction.valueOf(order), orderField).thenReturn(sort);
Mockito.when(queryLimit.with(sort)).thenReturn(query);
Mockito.when(mongoTemplate.find(query, Feature.class, collectionName+idApplication)).thenReturn(features);
//Experimentation
Collection<Feature> featuresResponse=featureRepository.searchIDAppAndQuery(idApplication, queryJSON, pageIndex, pageSize, orderField, order);
//Expectations
Mockito.verify(mongoTemplate).find(query, Feature.class, collectionName+idApplication);
Assert.assertEquals("Features must be equals", featuresResponse, features);
}