コード例 #1
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
 /** CMS-2935 */
 @Test
 public void testSub_CMS2935_03() {
   String query =
       "ServiceInstance[@_oid =& ServiceInstance[@name=~\"srp-app.*\"]{@_oid}.runsOn[@name=\"compute-00002\"]]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertEquals(1, result.getEntities().size());
   for (IEntity entity : result.getEntities()) {
     Assert.assertEquals("ServiceInstance", entity.getType());
   }
 }
コード例 #2
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
  @Test
  public void testSub04WithSetUnion() {
    String query =
        "Environment[@applications =& ApplicationService{*}.(services[@name=~\"srp-app.*\"] || updateStrategies[@name=\"1-100\"])]";
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertTrue(result.getEntities().size() == 1);

    for (IEntity entity : result.getEntities()) {
      Assert.assertEquals("Environment", entity.getType());
    }
  }
コード例 #3
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
  @Test
  public void testSub_CMS2935_02() {
    String query =
        "Environment[@applications =& ServiceInstance.(appService{*} && runsOn[@_oid=\"4fbb314fc681caf13e283a7b\"])]";
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertTrue(result.getEntities().size() == 1);

    for (IEntity entity : result.getEntities()) {
      Assert.assertEquals("Environment", entity.getType());
    }
  }
コード例 #4
0
 @SuppressWarnings("unchecked")
 private void addSearchResult(IEntity entity, ISearchField projectField) {
   String fieldName = projectField.getFieldName();
   if (isRelationshipField(projectField)) {
     // CMS-3430 : treat a projection of relationship field as
     // project on the reference oid
     List<IEntity> projectFieldValues = (List<IEntity>) entity.getFieldValues(fieldName);
     for (IEntity e : projectFieldValues) {
       rootProjections.add(e.getId());
     }
   } else {
     rootProjections.addAll(projectField.getSearchValue(entity));
   }
 }
コード例 #5
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
 @Test
 public void testSub05NonRef() {
   // sub query on non-
   String query =
       "Environment[@_status =& ApplicationService{@_status}.(services[@name=~\"srp-app.*\"] && updateStrategies[@name=\"1-100\"])]";
   raptorContext.setAllowFullTableScan(true);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertTrue(result.getEntities().size() == 1);
   for (IEntity entity : result.getEntities()) {
     Assert.assertEquals("Environment", entity.getType());
   }
 }
コード例 #6
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
  @Test
  public void testSub05NonRef_fieldProperty() {
    MetaClass metaClass = raptorMetaService.getMetaClass("ApplicationService");
    IEntity newApp = new JsonEntity(metaClass);
    newApp.setBranchId(IBranch.DEFAULT_BRANCH);
    newApp.addFieldValue("name", generateRandomName("cms3430-test"));

    EntityContext context = newEntityContext();
    String id = entityService.create(newApp, context);
    newApp.setId(id);

    String query =
        "Environment.applications[@services.$_length =& ApplicationService{@services.$_length}]";
    raptorContext.setHint(-1);
    raptorContext.setAllowFullTableScan(true);
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertEquals(1, result.getEntities().size());

    entityService.delete(newApp, context);
  }
コード例 #7
0
ファイル: SubQueryTest.java プロジェクト: RalphSu/yi-ms
  @Test
  public void testSub03() {
    String sub =
        "ServiceInstance[@name=~\"srp-app.*\" and @runsOn =& Compute[@name=~\"compute-0000.*\"]]";

    IQueryResult result = queryService.query(sub, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertEquals(8, result.getEntities().size());

    // the service instance that have no compute attached
    String notIn1 = "4fbb314fc681caf13e283a7a";
    // the service instance that have compute name as compute-00010 (not match the regex).
    String notIn2 = "4fbb314fc681caf13e283a8c";
    for (IEntity entity : result.getEntities()) {
      Assert.assertEquals("ServiceInstance", entity.getType());
      Assert.assertFalse(entity.getId().equals(notIn1));
      Assert.assertFalse(entity.getId().equals(notIn2));
    }
  }
コード例 #8
0
  @Override
  @SuppressWarnings("unchecked")
  public void processReference(IEntity currentEntity, MetaRelationship metaRelationship) {
    ParseQueryNode oldPrevQueryNode = prevQueryNode;
    ParseQueryNode oldCurrQueryNode = currQueryNode;

    String relationName = metaRelationship.getName();
    List<ParseQueryNode> nextNodes = currQueryNode.getNextQueryNode(metaRelationship);

    for (ParseQueryNode nextNode : nextNodes) {
      prevQueryNode = currQueryNode;
      currQueryNode = nextNode;

      List<IEntity> relationEntityList = (List<IEntity>) currentEntity.getFieldValues(relationName);
      for (IEntity entity : relationEntityList) {
        entity.traverse(this);
      }

      prevQueryNode = oldPrevQueryNode;
      currQueryNode = oldCurrQueryNode;
    }
  }