Uploaded image for project: 'Spring Data for Apache Cassandra'
  1. Spring Data for Apache Cassandra
  2. DATACASS-814

MapPreparedStatementCache.CacheKey uses DefaultSimpleStatement.toString() inherited from Object.toString()

    XMLWordPrintable

    Details

      Description

      Attached there is a screenshot from YourKit, displaying the internals of a MapPreparedStatementCache instance of a running application, using Spring Data Cassandra 3.0.3 and DataStax Driver 4.6.1.

      It seems clear that the key of stored prepared statements is composed using a cql field which is not the expected CQL text coming from the prepared statement (the Javadoc says Statements are cached with a key consisting of session name, keyspace and the cql text).

      Tracking down the problem, it originates from this line : instead of invoking getQuery() (which returns the CQL text) the toString() method is invoked, which is not overriden by DefaultSimpleStatement.

      Luckily, the toString() method benefits from the hashCode() method, which is implemented by DefaultSimpleStatement. So in the end building different statements using the same calls to QueryBuilder results in different objects having the same internal fields and thus generating the same toString() value. So it works ... but seems a bit fragile, in case Datastax change/remove the hashCode method from DefaultSimpleStatement.

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            aldobongio aldobongio
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 21 weeks, 1 day ago