This discussion is archived
7 Replies Latest reply: Feb 19, 2013 12:07 PM by 798480 RSS

ContainsAllFilter on array property and GreaterFilter on DateTime property

892908 Newbie
Currently Being Moderated
I am very new to Coherence, trying to learn... We're using Coherence 3.7, and trying to get ContainsAllFilter on string[] property and GreaterFilter on DateTime to work. Java side implements hashCode (using Arrays.equals and RawDateTime) and equals on my POF; dotnet side also implements GetHashCode and Equals; in both cases, filters return with 0 result collection. What am I doing wrong? Thank you very much!
  • 1. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    user738616 Pro
    Currently Being Moderated
    Hi,

    It should work ! Post your java object class, serialization methods and your sample test code.

    Cheers,
    NJ
  • 2. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    892908 Newbie
    Currently Being Moderated
    Thank you very much for helping me on this!

    JAVA SIDE:

    /**
    * The Test class
    */
    public class Test
    extends Base
    implements PortableObject
    {
    // ----- constructors ---------------------------------------------------

    public Test()
    {}


    private RawDateTime m_dtComparableProp;
    public RawDateTime getComparableProp() {
         return m_dtComparableProp;
    }
    public void setComparableProp(RawDateTime ComparableProp) {
         m_dtComparableProp = ComparableProp;
    }

    private String[] m_arrStringArrProp;
    public String[] getStringArrProp() {
         return m_arrStringArrProp;
    }
    public void setStringArrProp(String[] StringArrProp) {
         m_arrStringArrProp = StringArrProp;
    }

    public void readExternal(PofReader reader)
         throws IOException {

         reader.readObjectArray(0, m_arrStringArrProp);
         setComparableProp(reader.readRawDateTime(1));
    }

    public void writeExternal(PofWriter writer)
              throws IOException {

         writer.writeObjectArray(0,getStringArrProp());
         writer.writeRawDateTime(1, getComparableProp());
    }


    DOTNET SIDE:

    public class Test : IPortableObject
    {
    public string[] StringArrProp { get; set; }
    public DateTime ComparableProp { get; set; }

    public void ReadExternal(IPofReader reader)
    {
    StringArrProp = (reader.ReadCollection<string>(0, new List<string>()) as List<string>).ToArray();
    ComparableProp = reader.ReadDateTime(1);
    }

    public void WriteExternal(IPofWriter writer)
    {
    if (null != StringArrProp && StringArrProp.Length>0)
    writer.WriteCollection<string>(0, StringArrProp);
    writer.WriteDateTime(1,ComparableProp);
    }
    }


    TEST:

    INamedCache nc = CacheFactory.GetCache("cachename");

    nc.Clear();

    Test x = new Test();
    DateTime now = DateTime.Now;
    x.ComparableProp = now;
    x.StringArrProp = new string[] { "Prop1", "Prop2" };
    nc.Insert("Key", x);

    int cnt = nc.Count;

    object retr = nc["Key"];

    //// the above works fine, but the following both return zero items

    ContainsAllFilter caf = new ContainsAllFilter("getStringArrProp", x.StringArrProp);
    var mmm = nc.GetValues(caf);
    EqualsFilter dtf = new EqualsFilter("getComparableProp", x.ComparableProp);
    var rrr = nc.GetValues(dtf);

    Edited by: 889905 on Oct 14, 2011 10:15 AM
  • 3. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    798480 Newbie
    Currently Being Moderated
    Did you get this working for your DateTime problem? I am having a similar issue with the DateTime filtering in that it is NOT filtering at all. Thanks and any advice would be most appreciated.
  • 4. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    user639604 Journeyer
    Currently Being Moderated
    I checked the JavaDoc of RawDateTime, doesn't look like it implement Comparable interface. This might be why the GreatFilter is not working if you are using RawDateTime on Java side.

    You might want to try use the toSqlTimestamp() of the RawDatTime object since java.sql.Timestamp implement Comparable interface.

    If possible, please post the Java side implementation of your business object.
  • 5. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    798480 Newbie
    Currently Being Moderated
    Thanks for the response. I have included my Java object below.....where in this would I convert to the SQL Timestamp? Do you mean, that I would be storing the SQLTimestamp rather than RawDateTime as part of this object?
    public class RflxJournalEntry implements PortableObject {
    
         public RflxJournalEntry(){}
         
         public enum JournalOperation
         {
              INSERT,UPDATE,DELETE;
         }
    
         private JournalOperation operationType; 
        private RawDateTime operationTime;
         private String process;
         private String version;
         private String username;
         private String tradeId;
        private int sequenceId;
         private RflxJournaledTrade updateList;
        private RflxTrade trade;
         
         @SuppressWarnings("unchecked")
         @Override
         public void readExternal(PofReader reader) throws IOException {
              setOperationType(reader.readInt(0));
              setOperationTime(reader.readRawDateTime(1));
              setProcess(reader.readString(2));
              setUsername(reader.readString(3));
              setTradeId(reader.readString(4));
              setSequenceId(reader.readInt(5));
              setUpdateList((RflxJournaledTrade)reader.readObject(6));
              setTrade((RflxTrade)reader.readObject(7));
              setVersion(reader.readString(8));
         }
    
         @Override
         public void writeExternal(PofWriter writer) throws IOException {
            writer.writeInt(0, getOperationType());
            writer.writeRawDateTime(1, getOperationTime());
            writer.writeString(2, getProcess());
            writer.writeString(3, getUsername());
            writer.writeString(4, getTradeId());
            writer.writeInt(5, getSequenceId());
            writer.writeObject(6, getUpdateList());
            writer.writeObject(7, getTrade());
            writer.writeString(8, getVersion());
         }
    
         public void setOperationType(int operationType) {
              this.operationType = RflxJournalEntry.JournalOperation.values()[operationType];
         }
    
         public int getOperationType() {
              return operationType.ordinal();
         }
    
         public void setProcess(String process) {
              this.process = process;
         }
    
         public String getProcess() {
              return process;
         }
    
         public void setUsername(String username) {
              this.username = username;
         }
    
         public String getUsername() {
              return username;
         }
    
         public void setTradeId(String tradeId) {
              this.tradeId = tradeId;
         }
    
         public String getTradeId() {
              return tradeId;
         }
    
         public void setOperationTime(RawDateTime operationTime) {
              this.operationTime = operationTime;
         }
    
         public RawDateTime getOperationTime() {
              return operationTime;
         }
    
         public void setSequenceId(int sequenceId) {
              this.sequenceId = sequenceId;
         }
    
         public int getSequenceId() {
              return sequenceId;
         }
    
         public void setUpdateList(RflxJournaledTrade updateList) {
              this.updateList = updateList;
         }
    
         public RflxJournaledTrade getUpdateList() {
              return updateList;
         }
    
         public void setTrade(RflxTrade trade) {
              this.trade = trade;
         }
    
         public RflxTrade getTrade() {
              return trade;
         }
    
         public void setVersion(String version) {
              this.version = version;
         }
    
         public String getVersion() {
              return version;
         }
    }
  • 6. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    user639604 Journeyer
    Currently Being Moderated
    I assume that you were using "getOperationTime", then most likely it not going to work.

    The safer approach is to compare long.

    So in your Java implementation, you can add another method like getTime() like this.

    public long getTime() {
    // Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
    return operationTime.toSqlTimestamp().getTime();
    }

    Then when you invoke the filter on your .NetClient side, just pass the desired long value and use the "getTime" for the filter.
  • 7. Re: ContainsAllFilter on array property and GreaterFilter on DateTime property
    798480 Newbie
    Currently Being Moderated
    Not sure what is wrong but I did just what you said, added the Java method exactly as you had and then used:
    var journalEntriesFrom = DateTime.UtcNow - timeSpan;
    var msFromEpoch = (long) (journalEntriesFrom - EPOCH).TotalMilliseconds;
    var reflectionTimeExtractor = new ReflectionExtractor("getTime");
    filter = new AndFilter(new GreaterEqualsFilter(reflectionTimeExtractor, msFromEpoch), filter);
    The filter does work as the 2nd operator of the And filter is giving me the trades I need to see but this set should then be further filtered by the time constraint.

    STRANGE!

    As a temporary workaround I am now storing the datetime as a double (OLE format) and using this in the filter and this is working fine.

    Edited by: Kunal on Feb 19, 2013 8:06 PM - added variable definition.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points