Skip to content

Commit b1cb025

Browse files
committed
Updated versions, Gradle wrapper and fixed a few bugs
Signed-off-by: Joern Bernhardt <jb@campudus.com>
1 parent 341801a commit b1cb025

File tree

11 files changed

+162
-130
lines changed

11 files changed

+162
-130
lines changed

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ modname=mod-mysql-postgresql
88
version=0.3.0-SNAPSHOT
99

1010
# The version of mauricios async driver
11-
asyncDriverVersion=0.2.11
11+
asyncDriverVersion=0.2.12
1212

1313
# The test timeout in seconds
1414
testtimeout=5
@@ -20,16 +20,16 @@ pullInDeps=true
2020
produceJar=false
2121

2222
# The version of the Scala module
23-
scalaLangModVersion=0.3.0
23+
scalaLangModVersion=1.0.0-RC1
2424

2525
# The version of Scala to use
2626
scalaVersion=2.10.2
2727

2828
# Gradle version
29-
gradleVersion=1.6
29+
gradleVersion=1.11
3030

3131
# The version of Vert.x
32-
vertxVersion=2.1M2
32+
vertxVersion=2.1RC1
3333

3434
# The version of Vert.x test tools
3535
toolsVersion=2.0.2-final

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip
6+
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip

src/main/resources/langs.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
scala=io.vertx~lang-scala~0.3.0:org.vertx.scala.platform.impl.ScalaVerticleFactory
2-
.scala=scala
1+
scala=io.vertx~lang-scala~1.0.0-RC1:org.vertx.scala.platform.impl.ScalaVerticleFactory
2+
.scala=scala

src/main/scala/io/vertx/asyncsql/database/ConnectionHandler.scala

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ package io.vertx.asyncsql.database
22

33
import scala.collection.JavaConverters.iterableAsScalaIterableConverter
44
import scala.concurrent.Future
5-
import org.vertx.scala.core.eventbus.Message
6-
import org.vertx.scala.core.json.{ JsonArray, JsonObject }
5+
import org.vertx.scala.core.json.{JsonElement, JsonArray, JsonObject, Json}
76
import org.vertx.scala.core.logging.Logger
8-
import org.vertx.scala.platform.Verticle
97
import com.github.mauricio.async.db.{ Configuration, Connection, QueryResult, RowData }
108
import com.github.mauricio.async.db.postgresql.exceptions.GenericDatabaseException
119
import io.vertx.asyncsql.database.pool.AsyncConnectionPool
12-
import org.vertx.scala.core.json.Json
1310
import org.vertx.scala.mods.ScalaBusMod
1411
import org.vertx.scala.mods.replies._
1512
import org.vertx.scala.core.Vertx
1613
import org.vertx.scala.platform.Container
1714
import io.vertx.asyncsql.Starter
15+
import org.vertx.scala.mods.ScalaBusMod.Receive
1816

