4 Replies Latest reply: Mar 27, 2013 7:56 AM by 998703 RSS

    Enum value displays different results with different query patterns

    998703
      Hi ,

      We are using 3.7.1.0 version of coherence , We have stored a DTO in coherence which contains enum values,

      This enum value returns differnt values with differnt queries and has random behaviour

      Sometimes if we query displaystatus value using cohql tool , it returns the default value as shown below

      COHQL Query
      select displayStatus.status from events where id='216923764'
      Results
      NotDisplayed

      Comment :Above query is returning incorrect results

      However since we have overridden the toString method of EventCacheDTO , hence if we directly query all attributes , it displays the following correct result as shown below

      select * from events where id='216923764'
      Results
      EventCacheDTO [displayStatus=DISPLAYED,id=4805]

      Comment :Correct results

      Further if we use API eventCacheDTO.getDisplayStatus().getStatus() it retuns correct values

      Can you please provide us the reason of this inconsistent behavior with different query .

      Also P.S :The above behavior is not consistent and is random for some data set, i am not sure why above behaviour is impacting few data set and is working proerly for rest.

      Below is the DTO structure

      public class EventCacheDTO extends AbstractEvolvable implements EvolvablePortableObject {

      /** The Constant DISPLAY_STATUS. */
      private static final int DISPLAY_STATUS = 1;
      /** The Constant IDENTIFIER. */
      private static final int IDENTIFIER = 0;

      /** The display status. */
      private CacheDisplayStatus displayStatus;
           
           /** The id. */
      private E id;

      /**
      * Gets the display status.
      * @return the displayStatus
      */
      public CacheDisplayStatus getDisplayStatus() {
      return displayStatus;
      }

      /**
      * Sets the display status.
      * @param displayStatus
      * the displayStatus to set
      */
      public void setDisplayStatus(final CacheDisplayStatus displayStatus) {
      this.displayStatus = displayStatus;
      }
           
           /**
      * Gets the id.
      *
      * @return the id
      */
      public E getId() {
      return id;
      }

      /**
      * Sets the id.
      *
      * @param id
      * the new id
      */
      public void setId(final E id) {
      this.id = id;
      }

      /**
      * Hash code.
      * @return the int
      * @see java.lang.Object#hashCode()
      */
      @Override
      public int hashCode() {
      return getId().hashCode();
      }

      /**
      * Equals.
      * @param obj
      * the obj
      * @return true, if successful
      * @see java.lang.Object#equals(java.lang.Object)
      */
      @Override
      public boolean equals(final Object obj) {
      if (null == obj) {
      return false;
      } else if (obj instanceof EventCacheDTO) {
      return getId().equals(((EventCacheDTO) obj).getId());
      } else {
      return false;
      }
      }


      /**
      * Read external.
      * @param reader
      * the reader
      * @throws IOException
      * Signals that an I/O exception has occurred.
      * @see com.ladbrokes.dtos.cache.AbstractCacheDTO#readExternal(com.tangosol.io .pof.PofReader)
      */
      @Override
      public void readExternal(final PofReader reader) throws IOException {
      super.readExternal(reader);
           id = (E) reader.readObject(IDENTIFIER);
      final String tempDisplayStatus = reader.readString(DISPLAY_STATUS);

      if (null != tempDisplayStatus) {

      displayStatus = CacheDisplayStatus.valueOf(CacheDisplayStatus.class, tempDisplayStatus);
      }

      }

      /**
      * Write external.
      * @param writer
      * the writer
      * @throws IOException
      * Signals that an I/O exception has occurred.
      * @see com.ladbrokes.dtos.cache.AbstractCacheDTO#writeExternal(com.tangosol. io.pof.PofWriter)
      */
      @Override
      public void writeExternal(final PofWriter writer) throws IOException {
      super.writeExternal(writer);
      writer.writeObject(IDENTIFIER, id);

      if (null != displayStatus) {
      writer.writeString(DISPLAY_STATUS, displayStatus.name());
      }

      }

      /**
      * @return string.
      */
      @Override
      public String toString() {
      return "EventCacheDTO [ displayStatus=" + displayStatus + ", id=" + id "]";
      }

      }

      The above class contains an Enum CacheDisplayStatus which has following values

      /** The displayed. */
      DISPLAYED("Displayed"), /** The notdisplayed. */
      NOTDISPLAYED("NotDisplayed");



      Please provide your help.

      Regards,
      Mehak

      Edited by: 995700 on Mar 26, 2013 10:27 AM
        • 1. Re: Enum value displays different results with different query patterns
          Jonathan.Knight
          Hi Mehak,

          What class are you using for your ID?

          I am a bit confused about this bit in your post...
          995700 wrote:
          select * from events where id='216923764'
          Results
          EventCacheDTO [displayStatus=DISPLAYED,id=4805]

          Comment :Correct results
          You say that the result is correct but it seems that you have queried for somthing with ID = 216923764 but you have retrieved something with ID = 4805 which does not seem correct to me.

          JK
          • 2. Re: Enum value displays different results with different query patterns
            998703
            Hi Jonathan,

            I am using EventCacheDTO for ID,

            I had by mistake written ID =4805

            Ideally when i query

            select * from events where id='216923764'
            Results
            EventCacheDTO [displayStatus=DISPLAYED,id=216923764]

            Regards,
            Mehak
            • 3. Re: Enum value displays different results with different query patterns
              Jonathan.Knight
              Hi Mehak,
              995700 wrote:
              I am using EventCacheDTO for ID,
              So you are saying that the cache contains EventCacheDTO objects and the id field of an EventCacheDTO is another EventCacheDTO? That does not seem to make sense and does not match what you already posted..

              What is the class of the value in this field (which looks to me like it is using generics but the class declaration is not generic)
              /** The id. */
              private E id;
              What type is "E"?

              JK
              • 4. Re: Enum value displays different results with different query patterns
                998703
                Hi Jonathan,

                Actually i had taken this snippet from the original Design,

                I will re-summarize the actual DTO structure to avoid any confusion

                We have a DTO with Name EventCacheDTO and below is the structure



                public class EventCacheDTO extends AbstractCacheDTO<String> {

                /** The Constant STATUS. */
                private static final int STATUS = 3;

                /** The Constant DISPLAY_STATUS. */
                private static final int DISPLAY_STATUS = 4;

                /** The Constant SCORE_DATA. */
                private static final int SCORE_DATA = 5;

                /** The Constant EVENT_FINISHED. */
                private static final int EVENT_FINISHED = 6;

                /** The Constant DISPLAY_STATUS_SEQ_ID. */
                private static final int DISPLAY_STATUS_MESSAGE_ID = 7;

                /** The Constant STATUS_SEQ_ID. */
                private static final int STATUS_MESSAGE_ID = 8;

                /** The Constant STATUS_SEQ_ID. */
                private static final int SCORE_MESSAGE_ID = 9;

                /** The Constant EVENT_ClASS_ID. */
                private static final int EVENT_CLASS_ID = 10;

                /** The Constant EVENT_TYPE_ID. */
                private static final int EVENT_TYPE_ID = 11;

                /** The Constant EVENT_SUB_TYPE_ID. */
                private static final int EVENT_SUB_TYPE_ID = 12;

                /** The status. */
                private CacheActivationStatus status;

                /** The display status. */
                private CacheDisplayStatus displayStatus;

                /** The score data. */
                private String scoreData;

                /** The event finished. */
                private boolean eventFinished;

                /** The display status seq id. */
                private long displayStatusMsgId;

                /** The status seq id. */
                private long statusMsgId;

                /** The status seq id. */
                private long scoreMsgId;

                /** The type eventClassID. */
                private String eventClassID;

                /** The eventTypeID. */
                private String eventTypeID;

                /** The eventSubTypeID. */
                private String eventSubTypeID;

                /**
                * Gets the status.
                * @return the status
                */
                public CacheActivationStatus getStatus() {
                return status;
                }

                /**
                * Sets the status.
                * @param status
                * the status to set
                */
                public void setStatus(final CacheActivationStatus status) {
                this.status = status;
                }

                /**
                * Gets the display status.
                * @return the displayStatus
                */
                public CacheDisplayStatus getDisplayStatus() {
                return displayStatus;
                }

                /**
                * Sets the display status.
                * @param displayStatus
                * the displayStatus to set
                */
                public void setDisplayStatus(final CacheDisplayStatus displayStatus) {
                this.displayStatus = displayStatus;
                }

                /**
                * Hash code.
                * @return the int
                * @see java.lang.Object#hashCode()
                */
                @Override
                public int hashCode() {
                return getId().hashCode();
                }

                /**
                * Equals.
                * @param obj
                * the obj
                * @return true, if successful
                * @see java.lang.Object#equals(java.lang.Object)
                */
                @Override
                public boolean equals(final Object obj) {
                if (null == obj) {
                return false;
                } else if (obj instanceof EventCacheDTO) {
                return getId().equals(((EventCacheDTO) obj).getId());
                } else {
                return false;
                }
                }

                /**
                * Sets the score data.
                * @param scoreData
                * the scoreData to set
                */
                public void setScoreData(final String scoreData) {
                this.scoreData = scoreData;
                }

                /**
                * Gets the score data.
                * @return the scoreData
                */
                public String getScoreData() {
                return scoreData;
                }

                /**
                * Checks if is event finished.
                * @return the eventFinished
                */
                public boolean isEventFinished() {
                return eventFinished;
                }

                /**
                * Sets the event finished.
                * @param eventFinished
                * the eventFinished to set
                */
                public void setEventFinished(final boolean eventFinished) {
                this.eventFinished = eventFinished;
                }

                /**
                * Read external.
                * @param reader
                * the reader
                * @throws IOException
                * Signals that an I/O exception has occurred.
                * @see com.ladbrokes.dtos.cache.AbstractCacheDTO#readExternal(com.tangosol.io .pof.PofReader)
                */
                @Override
                public void readExternal(final PofReader reader) throws IOException {
                super.readExternal(reader);

                final String tempStatus = reader.readString(STATUS);

                if (null != tempStatus) {

                status = CacheActivationStatus.valueOf(CacheActivationStatus.class, tempStatus);
                }

                final String tempDisplayStatus = reader.readString(DISPLAY_STATUS);

                if (null != tempDisplayStatus) {

                displayStatus = CacheDisplayStatus.valueOf(CacheDisplayStatus.class, tempDisplayStatus);
                }

                final String tempScoreData = reader.readString(SCORE_DATA);

                if (null != tempScoreData) {
                scoreData = tempScoreData;
                }

                eventFinished = reader.readBoolean(EVENT_FINISHED);
                displayStatusMsgId = reader.readLong(DISPLAY_STATUS_MESSAGE_ID);
                statusMsgId = reader.readLong(STATUS_MESSAGE_ID);
                scoreMsgId = reader.readLong(SCORE_MESSAGE_ID);
                eventClassID = reader.readString(EVENT_CLASS_ID);
                eventTypeID = reader.readString(EVENT_TYPE_ID);
                eventSubTypeID = reader.readString(EVENT_SUB_TYPE_ID);

                }

                /**
                * Write external.
                * @param writer
                * the writer
                * @throws IOException
                * Signals that an I/O exception has occurred.
                * @see com.ladbrokes.dtos.cache.AbstractCacheDTO#writeExternal(com.tangosol. io.pof.PofWriter)
                */
                @Override
                public void writeExternal(final PofWriter writer) throws IOException {
                super.writeExternal(writer);

                if (null != status) {
                writer.writeString(STATUS, status.name());
                }

                if (null != displayStatus) {
                writer.writeString(DISPLAY_STATUS, displayStatus.name());
                }
                if (null != scoreData) {
                writer.writeString(SCORE_DATA, scoreData);
                }

                writer.writeBoolean(EVENT_FINISHED, eventFinished);
                writer.writeLong(DISPLAY_STATUS_MESSAGE_ID, displayStatusMsgId);
                writer.writeLong(STATUS_MESSAGE_ID, statusMsgId);
                writer.writeString(EVENT_CLASS_ID, eventClassID);
                writer.writeString(EVENT_TYPE_ID, eventTypeID);
                writer.writeString(EVENT_SUB_TYPE_ID, eventSubTypeID);

                }

                /**
                * Gets the display status msg id.
                * @return the display status msg id
                */
                public long getDisplayStatusMsgId() {
                return displayStatusMsgId;
                }

                /**
                * Sets the display status msg id.
                * @param displayStatusMsgId
                * the new display status msg id
                */
                public void setDisplayStatusMsgId(final long displayStatusMsgId) {
                this.displayStatusMsgId = displayStatusMsgId;
                }

                /**
                * Gets the status msg id.
                * @return the status msg id
                */
                public long getStatusMsgId() {
                return statusMsgId;
                }

                /**
                * Sets the status msg id.
                * @param statusMsgId
                * the new status msg id
                */
                public void setStatusMsgId(final long statusMsgId) {
                this.statusMsgId = statusMsgId;
                }

                /**
                * Gets the score msg id.
                * @return the scoreMsgId
                */
                public long getScoreMsgId() {
                return scoreMsgId;
                }

                /**
                * Sets the score msg id.
                * @param scoreMsgId
                * the scoreMsgId to set
                */
                public void setScoreMsgId(final long scoreMsgId) {
                this.scoreMsgId = scoreMsgId;
                }

                /**
                * Gets the event class id.
                * @return the eventClassID
                */
                public String getEventClassID() {
                return eventClassID;
                }

                /**
                * Sets the event class id.
                * @param eventClassID
                * the eventClassID to set
                */
                public void setEventClassID(final String eventClassID) {
                this.eventClassID = eventClassID;
                }

                /**
                * Gets the event type id.
                * @return the eventTypeID
                */
                public String getEventTypeID() {
                return eventTypeID;
                }

                /**
                * Sets the event type id.
                * @param eventTypeID
                * the eventTypeID to set
                */
                public void setEventTypeID(final String eventTypeID) {
                this.eventTypeID = eventTypeID;
                }

                /**
                * Gets the event sub type id.
                * @return the eventSubTypeID
                */
                public String getEventSubTypeID() {
                return eventSubTypeID;
                }

                /**
                * Sets the event sub type id.
                * @param eventSubTypeID
                * the eventSubTypeID to set
                */
                public void setEventSubTypeID(final String eventSubTypeID) {
                this.eventSubTypeID = eventSubTypeID;
                }

                /**
                * @return string.
                */
                @Override
                public String toString() {
                return "EventCacheDTO [status=" + status + ", displayStatus=" + displayStatus + ", scoreData=" + scoreData
                            + ", eventFinished=" + eventFinished + ", displayStatusMsgId=" + displayStatusMsgId + ", statusMsgId="
                            + statusMsgId + ", scoreMsgId=" + scoreMsgId + ", eventClassID=" + eventClassID + ", eventTypeID="
                            + eventTypeID + ", eventSubTypeID=" + eventSubTypeID + "]";
                }

                }


                Further The Structure of parent DTO AbstractCacheDTO is

                public abstract class AbstractCacheDTO<E> extends AbstractEvolvable implements EvolvablePortableObject {
                /** The Constant IDENTIFIER. */
                private static final int IDENTIFIER = 0;

                /** The Constant CREATION_TIME. */
                private static final int CREATION_TIME = 1;

                /** The Constant MODIFICATION_TIME. */
                private static final int MODIFICATION_TIME = 2;

                /** The version number of cache DTO implementation. **/
                private static final int VERSION = 11665;

                /** The id. */
                private E id;

                /** The creation time. */
                private Date creationTime = new Date();

                /** The modification time. */
                private Date modificationTime;

                /**
                * Gets the id.
                *
                * @return the id
                */
                public E getId() {
                return id;
                }

                /**
                * Sets the id.
                *
                * @param id
                * the new id
                */
                public void setId(final E id) {
                this.id = id;
                }

                /**
                * Gets the creation time.
                *
                * @return the creation time
                */
                public Date getCreationTime() {
                return creationTime;
                }

                /**
                * Gets the modification time.
                *
                * @return the modification time
                */
                public Date getModificationTime() {
                return modificationTime;
                }

                /**
                * Sets the modification time.
                *
                * @param modificationTime
                * the new modification time
                */
                public void setModificationTime(final Date modificationTime) {
                this.modificationTime = modificationTime;
                }

                /**
                * Read external.
                *
                * @param reader
                * the reader
                * @throws IOException
                * Signals that an I/O exception has occurred.
                * @see com.tangosol.io.pof.PortableObject#readExternal(com.tangosol.io.pof.PofReader)
                */
                @Override
                public void readExternal(final PofReader reader) throws IOException {
                id = (E) reader.readObject(IDENTIFIER);
                creationTime = reader.readDate(CREATION_TIME);
                modificationTime = reader.readDate(MODIFICATION_TIME);
                }

                /**
                * Write external.
                *
                * @param writer
                * the writer
                * @throws IOException
                * Signals that an I/O exception has occurred.
                * @see com.tangosol.io.pof.PortableObject#writeExternal(com.tangosol.io.pof.PofWriter)
                */
                @Override
                public void writeExternal(final PofWriter writer) throws IOException {
                writer.writeObject(IDENTIFIER, id);
                writer.writeDateTime(CREATION_TIME, creationTime);
                writer.writeDateTime(MODIFICATION_TIME, modificationTime);
                }

                /**
                * Gets the impl version.
                *
                * @return the impl version
                * @see com.tangosol.io.AbstractEvolvable#getImplVersion()
                */
                @Override
                public int getImplVersion() {
                return VERSION;
                }

                /* *//**
                * To string.
                *
                * @return the string
                * @see java.lang.Object#toString()
                */

                @Override
                public String toString() {
                return "AbstractCacheDTO [id=" + id + ", creationTime=" + creationTime + ", modificationTime="
                            + modificationTime + "]";
                }

                }

                We are specifically facing the problem with enum field as already explained above

                /** The status. */
                private CacheActivationStatus status;

                /** The display status. */
                private CacheDisplayStatus displayStatus;

                Please do let me know if you need more information ?

                Regards,
                Mehak