2 Replies Latest reply: May 9, 2013 3:19 AM by Jonathan.Knight RSS

    Querying cache data using EqualsFilter not workng using cache object getter

    1007895
      HI,

      My cache object structure is like this
      public class AccountTransactions implements Serializable{
      protected FICustomerId fiCustomerId;
      protected IdType fiId;

      public FICustomerId getFiCustomerId() {
      return fiCustomerId;
      }

      public void setFiCustomerId(FICustomerId value) {
      this.fiCustomerId = value;
      }

      public IdType getFiId() {
      return fiId;
      }
      public void setFiId(IdType value) {
      this.fiId = value;
      }
      }

      public class FICustomerId
      extends IdType
      implements Serializable{
      }
      public class IdType
      implements Serializable{
      protected String value;

      public String getValue() {
      return value;
      }

      public void setValue(String value) {
      this.value = value;
      }
      }

      I am storing AccountTransactions object in cache and try to retrieve them later using below code

      NamedCache cache = CacheFactory.getCache(CACHE_NAME);
      cache.addIndex(new ReflectionExtractor("getFiCustomerId.getValue"),false,null);
      cache.addIndex(new ReflectionExtractor("getFiId.getValue"),false,null);

      Filter userFilter = new EqualsFilter("getFiCustomerId.getValue", 'MEM01');
      Filter fiFilter = new EqualsFilter("getFiId.getValue", 'DIT01' );

      AndFilter fiAndUserIdFilter = new AndFilter(userFilter,fiFilter);
      Iterator historyCacheIterator = cache.entrySet(fiAndUserIdFilter).iterator();

      Always I get the set as null. If I try to get using fiFilter, it is working fine. But If try with userFilter, it is givign null.
      I am suspecting some issue with object structure of FICustomer Id.

      Need your help to resolve this issue. Any help is highly appreciated.
        • 1. Re: Querying cache data using EqualsFilter not workng using cache object getter
          Rock Ching-Oracle
          Use ChainedExtractor instead of ReflectionExtractor.

          Regards,
          Rock (Oracle ACS)
          • 2. Re: Querying cache data using EqualsFilter not workng using cache object getter
            Jonathan.Knight
            Hi,

            I am pretty sure that using ChainedExtractor rather than ReflectionExtractor is not your problem.

            First, Rock is correct that you are using the wrong extractor to create your index
            cache.addIndex(new ReflectionExtractor("getFiCustomerId.getValue"),false,null);
            cache.addIndex(new ReflectionExtractor("getFiId.getValue"),false,null);
            The lines above will try to use methods called AccountTransactions.getFiCustomerId.getValue() and AccountTransactions.getFiId.getValue() which is obviously wrong. ReflectionExtractor does not support dot notation in method names so as Rock says you should use ChainedExtractor
            cache.addIndex(new ChainedExtractor("getFiCustomerId.getValue"),false,null);
            cache.addIndex(new ChainedExtractor("getFiId.getValue"),false,null);
            This means that the indexes will be broken, but this should not affect your query.

            So, as I said, that is not the cause of your problem.

            Using the code you posted above I ran this test...
            public static void main(String[] args) {
                AccountTransactions transactions = new AccountTransactions();
                FICustomerId fiCustomerId = new FICustomerId();
                fiCustomerId.setValue("MEM01");
            
                IdType id = new IdType();
                id.setValue("DIT01");
            
                transactions.setFiCustomerId(fiCustomerId);
                transactions.setFiId(id);
            
                Filter userFilter = new EqualsFilter("getFiCustomerId.getValue", "MEM01");
                Filter fiFilter = new EqualsFilter("getFiId.getValue", "DIT01" );
            
                AndFilter fiAndUserIdFilter = new AndFilter(userFilter,fiFilter);
            
                System.out.println(userFilter.evaluate(transactions));
                System.out.println(fiFilter.evaluate(transactions));
                System.out.println(fiAndUserIdFilter.evaluate(transactions));
            }
            which printed out...
            true
            true
            true
            ...so there is nothing wrong with the code.

            When you say that "Always I get the set as null" presumably you mean the call to cache.entrySet() returns an empty set, not that it returns null.

            It might sound like a stupid question, but are you sure you are actually putting AccountTransactions into the cache that have the values matching the filters?

            JK