1917
trait ConnectionHandler extends ScalaBusMod {
2018
val verticle: Starter
@@ -32,23 +30,24 @@ trait ConnectionHandler extends ScalaBusMod {
3230
def statementDelimiter: String = ";"
3331

3432
import org.vertx.scala.core.eventbus._
35-
override def receive(msg: Message[JsonObject]) = {
33+
override def receive: Receive = (msg: Message[JsonObject]) => {
3634
case "select" => select(msg.body)
3735
case "insert" => insert(msg.body)
3836
case "prepared" => AsyncReply(sendWithPool(prepared(msg.body)))
3937
case "transaction" => transaction(msg.body)
4038
case "raw" => AsyncReply(sendWithPool(rawCommand(msg.body.getString("command"))))
4139
}
4240

43-
def close() = pool.close
41+
def close() = pool.close()
4442

4543
protected def escapeField(str: String): String = "\"" + str.replace("\"", "\"\"") + "\""
4644
protected def escapeString(str: String): String = "'" + str.replace("'", "''") + "'"
4745

4846
protected def escapeValue(v: Any): String = v match {
49-
case v: Int => v.toString
50-
case v: Boolean => v.toString
51-
case v => escapeString(v.toString)
47+
case x: Int => x.toString
48+
case x: Boolean => x.toString
49+
case null => "NULL"
50+
case x => escapeString(x.toString)
5251
}
5352

5453
protected def selectCommand(json: JsonObject): String = {
@@ -93,7 +92,7 @@ trait ConnectionHandler extends ScalaBusMod {
9392

9493
Option(json.getArray("statements")) match {
9594
case Some(statements) => c.inTransaction { conn: Connection =>
96-
val futures = (statements.asScala.map {
95+
val futures = statements.asScala.map {
9796
case js: JsonObject =>
9897
js.getString("action") match {
9998
case "select" => Raw(selectCommand(js))
@@ -102,8 +101,8 @@ trait ConnectionHandler extends ScalaBusMod {
102101
case "raw" => Raw(js.getString("command"))
103102
}
104103
case _ => throw new IllegalArgumentException("'statements' needs JsonObjects!")
105-
})
106-
val f = (futures.foldLeft(Future[Any]()) { case (f, cmd) => f flatMap (_ => cmd.query(conn)) })
104+
}
105+
val f = futures.foldLeft(Future[Any]()) { case (fut, cmd) => fut flatMap (_ => cmd.query(conn)) }
107106
f map (_ => Ok(Json.obj()))
108107
}
109108
case None => throw new IllegalArgumentException("No 'statements' field in request!")
@@ -149,5 +148,15 @@ trait ConnectionHandler extends ScalaBusMod {
149148
Ok(result)
150149
}
151150

152-
private def rowDataToJsonArray(rowData: RowData): JsonArray = Json.arr(rowData.toList: _*)
151+
private def dataToJson(data: Any): Any = data match {
152+
case null => null
153+
case x: Boolean => x
154+
case x: Number => x
155+
case x: String => x
156+
case x: Array[Byte] => x
157+
case x: JsonElement => x
158+
case x => x.toString()
159+
}
160+
161+
private def rowDataToJsonArray(rowData: RowData): JsonArray = Json.arr(rowData.map(dataToJson).toList: _*)
153162
}

src/main/scala/io/vertx/asyncsql/database/pool/AsyncConnectionPool.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package io.vertx.asyncsql.database.pool
22

3-
import scala.annotation.implicitNotFound
43
import scala.collection.mutable.Queue
54
import scala.concurrent.{ ExecutionContext, Future, Promise }
65
import scala.util.{ Failure, Success }
76
import org.vertx.java.core.impl.EventLoopContext
8-
import org.vertx.scala.platform.Verticle
97
import com.github.mauricio.async.db.{ Configuration, Connection }
108
import io.vertx.asyncsql.Starter
119
import org.vertx.scala.core.VertxExecutionContext
1210

13-
trait AsyncConnectionPool extends VertxExecutionContext {
11+
trait AsyncConnectionPool {
1412

1513
val maxPoolSize: Int
14+
val verticle: Starter
15+
implicit val executionContext = VertxExecutionContext.fromVertxAccess(verticle)
1616

1717
private var poolSize: Int = 0
1818
private val availableConnections: Queue[Connection] = Queue.empty

src/main/scala/io/vertx/asyncsql/database/pool/MySqlAsyncConnectionPool.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import org.vertx.scala.core.Vertx
1010
import org.vertx.scala.platform.Verticle
1111
import io.vertx.asyncsql.Starter
1212

13-
class MySqlAsyncConnectionPool(verticle: Starter, config: Configuration, eventLoop: EventLoop, val maxPoolSize: Int) extends AsyncConnectionPool {
13+
class MySqlAsyncConnectionPool(val verticle: Starter, config: Configuration, eventLoop: EventLoop, val maxPoolSize: Int) extends AsyncConnectionPool {
14+
15+
implicit val executionContext = VertxExecutionContext.fromVertxAccess(verticle)
16+
verticle.
1417

1518
override def create() = new MySQLConnection(configuration = config, group = eventLoop).connect
1619

src/main/scala/io/vertx/asyncsql/database/pool/PostgreSqlAsyncConnectionPool.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.vertx.scala.core.VertxExecutionContext
88
import org.vertx.scala.platform.Verticle
99
import io.vertx.asyncsql.Starter
1010

11-
class PostgreSqlAsyncConnectionPool(verticle: Starter, config: Configuration, eventLoop: EventLoop, val maxPoolSize: Int) extends AsyncConnectionPool {
11+
class PostgreSqlAsyncConnectionPool(val verticle: Starter, config: Configuration, eventLoop: EventLoop, val maxPoolSize: Int) extends AsyncConnectionPool {
1212

1313
override def create() = new PostgreSQLConnection(configuration = config, group = eventLoop).connect
1414

0 commit comments

Comments
 (0)