cassandra-connector4s


License

License

Categories

Categories

IDE Development Tools Cassandra Data Databases
GroupId

GroupId

com.github.mideo
ArtifactId

ArtifactId

cassandra-connector4s_2.12
Last Version

Last Version

0.0.15
Release Date

Release Date

Type

Type

jar
Description

Description

cassandra-connector4s
cassandra-connector4s
Project URL

Project URL

https://github.com/MideO/cassandra-connector4s
Project Organization

Project Organization

com.github.mideo
Source Code Management

Source Code Management

https://github.com/MideO/cassandra-connector4s

Download cassandra-connector4s_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mideo/cassandra-connector4s_2.12/ -->
<dependency>
    <groupId>com.github.mideo</groupId>
    <artifactId>cassandra-connector4s_2.12</artifactId>
    <version>0.0.15</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mideo/cassandra-connector4s_2.12/
implementation 'com.github.mideo:cassandra-connector4s_2.12:0.0.15'
// https://jarcasting.com/artifacts/com.github.mideo/cassandra-connector4s_2.12/
implementation ("com.github.mideo:cassandra-connector4s_2.12:0.0.15")
'com.github.mideo:cassandra-connector4s_2.12:jar:0.0.15'
<dependency org="com.github.mideo" name="cassandra-connector4s_2.12" rev="0.0.15">
  <artifact name="cassandra-connector4s_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mideo', module='cassandra-connector4s_2.12', version='0.0.15')
)
libraryDependencies += "com.github.mideo" % "cassandra-connector4s_2.12" % "0.0.15"
[com.github.mideo/cassandra-connector4s_2.12 "0.0.15"]

Dependencies

compile (9)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.6
com.datastax.cassandra : cassandra-driver-mapping jar 3.6.0
com.typesafe.akka : akka-actor_2.12 jar 2.5.17
net.databinder.dispatch : dispatch-core_2.12 jar 0.13.2
com.typesafe : config jar 1.3.3
org.apache.cassandra : cassandra-all jar 3.11.4
org.cassandraunit : cassandra-unit jar 3.5.0.1
uk.sky : cqlmigrate jar 0.9.8
io.netty : netty-all jar 4.0.56.Final

runtime (1)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.2.3

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.5
org.mockito : mockito-all jar 1.10.19

Project Modules

There are no modules declared in this project.

cassandra-connector

Build Status

Maven Central

Cassandra DB bundle to enable

  • Connection to cassandra
  • Connection to cassandra embedded cassadra for testing
  • Generic materialised repository
  • Managing migrations with Cqlmigrate
Docs?

See Integration tests: IntegrationTests.scala

Uage

Create cassandra-connector.conf in resources directory
cassandra-connector {
  cluster {
    username: user
    password: pass
    keyspace: cassandra_connector
    port: 9402
    contactPoints: localhost
    dc: DC1
  }
  session {
    consistencyLevel: local_quorum
  }
}
Define a repository
@Table(keyspace = "cassandra_connector", name = "users", caseSensitiveKeyspace = false, caseSensitiveTable = false)
class User() {
  @PartitionKey
  @Column(name = "user_id")
  @BeanProperty var userId: UUID = _
  @BeanProperty var name: String = _

  // Define auxiliary constructor due to cassandra driver limitation i.e. using reflection 
  def this(userId: UUID, name: String) = {
    this()
    this.userId = userId
    this.name = name
  }
}
Define a customer Repository Accessor
@Accessor trait TestUserAccessor {
  @Query("SELECT * FROM users") def getAll: Result[TestUser]
  @Query("TRUNCATE users") def truncate: Result[TestUser]
}
Perform CRUD Ops
// Either Create a connected Keyspace from the above config without cql migration
val connectedKeyspace = ConnectedKeyspace("cassandra_connector")

// or with cql migration if needed
val connectedKeyspace = ConnectedKeyspace("cassandra_connector", "aGivenDirectoryWithDotCqlFiles")


//Or alternatively, initialise without config file
import com.github.mideo.cassandra.connector.fluent.Connector

val connectedKeyspace = Connector.keyspace("keyspace" )
      .withUserName("mideo")
      .withPassword("password")
      .withConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM)
      .withContactPoints(List("localhost"))
      .onPort(9402)
      .withDC("DC1")
      .withMigrationsDirectory("aGivenDirectoryWithDotCqlFiles")
      .connect()


// create a connectedTable
val futureTable: Future[ConnectedTable[TestUser, TestUserAccessor]] = connectedKeyspace.materialise[TestUser, TestUserAccessor]


 futureTable map {
      table => table.accessor.truncate
                table.mapper.save(new User(UUID.randomUUID, "mideo"))
                table.accessor.getAll
      } 

// alternatively create a repository
val userMapper: Future[Mapper[TestUser]] = connectedKeyspace.materialise[TestUser]

// Create an instance of repository entity
val mideo = new User(UUID.randomUUID, "mideo")

// Create an instance of repository entity
userMapper.map { _.save(mideo) }

// Get user
userMapper.map { _.get(mideo.userId) }


// Delete user
userMapper.map { _.delete(mideo.userId) }


// alternatively  user custom accessor
val accessor: Future[TestUserAccessor] = connectedKeyspace.materialiseAccessor[TestUserAccessor]

accessor.map { _.getAll }

accessor.map { _.truncate }

Testing with EmbeddedCassandra
// Connect with the ConnectedInMemoryRepository object
val connectedKeyspace: ConnectedKeyspace = ConnectedInMemoryKeyspace("cassandra_connector")

val isRunning = EmbeddedCassandra.isRunning 

val port = EmbeddedCassandra.runningPort 

val hosts = EmbeddedCassandra.getHosts 

Versions

Version
0.0.15
0.0.13
0.0.12
0.0.11
0.0.9
0.0.8
0.0.7
0.0.6
0.0.4
0.0.3
0.0.2
0.0.1