Skip to content

Commit 4680c6d

Browse files
committed
more porting to lang-scala 0.2.0-SNAPSHOT
1 parent 129e743 commit 4680c6d

14 files changed

+85
-124
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ scalaVersion=2.10.2
2929
gradleVersion=1.6
3030

3131
# The version of Vert.x
32-
vertxVersion=2.0.0-final
32+
vertxVersion=2.0.1-final
3333

3434
# The version of Vert.x test tools
35-
toolsVersion=2.0.0-final
35+
toolsVersion=2.0.2-SNAPSHOT
3636

3737
# The version of JUnit
3838
junitVersion=4.10

src/main/scala/io/vertx/asyncsql/Starter.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package io.vertx.asyncsql
22

3-
import io.vertx.helpers.Verticle
3+
import scala.concurrent.Promise
4+
5+
import org.vertx.scala.core.json.{ Json, JsonObject }
6+
import org.vertx.scala.platform.Verticle
7+
48
import com.github.mauricio.async.db.Configuration
5-
import org.vertx.scala.core.eventbus.EventBus._
6-
import org.vertx.scala.core.json._
7-
import io.vertx.asyncsql.database.ConnectionHandler
8-
import io.vertx.asyncsql.database.MySqlConnectionHandler
9-
import io.vertx.asyncsql.database.PostgreSqlConnectionHandler
10-
import org.vertx.scala.core.Future
9+
10+
import io.vertx.asyncsql.database.{ ConnectionHandler, MySqlConnectionHandler, PostgreSqlConnectionHandler }
1111

