Skip to content

Commit

Permalink
Merge 9bce6b5 into 95fc337
Browse files Browse the repository at this point in the history
  • Loading branch information
ajozwik committed Aug 19, 2019
2 parents 95fc337 + 9bce6b5 commit 42f32f7
Show file tree
Hide file tree
Showing 79 changed files with 633 additions and 80 deletions.
59 changes: 54 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ val `scalaVersion_2.13` = "2.13.0"

val `scalaVersion_2.12` = "2.12.9"

name := "quill-macro-parent"

ThisBuild / scapegoatVersion := "1.3.9"

resolvers += Resolver.sonatypeRepo("releases")
Expand Down Expand Up @@ -44,24 +46,71 @@ val `io.getquill_quill-async` = "io.getquill" %% "quill-async" % quillVersion

val `io.getquill_quill-async-mysql` = "io.getquill" %% "quill-async-mysql" % quillVersion

val `io.getquill_quill-jdbc` = "io.getquill" %% "quill-jdbc-monix" % quillVersion
val `io.getquill_quill-cassandra-monix` = "io.getquill" %% "quill-cassandra-monix" % quillVersion

val `io.getquill_quill-cassandra` = "io.getquill" %% "quill-cassandra" % quillVersion

val `io.getquill_quill-jdbc` = "io.getquill" %% "quill-jdbc" % quillVersion

val `io.getquill_quill-jdbc-monix` = "io.getquill" %% "quill-jdbc-monix" % quillVersion

val `io.getquill_quill-monix` = "io.getquill" %% "quill-monix" % quillVersion

val `org.scalatest_scalatest` = "org.scalatest" %% "scalatest" % "3.0.8" % Test

val `org.scalacheck_scalacheck` = "org.scalacheck" %% "scalacheck" % "1.14.0" % Test

