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

Allow keyspace customization for CassandraPersistentEntity

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0 RC1 (Neumann)
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      In the data stax 4.5 manual it is indicated that creating session/keyspace (https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/) is an anti-pattern:

      "// Anti-pattern: creating two sessions doubles the number of TCP connections opened by the driver"

      You have a solution that uses the AbstractRoutingSessionFactory that just implement that anti-pattern.

      But the data stax driver provides actually two different solutions to avoid having that antipattern.

      1. use the setKeypace when creating a Statement - but this is OK only if the version supported if > V4. Which would not be available for all.
      2. use the built-in QueryBuilder queries that have the keyspace as a parameter. Example: looking at the QueryBuilder.insertInto - it could be changed to use the keyspace since the insertInto signature allows for a a keyspace & a table name. The Statement builder will then build the query by having the keyspace + "." + tablename.

       

      The impacted classes are CassandraTemplate & StatementFactory. I attach example code of above where I test the insertTo successfully.

      At the same time, while the framework allows me in CassandraConfig to specify a bean to create a cassandraTemplate that can be different than the default CassandraTemplate it does not allow me to re-use the existing framework classes in order to implement my self a template & statement factory where I can specify the keyspace without being forced to copy them out of the framework.

      The keyspace can be kept in a ThreadLocal - using the same principle used for AbstractRoutingSessionFactory .

      If we cannot have a template as such in the framework, can we at least have the possibility to implement a CassandraTemplace without being forced to copy a lot of code in order to access the existing framework classes ? The template requires quite a few classes that are private.

      This assumes that the keyspace schema are the same.

      Thank you.

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            lmcdasi lmcdasi
            Last updater:
            Mark Paluch
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Days since last comment:
              6 weeks, 4 days ago