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

Use CqlTemplate.newPreparedStatementCreator for creation of PreparedStatementCreator

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 2.0.7 (Kay SR7)
    • Component/s: Core
    • Labels:
      None

      Description

      Was curious about the creation of the `PreparedStatement` in the `CqlTemplate`

      It is using an inner class `SimplePreparedStatementCreator` instead of an approach that caches the statements.

      When I run code like this

      cqlTemplate.query(SELECT_VENDOR_BY_DUNS_AND_COMM_ID,(row, rowNum) -> this.rowToVendorDetails(row), commId, duns);
      

      I see this in the logs

      14:38:56.283 [main] DEBUG o.s.d.cassandra.core.cql.CqlTemplate - Executing CQL Statement [INSERT INTO vendor_details (duns,comm_id,vendor_name,vendor_id) VALUES ('222','111','vendor 2','v-id-2');]
      ...
      14:39:18.994 [main] DEBUG o.s.d.cassandra.core.cql.CqlTemplate - Preparing statement [SELECT comm_id, duns, vendor_id, vendor_name FROM vendor_details WHERE comm_id = ? AND duns = ?] using org.springframework.data.cassandra.core.cql.CqlTemplate$SimplePreparedStatementCreator@2f860823
      14:39:19.018 [main] DEBUG o.s.d.cassandra.core.cql.CqlTemplate - Executing prepared statement [com.datastax.driver.core.DefaultPreparedStatement@330c1f61]
      ...
      14:39:22.091 [main] DEBUG o.s.d.cassandra.core.cql.CqlTemplate - Preparing statement [SELECT comm_id, duns, vendor_id, vendor_name FROM vendor_details WHERE comm_id = ? AND duns = ?] using org.springframework.data.cassandra.core.cql.CqlTemplate$SimplePreparedStatementCreator@58b91d57
      14:39:22.094 [cluster-worker-1] WARN  com.datastax.driver.core.Cluster - Re-preparing already prepared query is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once. Query='SELECT comm_id, duns, vendor_id, vendor_name FROM vendor_details WHERE comm_id = ? AND duns = ?'
      

      Wanted to know if there was a reason for this approach before looking into working on a PR that uses the CachedPreparedStatementCreator

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            codesmell Mike Barlotta
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 19 weeks, 2 days ago