lazy val `macro-quill` = projectWithName("macro-quill", file(".")).settings(
val `org.cassandraunit_cassandra-unit` = "org.cassandraunit" % "cassandra-unit" % "3.11.2.0"

val `com.datastax.cassandra_cassandra-driver-extras` = "com.datastax.cassandra" % "cassandra-driver-extras" % "3.7.2"

lazy val `macro-quill` = projectWithName("macro-quill", file("macro-quill")).settings(
libraryDependencies ++= Seq(
`io.getquill_quill-async`,
`ch.qos.logback_logback-classic` % Test,
`com.typesafe.scala-logging_scala-logging` % Test,
`io.getquill_quill-async-mysql` % Test,
`io.getquill_quill-jdbc`,
`com.h2database_h2` % Test
`com.h2database_h2` % Test
),
scapegoatIgnoredFiles := Seq(".*/*Macro.*.scala", ".*/.*Queries.*.scala")
)

lazy val `quill-jdbc-monix-macro` = projectWithName("quill-jdbc-monix-macro", file("quill-jdbc-monix-macro"))
.settings(libraryDependencies ++= Seq(`io.getquill_quill-jdbc-monix`))
.dependsOn(`quill-monix-macro`)
.dependsOn(Seq(`macro-quill`, `quill-monix-macro`).map(_ % "test->test"): _*)

lazy val `quill-monix-macro` = projectWithName("quill-monix-macro", file("quill-monix-macro"))
.settings(libraryDependencies ++= Seq(`io.getquill_quill-monix`))
.dependsOn(`macro-quill`, `macro-quill` % "test->test")

lazy val `quill-cassandra-monix-macro` = projectWithName("quill-cassandra-monix-macro", file("quill-cassandra-monix-macro"))
.settings(
libraryDependencies ++= Seq(
`io.getquill_quill-cassandra-monix`,
`org.cassandraunit_cassandra-unit` % Test,
`com.datastax.cassandra_cassandra-driver-extras` % Test
),
Test / fork := true
)
.dependsOn(`quill-monix-macro`)
.dependsOn(Seq(`macro-quill`, `quill-monix-macro`).map(_ % "test->test"): _*)

lazy val `quill-cassandra-macro` = projectWithName("quill-cassandra-macro", file("quill-cassandra-macro"))
.settings(
libraryDependencies ++= Seq(
`io.getquill_quill-cassandra`,
`org.cassandraunit_cassandra-unit` % Test,
`com.datastax.cassandra_cassandra-driver-extras` % Test
),
Test / fork := true
)
.dependsOn(`macro-quill`)
.dependsOn(Seq(`macro-quill`, `quill-monix-macro`).map(_ % "test->test"): _*)

lazy val `quill-jdbc-macro` = projectWithName("quill-jdbc-macro", file("quill-jdbc-macro"))
.settings(libraryDependencies ++= Seq(`io.getquill_quill-jdbc`, `io.getquill_quill-async-mysql` % Test))
.dependsOn(`macro-quill`, `macro-quill` % "test->test")

def projectWithName(name: String, file: File): Project = Project(name, file).settings(
libraryDependencies ++= Seq(
`org.scalatest_scalatest`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package pl.jozwik.quillgeneric.quillmacro.sync

import pl.jozwik.quillgeneric.quillmacro.AbstractCrudMacro
package pl.jozwik.quillgeneric.quillmacro

import scala.reflect.macros.whitebox.{ Context => MacroContext }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.jozwik.quillgeneric.quillmacro.quotes
package pl.jozwik.quillgeneric.quillmacro

import java.time.{ LocalDate, LocalDateTime }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ trait Repository[K, T <: WithId[K]] extends BaseRepository[K, T] {

trait BaseRepository[K, T <: WithId[K]] extends WithMonad {

type U

def all: F[Seq[T]]

def read(id: K): F[Option[T]]

def update(t: T): F[Long]
def update(t: T): F[U]

def updateAndRead(t: T): F[T]

def delete(id: K): F[Long]
def delete(id: K): F[U]

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pl.jozwik.quillgeneric.quillmacro

trait WithUpdate[UPDATE] {
type U = UPDATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package pl.jozwik.quillgeneric.quillmacro.mirror

import io.getquill.idiom.Idiom
import io.getquill.{ MirrorContext, NamingStrategy }
import pl.jozwik.quillgeneric.quillmacro.WithId
import pl.jozwik.quillgeneric.quillmacro.quotes.DateQuotes
import pl.jozwik.quillgeneric.quillmacro.sync.CrudMacro
import pl.jozwik.quillgeneric.quillmacro.{ DateQuotes, WithId }
import pl.jozwik.quillgeneric.quillmacro.CrudMacro

import scala.language.experimental.macros

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package pl.jozwik.quillgeneric.quillmacro.sync
import io.getquill.NamingStrategy
import io.getquill.context.Context
import io.getquill.idiom.Idiom
import pl.jozwik.quillgeneric.quillmacro.WithId
import pl.jozwik.quillgeneric.quillmacro.quotes.DateQuotes
import pl.jozwik.quillgeneric.quillmacro.{ CrudMacro, DateQuotes, WithId }

import scala.language.experimental.macros

object CrudWithContext {
type ContextDateQuotes[D <: Idiom, N <: NamingStrategy] = Context[D, N] with CrudWithContext with DateQuotes
}

trait CrudWithContext {
trait CrudWithContext[U] {
this: Context[_, _] =>
type dQuery[T] = this.DynamicEntityQuery[T]

Expand All @@ -35,13 +30,13 @@ trait CrudWithContext {
def createWithGenerateIdOrUpdateAndRead[K, T <: WithId[K]](entity: T)(implicit dSchema: dQuery[T]): T =
macro CrudMacro.createWithGenerateIdOrUpdateAndRead[K, T]

def update[K, T <: WithId[K]](entity: T)(implicit dSchema: dQuery[T]): Long = macro CrudMacro.update[K, T]
def update[K, T <: WithId[K]](entity: T)(implicit dSchema: dQuery[T]): U = macro CrudMacro.update[K, T]

def updateAndRead[K, T <: WithId[K]](entity: T)(implicit dSchema: dQuery[T]): T = macro CrudMacro.updateAndRead[K, T]

def read[K, T <: WithId[K]](id: K)(implicit dSchema: dQuery[T]): Option[T] = macro CrudMacro.read[K, T]

def delete[K, T <: WithId[K]](id: K)(implicit dSchema: dQuery[T]): Long = macro CrudMacro.delete[K]
def delete[K, T <: WithId[K]](id: K)(implicit dSchema: dQuery[T]): U = macro CrudMacro.delete[K]

def deleteByFilter[T](filter: T => Boolean)(implicit dSchema: dQuery[T]): Long = macro CrudMacro.deleteByFilter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ h2.dataSource.user=sa

h2Monix.dataSourceClassName=org.h2.jdbcx.JdbcDataSource
h2Monix.dataSource.url=jdbc:h2:mem:monix;INIT=RUNSCRIPT FROM 'classpath:scripts/create.sql'
h2Monix.dataSource.user=sa
h2Monix.dataSource.user=sa
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</appender>

<logger name="com.zaxxer" level="INFO" />
<logger name="org.cassandra" level="INFO" />
<logger name="org.apache.cassandra" level="INFO" />



Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.jozwik.quillgeneric

import java.time.{ LocalDate, LocalDateTime }

import com.typesafe.scalalogging.StrictLogging
import org.scalatest.concurrent.{ AsyncTimeLimitedTests, TimeLimitedTests }
import org.scalatest.time.{ Seconds, Span }
Expand All @@ -17,6 +16,7 @@ trait Spec extends StrictLogging {
}

trait AbstractSpec extends WordSpecLike with TimeLimitedTests with Spec with Matchers with BeforeAndAfterAll {

protected val now: LocalDateTime = LocalDateTime.now()
protected val today: LocalDate = now.toLocalDate
protected val strategy = Strategy.namingStrategy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pl.jozwik.quillgeneric.quillmacro.cassandra.sync

import io.getquill.{ CassandraSyncContext, NamingStrategy }
import pl.jozwik.quillgeneric.quillmacro.cassandra.sync.CassandraRepository.CassandraContextDateQuotes
import pl.jozwik.quillgeneric.quillmacro.sync.{ CrudWithContext, SyncRepository }
import pl.jozwik.quillgeneric.quillmacro.{ CompositeKey, DateQuotes, WithId, WithUpdate }

object CassandraRepository {
type CassandraContextDateQuotes[N <: NamingStrategy] = CassandraSyncContext[N] with CrudWithContext[Unit] with DateQuotes
}

trait CassandraRepository[K, T <: WithId[K], N <: NamingStrategy] extends SyncRepository[K, T] with WithUpdate[Unit] {
protected val context: CassandraContextDateQuotes[N]

protected def dynamicSchema: context.DynamicEntityQuery[T]

}

trait CassandraMonixRepositoryCompositeKey[K <: CompositeKey[_, _], T <: WithId[K], N <: NamingStrategy] extends CassandraRepository[K, T, N]
11 changes: 11 additions & 0 deletions quill-cassandra-macro/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cassandra.keyspace=demo
cassandra.preparedStatementCacheSize=1000
cassandra.session.contactPoint=127.0.0.1
cassandra.session.withPort=9142
cassandra.session.queryOptions.consistencyLevel=LOCAL_QUORUM
cassandra.session.withoutMetrics=true
cassandra.session.withoutJMXReporting=false
cassandra.session.credentials.0=root
cassandra.session.credentials.1=pass
cassandra.session.maxSchemaAgreementWaitSeconds=1
cassandra.session.addressTranslator=com.datastax.driver.core.policies.IdentityTranslator
69 changes: 69 additions & 0 deletions quill-cassandra-macro/src/test/resources/scripts/create.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
CREATE TABLE IF NOT EXISTS ADDRESS
(
ID UUID PRIMARY KEY,
COUNTRY TEXT,
CITY TEXT,
STREET TEXT,
BUILDING_NUMBER TEXT,
LOCAL_NUMBER TEXT,
UPDATED TIMESTAMP
);
/**
CREATE TABLE IF NOT EXISTS PERSON
(
ID INT NOT NULL,
FIRST_NAME VARCHAR(50) NOT NULL,
LAST_NAME VARCHAR(20) NOT NULL,
BIRTH_DATE DATE,
ADDRESS_ID INT DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS PERSON2
(
ID INT NOT NULL AUTO_INCREMENT,
FIRST_NAME VARCHAR(50) NOT NULL,
LAST_NAME VARCHAR(20) NOT NULL,
BIRTH_DATE DATE,
ADDRESS_ID INT DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS PERSON3
(
ID INT NOT NULL AUTO_INCREMENT,
FIRST_NAME VARCHAR(50) NOT NULL,
LAST_NAME VARCHAR(20) NOT NULL,
DOB DATE,
ADDRESS_ID INT DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS CONFIGURATION (
`KEY` VARCHAR(20) NOT NULL,
`VALUE` VARCHAR(20) NOT NULL,
PRIMARY KEY (`KEY`)
);
CREATE TABLE IF NOT EXISTS PRODUCT (
`ID` INT NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(20) NOT NULL,
PRIMARY KEY (`ID`)
);
CREATE TABLE IF NOT EXISTS SALE (
`PRODUCT_ID` INT NOT NULL,
`PERSON_ID` INT NOT NULL,
`SALE_DATE` DATETIME,
PRIMARY KEY (`PRODUCT_ID`,`PERSON_ID`)
);
CREATE TABLE IF NOT EXISTS CELL4D (
`X` INT NOT NULL,
`Y` INT NOT NULL,
`Z` INT NOT NULL,
`T` INT NOT NULL,
`OCCUPIED` BOOLEAN,
PRIMARY KEY (`X`, `Y`, `Z`, `T`)
);
**/
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package pl.jozwik.quillgeneric.cassandra

import com.datastax.driver.core.{ Cluster, Session }
import com.datastax.driver.extras.codecs.jdk8.LocalDateTimeCodec
import io.getquill.{ CassandraSyncContext, SnakeCase }
import monix.execution.Scheduler
import org.cassandraunit.CQLDataLoader
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
import org.scalatest.BeforeAndAfterAll
import pl.jozwik.quillgeneric.AbstractSpec
import pl.jozwik.quillgeneric.cassandra.model.{ Address, AddressId }
import pl.jozwik.quillgeneric.quillmacro.DateQuotes

class CassandraTest extends AbstractSpec with BeforeAndAfterAll {
protected implicit val scheduler: Scheduler = Scheduler.Implicits.global
sys.props.put("quill.binds.log", true.toString)
protected lazy val cluster: Cluster = {
//EmbeddedCassandraServerHelper.CASSANDRA_RNDPORT_YML_FILE
EmbeddedCassandraServerHelper.startEmbeddedCassandra()
EmbeddedCassandraServerHelper.getCluster
}
protected lazy val session: Session = cluster.connect()

protected val keySpace = "demo"

lazy val syncCtx = new CassandraSyncContext(SnakeCase, "cassandra") with DateQuotes

override def beforeAll(): Unit = {
cluster.getConfiguration.getCodecRegistry.register(LocalDateTimeCodec.instance)
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra()
val dataLoader = new CQLDataLoader(session)
dataLoader.load(new ClassPathCQLDataSet("scripts/create.cql", keySpace))
}

override protected def afterAll(): Unit = {
super.afterAll()
session.close()
cluster.close()
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra()
}

"really simple transformation" should {

"run sync" in {
val id = AddressId.random
val address = Address(id, "country", "city")
import syncCtx._
val schema = syncCtx.dynamicQuerySchema[Address]("Address")
syncCtx
.run {
schema.insertValue(address)
}
syncCtx
.run {
schema.insertValue(address)
}
val v = syncCtx
.run(
schema.filter(_.id == lift(id))
)
logger.debug(s"$v")
syncCtx
.run(
schema.filter(_.id == lift(id)).delete
)
}
}

}

0 comments on commit 42f32f7

Please sign in to comment.