-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. quill-cassandra, basic cassandra driver. 2. quill-cassandra-datastax that depends on quill-cassandra and uses the datastax driver
- Loading branch information
1 parent
5424ef7
commit 6493f89
Showing
39 changed files
with
715 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
50 changes: 50 additions & 0 deletions
50
quill-cassandra-datastax/src/main/scala/io/getquill/CassandraDatastaxSessionContext.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.getquill | ||
|
||
import com.datastax.driver.core.{ Cluster, _ } | ||
import io.getquill.context.cassandra.{ CassandraSessionContext, PrepareStatementCache } | ||
import io.getquill.util.Messages.fail | ||
import io.getquill.context.cassandra.util.FutureConversions._ | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
abstract class CassandraDatastaxSessionContext[N <: NamingStrategy]( | ||
val naming: N, | ||
cluster: Cluster, | ||
keyspace: String, | ||
preparedStatementCacheSize: Long | ||
) | ||
extends CassandraSessionContext[N] { | ||
|
||
private val preparedStatementCache = | ||
new PrepareStatementCache(preparedStatementCacheSize) | ||
|
||
protected lazy val session = cluster.connect(keyspace) | ||
|
||
protected val udtMetadata: Map[String, List[UserType]] = cluster.getMetadata.getKeyspaces.asScala.toList | ||
.flatMap(_.getUserTypes.asScala) | ||
.groupBy(_.getTypeName) | ||
|
||
def udtValueOf(udtName: String, keyspace: Option[String] = None): UDTValue = | ||
udtMetadata.getOrElse(udtName.toLowerCase, Nil) match { | ||
case udt :: Nil => udt.newValue() | ||
case Nil => | ||
fail(s"Could not find UDT `$udtName` in any keyspace") | ||
case udts => udts | ||
.find(udt => keyspace.contains(udt.getKeyspace) || udt.getKeyspace == session.getLoggedKeyspace) | ||
.map(_.newValue()) | ||
.getOrElse(fail(s"Could not determine to which keyspace `$udtName` UDT belongs. " + | ||
s"Please specify desired keyspace using UdtMeta")) | ||
} | ||
|
||
protected def prepare(cql: String): BoundStatement = | ||
preparedStatementCache(cql)(session.prepare) | ||
|
||
protected def prepareAsync(cql: String)(implicit executionContext: ExecutionContext): Future[BoundStatement] = | ||
preparedStatementCache.async(cql)(session.prepareAsync(_)) | ||
|
||
def close() = { | ||
session.close | ||
cluster.close | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...la/io/getquill/CassandraSyncContext.scala → ...la/io/getquill/CassandraSyncContext.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
quill-cassandra-datastax/src/test/resources/application.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
testSyncDB.keyspace=quill_test | ||
testSyncDB.preparedStatementCacheSize=1000 | ||
testSyncDB.session.contactPoint=${?CASSANDRA_HOST} | ||
testSyncDB.session.port=${?CASSANDRA_PORT} | ||
testSyncDB.session.queryOptions.fetchSize=1 | ||
testSyncDB.session.queryOptions.consistencyLevel=LOCAL_QUORUM | ||
testSyncDB.session.withoutMetrics=true | ||
testSyncDB.session.withoutJMXReporting=false | ||
testSyncDB.session.credentials.0=root | ||
testSyncDB.session.credentials.1=pass | ||
testSyncDB.session.maxSchemaAgreementWaitSeconds=1 | ||
testSyncDB.session.addressTranslator=com.datastax.driver.core.policies.IdentityTranslator | ||
|
||
testAsyncDB.keyspace=quill_test | ||
testAsyncDB.preparedStatementCacheSize=1000 | ||
testAsyncDB.session.contactPoint=${?CASSANDRA_HOST} | ||
testAsyncDB.session.port=${?CASSANDRA_PORT} | ||
testAsyncDB.session.queryOptions.fetchSize=1 | ||
testAsyncDB.session.queryOptions.consistencyLevel=LOCAL_QUORUM |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
quill-cassandra-datastax/src/test/scala/io/getquill/context/cassandra/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.getquill.context | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.Future | ||
import scala.concurrent.duration.Duration | ||
|
||
import io.getquill._ | ||
import io.getquill.Literal | ||
|
||
package object cassandra { | ||
|
||
lazy val mirrorContext = new CassandraMirrorContext(Literal) with CassandraTestEntities | ||
|
||
lazy val testSyncDB = new CassandraSyncContext(Literal, "testSyncDB") with CassandraTestEntities | ||
|
||
lazy val testAsyncDB = new CassandraAsyncContext(Literal, "testAsyncDB") with CassandraTestEntities | ||
|
||
def await[T](f: Future[T]): T = Await.result(f, Duration.Inf) | ||
} |
File renamed without changes.
Oops, something went wrong.