Skip to content

Commit

Permalink
wip - scala 2.11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Sep 17, 2014
1 parent 1aa5e3e commit 8c8fc5a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 79 deletions.
Expand Up @@ -34,18 +34,18 @@ import net.fwbrasil.activate.entity.BaseEntity
import net.fwbrasil.activate.entity.id.EntityId

trait ActivateContext
extends EntityContext
with QueryContext
with MassUpdateContext
with MassDeleteContext
with NamedSingletonSerializable
with Logging
with DelayedInit
with DurableContext
with StatementsContext
with SerializationContext
with MigrationContext
with ActivateIndexContext {
extends EntityContext
with QueryContext
with MassUpdateContext
with MassDeleteContext
with NamedSingletonSerializable
with Logging
with DelayedInit
with DurableContext
with StatementsContext
with SerializationContext
with MigrationContext
with ActivateIndexContext {

info("Initializing context " + contextName)

Expand All @@ -60,8 +60,8 @@ trait ActivateContext
(additionalStorages.keys.toSet + storage).toList

private[activate] def storageFor(query: Query[_]): Storage[_] =
query.from.entitySources.map(source => storageFor(source.entityClass))
.toSet.onlyOne(storages => s"Query $query uses entities from different storages: $storages.")
query.from.entitySources.map(source => storageFor(source.entityClass)).distinct
.onlyOne(storages => s"Query $query uses entities from different storages: $storages.")

private[activate] def storageFor(entityClass: Class[_]): Storage[Any] =
additionalStoragesByEntityClasses.getOrElse(
Expand Down Expand Up @@ -94,7 +94,7 @@ trait ActivateContext
contextEntities.map(_.contains(entityClass)).getOrElse(true)

protected val contextEntities: Option[List[Class[_ <: BaseEntity]]] = None

override def toString = "ActivateContext: " + name

}
Expand All @@ -117,7 +117,7 @@ object ActivateContext {
classOf[BaseEntity].getClassLoader()
else
currentClassLoader

private[activate] val contextCache =
new ConcurrentHashMap[Class[_], ActivateContext]()

Expand Down
Expand Up @@ -265,7 +265,7 @@ class LiveCache(
entityId.toString.intern.synchronized(f)
case entityId: Integer =>
entityId.toString.intern.synchronized(f)
case entityId =>
case entityId: AnyRef =>
entityId.synchronized(f)
}

Expand Down
Expand Up @@ -72,7 +72,7 @@ trait StatementValueContext extends ValueContext {
// Just to evaluate
value
StatementMocks.lastFakeVarCalled match {
case Some(ref: Var[V]) =>
case Some(ref: FakeVar[V]) =>
toStatementValueRef(ref)
case other =>
value.getOrElse(null.asInstanceOf[V]) match {
Expand Down
Expand Up @@ -13,7 +13,7 @@ abstract class MassModificationStatement(from: From, where: Where)
def execute: Unit = {
val context =
(for (src <- from.entitySources)
yield ActivateContext.contextFor(src.entityClass)).toSet.onlyOne
yield ActivateContext.contextFor(src.entityClass)).distinct.onlyOne
context.executeMassModification(this)
}
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ class Query[S](override val from: From, override val where: Where, val select: S
def context =
(for (src <- from.entitySources)
yield ActivateContext.contextFor(src.entityClass))
.toSet.onlyOne("All query entities sources must be from the same context.")
.distinct.onlyOne("All query entities sources must be from the same context.")

private[activate] def orderByClause: Option[OrderBy] = None

Expand Down
Expand Up @@ -275,7 +275,7 @@ trait QueryContext extends StatementContext
def byId[T <: BaseEntity: Manifest](id: => T#ID, initialized: Boolean = true): Option[T] =
byId(id, erasureOf[T], initialized)

def byId[T <: BaseEntity](id: => T#ID, entityClass: Class[T], initialized: Boolean = true) = {
def byId[T <: BaseEntity](id: => T#ID, entityClass: Class[T], initialized: Boolean) = {
startTransaction
val manifest = ManifestUtil.manifestClass[BaseEntity](entityClass)
val isPolymorfic =
Expand Down Expand Up @@ -309,7 +309,7 @@ trait QueryContext extends StatementContext
def asyncById[T <: BaseEntity: Manifest](id: => T#ID, initialized: Boolean = true)(implicit texctx: TransactionalExecutionContext): Future[Option[T]] =
asyncById[T](id, erasureOf[T], initialized)

def asyncById[T <: BaseEntity](id: => T#ID, entityClass: Class[T], initialized: Boolean = true)(implicit texctx: TransactionalExecutionContext) = {
def asyncById[T <: BaseEntity](id: => T#ID, entityClass: Class[T], initialized: Boolean)(implicit texctx: TransactionalExecutionContext) = {
import texctx.ctx._
texctx.transactional(byId(id, entityClass, initialized = false)).map { entity =>
if (initialized)
Expand Down
Expand Up @@ -58,24 +58,24 @@ trait SlickQueryContext {
}

import driver.simple._

implicit def entityIdColumnType[E <: BaseEntity: ClassTag] = {
val entityValue = EntityId.idTvalFunctionFor(classTag[E].erasure)(None).asInstanceOf[EntityValue[_]]
entityValue match {
case value: StringEntityValue =>
driver.columnTypes.stringJdbcType
driver.columnTypes.stringJdbcType
case value: IntEntityValue =>
driver.columnTypes.intJdbcType
case value: LongEntityValue =>
driver.columnTypes.longJdbcType
}
}.asInstanceOf[driver.BaseColumnType[E#ID]]

implicit def EntityMappedColumnType[E <: BaseEntity: ClassTag] = MappedColumnType.base[E, E#ID](_.id, byId[E](_)(manifestClass(classTag[E].erasure)).get)

class EntityTable[E <: BaseEntity: Manifest](tag: Tag)
extends Table[E](
tag, EntityHelper.getEntityName(erasureOf[E])) {
extends Table[E](
tag, EntityHelper.getEntityName(erasureOf[E])) {
def mock = StatementMocks.mockEntity(erasureOf[E])
def idColumn = column[E#ID]("id")
def * = idColumn <> (fromId, (entity: E) => toId(entity))
Expand All @@ -99,7 +99,7 @@ trait SlickQueryContext {
tableThreadLocal.set(table)
table.mock
}

implicit def EntityColumnToFK[E <: BaseEntity: Manifest](column: Column[E]) = {
val table = tableThreadLocal.get
val otherTable = TableQuery[EntityTable[E]]
Expand Down Expand Up @@ -130,11 +130,11 @@ trait SlickQueryContext {
def col = column
}

implicit class QueryRun[T, U](query: Query[T, U]) {
implicit class QueryRun[T, U, C[U]](query: Query[T, U, C]) {
def execute =
backend.withSession {
session: Session =>
query.run(session).toList
implicit session: Session =>
query.buildColl[List]
}
}

Expand Down
Expand Up @@ -116,7 +116,7 @@ trait SprayJsonContext extends JsonContext[JsObject] {

private def entity(value: JsValue, entityClass: Class[_]) = {
val id = entityId(value, entityClass)
context.byId[BaseEntity](id, entityClass.asInstanceOf[Class[BaseEntity]])
context.byId[BaseEntity](id, entityClass.asInstanceOf[Class[BaseEntity]], true)
.getOrElse(throw new IllegalStateException("Invalid id " + value))
}

Expand Down
Expand Up @@ -56,11 +56,11 @@ import net.fwbrasil.activate.entity.TestValidationEntity
import net.fwbrasil.activate.slick.SlickQueryContext
import net.fwbrasil.activate.storage.relational.async.AsyncMySQLStorage
import com.github.mauricio.async.db.mysql.pool.MySQLConnectionFactory
import net.fwbrasil.activate.storage.relational.async.FinagleMySQLStorage
import com.twitter.finagle.exp.MysqlClient
import com.twitter.finagle.exp.MysqlStackClient
import com.twitter.finagle.client.DefaultPool
import com.twitter.util.Duration
//import net.fwbrasil.activate.storage.relational.async.FinagleMySQLStorage
//import com.twitter.finagle.exp.MysqlClient
//import com.twitter.finagle.exp.MysqlStackClient
//import com.twitter.finagle.client.DefaultPool
//import com.twitter.util.Duration
import net.fwbrasil.activate.entity.EntityWithCustomID

case class DummySeriablizable(val string: String)
Expand Down Expand Up @@ -208,21 +208,7 @@ class AsyncMysqlActivateTestMigrationCustomColumnType extends ActivateTestMigrat
}

object asyncFinagleMysqlContext extends ActivateTestContext {
lazy val storage = new FinagleMySQLStorage {

val dbPoolConfig = DefaultPool.Param(
low = 10,
high = 50,
bufferSize = 0,
idleTime = Duration.Top,
maxWaiters = 200)

val client =
new MysqlClient(MysqlStackClient.configured(dbPoolConfig))
.withCredentials("finagle", "finagle")
.withDatabase("activate_test_finagle")
.newRichClient("localhost:3306")
}
lazy val storage = new TransientMemoryStorage
}
class AsyncFinagleMysqlActivateTestMigration extends ActivateTestMigration()(asyncFinagleMysqlContext)
class AsyncFinagleMysqlActivateTestMigrationCustomColumnType extends ActivateTestMigrationCustomColumnType()(asyncFinagleMysqlContext) {
Expand Down
Expand Up @@ -52,10 +52,10 @@ class SlickQuerySpecs extends ActivateTest {
new Coffee("French_Roast_Decaf", sup2, 9.99)
}

def testCompare[T](slick: Query[_, _], activate: List[_]) =
def testCompare[T](slick: Query[_, _, Seq], activate: List[_]) =
slick.execute === activate

def testCompareSet(slick: Query[_, _], activate: List[_]) =
def testCompareSet(slick: Query[_, _, Seq], activate: List[_]) =
slick.execute.toSet === activate.toSet

step {
Expand Down
47 changes: 23 additions & 24 deletions project/ActivateBuild.scala
Expand Up @@ -11,7 +11,7 @@ object ActivateBuild extends Build {
val objenesis = "org.objenesis" % "objenesis" % "2.1"
val jug = "com.fasterxml.uuid" % "java-uuid-generator" % "3.1.3"
val reflections = "org.reflections" % "reflections" % "0.9.8" exclude ("javassist", "javassist") exclude ("dom4j", "dom4j")
val grizzled = "org.clapper" %% "grizzled-slf4j" % "1.0.1"
val grizzled = "org.clapper" %% "grizzled-slf4j" % "1.0.2"
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.1.0"
val jodaTime = "joda-time" % "joda-time" % "2.3"
val jodaConvert = "org.joda" % "joda-convert" % "1.6"
Expand Down Expand Up @@ -55,7 +55,7 @@ object ActivateBuild extends Build {
activateJdbc, activateMongo, activateTest, activatePlay,
activateGraph, activateSprayJson, activateJdbcAsync,
activateSlick, activateMongoAsync, activatePrevalent,
activateCassandraAsync, activateLift, activateFinagleMysql),
activateCassandraAsync, activateLift),
settings = commonSettings
)

Expand Down Expand Up @@ -112,8 +112,8 @@ object ActivateBuild extends Build {
)
)

val slick = "com.typesafe.slick" % "slick_2.10" % "2.0.0"
val scalaCompiler = "org.scala-lang" % "scala-compiler" % "2.10.3"
val slick = "com.typesafe.slick" %% "slick" % "2.1.0"
val scalaCompiler = "org.scala-lang" % "scala-compiler" % "2.11.2"

lazy val activateSlick =
Project(
Expand All @@ -126,8 +126,8 @@ object ActivateBuild extends Build {
)
)

val postgresqlAsync = "com.github.mauricio" %% "postgresql-async" % "0.2.13"
val mysqlAsync = "com.github.mauricio" %% "mysql-async" % "0.2.13"
val postgresqlAsync = "com.github.mauricio" %% "postgresql-async" % "0.2.15"
val mysqlAsync = "com.github.mauricio" %% "mysql-async" % "0.2.15"

lazy val activateJdbcAsync =
Project(
Expand All @@ -140,18 +140,18 @@ object ActivateBuild extends Build {
)
)

val finagleMysql = "com.twitter" %% "finagle-mysql" % "6.16.0"
// val finagleMysql = "com.twitter" %% "finagle-mysql" % "6.16.0"

lazy val activateFinagleMysql =
Project(
id = "activate-finagle-mysql",
base = file("activate-finagle-mysql"),
dependencies = Seq(activateCore, activateJdbc),
settings = commonSettings ++ Seq(
libraryDependencies ++=
Seq(finagleMysql)
)
)
// lazy val activateFinagleMysql =
// Project(
// id = "activate-finagle-mysql",
// base = file("activate-finagle-mysql"),
// dependencies = Seq(activateCore, activateJdbc),
// settings = commonSettings ++ Seq(
// libraryDependencies ++=
// Seq(finagleMysql)
// )
// )

lazy val activateMongo =
Project(
Expand Down Expand Up @@ -202,7 +202,7 @@ object ActivateBuild extends Build {
)
)

val lift = "net.liftweb" %% "lift-webkit" % "2.5.1"
val lift = "net.liftweb" %% "lift-webkit" % "2.6-RC1"

lazy val activateLift =
Project(
Expand All @@ -215,7 +215,7 @@ object ActivateBuild extends Build {
)
)

val sprayJson = "io.spray" %% "spray-json" % "1.2.5"
val sprayJson = "io.spray" %% "spray-json" % "1.2.6"

lazy val activateSprayJson =
Project(
Expand All @@ -232,7 +232,7 @@ object ActivateBuild extends Build {
"com.fasterxml.jackson.core" % "jackson-core" % "2.3.1",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.3.1",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.3.1",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.3.1")
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.4.2")

lazy val activateJacksonJson =
Project(
Expand All @@ -246,15 +246,14 @@ object ActivateBuild extends Build {
)

val junit = "junit" % "junit" % "4.11"
val specs2 = "org.specs2" %% "specs2" % "2.3.7"
val specs2 = "org.specs2" %% "specs2" % "2.4.2"

lazy val activateTest =
Project(id = "activate-test",
base = file("activate-test"),
dependencies = Seq(activateCore, activatePrevayler % "test", activateJdbc % "test",
activateMongo % "test", activateGraph % "test", activateSprayJson % "test", activateJacksonJson % "test", activateJdbcAsync % "test",
activateSlick % "test", activateMongoAsync % "test", activatePrevalent % "test", activateCassandraAsync % "test", activateLift % "test",
activateFinagleMysql % "test"),
activateSlick % "test", activateMongoAsync % "test", activatePrevalent % "test", activateCassandraAsync % "test", activateLift % "test"),
settings = commonSettings ++ Seq(
libraryDependencies ++=
Seq(junit % "test", specs2 % "test", mysql % "test", objbd6 % "test", postgresql % "test", db2jcc % "test",
Expand All @@ -279,7 +278,7 @@ object ActivateBuild extends Build {
Defaults.defaultSettings ++ Seq(
organization := "net.fwbrasil",
version := "1.6.2",
scalaVersion := "2.10.3",
scalaVersion := "2.11.2",
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
publishMavenStyle := true,
// publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository"))),
Expand Down

0 comments on commit 8c8fc5a

Please sign in to comment.