Package org.infinispan.objectfilter

Examples of org.infinispan.objectfilter.Matcher


   }


   @Test
   public void testObjectFilterWithDSL() throws Exception {
      Matcher matcher = createMatcher();
      Object person = createPerson1();

      QueryFactory qf = matcher.getQueryFactory();
      Query q = qf.from(Person.class)
            .having("name").eq("John").toBuilder().build();

      ObjectFilter objectFilter = matcher.getObjectFilter(q);

      ObjectFilter.FilterResult result = objectFilter.filter(person);
      assertNotNull(result);
      assertTrue(result.getInstance() == person);
   }
View Full Code Here


   @Test
   public void testUnregistration() throws Exception {
      String queryString = "from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";

      Matcher matcher = createMatcher();
      Object person = createPerson1();

      final int matchCount[] = new int[1];
      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
            matchCount[0]++;
         }
      });

      matcher.match(person);

      assertEquals(1, matchCount[0]);

      matcher.unregisterFilter(filterSubscription);
      matcher.match(person);

      // check that unregistration really took effect
      assertEquals(1, matchCount[0]);
   }
View Full Code Here

   @Test
   public void testProjections() throws Exception {
      String queryString = "select p.name, p.address.postCode from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";

      Matcher matcher = createMatcher();
      Object person = createPerson1();

      final List<Object[]> result = new ArrayList<Object[]>();

      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
            result.add(projection);
         }
      });

      assertNotNull(filterSubscription.getProjection());
      assertEquals(2, filterSubscription.getProjection().length);
      assertEquals("name", filterSubscription.getProjection()[0]);
      assertEquals("address.postCode", filterSubscription.getProjection()[1]);

      matcher.match(person);

      matcher.unregisterFilter(filterSubscription);

      assertEquals(1, result.size());
      assertEquals(2, result.get(0).length);
      assertEquals("John", result.get(0)[0]);
      assertEquals("SW12345", result.get(0)[1]);
View Full Code Here

   @Test
   public void testDuplicateProjections() throws Exception {
      String queryString = "select p.name, p.name, p.address.postCode from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";

      Matcher matcher = createMatcher();
      Object person = createPerson1();

      final List<Object[]> result = new ArrayList<Object[]>();

      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
            result.add(projection);
         }
      });

      assertNotNull(filterSubscription.getProjection());
      assertEquals(3, filterSubscription.getProjection().length);
      assertEquals("name", filterSubscription.getProjection()[0]);
      assertEquals("name", filterSubscription.getProjection()[1]);
      assertEquals("address.postCode", filterSubscription.getProjection()[2]);

      matcher.match(person);

      matcher.unregisterFilter(filterSubscription);

      assertEquals(1, result.size());
      assertEquals(3, result.get(0).length);
      assertEquals("John", result.get(0)[0]);
      assertEquals("John", result.get(0)[1]);
View Full Code Here

   @Test
   public void testProjectionOnRepeatedAttribute() throws Exception {
      String queryString = "select p.address.postCode, p.phoneNumbers.number from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";

      Matcher matcher = createMatcher();
      Object person = createPerson1();

      final List<Object[]> result = new ArrayList<Object[]>();

      FilterSubscription filterSubscription = matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
            result.add(projection);
         }
      });

      assertNotNull(filterSubscription.getProjection());
      assertEquals(2, filterSubscription.getProjection().length);
      assertEquals("address.postCode", filterSubscription.getProjection()[0]);
      assertEquals("phoneNumbers.number", filterSubscription.getProjection()[1]);

      matcher.match(person);

      matcher.unregisterFilter(filterSubscription);

      assertEquals(1, result.size());
      assertEquals(2, result.get(0).length);
      assertEquals("SW12345", result.get(0)[0]);
      //todo [anistor] it is unclear what whe should expect here...
View Full Code Here

      expectedException.expect(ParsingException.class);
      expectedException.expectMessage("ISPN000405");

      String queryString = "select p.phoneNumbers from org.infinispan.objectfilter.test.model.Person p";

      Matcher matcher = createMatcher();

      matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
         }
      });
   }
View Full Code Here

      long time = measureMatch("from org.infinispan.objectfilter.test.model.Person p where p.surname = 'Batman' and p.age > 30 and p.name > 'A' and p.address.postCode = 'SW12345'");
      printTime("testComplexMatchPerf", time);
   }

   protected long measureMatch(String query) throws Exception {
      Matcher matcher = createMatcher();

      Object obj = createPerson1();

      final int[] matchCount = new int[1];

      for (int k = 0; k < NUM_FILTERS; k++) {
         matcher.registerFilter(query, new FilterCallback() {
            @Override
            public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
               matchCount[0]++;
            }
         });
      }

      long stime = System.nanoTime();
      for (int i = 0; i < ITERATIONS; i++) {
         matchCount[0] = 0;
         matcher.match(obj);
         assertEquals(NUM_FILTERS, matchCount[0]);
      }
      return System.nanoTime() - stime;
   }
View Full Code Here

      long time = measureFilter("from org.infinispan.objectfilter.test.model.Person p where p.surname = 'Batman' and p.age > 30 and p.name > 'A' and p.address.postCode = 'SW12345'");
      printTime("testComplexObjectFilterPerf", time);
   }

   protected long measureFilter(String query) throws Exception {
      Matcher matcher = createMatcher();

      Object obj = createPerson1();

      ObjectFilter objectFilter = matcher.getObjectFilter(query);

      long stime = System.nanoTime();
      for (int i = 0; i < ITERATIONS; i++) {
         ObjectFilter.FilterResult result = objectFilter.filter(obj);
         assertNotNull(result);
View Full Code Here

         }
      });

      // create a sub-matcher with a single filter
      final int[] matchCount2 = new int[1];
      Matcher subMatcher = matcher.getSingleFilterMatcher(filterSubscription, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, boolean isMatching) {
            if (isMatching) {
               matchCount2[0]++;
            }
         }
      });

      matcher.match(person);
      assertEquals(1, matchCount[0]);
      assertEquals(0, matchCount2[0]);

      subMatcher.match(person);
      assertEquals(1, matchCount[0]);
      assertEquals(1, matchCount2[0]);
   }
View Full Code Here

   }

   protected abstract Matcher createMatcher();

   protected boolean match(String queryString, Object obj) throws Exception {
      Matcher matcher = createMatcher();

      final int[] matchCount = new int[1];

      matcher.registerFilter(queryString, new FilterCallback() {
         @Override
         public void onFilterResult(Object instance, Object[] projection, Comparable[] sortProjection) {
            matchCount[0]++;
         }
      });

      matcher.match(obj);
      return matchCount[0] == 1;
   }
View Full Code Here

TOP

Related Classes of org.infinispan.objectfilter.Matcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.