1 Reply Latest reply on Dec 13, 2007 8:47 AM by Jason Greene

    Pojo doesn't get replicated in datastore

    Damien Newbie

      Hi,

      I've got a POJO which contains another POJO extends an ArrayList and when I put in cache, it store in datastore only the POJO which extends ArrayList but not its child elements.
      If I use directly an ArrayList, it works like a charm.

      Here is the code :

      @PojoCacheable
      public class SimpleCircularBuffer<T> extends ArrayList<T> {
      
       private int capacity;
      
       public SimpleCircularBuffer() {
       super(1);
       this.capacity = 1;
       }
      
       /**
       * @param capacity
       */
       public SimpleCircularBuffer(int capacity) {
       super(capacity);
       this.capacity = capacity;
       }
      
       public boolean add(T o) {
       if (this.capacity == this.size())
       super.remove(this.size() - 1);
       // super.poll();
       super.add(o);
       return true;
       }
      
       public int getCapacity() {
       return this.capacity;
       }
      
       public void setCapacity(int capacity) {
       this.capacity = capacity;
       }
      }
      


        • 1. Re: Pojo doesn't get replicated in datastore
          Jason Greene Master

          This is an Interesting use case. It poses a problem because with inheritance, field changes can, and in this case are performed by the code in the super class. This is normally solved by instrumenting the super class as well. However, with JDK collection types, we can not redefine them, since they are on the bootclasspath, and thus would violate the JRE license. So for those types proxies are used. The proxies only follow the collection interfaces, so any additional state can't be stored. Perhaps an extendable type handler system is needed, that would you to customize how a type is stored in the cache. I will look at that as a future enhancement.

          For now you should be able to work around this problem, by using delegation instead of inheritance. Try modifying SimpleCircularBuffer to implement List, and then add a field which is an ArrayList, which you delegate all calls too (with the exception of your additional methods)

          Let me know your findings. Thanks.