Skip to content

How to create a new JDBC back end

John Sullivan edited this page Feb 8, 2017 · 4 revisions
  • First, try the generic JDBC back end. You can set longevity.jdbc.driverClass to be whatever you want.
  • Wait for something to go wrong. If nothing goes wrong, JDBC back end should be fine for you.
  • If something goes wrong, talk to us about it on the message board or on Gitter.
  • Add your back end into the build
    • Add your driver as a ModuleId into project/Dependencies.scala
    • Add your driver as both an optional and test dependency in the longevity project in build.sbt
    • Create an SBT sub-project longevityYourBackEndDeps that mirrors longevitySqliteDeps
    • Add your SBT sub-project to the aggregate clause for the root project
  • Add a new longevity.config.BackEnd for your JDBC driver.
  • Create package longevity.persistence.yourBackEnd, and add YourBackEndRepo, DerivedYourBackEndRepo, and PolyYourBackEndRepo. See SQLite equivalents of these classes for an example.
  • Copy/paste SQLite code in longevity.persistence.RepoPoolBuilder to your back end.
    • There is a lot of duplication in this source file! If you could help us clean this up we would greatly appreciate it!
  • Now, figure out which parts of longevity.persistence.jdbc need to be changed to fix your problem. Your fixes are most likely going to diverge from what is needed by other JDBC drivers. Have your repo classes override JdbcRepo behavior appropriately.
    • Consider overriding JdbcRepo.convertDuplicateKeyException so you get longevity exceptions for these that contain the violated key. See the override in SQLiteRepo for an example.
  • Run the tests. You will need to have MongoDB and Cassandra installed for them to run. See the Developer Setup page for details.
  • By virtue of adding your own BackEnd to longevity.config.BackEnd.values, a lot of the tests will pick up your back end automatically. If you get a lot of errors and want to narrow things down a bit to start clearing problems, I typically start with test-only longevity.integration.domain.basics.*.
  • There are some tests that you will have to add - see specifically:
    • longevity.integration.duplicateKeyVal
    • longevity.integration.poly
    • longevity.integration.queries
    • longevity.integration.unstablePartitionKey
    • longevity.integration.writeConflict
  • It would really be nice if more of these tests would just automatically adapt to a new back end. If you could add that in for us, we would be eternally grateful!