1212
class Starter extends Verticle {
1313

1414
var handler: ConnectionHandler = null
1515

16-
override def start(startedResult: org.vertx.scala.core.Future[Void]) = {
16+
override def start(startedResult: Promise[Unit]) = {
1717

1818
logger.error("Starting async database module for MySQL and PostgreSQL.")
1919

@@ -32,11 +32,11 @@ class Starter extends Verticle {
3232

3333
logger.error("Async database module for MySQL and PostgreSQL started with config " + configuration)
3434

35-
startedResult.setResult(null)
35+
startedResult.success()
3636
} catch {
3737
case ex: Throwable =>
3838
logger.fatal("could not start async database module!", ex)
39-
startedResult.setFailure(ex)
39+
startedResult.failure(ex)
4040
}
4141
}
4242

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
package io.vertx.asyncsql.database
22

3-
import org.vertx.scala.core.eventbus.Message
4-
import com.github.mauricio.async.db.Configuration
5-
import io.vertx.asyncsql.database.pool.PostgreSqlAsyncConnectionPool
6-
import io.vertx.helpers.VertxExecutionContext
7-
import com.github.mauricio.async.db.Connection
8-
import io.vertx.busmod.ScalaBusMod
3+
import scala.collection.JavaConverters.iterableAsScalaIterableConverter
94
import scala.concurrent.Future
5+
6+
import org.vertx.scala.core.eventbus.Message
7+
import org.vertx.scala.core.json.{ JsonArray, JsonObject }
8+
import org.vertx.scala.core.logging.Logger
9+
import org.vertx.scala.platform.Verticle
10+
11+
import com.github.mauricio.async.db.{ Configuration, Connection, QueryResult, RowData }
12+
import com.github.mauricio.async.db.postgresql.exceptions.GenericDatabaseException
13+
1014
import io.vertx.asyncsql.database.pool.AsyncConnectionPool
11-
import org.vertx.scala.core.Vertx
12-
import io.vertx.helpers.Verticle
13-
import com.github.mauricio.async.db.QueryResult
15+
import io.vertx.busmod.ScalaBusMod
1416
import io.vertx.helpers.VertxScalaHelpers
15-
import com.github.mauricio.async.db.RowData
16-
import collection.JavaConverters._
17-
import com.github.mauricio.async.db.postgresql.exceptions.GenericDatabaseException
18-
import org.vertx.scala.core.json._
19-
import org.vertx.scala.core.logging.Logger
2017

2118
trait ConnectionHandler extends ScalaBusMod with VertxScalaHelpers {
2219
val verticle: Verticle
2320
def dbType: String
2421
val config: Configuration
25-
val logger: Logger // = verticle.container.logger()
22+
lazy val logger: Logger = verticle.logger
2623
val pool = AsyncConnectionPool(verticle.vertx, dbType, config)
2724

2825
def transactionStart: String = "START TRANSACTION;"
@@ -31,11 +28,11 @@ trait ConnectionHandler extends ScalaBusMod with VertxScalaHelpers {
3128

3229
import org.vertx.scala.core.eventbus._
3330
override def asyncReceive(msg: Message[JsonObject]) = {
34-
case "select" => select(msg.body.asInstanceOf[JsonObject])
35-
case "insert" => insert(msg.body.asInstanceOf[JsonObject])
36-
case "prepared" => prepared(msg.body.asInstanceOf[JsonObject])
37-
case "transaction" => transaction(msg.body.asInstanceOf[JsonObject])
38-
case "raw" => rawCommand(msg.body.asInstanceOf[JsonObject].getString("command"))
31+
case "select" => select(msg.body)
32+
case "insert" => insert(msg.body)
33+
case "prepared" => prepared(msg.body)
34+
case "transaction" => transaction(msg.body)
35+
case "raw" => rawCommand(msg.body.getString("command"))
3936
}
4037

4138
def close() = pool.close
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package io.vertx.asyncsql.database
22

3-
import io.vertx.helpers.Verticle
3+
import org.vertx.scala.platform.Verticle
4+
45
import com.github.mauricio.async.db.Configuration
5-
import org.vertx.scala.core.logging.Logger
66

77
class MySqlConnectionHandler(val verticle: Verticle, val config: Configuration, val dbType: String = "mysql") extends ConnectionHandler {
8-
val logger = new Logger(verticle.container.logger)
98
override protected def escapeField(str: String): String = "`" + str.replace("`", "\\`") + "`"
109
override protected def escapeString(str: String): String = "'" + str.replace("'", "''") + "'"
1110

12-
// override def transactionStart = "START TRANSACTION;"
13-
// override def transactionEnd = ";COMMIT;"
14-
// override def statementDelimiter = ";"
11+
// override def transactionStart = "START TRANSACTION;"
12+
// override def transactionEnd = ";COMMIT;"
13+
// override def statementDelimiter = ";"
1514
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package io.vertx.asyncsql.database
22

3-
import io.vertx.helpers.Verticle
3+
import org.vertx.scala.platform.Verticle
4+
45
import com.github.mauricio.async.db.Configuration
5-
import org.vertx.scala.core.logging.Logger
66

77
class PostgreSqlConnectionHandler(val verticle: Verticle, val config: Configuration, val dbType: String = "postgresql") extends ConnectionHandler {
8-
val logger = new Logger(verticle.container.logger)
98
}

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

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

3-
import com.github.mauricio.async.db.Configuration
3+
import scala.concurrent.{ ExecutionContext, Future }
4+
import com.github.mauricio.async.db.{ Configuration, Connection }
5+
import com.github.mauricio.async.db.mysql.MySQLConnection
46
import com.github.mauricio.async.db.postgresql.PostgreSQLConnection
5-
import scala.concurrent.Future
6-
import scala.concurrent.ExecutionContext
7-
import io.vertx.helpers.VertxExecutionContext
8-
import com.github.mauricio.async.db.Connection
9-
import org.vertx.java.core.impl.EventLoopContext
107
import io.netty.channel.EventLoop
11-
import com.github.mauricio.async.db.mysql.MySQLConnection
8+
import org.vertx.scala.core.VertxExecutionContext
129

1310
class MySqlAsyncConnectionPool(config: Configuration, eventLoop: EventLoop, implicit val executionContext: ExecutionContext = VertxExecutionContext) extends AsyncConnectionPool[PostgreSQLConnection] {
1411

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

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

3-
import com.github.mauricio.async.db.Configuration
3+
import scala.concurrent.{ ExecutionContext, Future }
4+
import com.github.mauricio.async.db.{ Configuration, Connection }
45
import com.github.mauricio.async.db.postgresql.PostgreSQLConnection
5-
import scala.concurrent.Future
6-
import scala.concurrent.ExecutionContext
7-
import io.vertx.helpers.VertxExecutionContext
8-
import com.github.mauricio.async.db.Connection
9-
import org.vertx.java.core.impl.EventLoopContext
106
import io.netty.channel.EventLoop
7+
import org.vertx.scala.core.VertxExecutionContext
118

129
class PostgreSqlAsyncConnectionPool(config: Configuration, eventLoop: EventLoop, implicit val executionContext: ExecutionContext = VertxExecutionContext) extends AsyncConnectionPool[PostgreSQLConnection] {
1310

src/main/scala/io/vertx/busmod/ScalaBusMod.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package io.vertx.busmod
22

33
import scala.concurrent.Future
44

5-
import org.vertx.scala.core.json._
6-
import org.vertx.scala.core.eventbus.Message
5+
import org.vertx.scala.core.VertxExecutionContext
6+
import org.vertx.scala.core.eventbus.{ JsonObjectData, Message }
7+
import org.vertx.scala.core.json.{ Json, JsonObject }
78

8-
import io.vertx.helpers.VertxExecutionContext
99
import io.vertx.asyncsql.messages.MessageHelper
1010

1111
trait ScalaBusMod extends MessageHelper with VertxExecutionContext with (Message[JsonObject] => Unit) {
1212

1313
override def apply(msg: Message[JsonObject]) = {
14-
val action = msg.body.asInstanceOf[JsonObject].getString("action")
14+
val action = msg.body.getString("action")
1515

1616
val fut: Future[Reply] = try {
1717
if (receive(msg).isDefinedAt(action)) {

src/main/scala/io/vertx/helpers/Verticle.scala

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/scala/io/vertx/helpers/VertxExecutionContext.scala

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/scala/io/vertx/helpers/VertxFutureHelpers.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package io.vertx.helpers
22

3-
import java.net.URI
4-
import scala.concurrent.{ Future, Promise }
5-
import org.vertx.java.core.AsyncResult
6-
import org.vertx.java.core.buffer.Buffer
7-
import org.vertx.java.core.eventbus.Message
8-
import org.vertx.java.core.file.AsyncFile
9-
import org.vertx.java.core.http.HttpClientResponse
10-
import org.vertx.java.core.json.JsonObject
3+
import scala.concurrent.Promise
4+
import org.vertx.scala.platform.Verticle
115

126
trait VertxFutureHelpers extends VertxScalaHelpers {
137
this: Verticle =>

src/test/scala/io/vertx/asyncsql/test/BaseSqlTests.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.vertx.asyncsql.test
22

3+
import scala.collection.JavaConversions.iterableAsScalaIterable
34
import scala.concurrent.Future
4-
import org.vertx.scala.core.json.JsonArray
5-
import org.vertx.testtools.VertxAssert._
6-
import org.vertx.scala.core.json.Json
7-
import org.vertx.scala.core.logging.Logger
5+
6+
import org.vertx.scala.core.json.{Json, JsonArray}
7+
import org.vertx.testtools.VertxAssert.{assertEquals, assertTrue}
88

99
trait BaseSqlTests { this: SqlTestVerticle =>
10-
lazy val logger = new Logger(container.logger())
1110

1211
def withTable[X](tableName: String)(fn: => Future[X]) = {
1312
(for {
@@ -153,7 +152,7 @@ trait BaseSqlTests { this: SqlTestVerticle =>
153152
val receivedFields = reply.getArray("fields")
154153
assertTrue("arrays " + fieldsArray.encode() + " and " + receivedFields.encode() +
155154
" should match", fieldsArray == receivedFields)
156-
// assertEquals(2, reply.getInteger("rows"))
155+
// assertEquals(2, reply.getInteger("rows"))
157156
val results = reply.getArray("results")
158157
val mrOrMrs = results.get[JsonArray](0)
159158
mrOrMrs.get[String](0) match {
@@ -171,7 +170,7 @@ trait BaseSqlTests { this: SqlTestVerticle =>
171170
expectOk(prepared("SELECT email FROM some_test WHERE name=? AND age=?", Json.arr(List("Mr. Test", 15)))) map { reply =>
172171
val receivedFields = reply.getArray("fields")
173172
assertEquals(Json.arr(List("email")), receivedFields)
174-
// assertEquals(1, reply.getInteger("rows"))
173+
// assertEquals(1, reply.getInteger("rows"))
175174
assertEquals("test@example.com", reply.getArray("results").get[JsonArray](0).get[String](0))
176175
}
177176
}

src/test/scala/io/vertx/asyncsql/test/BaseVertxIntegrationTest.scala

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package io.vertx.asyncsql.test
22

3-
import org.vertx.scala.core.json.JsonObject
4-
import scala.concurrent.Future
5-
import scala.concurrent.Promise
6-
import org.vertx.scala.core.Vertx
7-
import org.vertx.scala.testtools.TestVerticle
8-
import org.vertx.testtools.VertxAssert._
9-
import io.vertx.helpers.VertxExecutionContext
3+
import scala.concurrent.{ Future, Promise }
4+
105
import org.vertx.scala.core.eventbus.Message
11-
import java.util.concurrent.atomic.AtomicInteger
6+
import org.vertx.scala.core.json.JsonObject
127
import org.vertx.scala.core.logging.Logger
8+
import org.vertx.scala.testtools.TestVerticle
9+
import org.vertx.testtools.VertxAssert.{ assertEquals, fail, testComplete }
1310

1411
trait BaseVertxIntegrationTest { this: TestVerticle =>
15-
var log: Logger = null
16-
1712
val address: String
1813

1914
protected def asyncTest[X](fn: => Future[X]): Future[Unit] = {
2015
fn recover {
2116
case x =>
22-
log.error("async fail in test code!", x)
17+
logger.error("async fail in test code!", x)
2318
fail("Something failed asynchronously: " + x.getClass() + x.getMessage())
2419
} map { _ =>
2520
testComplete
@@ -28,9 +23,9 @@ trait BaseVertxIntegrationTest { this: TestVerticle =>
2823

2924
protected def ebSend(q: JsonObject): Future[JsonObject] = {
3025
val p = Promise[JsonObject]
31-
log.info("sending " + q.encode() + " to " + address)
26+
logger.info("sending " + q.encode() + " to " + address)
3227
vertx.eventBus.send(address, q, { reply: Message[JsonObject] =>
33-
log.info("got a reply: " + reply.body.asInstanceOf[JsonObject].encode())
28+
logger.info("got a reply: " + reply.body.asInstanceOf[JsonObject].encode())
3429
p.success(reply.body.asInstanceOf[JsonObject])
3530
})
3631
p.future

src/test/scala/io/vertx/asyncsql/test/SqlTestVerticle.scala

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

3-
import io.vertx.helpers.VertxExecutionContext
4-
import scala.concurrent.Future
5-
import org.vertx.testtools.VertxAssert._
6-
import org.vertx.scala.platform.Verticle
7-
import org.junit.runner.RunWith
8-
import java.lang.reflect.InvocationTargetException
9-
import org.vertx.java.core.logging.impl.LoggerFactory
10-
import scala.concurrent.Promise
11-
import org.vertx.scala.core.eventbus.Message
12-
import org.vertx.scala.core.Vertx
13-
import io.vertx.helpers.VertxScalaHelpers
14-
import org.vertx.scala.core.json._
15-
import org.vertx.scala.core.logging.Logger
16-
import org.vertx.scala.testtools.TestVerticle
3+
import scala.concurrent.{ Future, Promise }
4+
import scala.util.{ Failure, Success }
5+
176
import org.vertx.scala.core.AsyncResult
7+
import org.vertx.scala.core.json.{ Json, JsonArray, JsonObject }
8+
import org.vertx.scala.testtools.TestVerticle
9+
import org.vertx.testtools.VertxAssert.{ assertEquals, assertTrue }
10+
11+
import io.vertx.helpers.VertxScalaHelpers
1812

1913
abstract class SqlTestVerticle extends TestVerticle with BaseVertxIntegrationTest with VertxScalaHelpers {
2014

2115
override final def before() {}
2216
override def asyncBefore(): Future[Unit] = {
2317
val p = Promise[Unit]
18+
println("DEPLOYING !!!")
2419
container.deployModule(System.getProperty("vertx.modulename"), getConfig(), 1, { deploymentID: AsyncResult[String] =>
20+
println("deployed? " + deploymentID.succeeded())
2521
if (deploymentID.failed()) {
26-
log.info(deploymentID.cause())
22+
logger.info(deploymentID.cause())
23+
p.failure(deploymentID.cause())
2724
}
2825
assertTrue("deploymentID should not be null", deploymentID.succeeded())
2926

30-
doBefore() map { _ =>
31-
log.info("starting tests")
32-
p.success()
27+
before()
28+
doBefore() onComplete {
29+
case Success(_) =>
30+
logger.info("starting tests")
31+
println("should start tests now...")
32+
p.success()
33+
case Failure(ex) => p.failure(ex)
3334
}
35+
println("async doBefore() started")
3436
})
3537
p.future
3638
}
3739

3840
def doBefore(): Future[_] = {
41+
println("in doBefore()")
42+
3943
Future.successful()
4044
}
4145

0 commit comments

Comments
 (0)