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


Java FindRequest.setQuery方法代码示例

本文整理汇总了Java中com.redhat.lightblue.crud.FindRequest.setQuery方法的典型用法代码示例。如果您正苦于以下问题:Java FindRequest.setQuery方法的具体用法?Java FindRequest.setQuery怎么用?Java FindRequest.setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.redhat.lightblue.crud.FindRequest的用法示例。


在下文中一共展示了FindRequest.setQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSimpleRequest

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
public static FindRequest buildSimpleRequest(String entity, String version, String q, String p, String s, Long from, Long to, Long maxResults)
        throws IOException {
    // spec -> https://github.com/lightblue-platform/lightblue/wiki/Rest-Spec-Data#get-simple-find
    String sq = QueryTemplateUtils.buildQueryFieldsTemplate(q);
    LOGGER.debug("query: {} -> {}", q, sq);

    String sp = QueryTemplateUtils.buildProjectionsTemplate(p);
    LOGGER.debug("projection: {} -> {}", p, sp);

    String ss = QueryTemplateUtils.buildSortsTemplate(s);
    LOGGER.debug("sort:{} -> {}", s, ss);

    FindRequest findRequest = new FindRequest();
    findRequest.setEntityVersion(new EntityVersion(entity, version));
    findRequest.setQuery(sq == null ? null : QueryExpression.fromJson(JsonUtils.json(sq)));
    findRequest.setProjection(sp == null ? null : Projection.fromJson(JsonUtils.json(sp)));
    findRequest.setSort(ss == null ? null : Sort.fromJson(JsonUtils.json(ss)));
    findRequest.setFrom(from);
    if(to!=null) {
        findRequest.setTo(to);
    } else if(maxResults!=null&&maxResults>0) {
        findRequest.setTo((from == null ? 0 : from) + maxResults - 1);
    }
    return findRequest;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:26,代码来源:LightblueRequestUtils.java

示例2: buildSimpleRequest

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
private FindRequest buildSimpleRequest(String entity,String version, String q,String p, String s, Long from, Long to,Long maxResults)
    throws IOException {            
    // spec -> https://github.com/lightblue-platform/lightblue/wiki/Rest-Spec-Data#get-simple-find
    String sq = QueryTemplateUtils.buildQueryFieldsTemplate(q);
    LOGGER.debug("query: {} -> {}", q, sq);

    String sp = QueryTemplateUtils.buildProjectionsTemplate(p);
    LOGGER.debug("projection: {} -> {}", p, sp);

    String ss = QueryTemplateUtils.buildSortsTemplate(s);
    LOGGER.debug("sort:{} -> {}", s, ss);

    FindRequest findRequest = new FindRequest();
    findRequest.setEntityVersion(new EntityVersion(entity, version));
    findRequest.setQuery(sq == null ? null : QueryExpression.fromJson(JsonUtils.json(sq)));
    findRequest.setProjection(sp == null ? null : Projection.fromJson(JsonUtils.json(sp)));
    findRequest.setSort(ss == null ? null : Sort.fromJson(JsonUtils.json(ss)));
    findRequest.setFrom(from);
    if(to!=null) {
        findRequest.setTo(to);
    } else if(maxResults!=null&&maxResults>0) {
        findRequest.setTo((from == null ? 0 : from) + maxResults - 1);
    }
    return findRequest;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:26,代码来源:AbstractCrudResource.java

示例3: findQueryFieldRoleTest

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void findQueryFieldRoleTest() throws Exception {
    FindRequest req = new FindRequest();
    req.setEntityVersion(new EntityVersion("test", "1.0"));
    req.setQuery(new ValueComparisonExpression(new Path("field1"), BinaryComparisonOperator._eq, new Value("x")));
    req.setClientId(new RestClientIdentification(Arrays.asList("test-find")));

    mockCrudController.findResponse = new CRUDFindResponse();
    mockCrudController.findCb=ctx->ctx.setDocumentStream(new ListDocumentStream<DocCtx>(new ArrayList<DocCtx>()));
    Response response = mediator.find(req);
    Assert.assertEquals(OperationStatus.ERROR, response.getStatus());

    req.setQuery(new ValueComparisonExpression(new Path("field2"), BinaryComparisonOperator._eq, new Value("x")));
    response = mediator.find(req);
    Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:17,代码来源:MediatorTest.java

示例4: test_self_ref_array_not_contains

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void test_self_ref_array_not_contains() throws Exception {
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'!=','rvalue':''}"));
    fr.setProjection(projection("[{'field':'*','recursive':true},{'field':'test_reference'}]"));
    fr.setEntityVersion(new EntityVersion("self_ref_array_not_contains","0.0.1-SNAPSHOT"));
    Response response=mediator.find(fr);
    System.out.println(response.getEntityData());
    for(JsonNode doc:response.getEntityData()) {
        String id=doc.get("_id").asText();
        if("Q".equals(id)) {
            Assert.assertEquals(2,doc.get("test_reference").size());
            Assert.assertTrue("ST".indexOf(doc.get("test_reference").get(0).get("_id").asText())!=-1);
            Assert.assertTrue("ST".indexOf(doc.get("test_reference").get(1).get("_id").asText())!=-1);
        } else if("R".equals(id)) {
            Assert.assertEquals(2,doc.get("test_reference").size());
            Assert.assertTrue("ST".indexOf(doc.get("test_reference").get(0).get("_id").asText())!=-1);
            Assert.assertTrue("ST".indexOf(doc.get("test_reference").get(1).get("_id").asText())!=-1);
        } else if("S".equals(id)) {
            Assert.assertEquals(1,doc.get("test_reference").size());
            Assert.assertEquals("T",doc.get("test_reference").get(0).get("_id").asText());
        } else {
            Assert.assertNull(doc.get("test_reference"));
        }
    }
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:27,代码来源:CompositeFinderTest.java

示例5: looping_entities_with_or_query_709_w_n_to_n_refs

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void looping_entities_with_or_query_709_w_n_to_n_refs() throws Exception {
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'$and':["+
                      "           {'field':'repository','regex':'repo.*'},"+
                      "           {'field':'images.*.repositories.*.published','op':'=','rvalue':true},"+
                      "           {'$or':["+
                      "                     {'$and':["+
                      "                                {'field':'vendorLabel','op':'!=','rvalue':'Red Hat'},"+
                      "                                {'field':'images.*.certified','op':'=','rvalue':true}"+
                      "                             ]},"+
                      "                     {'field':'vendorLabel','op':'=','rvalue':'Red Hat'}"+
                      "                  ]}"+
                      "]}"));
    fr.setProjection(projection("[{'field':'*'},{'field':'refchild'}]"));
    fr.setEntityVersion(new EntityVersion("containerRepository","1.0.0."));
    Response response=mediator.find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(3,response.getMatchCount());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:21,代码来源:CompositeFinderTest.java

示例6: query_processing_error_707

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void query_processing_error_707() throws Exception {
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'$and':["+
                      "          {'$or':["+
                      "             {'field':'field1','op':'=','rvalue':'f1value'},"+
                      "             {'array':'refchild.*.array','elemMatch':{"+
                      "                       '$and':["+
                      "                                 {'field':'field1','op':'=','rvalue':'value1'},"+
                      "                                 {'field':'field2','regex':'value2'}"+
                      "                              ]"+
                      "                   }"+
                      "             }"+
                      "          ]},"+
                      "          {'field':'refchild.*.refparent.*.field2','op':'=','rvalue':true}"+
                      "]}"));
    fr.setProjection(projection("[{'field':'*'},{'field':'refchild'}]"));
    fr.setEntityVersion(new EntityVersion("root_loop","1.0.0."));
    Response response=mediator.find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(5,response.getMatchCount());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:23,代码来源:CompositeFinderTest.java

示例7: assoc_errors_propagate

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void assoc_errors_propagate() throws Exception {
    FindRequest fr = new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':1}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'us','recursive':1}]"));
    fr.setEntityVersion(new EntityVersion("L", "0.0.1"));
    findError = Error.get("NoAccess", "blah");
    errorEntity = "U";
    Response response = mediator.find(fr);
    System.out.println(response.getEntityData());
    Assert.assertTrue(response.getEntityData()==null||response.getEntityData().size()==0);
    Assert.assertEquals(1, response.getErrors().size());

    findError = Error.get("NoAccess", "blah");
    errorEntity = "L";
    response = mediator.find(fr);
    System.out.println(response.getEntityData());
    Assert.assertTrue(response.getEntityData()==null||response.getEntityData().size()==0);
    Assert.assertEquals(1, response.getErrors().size());

}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:22,代码来源:CompositeFinderTest.java

示例8: array_in_reference_fullarr

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void array_in_reference_fullarr() throws Exception {
    init_arr();
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':'1'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'ref'}]"));
    fr.setEntityVersion(new EntityVersion("arr_parent","1.0.0"));
    Response response=getMediator().find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertEquals(3,response.getEntityData().get(0).get("ref").size());
    cleanup_arr();
}
 
开发者ID:lightblue-platform,项目名称:lightblue-mongo,代码行数:14,代码来源:AssocTest.java

示例9: array_in_reference_emptyarr

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void array_in_reference_emptyarr() throws Exception {
    init_arr();
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':'2'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'ref'}]"));
    fr.setEntityVersion(new EntityVersion("arr_parent","1.0.0"));
    Response response=getMediator().find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertNull(response.getEntityData().get(0).get("ref"));
    cleanup_arr();
}
 
开发者ID:lightblue-platform,项目名称:lightblue-mongo,代码行数:14,代码来源:AssocTest.java

示例10: array_in_reference_nullarr

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void array_in_reference_nullarr() throws Exception {
    init_arr();
    FindRequest fr=new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':'3'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'ref'}]"));
    fr.setEntityVersion(new EntityVersion("arr_parent","1.0.0"));
    Response response=getMediator().find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertNull(response.getEntityData().get(0).get("ref"));
    cleanup_arr();
}
 
开发者ID:lightblue-platform,项目名称:lightblue-mongo,代码行数:14,代码来源:AssocTest.java

示例11: retrieveAandBonly

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void retrieveAandBonly() throws Exception {
    FindRequest fr = new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':'A01'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'b'}]"));
    fr.setEntityVersion(new EntityVersion("A", "1.0.0"));
    Response response = mediator.find(fr);
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertEquals("A01", response.getEntityData().get(0).get("_id").asText());
    QueryPlan qplan = (QueryPlan) getLastContext(mediator).getProperty(Mediator.CTX_QPLAN);
    // This one must have A -> B
    Assert.assertEquals(1, qplan.getSources().length);
    Assert.assertEquals("A", qplan.getSources()[0].getMetadata().getName());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:15,代码来源:CompositeFinderTest.java

示例12: assocTestProjection_369

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void assocTestProjection_369() throws Exception {
    FindRequest fr = new FindRequest();
    fr.setQuery(query("{'field':'A.*.objectType','op':'=','rvalue':'jA'}"));
    fr.setProjection(projection("[{'field':'A.*','recursive':1}]"));
    fr.setEntityVersion(new EntityVersion("jB", "1.0.1-SNAPSHOT"));

    Response response = mediator.find(fr);
    System.out.println(response.getEntityData());
    Assert.assertEquals(2, response.getEntityData().size());
    Assert.assertNull(JsonDoc.get(response.getEntityData().get(0), new Path("_id")));
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:13,代码来源:CompositeFinderTest.java

示例13: retrieveAandBonly_defaultVersion

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
public void retrieveAandBonly_defaultVersion() throws Exception {
    FindRequest fr = new FindRequest();
    fr.setQuery(query("{'field':'_id','op':'=','rvalue':'A01'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'b'}]"));
    fr.setEntityVersion(new EntityVersion("A_def", "1.0.0"));
    Response response = mediator.find(fr);
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertEquals("A01", response.getEntityData().get(0).get("_id").asText());
    QueryPlan qplan = (QueryPlan) getLastContext(mediator).getProperty(Mediator.CTX_QPLAN);
    // This one must have A -> B
    Assert.assertEquals(1, qplan.getSources().length);
    Assert.assertEquals("A_def", qplan.getSources()[0].getMetadata().getName());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:14,代码来源:CompositeFinderTest.java

示例14: retrieveNestedArrayRef_reversed

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
@Test
public void retrieveNestedArrayRef_reversed() throws Exception {
    FindRequest fr = new FindRequest();
    fr.setQuery(query("{'field':'level1.arr1.*.ref.*.field1','op':'=','rvalue':'bdeep1'}"));
    fr.setProjection(projection("[{'field':'*','recursive':1},{'field':'level1.arr1.*.ref'}]"));
    fr.setEntityVersion(new EntityVersion("A", "1.0.0"));
    Response response = mediator.find(fr);
    Assert.assertEquals(1, response.getEntityData().size());
    Assert.assertEquals("ADEEP", response.getEntityData().get(0).get("_id").asText());
    Assert.assertEquals("BDEEP1", JsonDoc.get(response.getEntityData().get(0), new Path("level1.arr1.0.ref.0._id")).asText());
    Assert.assertEquals("BDEEP2", JsonDoc.get(response.getEntityData().get(0), new Path("level1.arr1.1.ref.0._id")).asText());
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:13,代码来源:CompositeFinderTest.java

示例15: getSavedSearchFromDB

import com.redhat.lightblue.crud.FindRequest; //导入方法依赖的package包/类
/**
 * Retrieves a saved search from the database. 
 *
 * @param m Mediator instance
 * @param clid The client id
 * @param searchName name of the saved search
 * @param entit Name of the entity
 * @param version Entity version the search should run on
 * 
 * The returned JsonNode can be an ObjectNode, or an ArrayNode
 * containing zero or more documents. If there are more than one
 * documents, only one of them is for the requested version, and
 * the other is for the null version that applies to all
 * versions. It returns null or empty array if nothing is found.
 * In case of retrieval error, a RetrievalError is thrown
 * containing the errors.
 */
public JsonNode getSavedSearchFromDB(Mediator m,
                                     ClientIdentification clid,
                                     String searchName,
                                     String entity,
                                     String version) {
    
    FindRequest findRequest=new FindRequest();
    findRequest.setEntityVersion(new EntityVersion(savedSearchEntity,savedSearchVersion));
    findRequest.setClientId(clid);
    List<Value> versionList=new ArrayList<>(2);
    versionList.add(NULL_VALUE);
    // Include all segments of the version in the search list
    if(version!=null) {
        int index=0;
        while((index=version.indexOf('.',index))!=-1) {
            versionList.add(new Value(version.substring(0,index)));
            index++;
        }
        versionList.add(new Value(version));
    }
    QueryExpression q=new NaryLogicalExpression(NaryLogicalOperator._and,
                                                new ValueComparisonExpression(P_NAME,
                                                                              BinaryComparisonOperator._eq,
                                                                              new Value(searchName)),
                                                new ValueComparisonExpression(P_ENTITY,
                                                                              BinaryComparisonOperator._eq,
                                                                              new Value(entity)),
                                                new ArrayContainsExpression(P_VERSIONS,
                                                                            ContainsOperator._any,
                                                                            versionList));
    LOGGER.debug("Searching {}",q);
    findRequest.setQuery(q);
    findRequest.setProjection(FieldProjection.ALL);
    Response response=m.find(findRequest);
    if(response.getErrors()!=null&&!response.getErrors().isEmpty())
        throw new RetrievalError(response.getErrors());
    LOGGER.debug("Found {}",response.getEntityData());
    return response.getEntityData();
}
 
开发者ID:lightblue-platform,项目名称:lightblue-core,代码行数:57,代码来源:SavedSearchCache.java


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