From 8670b1076d2bed64f7f91b446301e74094bf422d Mon Sep 17 00:00:00 2001 From: Petr Osipov Date: Fri, 25 Mar 2022 21:30:49 +0900 Subject: [PATCH 1/3] compiling project for scala 2.13 --- project/Build.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Build.scala b/project/Build.scala index b543b050..59a2cd4f 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -50,7 +50,7 @@ object ProjectBuild extends Build { object Configuration { val commonVersion = "0.2.22-SNAPSHOT" - val projectScalaVersion = "2.12.1" + val projectScalaVersion = "2.13.8" val specs2Version = "3.8.6" val specs2Dependency = "org.specs2" %% "specs2-core" % specs2Version % "test" From 4ee9aff5299e6a5be4d7d8397aab9d08aec3a1a0 Mon Sep 17 00:00:00 2001 From: Petr Osipov Date: Fri, 25 Mar 2022 21:32:02 +0900 Subject: [PATCH 2/3] using 0.2.21 version --- project/Build.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Build.scala b/project/Build.scala index 59a2cd4f..7539d9fd 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -49,7 +49,7 @@ object ProjectBuild extends Build { object Configuration { - val commonVersion = "0.2.22-SNAPSHOT" + val commonVersion = "0.2.21" val projectScalaVersion = "2.13.8" val specs2Version = "3.8.6" From e603d696f061fce9f3a895fcbdae38883578d47d Mon Sep 17 00:00:00 2001 From: Petr Osipov Date: Sat, 26 Mar 2022 16:10:11 +0900 Subject: [PATCH 3/3] adapting project code to 2.13 --- .../async/db/mysql/MySQLConnection.scala | 4 +-- .../mysql/codec/MySQLConnectionHandler.scala | 18 +++++------ .../message/server/ResultSetRowMessage.scala | 30 ++++++++++++------- .../PostgreSQLColumnEncoderRegistry.scala | 4 +-- project/Build.scala | 16 ++++++---- 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/MySQLConnection.scala b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/MySQLConnection.scala index cb4a85b0..2ec19a89 100644 --- a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/MySQLConnection.scala +++ b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/MySQLConnection.scala @@ -81,8 +81,8 @@ class MySQLConnection( override def eventLoopGroup : EventLoopGroup = group def connect: Future[Connection] = { - this.connectionHandler.connect.onFailure { - case e => this.connectionPromise.tryFailure(e) + this.connectionHandler.connect.onComplete { + case Failure(e) => this.connectionPromise.tryFailure(e) } this.connectionPromise.future diff --git a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/MySQLConnectionHandler.scala b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/MySQLConnectionHandler.scala index 792aff77..e18e0787 100644 --- a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/MySQLConnectionHandler.scala +++ b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/MySQLConnectionHandler.scala @@ -19,7 +19,6 @@ package com.github.mauricio.async.db.mysql.codec import java.net.InetSocketAddress import java.nio.ByteBuffer import java.util.concurrent.TimeUnit - import com.github.mauricio.async.db.Configuration import com.github.mauricio.async.db.exceptions.DatabaseException import com.github.mauricio.async.db.general.MutableResultSet @@ -39,6 +38,7 @@ import scala.annotation.switch import scala.collection.mutable.{ArrayBuffer, HashMap} import scala.concurrent._ import scala.concurrent.duration.Duration +import scala.util.Failure class MySQLConnectionHandler( configuration: Configuration, @@ -84,8 +84,8 @@ class MySQLConnectionHandler( this.bootstrap.option[java.lang.Boolean](ChannelOption.SO_KEEPALIVE, true) this.bootstrap.option[ByteBufAllocator](ChannelOption.ALLOCATOR, LittleEndianByteBufAllocator.INSTANCE) - this.bootstrap.connect(new InetSocketAddress(configuration.host, configuration.port)).onFailure { - case exception => this.connectionPromise.tryFailure(exception) + this.bootstrap.connect(new InetSocketAddress(configuration.host, configuration.port)).onComplete { + case Failure(exception) => this.connectionPromise.tryFailure(exception) } this.connectionPromise.future @@ -143,7 +143,7 @@ class MySQLConnectionHandler( } case ServerMessage.BinaryRow => { val message = m.asInstanceOf[BinaryRowMessage] - this.currentQuery.addRow( this.binaryRowDecoder.decode(message.buffer, this.currentColumns )) + this.currentQuery.addRow( this.binaryRowDecoder.decode(message.buffer, this.currentColumns.toSeq )) } case ServerMessage.ParamProcessingFinished => { } @@ -201,7 +201,7 @@ class MySQLConnectionHandler( this.parsedStatements.get(preparedStatement.statement) match { case Some( item ) => { - this.executePreparedStatement(item.statementId, item.columns.size, preparedStatement.values, item.parameters) + this.executePreparedStatement(item.statementId, item.columns.size, preparedStatement.values, item.parameters.toSeq) } case None => { decoder.preparedStatementPrepareStarted() @@ -305,7 +305,7 @@ class MySQLConnectionHandler( this.currentColumns } - this.currentQuery = new MutableResultSet[ColumnDefinitionMessage](columns) + this.currentQuery = new MutableResultSet[ColumnDefinitionMessage](columns.toIndexedSeq) if ( this.currentPreparedStatementHolder != null ) { this.parsedStatements.put( this.currentPreparedStatementHolder.statement, this.currentPreparedStatementHolder ) @@ -313,7 +313,7 @@ class MySQLConnectionHandler( this.currentPreparedStatementHolder.statementId, this.currentPreparedStatementHolder.columns.size, this.currentPreparedStatement.values, - this.currentPreparedStatementHolder.parameters + this.currentPreparedStatementHolder.parameters.toSeq ) this.currentPreparedStatementHolder = null this.currentPreparedStatement = null @@ -324,8 +324,8 @@ class MySQLConnectionHandler( if ( this.currentContext.channel().isActive ) { val res = this.currentContext.writeAndFlush(message) - res.onFailure { - case e : Throwable => handleException(e) + res.onComplete { + case Failure(e) => handleException(e) } res diff --git a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ResultSetRowMessage.scala b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ResultSetRowMessage.scala index da752575..05524d39 100644 --- a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ResultSetRowMessage.scala +++ b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ResultSetRowMessage.scala @@ -35,20 +35,10 @@ class ResultSetRowMessage buffer.update(n, newelem) } - def +=(elem: ByteBuf): this.type = { - this.buffer += elem - this - } - def clear() { this.buffer.clear() } - def +=:(elem: ByteBuf): this.type = { - this.buffer.+=:(elem) - this - } - def insertAll(n: Int, elems: Traversable[ByteBuf]) { this.buffer.insertAll(n, elems) } @@ -59,4 +49,24 @@ class ResultSetRowMessage override def iterator: Iterator[ByteBuf] = this.buffer.iterator + override def prepend(elem: ByteBuf): ResultSetRowMessage.this.type = { + buffer.prepend(elem) + this + } + + override def insert(idx: Int, elem: ByteBuf): Unit = buffer.insert(idx, elem) + + override def insertAll(idx: Int, elems: IterableOnce[ByteBuf]): Unit = buffer.insertAll(idx, elems) + + override def remove(idx: Int, count: Int): Unit = buffer.remove(idx, count) + + override def patchInPlace(from: Int, patch: IterableOnce[ByteBuf], replaced: Int): ResultSetRowMessage.this.type = { + buffer.patchInPlace(from, patch, replaced) + this + } + + override def addOne(elem: ByteBuf): ResultSetRowMessage.this.type = { + buffer.addOne(elem) + this + } } \ No newline at end of file diff --git a/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala b/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala index c9f95f43..9e0ae64e 100644 --- a/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala +++ b/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala @@ -22,7 +22,7 @@ import com.github.mauricio.async.db.column._ import io.netty.buffer.ByteBuf import org.joda.time._ -import scala.collection.JavaConversions._ +import scala.collection.p._ object PostgreSQLColumnEncoderRegistry { val Instance = new PostgreSQLColumnEncoderRegistry() @@ -107,7 +107,7 @@ class PostgreSQLColumnEncoderRegistry extends ColumnEncoderRegistry { encoder.get._1.encode(value) } else { value match { - case i: java.lang.Iterable[_] => encodeArray(i.toIterable) + case i: java.lang.Iterable[_] => encodeArray(i.toTraversable) case i: Traversable[_] => encodeArray(i) case i: Array[_] => encodeArray(i.toIterable) case p: Product => encodeComposite(p) diff --git a/project/Build.scala b/project/Build.scala index 7539d9fd..0eb00d43 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -13,7 +13,8 @@ object ProjectBuild extends Build { settings = Configuration.baseSettings ++ Seq( publish := (), publishLocal := (), - publishArtifact := false + publishArtifact := false, + scalaVersion := Configuration.projectScalaVersion ), aggregate = Seq(common, postgresql, mysql) ) @@ -23,7 +24,8 @@ object ProjectBuild extends Build { base = file(commonName), settings = Configuration.baseSettings ++ Seq( name := commonName, - libraryDependencies ++= Configuration.commonDependencies + libraryDependencies ++= Configuration.commonDependencies, + scalaVersion := Configuration.projectScalaVersion ) ) @@ -32,7 +34,8 @@ object ProjectBuild extends Build { base = file(postgresqlName), settings = Configuration.baseSettings ++ Seq( name := postgresqlName, - libraryDependencies ++= Configuration.implementationDependencies + libraryDependencies ++= Configuration.implementationDependencies, + scalaVersion := Configuration.projectScalaVersion ) ) dependsOn (common) @@ -41,7 +44,8 @@ object ProjectBuild extends Build { base = file(mysqlName), settings = Configuration.baseSettings ++ Seq( name := mysqlName, - libraryDependencies ++= Configuration.implementationDependencies + libraryDependencies ++= Configuration.implementationDependencies, + scalaVersion := Configuration.projectScalaVersion ) ) dependsOn (common) @@ -51,7 +55,7 @@ object Configuration { val commonVersion = "0.2.21" val projectScalaVersion = "2.13.8" - val specs2Version = "3.8.6" + val specs2Version = "4.5.1" val specs2Dependency = "org.specs2" %% "specs2-core" % specs2Version % "test" val specs2JunitDependency = "org.specs2" %% "specs2-junit" % specs2Version % "test" @@ -84,7 +88,7 @@ object Configuration { , testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential"), scalacOptions in doc := Seq("-doc-external-doc:scala=http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/"), - crossScalaVersions := Seq(projectScalaVersion, "2.10.6", "2.11.8"), + crossScalaVersions := Seq(projectScalaVersion), javacOptions := Seq("-source", "1.6", "-target", "1.6", "-encoding", "UTF8"), organization := "com.github.mauricio", version := commonVersion,