├── project
├── build.properties
└── plugins.sbt
├── Procfile
├── postgresql-async
└── src
│ ├── main
│ └── scala
│ │ └── com
│ │ └── github
│ │ └── mauricio
│ │ └── async
│ │ └── db
│ │ └── postgresql
│ │ ├── messages
│ │ ├── frontend
│ │ │ ├── InitialClientMessage.scala
│ │ │ ├── SSLRequestMessage.scala
│ │ │ ├── StartupMessage.scala
│ │ │ ├── ClientMessage.scala
│ │ │ ├── CloseMessage.scala
│ │ │ ├── QueryMessage.scala
│ │ │ ├── PreparedStatementExecuteMessage.scala
│ │ │ ├── CredentialMessage.scala
│ │ │ ├── PreparedStatementOpeningMessage.scala
│ │ │ └── PreparedStatementMessage.scala
│ │ └── backend
│ │ │ ├── SSLResponseMessage.scala
│ │ │ ├── NoData.scala
│ │ │ ├── CloseComplete.scala
│ │ │ ├── BindComplete.scala
│ │ │ ├── ParseComplete.scala
│ │ │ ├── EmptyQueryString.scala
│ │ │ ├── AuthenticationMessage.scala
│ │ │ ├── ErrorMessage.scala
│ │ │ ├── NoticeMessage.scala
│ │ │ ├── ReadyForQueryMessage.scala
│ │ │ ├── ProcessData.scala
│ │ │ ├── DataRowMessage.scala
│ │ │ ├── ParameterStatusMessage.scala
│ │ │ ├── RowDescriptionMessage.scala
│ │ │ ├── CommandCompleteMessage.scala
│ │ │ ├── AuthenticationChallengeMD5.scala
│ │ │ ├── AuthenticationResponseType.scala
│ │ │ ├── AuthenticationOkMessage.scala
│ │ │ ├── NotificationResponse.scala
│ │ │ ├── AuthenticationChallengeMessage.scala
│ │ │ ├── AuthenticationChallengeCleartextMessage.scala
│ │ │ └── PostgreSQLColumnData.scala
│ │ ├── encoders
│ │ ├── SSLMessageEncoder.scala
│ │ ├── Encoder.scala
│ │ └── CloseMessageEncoder.scala
│ │ ├── exceptions
│ │ ├── NotConnectedException.scala
│ │ ├── ColumnDecoderNotFoundException.scala
│ │ ├── InvalidArrayException.scala
│ │ ├── MessageTooLongException.scala
│ │ ├── GenericDatabaseException.scala
│ │ ├── QueryMustNotBeNullOrEmptyException.scala
│ │ └── ByteArrayFormatNotSupportedException.scala
│ │ ├── column
│ │ ├── CharEncoderDecoder.scala
│ │ ├── SingleByteEncoderDecoder.scala
│ │ └── BooleanEncoderDecoder.scala
│ │ ├── parsers
│ │ ├── MessageParser.scala
│ │ ├── ErrorParser.scala
│ │ ├── NoticeParser.scala
│ │ ├── BackendKeyDataParser.scala
│ │ ├── ReadyForQueryParser.scala
│ │ ├── ParameterStatusParser.scala
│ │ ├── NotificationResponseParser.scala
│ │ ├── DataRowParser.scala
│ │ └── ReturningMessageParser.scala
│ │ ├── util
│ │ ├── ArrayStreamingParserDelegate.scala
│ │ └── package.scala
│ │ └── codec
│ │ └── PostgreSQLConnectionDelegate.scala
│ └── test
│ ├── resources
│ └── logback.xml
│ └── scala
│ └── com
│ └── github
│ └── mauricio
│ └── async
│ └── db
│ └── postgresql
│ ├── util
│ └── PasswordHelperSpec.scala
│ ├── TestUtils.scala
│ ├── encoders
│ └── ExecutePreparedStatementEncoderSpec.scala
│ ├── PostgreSQLSSLConnectionSpec.scala
│ └── parsers
│ └── ParserKSpec.scala
├── bootstrap.sh
├── mysql-async
└── src
│ ├── main
│ └── scala
│ │ └── com
│ │ └── github
│ │ └── mauricio
│ │ └── async
│ │ └── db
│ │ └── mysql
│ │ ├── message
│ │ ├── client
│ │ │ ├── QuitMessage.scala
│ │ │ ├── SendLongDataMessage.scala
│ │ │ ├── AuthenticationSwitchResponse.scala
│ │ │ ├── QueryMessage.scala
│ │ │ ├── PreparedStatementPrepareMessage.scala
│ │ │ ├── PreparedStatementExecuteMessage.scala
│ │ │ ├── ClientMessage.scala
│ │ │ └── HandshakeResponseMessage.scala
│ │ └── server
│ │ │ ├── AuthenticationSwitchRequest.scala
│ │ │ ├── EOFMessage.scala
│ │ │ ├── ErrorMessage.scala
│ │ │ ├── BinaryRowMessage.scala
│ │ │ ├── ColumnProcessingFinishedMessage.scala
│ │ │ ├── ParamProcessingFinishedMessage.scala
│ │ │ ├── ParamAndColumnProcessingFinishedMessage.scala
│ │ │ ├── PreparedStatementPrepareResponse.scala
│ │ │ ├── OkMessage.scala
│ │ │ ├── HandshakeMessage.scala
│ │ │ └── ServerMessage.scala
│ │ ├── binary
│ │ ├── encoder
│ │ │ ├── ByteBufEncoder.scala
│ │ │ ├── ByteBufferEncoder.scala
│ │ │ ├── BinaryEncoder.scala
│ │ │ ├── FloatEncoder.scala
│ │ │ ├── IntegerEncoder.scala
│ │ │ ├── LongEncoder.scala
│ │ │ ├── ShortEncoder.scala
│ │ │ ├── DoubleEncoder.scala
│ │ │ ├── ByteEncoder.scala
│ │ │ ├── SQLDateEncoder.scala
│ │ │ ├── BooleanEncoder.scala
│ │ │ ├── ReadableInstantEncoder.scala
│ │ │ ├── DateTimeEncoder.scala
│ │ │ ├── JavaDateEncoder.scala
│ │ │ ├── SQLTimeEncoder.scala
│ │ │ ├── SQLTimestampEncoder.scala
│ │ │ ├── ByteArrayEncoder.scala
│ │ │ ├── CalendarEncoder.scala
│ │ │ ├── StringEncoder.scala
│ │ │ └── LocalDateEncoder.scala
│ │ └── decoder
│ │ │ ├── BinaryDecoder.scala
│ │ │ ├── NullDecoder.scala
│ │ │ ├── ShortDecoder.scala
│ │ │ ├── LongDecoder.scala
│ │ │ ├── ByteDecoder.scala
│ │ │ ├── DoubleDecoder.scala
│ │ │ ├── FloatDecoder.scala
│ │ │ ├── IntegerDecoder.scala
│ │ │ ├── BigDecimalDecoder.scala
│ │ │ ├── DateDecoder.scala
│ │ │ ├── ByteArrayDecoder.scala
│ │ │ └── StringDecoder.scala
│ │ ├── decoder
│ │ ├── AuthenticationSwitchRequestDecoder.scala
│ │ ├── MessageDecoder.scala
│ │ ├── EOFMessageDecoder.scala
│ │ ├── ParamProcessingFinishedDecoder.scala
│ │ ├── ColumnProcessingFinishedDecoder.scala
│ │ ├── ParamAndColumnProcessingFinishedDecoder.scala
│ │ ├── OkDecoder.scala
│ │ └── ErrorDecoder.scala
│ │ ├── codec
│ │ ├── PreparedStatement.scala
│ │ ├── MySQLHandlerDelegate.scala
│ │ └── SendLongDataEncoder.scala
│ │ ├── encoder
│ │ ├── MessageEncoder.scala
│ │ ├── AuthenticationSwitchResponseEncoder.scala
│ │ ├── QuitMessageEncoder.scala
│ │ ├── auth
│ │ │ └── AuthenticationMethod.scala
│ │ ├── QueryMessageEncoder.scala
│ │ └── PreparedStatementPrepareEncoder.scala
│ │ ├── MySQLQueryResult.scala
│ │ ├── exceptions
│ │ ├── CharsetMappingNotAvailableException.scala
│ │ └── MySQLException.scala
│ │ ├── util
│ │ ├── MySQLIO.scala
│ │ └── URLParser.scala
│ │ └── column
│ │ ├── ByteArrayColumnDecoder.scala
│ │ └── TimeDecoder.scala
│ └── test
│ └── resources
│ └── logback.xml
├── db-async-common
└── src
│ ├── main
│ └── scala
│ │ └── com
│ │ └── github
│ │ └── mauricio
│ │ └── async
│ │ └── db
│ │ ├── exceptions
│ │ ├── ConnectionNotConnectedException.scala
│ │ ├── ConnectionTimeoutedException.scala
│ │ ├── UnknownLengthException.scala
│ │ ├── DatabaseException.scala
│ │ ├── NegativeMessageSizeException.scala
│ │ ├── ParserNotAvailableException.scala
│ │ ├── DateEncoderNotAvailableException.scala
│ │ ├── EncoderNotAvailableException.scala
│ │ ├── CanceledChannelFutureException.scala
│ │ ├── BufferNotFullyConsumedException.scala
│ │ ├── ConnectionStillRunningQueryException.scala
│ │ ├── UnableToParseURLException.scala
│ │ ├── UnsupportedAuthenticationMethodException.scala
│ │ └── InsufficientParametersException.scala
│ │ ├── KindedMessage.scala
│ │ ├── column
│ │ ├── ColumnEncoderDecoder.scala
│ │ ├── ColumnEncoder.scala
│ │ ├── ByteDecoder.scala
│ │ ├── LongEncoderDecoder.scala
│ │ ├── FloatEncoderDecoder.scala
│ │ ├── ShortEncoderDecoder.scala
│ │ ├── StringEncoderDecoder.scala
│ │ ├── BigIntegerEncoderDecoder.scala
│ │ ├── ColumnEncoderRegistry.scala
│ │ ├── DoubleEncoderDecoder.scala
│ │ ├── IntegerEncoderDecoder.scala
│ │ ├── BigDecimalEncoderDecoder.scala
│ │ ├── UUIDEncoderDecoder.scala
│ │ ├── ColumnDecoderRegistry.scala
│ │ ├── TimeWithTimezoneEncoderDecoder.scala
│ │ ├── TimestampWithTimezoneEncoderDecoder.scala
│ │ ├── SQLTimeEncoder.scala
│ │ ├── ColumnDecoder.scala
│ │ └── InetAddressEncoderDecoder.scala
│ │ ├── general
│ │ └── ColumnData.scala
│ │ ├── util
│ │ ├── Log.scala
│ │ ├── FutureUtils.scala
│ │ ├── NettyUtils.scala
│ │ ├── PrintUtils.scala
│ │ ├── ExecutorServiceUtils.scala
│ │ └── DaemonThreadsFactory.scala
│ │ ├── pool
│ │ ├── PoolAlreadyTerminatedException.scala
│ │ ├── PoolExhaustedException.scala
│ │ └── PartitionedConnectionPool.scala
│ │ ├── QueryResult.scala
│ │ └── ResultSet.scala
│ └── test
│ ├── resources
│ └── logback.xml
│ └── scala
│ └── com
│ └── github
│ └── mauricio
│ └── async
│ └── db
│ └── pool
│ └── DummyTimeoutScheduler.scala
├── .gitignore
└── .travis.yml
/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version = 0.13.13
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | postgresql: postgres -D vendor/postgresql
2 | mysql: mysqld --log-warnings --console
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/InitialClientMessage.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.messages.frontend
2 |
3 | trait InitialClientMessage
4 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/SSLResponseMessage.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.messages.backend
2 |
3 | case class SSLResponseMessage(supported: Boolean)
4 |
--------------------------------------------------------------------------------
/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | yum -y install mysql-server
3 | service mysqld start
4 | mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO root;"
5 | mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'mysql_vagrant' IDENTIFIED BY 'generic_password' WITH GRANT OPTION";
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/QuitMessage.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.message.client
2 |
3 | object QuitMessage {
4 | val Instance = new QuitMessage();
5 | }
6 |
7 | class QuitMessage extends ClientMessage( ClientMessage.Quit )
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/SSLRequestMessage.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.messages.frontend
2 |
3 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
4 |
5 | object SSLRequestMessage extends InitialClientMessage
6 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/AuthenticationSwitchRequest.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.message.server
2 |
3 | case class AuthenticationSwitchRequest(
4 | method : String,
5 | seed : String )
6 | extends ServerMessage(ServerMessage.EOF)
7 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/ConnectionNotConnectedException.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.exceptions
2 |
3 | import com.github.mauricio.async.db.Connection
4 |
5 | class ConnectionNotConnectedException( val connection : Connection )
6 | extends DatabaseException( "The connection %s is not connected to the database".format(connection) )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/ConnectionTimeoutedException.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.exceptions
2 |
3 | import com.github.mauricio.async.db.Connection
4 |
5 | class ConnectionTimeoutedException( val connection : Connection )
6 | extends DatabaseException( "The connection %s has a timeouted query and is being closed".format(connection) )
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | databases/*
2 | out/*
3 | generate_bundles.rb
4 | .cache
5 | target/*
6 | bin/*
7 | .idea*
8 | .classpath
9 | .project/*
10 | **/.settings/*
11 | project/target/*
12 | project/project/*
13 | postgresql-async/target/*
14 | db-async-common/target/*
15 | mysql-async/target/*
16 | .rvmrc
17 | .ruby-version
18 | .ruby-gemset
19 | *.jar
20 | *.iml
21 | .project
22 | .vagrant/*
23 | vendor/*
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/SendLongDataMessage.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.message.client
2 |
3 | import io.netty.buffer.ByteBuf
4 |
5 | case class SendLongDataMessage (
6 | statementId : Array[Byte],
7 | value : ByteBuf,
8 | paramId : Int )
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: scala
2 | scala:
3 | - 2.10.4
4 | - 2.11.7
5 | - 2.12.1
6 |
7 | jdk:
8 | - oraclejdk8
9 |
10 | services:
11 | - postgresql
12 | - mysql
13 | cache:
14 | directories:
15 | - vendor/bundle
16 | - $HOME/.m2
17 | - $HOME/.ivy2
18 | - $HOME/.sbt
19 | before_script:
20 | - ./script/prepare_build.sh
21 |
22 | notifications:
23 | email:
24 | - linhares.mauricio@gmail.com
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/AuthenticationSwitchResponse.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.message.client
2 |
3 | import com.github.mauricio.async.db.mysql.message.server.AuthenticationSwitchRequest
4 |
5 | case class AuthenticationSwitchResponse( password : Option[String], request : AuthenticationSwitchRequest )
6 | extends ClientMessage(ClientMessage.AuthSwitchResponse)
--------------------------------------------------------------------------------
/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
2 |
3 | addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
4 |
5 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
6 |
7 | addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.0")
8 |
9 | resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
10 |
11 | // pgpSigningKey := Some(0xB98761578C650D77L)
12 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/encoders/SSLMessageEncoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.encoders
2 |
3 | import io.netty.buffer.ByteBuf
4 | import io.netty.buffer.Unpooled
5 |
6 | object SSLMessageEncoder {
7 |
8 | def encode(): ByteBuf = {
9 | val buffer = Unpooled.buffer()
10 | buffer.writeInt(8)
11 | buffer.writeShort(1234)
12 | buffer.writeShort(5679)
13 | buffer
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ByteBufEncoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.binary.encoder
2 |
3 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
4 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
5 | import io.netty.buffer.ByteBuf
6 |
7 | object ByteBufEncoder extends BinaryEncoder {
8 | def encode(value: Any, buffer: ByteBuf) {
9 | val bytes = value.asInstanceOf[ByteBuf]
10 |
11 | buffer.writeLength(bytes.readableBytes())
12 | buffer.writeBytes(bytes)
13 | }
14 |
15 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_BLOB
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/mysql-async/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [%level][%thread][%d][%c{5}] %msg%ex%n
6 |
7 |
8 |
9 |
10 | target/mysql-async-tests.log
11 |
12 | [%level][%thread][%d][%c{5}] %msg%ex%n
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ByteBufferEncoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.binary.encoder
2 |
3 | import java.nio.ByteBuffer
4 |
5 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
6 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
7 | import io.netty.buffer.ByteBuf
8 |
9 | object ByteBufferEncoder extends BinaryEncoder {
10 | def encode(value: Any, buffer: ByteBuf) {
11 | val bytes = value.asInstanceOf[ByteBuffer]
12 |
13 | buffer.writeLength(bytes.remaining())
14 | buffer.writeBytes(bytes)
15 | }
16 |
17 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_BLOB
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/postgresql-async/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [%level][%thread][%d] %msg%ex%n
6 |
7 |
8 |
9 |
10 | target/postgresql-async-tests.log
11 |
12 | [%level][%thread][%d] %msg%ex%n
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/db-async-common/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [%level][%thread][%d][%c{5}] %msg%ex%n
6 |
7 |
8 |
9 |
10 | target/common-async-tests.log
11 |
12 | [%level][%thread][%d][%c{5}] %msg%ex%n
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/AuthenticationSwitchRequestDecoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.decoder
2 |
3 | import java.nio.charset.Charset
4 | import io.netty.buffer.ByteBuf
5 | import com.github.mauricio.async.db.mysql.message.server.{AuthenticationSwitchRequest, ServerMessage}
6 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
7 |
8 | class AuthenticationSwitchRequestDecoder( charset : Charset ) extends MessageDecoder {
9 | def decode(buffer: ByteBuf): ServerMessage = {
10 | new AuthenticationSwitchRequest(
11 | buffer.readCString(charset),
12 | buffer.readUntilEOF(charset)
13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/KindedMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db
18 |
19 | trait KindedMessage extends Serializable {
20 |
21 | def kind : Int
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ColumnEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | trait ColumnEncoderDecoder extends ColumnEncoder with ColumnDecoder
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/PreparedStatement.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.codec
18 |
19 | case class PreparedStatement ( statement : String, values : Seq[Any])
20 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/NoData.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object NoData extends ServerMessage( ServerMessage.NoData )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ColumnEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | trait ColumnEncoder {
20 |
21 | def encode(value: Any): String = value.toString
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ByteDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object ByteDecoder extends ColumnDecoder {
20 | override def decode(value: String): Any = value.toByte
21 | }
22 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/QueryMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.client
18 |
19 | case class QueryMessage( query : String ) extends ClientMessage( ClientMessage.Query )
20 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/CloseComplete.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object CloseComplete extends ServerMessage(ServerMessage.CloseComplete)
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/general/ColumnData.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.general
18 |
19 | trait ColumnData {
20 |
21 | def name : String
22 | def dataType : Int
23 | def dataTypeSize : Long
24 |
25 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/BindComplete.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object BindComplete extends ServerMessage(ServerMessage.BindComplete)
20 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/ParseComplete.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object ParseComplete extends ServerMessage(ServerMessage.ParseComplete)
20 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/EmptyQueryString.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object EmptyQueryString extends ServerMessage( ServerMessage.EmptyQueryString )
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/EOFMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class EOFMessage( warningCount : Int, flags : Int )
20 | extends ServerMessage( ServerMessage.EOF )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/LongEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object LongEncoderDecoder extends ColumnEncoderDecoder {
20 | override def decode(value: String): Long = value.toLong
21 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | abstract class AuthenticationMessage extends ServerMessage(ServerMessage.Authentication)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/StartupMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | class StartupMessage(val parameters: List[(String, Any)]) extends InitialClientMessage
20 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/FloatEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object FloatEncoderDecoder extends ColumnEncoderDecoder {
20 | override def decode(value: String): Float = value.toFloat
21 | }
22 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ShortEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object ShortEncoderDecoder extends ColumnEncoderDecoder {
20 |
21 | override def decode(value: String): Any = value.toShort
22 |
23 | }
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/StringEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 |
20 | object StringEncoderDecoder extends ColumnEncoderDecoder {
21 | override def decode(value: String): String = value
22 | }
23 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/UnknownLengthException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class UnknownLengthException ( length : Int )
20 | extends DatabaseException( "Can't handle the length %d".format(length) )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/BigIntegerEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object BigIntegerEncoderDecoder extends ColumnEncoderDecoder {
20 | override def decode(value: String): Any = BigInt(value)
21 | }
22 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ColumnEncoderRegistry.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | trait ColumnEncoderRegistry {
20 |
21 | def encode( value : Any ) : String
22 |
23 | def kindOf( value : Any ) : Int
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/DoubleEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 |
20 | object DoubleEncoderDecoder extends ColumnEncoderDecoder {
21 | override def decode(value: String): Double = value.toDouble
22 | }
23 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/IntegerEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object IntegerEncoderDecoder extends ColumnEncoderDecoder {
20 |
21 | override def decode(value: String): Int = value.toInt
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/BinaryDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | trait BinaryDecoder {
22 |
23 | def decode( buffer : ByteBuf ) : Any
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/ErrorMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class ErrorMessage(fields: Map[Char, String])
20 | extends InformationMessage(ServerMessage.Error, fields)
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/NoticeMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class NoticeMessage(fields: Map[Char, String])
20 | extends InformationMessage(ServerMessage.Notice, fields)
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/ReadyForQueryMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class ReadyForQueryMessage(transactionStatus: Char) extends ServerMessage(ServerMessage.ReadyForQuery)
20 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/BigDecimalEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | object BigDecimalEncoderDecoder extends ColumnEncoderDecoder {
20 |
21 | override def decode(value: String): Any = BigDecimal(value)
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ErrorMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class ErrorMessage( errorCode : Int, sqlState : String, errorMessage : String )
20 | extends ServerMessage( ServerMessage.Error )
21 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/NullDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object NullDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = null
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/ShortDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object ShortDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readShort()
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/BinaryRowMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | case class BinaryRowMessage ( buffer : ByteBuf ) extends ServerMessage( ServerMessage.BinaryRow )
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/ProcessData.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | case class ProcessData(val processId: Int, val secretKey: Int)
20 | extends ServerMessage(ServerMessage.BackendKeyData)
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/ClientMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.KindedMessage
20 |
21 | class ClientMessage(val kind: Int) extends KindedMessage
22 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/LongDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object LongDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readLong()
23 | }
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ColumnProcessingFinishedMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class ColumnProcessingFinishedMessage( eofMessage : EOFMessage ) extends ServerMessage( ServerMessage.ColumnDefinitionFinished )
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/ByteDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object ByteDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readByte()
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/PreparedStatementPrepareMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.client
18 |
19 | case class PreparedStatementPrepareMessage( statement : String )
20 | extends ClientMessage( ClientMessage.PreparedStatementPrepare )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/DatabaseException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class DatabaseException(message: String, cause : Throwable) extends RuntimeException(message) {
20 |
21 | def this( message : String ) = this(message, null)
22 |
23 | }
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/NegativeMessageSizeException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class NegativeMessageSizeException( code : Byte, size : Int )
20 | extends DatabaseException( "Message of type %d had negative size %s".format(code, size) )
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/DoubleDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object DoubleDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readDouble()
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/FloatDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object FloatDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readFloat()
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/IntegerDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object IntegerDecoder extends BinaryDecoder {
22 | def decode(buffer: ByteBuf): Any = buffer.readInt()
23 | }
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ParamProcessingFinishedMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class ParamProcessingFinishedMessage( eofMessage : EOFMessage )
20 | extends ServerMessage( ServerMessage.ParamProcessingFinished )
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/DataRowMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | case class DataRowMessage(val values: Array[ByteBuf]) extends ServerMessage(ServerMessage.DataRow)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/ParameterStatusMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | case class ParameterStatusMessage(val key: String, val value: String)
20 | extends ServerMessage(ServerMessage.ParameterStatus)
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/ParserNotAvailableException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class ParserNotAvailableException(t: Byte)
20 | extends DatabaseException("There is no parser available for message type '%s' (%s)".format(t, Integer.toHexString(t)))
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/RowDescriptionMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | case class RowDescriptionMessage(val columnDatas: Array[PostgreSQLColumnData])
20 | extends ServerMessage(ServerMessage.RowDescription)
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/UUIDEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import java.util.UUID
20 |
21 | object UUIDEncoderDecoder extends ColumnEncoderDecoder {
22 |
23 | override def decode(value: String): UUID = UUID.fromString(value)
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/NotConnectedException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 |
21 | class NotConnectedException(message: String) extends DatabaseException(message)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/CommandCompleteMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | case class CommandCompleteMessage(val rowsAffected: Int, val statusMessage: String)
20 | extends ServerMessage(ServerMessage.CommandComplete)
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/Log.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * with the License. You may obtain a copy of the License at:
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | * License for the specific language governing permissions and limitations
13 | * under the License.
14 | */
15 |
16 | package com.github.mauricio.async.db.util
17 |
18 | import org.slf4j.LoggerFactory
19 |
20 | object Log {
21 |
22 | def get[T](implicit tag: reflect.ClassTag[T]) = {
23 | LoggerFactory.getLogger(tag.runtimeClass.getName)
24 | }
25 |
26 | def getByName(name: String) = {
27 | LoggerFactory.getLogger(name)
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/BinaryEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | trait BinaryEncoder {
22 |
23 | def encode( value : Any, buffer : ByteBuf )
24 |
25 | def encodesTo : Int
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/ColumnDecoderNotFoundException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | class ColumnDecoderNotFoundException(kind: Int)
20 | extends IllegalArgumentException("There is no decoder available for kind %s".format(kind))
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/InvalidArrayException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 |
18 | package com.github.mauricio.async.db.postgresql.exceptions
19 |
20 | import com.github.mauricio.async.db.exceptions.DatabaseException
21 |
22 | class InvalidArrayException(message: String) extends DatabaseException(message)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationChallengeMD5.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class AuthenticationChallengeMD5(salt: Array[Byte])
20 | extends AuthenticationChallengeMessage(AuthenticationResponseType.MD5, Some(salt))
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/CloseMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
20 |
21 | object CloseMessage extends ClientMessage(ServerMessage.Close)
22 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationResponseType.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object AuthenticationResponseType extends Enumeration {
20 | type AuthenticationResponseType = Value
21 | val MD5, Cleartext, Ok = Value
22 | }
23 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/DateEncoderNotAvailableException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class DateEncoderNotAvailableException(value: Any)
20 | extends DatabaseException("There is no encoder for value [%s] of type %s".format(value, value.getClass.getCanonicalName))
21 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ParamAndColumnProcessingFinishedMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class ParamAndColumnProcessingFinishedMessage ( eofMessage : EOFMessage )
20 | extends ServerMessage( ServerMessage.ParamAndColumnProcessingFinished )
21 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/QueryMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
20 |
21 | class QueryMessage(val query: String) extends ClientMessage(ServerMessage.Query)
--------------------------------------------------------------------------------
/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/util/PasswordHelperSpec.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.util
2 |
3 | import org.specs2.mutable.Specification
4 | import io.netty.util.CharsetUtil
5 |
6 | /**
7 | * User: mauricio
8 | * Date: 5/9/13
9 | * Time: 5:43 PM
10 | */
11 | class PasswordHelperSpec extends Specification {
12 |
13 | val salt = Array[Byte](-31, 68, 99, 36)
14 | val result = Array[Byte](109,100,53,54,102,57,55,57,98,99,51,101,100,100,54,101,56,52,57,49,100,52,101,99,49,55,100,57,97,51,102,97,97,55,56)
15 |
16 | def printArray( name : String, bytes : Array[Byte] ) {
17 | printf("%s %s -> (%s)%n", name, bytes.length, bytes.mkString(","))
18 | }
19 |
20 |
21 | "helper" should {
22 |
23 | "generate the same value as the PostgreSQL code" in {
24 |
25 | val username = "mauricio"
26 | val password = "example"
27 |
28 | PasswordHelper.encode(username, password, salt, CharsetUtil.UTF_8) === result
29 |
30 | }
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationOkMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object AuthenticationOkMessage {
20 | val Instance = new AuthenticationOkMessage()
21 | }
22 |
23 | class AuthenticationOkMessage extends AuthenticationMessage
24 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/NotificationResponse.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 db-async-common
3 | *
4 | * The db-async-common project licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class NotificationResponse( val backendPid : Int, val channel : String, val payload : String )
20 | extends ServerMessage(ServerMessage.NotificationResponse)
--------------------------------------------------------------------------------
/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/TestUtils.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.postgresql
18 |
19 | import java.util.concurrent.atomic.AtomicInteger
20 |
21 | object TestUtils {
22 |
23 | private val count = new AtomicInteger()
24 |
25 | def nextInt: Int = {
26 | count.incrementAndGet()
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/pool/PoolAlreadyTerminatedException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 |
18 | package com.github.mauricio.async.db.pool
19 |
20 | /**
21 | *
22 | * Thrown when the pool has already been closed.
23 | *
24 | */
25 |
26 | class PoolAlreadyTerminatedException extends IllegalStateException( "This pool has already been terminated" )
27 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/MessageDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.ServerMessage
21 |
22 | trait MessageDecoder {
23 |
24 | def decode( buffer : ByteBuf ) : ServerMessage
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/pool/PoolExhaustedException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.pool
18 |
19 | /**
20 | *
21 | * Raised when a pool has reached it's limit of available objects.
22 | *
23 | * @param message
24 | */
25 |
26 | class PoolExhaustedException( message : String ) extends IllegalStateException( message )
27 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/MessageEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.client.ClientMessage
21 |
22 | trait MessageEncoder {
23 |
24 | def encode( message : ClientMessage ) : ByteBuf
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/EncoderNotAvailableException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | import com.github.mauricio.async.db.KindedMessage
20 |
21 | class EncoderNotAvailableException(message: KindedMessage)
22 | extends DatabaseException("Encoder not available for name %s".format(message.kind))
23 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/encoders/Encoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.encoders
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.frontend.ClientMessage
20 | import io.netty.buffer.ByteBuf
21 |
22 | trait Encoder {
23 |
24 | def encode(message: ClientMessage): ByteBuf
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/CanceledChannelFutureException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | import io.netty.channel.ChannelFuture
20 |
21 | class CanceledChannelFutureException( val channelFuture : ChannelFuture )
22 | extends IllegalStateException ( "This channel future was canceled -> %s".format(channelFuture) )
23 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/CharEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.column
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderDecoder
20 |
21 | object CharEncoderDecoder extends ColumnEncoderDecoder {
22 |
23 | override def decode(value: String): Any = value.charAt(0)
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/MessageParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
20 | import io.netty.buffer.ByteBuf
21 |
22 | trait MessageParser {
23 |
24 | def parseMessage(buffer: ByteBuf): ServerMessage
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/BufferNotFullyConsumedException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | class BufferNotFullyConsumedException ( buffer : ByteBuf )
22 | extends DatabaseException( "Buffer was not fully consumed by decoder, %s bytes to read".format(buffer.readableBytes()) )
23 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/FutureUtils.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.util
18 |
19 | import scala.concurrent.{Await, Future}
20 | import scala.concurrent.duration._
21 | import scala.language.postfixOps
22 |
23 | object FutureUtils {
24 |
25 | def awaitFuture[T]( future : Future[T] ) : T = {
26 | Await.result(future, 5 seconds )
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/NettyUtils.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.util
2 |
3 | import io.netty.channel.nio.NioEventLoopGroup
4 | import io.netty.util.internal.logging.{InternalLoggerFactory, Slf4JLoggerFactory}
5 |
6 | /*
7 | * Copyright 2013 Maurício Linhares
8 | *
9 | * Maurício Linhares licenses this file to you under the Apache License,
10 | * with the License. You may obtain a copy of the License at:
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 | * License for the specific language governing permissions and limitations
18 | * under the License.
19 | */
20 |
21 | object NettyUtils {
22 |
23 | InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE)
24 | lazy val DefaultEventLoopGroup = new NioEventLoopGroup(0, DaemonThreadsFactory("db-async-netty"))
25 |
26 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/util/ArrayStreamingParserDelegate.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.util
18 |
19 | trait ArrayStreamingParserDelegate {
20 |
21 | def arrayStarted: Unit = {}
22 |
23 | def arrayEnded: Unit = {}
24 |
25 | def elementFound(element: String): Unit = {}
26 |
27 | def nullElementFound: Unit = {}
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ColumnDecoderRegistry.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import java.nio.charset.Charset
20 | import io.netty.buffer.ByteBuf
21 | import com.github.mauricio.async.db.general.ColumnData
22 |
23 | trait ColumnDecoderRegistry {
24 |
25 | def decode(kind: ColumnData, value: ByteBuf, charset : Charset) : Any
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/TimeWithTimezoneEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import org.joda.time.format.DateTimeFormat
20 |
21 | object TimeWithTimezoneEncoderDecoder extends TimeEncoderDecoder {
22 |
23 | private val format = DateTimeFormat.forPattern("HH:mm:ss.SSSSSSZ")
24 |
25 | override def formatter = format
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/ConnectionStillRunningQueryException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class ConnectionStillRunningQueryException( connectionCount : Long, caughtRace : Boolean)
20 | extends DatabaseException ( "[%s] - There is a query still being run here - race -> %s".format(
21 | connectionCount,
22 | caughtRace
23 | ))
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/PreparedStatementPrepareResponse.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class PreparedStatementPrepareResponse (
20 | statementId : Array[Byte],
21 | warningCount : Short,
22 | paramsCount : Int,
23 | columnsCount : Int )
24 | extends ServerMessage( ServerMessage.PreparedStatementPrepareResponse )
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/UnableToParseURLException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | /**
20 | * Thrown to indicate that a URL Parser could not understand the provided URL.
21 | */
22 | class UnableToParseURLException(message: String, base: Throwable) extends RuntimeException(message, base) {
23 | def this(message: String) = this(message, null)
24 | }
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/UnsupportedAuthenticationMethodException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | class UnsupportedAuthenticationMethodException(val authenticationType: String)
20 | extends DatabaseException("Unknown authentication method -> '%s'".format(authenticationType)) {
21 |
22 | def this( authType : Int ) {
23 | this(authType.toString)
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/MessageTooLongException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 |
21 | class MessageTooLongException( code : Byte, length : Int, limit : Int )
22 | extends DatabaseException("Message of type %d has size %d, higher than the limit %d".format(code, length, limit))
23 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/GenericDatabaseException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 | import com.github.mauricio.async.db.postgresql.messages.backend.ErrorMessage
21 |
22 | class GenericDatabaseException(val errorMessage: ErrorMessage)
23 | extends DatabaseException(errorMessage.toString)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/util/package.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.github.mauricio.async.db.postgresql
17 |
18 | /**
19 | * Contains package level aliases and type renames.
20 | */
21 | package object util {
22 |
23 | /**
24 | * Alias to help compatibility.
25 | */
26 | @deprecated("Use com.github.mauricio.async.db.postgresql.util.URLParser", since = "0.2.20")
27 | val ParserURL = URLParser
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/MySQLQueryResult.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql
18 |
19 | import com.github.mauricio.async.db.{ResultSet, QueryResult}
20 |
21 | class MySQLQueryResult(
22 | rowsAffected: Long,
23 | message: String,
24 | val lastInsertId: Long,
25 | val statusFlags: Int,
26 | val warnings: Int,
27 | rows: Option[ResultSet] = None) extends QueryResult(rowsAffected, message, rows)
28 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/OkMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class OkMessage(
20 | affectedRows : Long,
21 | lastInsertId : Long,
22 | statusFlags : Int,
23 | warnings : Int,
24 | message : String )
25 | extends ServerMessage( ServerMessage.Ok )
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationChallengeMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | class AuthenticationChallengeMessage(
20 | val challengeType: AuthenticationResponseType.AuthenticationResponseType,
21 | val salt: Option[Array[Byte]])
22 | extends AuthenticationMessage
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/AuthenticationChallengeCleartextMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | object AuthenticationChallengeCleartextMessage {
20 | val Instance = new AuthenticationChallengeCleartextMessage()
21 | }
22 |
23 | class AuthenticationChallengeCleartextMessage
24 | extends AuthenticationChallengeMessage(AuthenticationResponseType.Cleartext, None)
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/exceptions/CharsetMappingNotAvailableException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 | import java.nio.charset.Charset
21 |
22 | class CharsetMappingNotAvailableException (charset : Charset)
23 | extends DatabaseException( "There is no MySQL charset mapping name for the Java Charset %s".format(charset.name()) )
24 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/ErrorParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ErrorMessage, ServerMessage}
20 | import java.nio.charset.Charset
21 |
22 | class ErrorParser(charset: Charset) extends InformationParser(charset) {
23 |
24 | def createMessage(fields: Map[Char, String]): ServerMessage = new ErrorMessage(fields)
25 |
26 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/NoticeParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ServerMessage, NoticeMessage}
20 | import java.nio.charset.Charset
21 |
22 | class NoticeParser(charset: Charset) extends InformationParser(charset) {
23 |
24 | def createMessage(fields: Map[Char, String]): ServerMessage = new NoticeMessage(fields)
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/FloatEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object FloatEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | buffer.writeFloat(value.asInstanceOf[Float])
25 | }
26 |
27 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_FLOAT
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/IntegerEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object IntegerEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | buffer.writeInt(value.asInstanceOf[Int])
25 | }
26 |
27 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_LONG
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/LongEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object LongEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | buffer.writeLong(value.asInstanceOf[Long])
25 | }
26 |
27 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_LONGLONG
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ShortEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object ShortEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | buffer.writeShort(value.asInstanceOf[Short])
25 | }
26 |
27 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_SHORT
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/exceptions/MySQLException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 | import com.github.mauricio.async.db.mysql.message.server.ErrorMessage
21 |
22 | class MySQLException( val errorMessage : ErrorMessage )
23 | extends DatabaseException("Error %d - %s - %s".format(errorMessage.errorCode, errorMessage.sqlState, errorMessage.errorMessage))
24 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/DoubleEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object DoubleEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | buffer.writeDouble(value.asInstanceOf[Double])
25 | }
26 |
27 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_DOUBLE
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/EOFMessageDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.EOFMessage
21 |
22 | object EOFMessageDecoder extends MessageDecoder {
23 |
24 | def decode(buffer: ByteBuf): EOFMessage = {
25 | new EOFMessage(
26 | buffer.readUnsignedShort(),
27 | buffer.readUnsignedShort() )
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/util/MySQLIO.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.util
18 |
19 | object MySQLIO {
20 |
21 | final val CLIENT_PROTOCOL_41 = 0x0200
22 | final val CLIENT_CONNECT_WITH_DB = 0x0008
23 | final val CLIENT_TRANSACTIONS = 0x2000
24 | final val CLIENT_MULTI_RESULTS = 0x20000
25 | final val CLIENT_LONG_FLAG = 0x0001
26 | final val CLIENT_PLUGIN_AUTH = 0x00080000
27 | final val CLIENT_SECURE_CONNECTION = 0x00008000
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/BackendKeyDataParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ProcessData, ServerMessage}
20 | import io.netty.buffer.ByteBuf
21 |
22 | object BackendKeyDataParser extends MessageParser {
23 |
24 | override def parseMessage(b: ByteBuf): ServerMessage = {
25 | new ProcessData(b.readInt(), b.readInt())
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/BigDecimalDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
20 | import java.nio.charset.Charset
21 | import io.netty.buffer.ByteBuf
22 |
23 | class BigDecimalDecoder( charset : Charset ) extends BinaryDecoder {
24 | def decode(buffer: ByteBuf): Any = {
25 | BigDecimal( buffer.readLengthEncodedString(charset) )
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/DateDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.LocalDate
21 |
22 | object DateDecoder extends BinaryDecoder {
23 | override def decode(buffer: ByteBuf): LocalDate = {
24 | val result = TimestampDecoder.decode(buffer)
25 |
26 | if ( result != null ) {
27 | result.toLocalDate
28 | } else {
29 | null
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/ReadyForQueryParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ReadyForQueryMessage, ServerMessage}
20 | import io.netty.buffer.ByteBuf
21 |
22 | object ReadyForQueryParser extends MessageParser {
23 |
24 | override def parseMessage(b: ByteBuf): ServerMessage = {
25 | new ReadyForQueryMessage(b.readByte().asInstanceOf[Char])
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/ByteArrayDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
21 |
22 | object ByteArrayDecoder extends BinaryDecoder {
23 | def decode(buffer: ByteBuf): Any = {
24 | val length = buffer.readBinaryLength
25 | val bytes = new Array[Byte](length.toInt)
26 | buffer.readBytes(bytes)
27 |
28 | bytes
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/ParamProcessingFinishedDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.{ParamProcessingFinishedMessage, ServerMessage}
21 |
22 | object ParamProcessingFinishedDecoder extends MessageDecoder {
23 |
24 | def decode(buffer: ByteBuf): ServerMessage = {
25 | new ParamProcessingFinishedMessage(EOFMessageDecoder.decode(buffer))
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ByteEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 | import com.github.mauricio.async.db.util.Log
22 |
23 | object ByteEncoder extends BinaryEncoder {
24 |
25 | def encode(value: Any, buffer: ByteBuf) {
26 | buffer.writeByte(value.asInstanceOf[Byte])
27 | }
28 |
29 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TINY
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/ColumnProcessingFinishedDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.{ColumnProcessingFinishedMessage, ServerMessage}
21 |
22 | object ColumnProcessingFinishedDecoder extends MessageDecoder {
23 |
24 | def decode(buffer: ByteBuf): ServerMessage = {
25 | new ColumnProcessingFinishedMessage( EOFMessageDecoder.decode(buffer) )
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/QueryMustNotBeNullOrEmptyException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 |
21 | /**
22 | *
23 | * Raised if the query string is null or empty.
24 | *
25 | * @param query the problematic query
26 | */
27 | class QueryMustNotBeNullOrEmptyException(query : String)
28 | extends DatabaseException("Query must not be null or empty, original query is [%s]".format(query))
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/ParamAndColumnProcessingFinishedDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.{ParamAndColumnProcessingFinishedMessage, ServerMessage}
21 |
22 | object ParamAndColumnProcessingFinishedDecoder extends MessageDecoder {
23 | def decode(buffer: ByteBuf): ServerMessage = {
24 | new ParamAndColumnProcessingFinishedMessage(EOFMessageDecoder.decode(buffer))
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/encoders/CloseMessageEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.encoders
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.frontend.ClientMessage
20 | import io.netty.buffer.{Unpooled, ByteBuf}
21 |
22 | object CloseMessageEncoder extends Encoder {
23 |
24 | override def encode(message: ClientMessage): ByteBuf = {
25 | val buffer = Unpooled.buffer(5)
26 | buffer.writeByte('X')
27 | buffer.writeInt(4)
28 |
29 | buffer
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/AuthenticationSwitchResponseEncoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.encoder
2 |
3 | import com.github.mauricio.async.db.mysql.message.client.{AuthenticationSwitchResponse, ClientMessage}
4 | import io.netty.buffer.ByteBuf
5 | import com.github.mauricio.async.db.exceptions.UnsupportedAuthenticationMethodException
6 | import com.github.mauricio.async.db.mysql.encoder.auth.AuthenticationMethod
7 | import java.nio.charset.Charset
8 | import com.github.mauricio.async.db.util.ByteBufferUtils
9 |
10 | class AuthenticationSwitchResponseEncoder( charset : Charset ) extends MessageEncoder {
11 |
12 | def encode(message: ClientMessage): ByteBuf = {
13 | val switch = message.asInstanceOf[AuthenticationSwitchResponse]
14 |
15 | val method = switch.request.method
16 | val authenticator = AuthenticationMethod.Availables.getOrElse(
17 | method, { throw new UnsupportedAuthenticationMethodException(method) })
18 |
19 | val buffer = ByteBufferUtils.packetBuffer()
20 |
21 | val bytes = authenticator.generateAuthentication(charset, switch.password, switch.request.seed.getBytes(charset) )
22 | buffer.writeBytes(bytes)
23 |
24 | buffer
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/TimestampWithTimezoneEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import org.joda.time.DateTime
20 | import org.joda.time.format.DateTimeFormat
21 |
22 | object TimestampWithTimezoneEncoderDecoder extends TimestampEncoderDecoder {
23 |
24 | private val format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSZ")
25 |
26 | override def formatter = format
27 |
28 | override def decode(value: String): Any = {
29 | formatter.parseDateTime(value)
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/PrintUtils.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.util
18 |
19 | import io.netty.buffer.ByteBuf
20 |
21 | object PrintUtils {
22 |
23 | private val log = Log.getByName(this.getClass.getName)
24 |
25 | def printArray( name : String, buffer : ByteBuf ) {
26 | buffer.markReaderIndex()
27 | val bytes = new Array[Byte](buffer.readableBytes())
28 | buffer.readBytes(bytes)
29 | buffer.resetReaderIndex()
30 | log.debug( s"$name Array[Byte](${bytes.mkString(", ")})" )
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/encoders/ExecutePreparedStatementEncoderSpec.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql.encoders
2 |
3 | import com.github.mauricio.async.db.postgresql.column.PostgreSQLColumnEncoderRegistry
4 | import com.github.mauricio.async.db.postgresql.messages.frontend.PreparedStatementExecuteMessage
5 | import io.netty.util.CharsetUtil
6 | import org.specs2.mutable.Specification
7 |
8 | class ExecutePreparedStatementEncoderSpec extends Specification {
9 |
10 | val registry = new PostgreSQLColumnEncoderRegistry()
11 | val encoder = new ExecutePreparedStatementEncoder(CharsetUtil.UTF_8, registry)
12 | val sampleMessage = Array[Byte](66,0,0,0,18,49,0,49,0,0,0,0,1,-1,-1,-1,-1,0,0,69,0,0,0,10,49,0,0,0,0,0,83,0,0,0,4,67,0,0,0,7,80,49,0)
13 |
14 | "encoder" should {
15 |
16 | "correctly handle the case where an encoder returns null" in {
17 |
18 | val message = new PreparedStatementExecuteMessage(1, "select * from users", List(Some(null)), registry)
19 |
20 | val result = encoder.encode(message)
21 |
22 | val bytes = new Array[Byte](result.readableBytes())
23 | result.readBytes(bytes)
24 |
25 | bytes === sampleMessage
26 | }
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/QuitMessageEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.client.ClientMessage
21 | import com.github.mauricio.async.db.util.ByteBufferUtils
22 |
23 | object QuitMessageEncoder extends MessageEncoder {
24 |
25 | def encode(message: ClientMessage): ByteBuf = {
26 | val buffer = ByteBufferUtils.packetBuffer(5)
27 | buffer.writeByte( ClientMessage.Quit )
28 | buffer
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/backend/PostgreSQLColumnData.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.backend
18 |
19 | import com.github.mauricio.async.db.general.ColumnData
20 |
21 | case class PostgreSQLColumnData(
22 | name: String,
23 | tableObjectId: Int,
24 | columnNumber: Int,
25 | dataType: Int,
26 | dataTypeSize: Long,
27 | dataTypeModifier: Int,
28 | fieldFormat: Int) extends ColumnData
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/PreparedStatementExecuteMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderRegistry
20 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
21 |
22 | class PreparedStatementExecuteMessage(statementId: Int, query: String, values: Seq[Any], encoderRegistry : ColumnEncoderRegistry)
23 | extends PreparedStatementMessage(statementId, ServerMessage.Execute, query, values, encoderRegistry)
24 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/SQLTimeEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import org.joda.time.format.DateTimeFormatterBuilder
20 | import org.joda.time.LocalTime
21 |
22 | object SQLTimeEncoder extends ColumnEncoder {
23 |
24 | final private val format = new DateTimeFormatterBuilder()
25 | .appendPattern("HH:mm:ss")
26 | .toFormatter
27 |
28 | override def encode(value: Any): String = {
29 | val time = value.asInstanceOf[java.sql.Time]
30 |
31 | format.print( new LocalTime(time.getTime) )
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/SQLDateEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.LocalDate
21 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
22 |
23 | object SQLDateEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val date = value.asInstanceOf[java.sql.Date]
26 |
27 | LocalDateEncoder.encode(new LocalDate(date), buffer)
28 | }
29 |
30 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_DATE
31 | }
32 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/SingleByteEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.column
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderDecoder
20 |
21 | object SingleByteEncoderDecoder extends ColumnEncoderDecoder {
22 |
23 | override def encode(value: Any): String = {
24 | val byte = value.asInstanceOf[Byte]
25 | ByteArrayEncoderDecoder.encode(Array(byte))
26 | }
27 |
28 | override def decode(value: String): Any = {
29 | ByteArrayEncoderDecoder.decode(value)(0)
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/QueryResult.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * with the License. You may obtain a copy of the License at:
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | * License for the specific language governing permissions and limitations
13 | * under the License.
14 | */
15 |
16 | package com.github.mauricio.async.db
17 |
18 | /**
19 | *
20 | * This is the result of the execution of a statement, contains basic information as the number or rows
21 | * affected by the statement and the rows returned if there were any.
22 | *
23 | * @param rowsAffected
24 | * @param statusMessage
25 | * @param rows
26 | */
27 |
28 | class QueryResult(val rowsAffected: Long, val statusMessage: String, val rows: Option[ResultSet] = None) {
29 |
30 | override def toString: String = {
31 | "QueryResult{rows -> %s,status -> %s}".format(this.rowsAffected, this.statusMessage)
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/BooleanEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 |
22 | object BooleanEncoder extends BinaryEncoder {
23 | def encode(value: Any, buffer: ByteBuf) {
24 | val boolean = value.asInstanceOf[Boolean]
25 | if ( boolean ) {
26 | buffer.writeByte(1)
27 | } else {
28 | buffer.writeByte(0)
29 | }
30 | }
31 |
32 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TINY
33 | }
34 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/ResultSet.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db
18 |
19 | /**
20 | *
21 | * Represents the collection of rows that is returned from a statement inside a {@link QueryResult}. It's basically
22 | * a collection of Array[Any]. Mutating fields in this array will not affect the database in any way
23 | *
24 | */
25 |
26 | trait ResultSet extends IndexedSeq[RowData] {
27 |
28 | /**
29 | *
30 | * The names of the columns returned by the statement.
31 | *
32 | * @return
33 | */
34 |
35 | def columnNames : IndexedSeq[String]
36 |
37 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/exceptions/ByteArrayFormatNotSupportedException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.exceptions
18 |
19 | import com.github.mauricio.async.db.exceptions.DatabaseException
20 |
21 | object ByteArrayFormatNotSupportedException {
22 |
23 | final val Message = """The bytea 'escape' format is not yet supported, you need to use a PG version that uses the 'hex' format (version 9 and onwards)"""
24 |
25 | }
26 |
27 | class ByteArrayFormatNotSupportedException
28 | extends DatabaseException( ByteArrayFormatNotSupportedException.Message )
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ReadableInstantEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 | import org.joda.time._
22 |
23 | object ReadableInstantEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val date = value.asInstanceOf[ReadableInstant]
26 | LocalDateTimeEncoder.encode(new LocalDateTime(date.getMillis), buffer)
27 | }
28 |
29 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIMESTAMP
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/decoder/StringDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
21 | import com.github.mauricio.async.db.util.Log
22 | import java.nio.charset.Charset
23 |
24 | object StringDecoder {
25 | final val log = Log.get[StringDecoder]
26 | }
27 |
28 | class StringDecoder( charset : Charset ) extends BinaryDecoder {
29 |
30 | def decode(buffer: ByteBuf): Any = {
31 | buffer.readLengthEncodedString(charset)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/DateTimeEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 | import org.joda.time._
22 |
23 | object DateTimeEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val instant = value.asInstanceOf[ReadableDateTime]
26 |
27 | LocalDateTimeEncoder.encode(new LocalDateTime(instant.getMillis), buffer)
28 | }
29 |
30 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIMESTAMP
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/JavaDateEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.{LocalDateTime, DateTime}
21 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
22 |
23 | object JavaDateEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val date = value.asInstanceOf[java.util.Date]
26 | LocalDateTimeEncoder.encode(new LocalDateTime(date.getTime), buffer)
27 | }
28 |
29 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIMESTAMP
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/SQLTimeEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.LocalTime
21 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
22 |
23 | object SQLTimeEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val sqlTime = value.asInstanceOf[java.sql.Time].getTime
26 | val time = new LocalTime( sqlTime )
27 | LocalTimeEncoder.encode(time, buffer)
28 | }
29 |
30 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIME
31 | }
32 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/SQLTimestampEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.{LocalDateTime, DateTime}
21 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
22 |
23 | object SQLTimestampEncoder extends BinaryEncoder {
24 | def encode(value: Any, buffer: ByteBuf) {
25 | val date = value.asInstanceOf[java.sql.Timestamp]
26 | LocalDateTimeEncoder.encode(new LocalDateTime(date.getTime), buffer)
27 | }
28 |
29 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIMESTAMP
30 | }
31 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/ColumnDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import java.nio.charset.Charset
20 | import io.netty.buffer.ByteBuf
21 | import com.github.mauricio.async.db.general.ColumnData
22 |
23 | trait ColumnDecoder {
24 |
25 | def decode( kind : ColumnData, value : ByteBuf, charset : Charset ) : Any = {
26 | val bytes = new Array[Byte](value.readableBytes())
27 | value.readBytes(bytes)
28 | decode(new String(bytes, charset))
29 | }
30 |
31 | def decode( value : String ) : Any
32 |
33 | def supportsStringDecoding : Boolean = true
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/auth/AuthenticationMethod.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.encoder.auth
18 |
19 | import java.nio.charset.Charset
20 |
21 | object AuthenticationMethod {
22 |
23 | final val Native = "mysql_native_password"
24 | final val Old = "mysql_old_password"
25 |
26 | final val Availables = Map(
27 | Native -> MySQLNativePasswordAuthentication,
28 | Old -> OldPasswordAuthentication
29 | )
30 | }
31 |
32 | trait AuthenticationMethod {
33 |
34 | def generateAuthentication( charset : Charset, password : Option[String], seed : Array[Byte] ) : Array[Byte]
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/ExecutorServiceUtils.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.util
18 |
19 | import java.util.concurrent.{ExecutorService, Executors}
20 | import scala.concurrent.ExecutionContext
21 |
22 | object ExecutorServiceUtils {
23 | implicit val CachedThreadPool = Executors.newCachedThreadPool(DaemonThreadsFactory("db-async-default"))
24 | implicit val CachedExecutionContext = ExecutionContext.fromExecutor( CachedThreadPool )
25 |
26 | def newFixedPool( count : Int, name: String ) : ExecutorService = {
27 | Executors.newFixedThreadPool( count, DaemonThreadsFactory(name) )
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/ByteArrayEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 |
18 | package com.github.mauricio.async.db.mysql.binary.encoder
19 |
20 | import io.netty.buffer.ByteBuf
21 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
22 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
23 |
24 | object ByteArrayEncoder extends BinaryEncoder {
25 | def encode(value: Any, buffer: ByteBuf) {
26 | val bytes = value.asInstanceOf[Array[Byte]]
27 |
28 | buffer.writeLength(bytes.length)
29 | buffer.writeBytes(bytes)
30 | }
31 |
32 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_BLOB
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/BooleanEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.column
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderDecoder
20 |
21 | object BooleanEncoderDecoder extends ColumnEncoderDecoder {
22 |
23 | override def decode(value: String): Any = {
24 | if ("t" == value) {
25 | true
26 | } else {
27 | false
28 | }
29 | }
30 |
31 | override def encode(value: Any): String = {
32 | val result = value.asInstanceOf[Boolean]
33 |
34 | if (result) {
35 | "t"
36 | } else {
37 | "f"
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/CalendarEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import java.util.Calendar
21 | import org.joda.time.{LocalDateTime, DateTime}
22 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
23 |
24 | object CalendarEncoder extends BinaryEncoder {
25 | def encode(value: Any, buffer: ByteBuf) {
26 | val calendar = value.asInstanceOf[Calendar]
27 | LocalDateTimeEncoder.encode(new LocalDateTime(calendar.getTimeInMillis), buffer)
28 | }
29 |
30 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_TIMESTAMP
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/HandshakeMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.server
18 |
19 | case class HandshakeMessage(
20 | serverVersion: String,
21 | connectionId: Long,
22 | seed: Array[Byte],
23 | serverCapabilities: Int,
24 | characterSet: Int,
25 | statusFlags: Int,
26 | authenticationMethod : String
27 | )
28 | extends ServerMessage(ServerMessage.ServerProtocolVersion)
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/util/DaemonThreadsFactory.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.util
18 |
19 | import java.util.concurrent.{ Executors, ThreadFactory }
20 | import java.util.concurrent.atomic.AtomicInteger
21 |
22 | case class DaemonThreadsFactory(name: String) extends ThreadFactory {
23 |
24 | private val threadNumber = new AtomicInteger(1)
25 |
26 | def newThread(r: Runnable): Thread = {
27 | val thread = Executors.defaultThreadFactory().newThread(r)
28 | thread.setDaemon(true)
29 | val threadName = name + "-thread-" + threadNumber.getAndIncrement
30 | thread.setName(threadName)
31 | thread
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/CredentialMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ServerMessage, AuthenticationResponseType}
20 |
21 |
22 | class CredentialMessage(
23 | val username: String,
24 | val password: String,
25 | val authenticationType: AuthenticationResponseType.AuthenticationResponseType,
26 | val salt: Option[Array[Byte]]
27 | )
28 | extends ClientMessage(ServerMessage.PasswordMessage)
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/PreparedStatementExecuteMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.client
18 |
19 | import com.github.mauricio.async.db.mysql.message.server.ColumnDefinitionMessage
20 |
21 | case class PreparedStatementExecuteMessage (
22 | statementId : Array[Byte],
23 | values : Seq[Any],
24 | valuesToInclude : Set[Int],
25 | parameters : Seq[ColumnDefinitionMessage] )
26 | extends ClientMessage( ClientMessage.PreparedStatementExecute )
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/util/URLParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 | package com.github.mauricio.async.db.mysql.util
17 |
18 | import com.github.mauricio.async.db.util.AbstractURIParser
19 | import com.github.mauricio.async.db.Configuration
20 |
21 | /**
22 | * The MySQL URL parser.
23 | */
24 | object URLParser extends AbstractURIParser {
25 |
26 | /**
27 | * The default configuration for MySQL.
28 | */
29 | override val DEFAULT = Configuration(
30 | username = "root",
31 | host = "127.0.0.1", //Matched JDBC default
32 | port = 3306,
33 | password = None,
34 | database = None
35 | )
36 |
37 | override protected val SCHEME = "^mysql$".r
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/ParameterStatusParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ParameterStatusMessage, ServerMessage}
20 | import com.github.mauricio.async.db.util.ByteBufferUtils
21 | import java.nio.charset.Charset
22 | import io.netty.buffer.ByteBuf
23 |
24 | class ParameterStatusParser(charset: Charset) extends MessageParser {
25 |
26 | import ByteBufferUtils._
27 |
28 | override def parseMessage(b: ByteBuf): ServerMessage = {
29 | new ParameterStatusMessage(readCString(b, charset), readCString(b, charset))
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/column/InetAddressEncoderDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.column
18 |
19 | import java.net.InetAddress
20 | import sun.net.util.IPAddressUtil.{textToNumericFormatV4,textToNumericFormatV6}
21 |
22 | object InetAddressEncoderDecoder extends ColumnEncoderDecoder {
23 |
24 | override def decode(value: String): Any = {
25 | if (value contains ':') {
26 | InetAddress.getByAddress(textToNumericFormatV6(value))
27 | } else {
28 | InetAddress.getByAddress(textToNumericFormatV4(value))
29 | }
30 | }
31 |
32 | override def encode(value: Any): String = {
33 | value.asInstanceOf[InetAddress].getHostAddress
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/PreparedStatementOpeningMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderRegistry
20 | import com.github.mauricio.async.db.postgresql.messages.backend.ServerMessage
21 |
22 | class PreparedStatementOpeningMessage(statementId: Int, query: String, values: Seq[Any], encoderRegistry : ColumnEncoderRegistry)
23 | extends PreparedStatementMessage(statementId: Int, ServerMessage.Parse, query, values, encoderRegistry) {
24 |
25 | override def toString() : String =
26 | s"${this.getClass.getSimpleName}(id=${statementId},query=${query},values=${values}})"
27 |
28 | }
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/OkDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.{OkMessage, ServerMessage}
21 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
22 | import java.nio.charset.Charset
23 |
24 | class OkDecoder( charset : Charset ) extends MessageDecoder {
25 |
26 | def decode(buffer: ByteBuf): ServerMessage = {
27 |
28 | new OkMessage(
29 | buffer.readBinaryLength,
30 | buffer.readBinaryLength,
31 | buffer.readShort(),
32 | buffer.readShort(),
33 | buffer.readUntilEOF(charset)
34 | )
35 |
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/decoder/ErrorDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.decoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.server.{ErrorMessage, ServerMessage}
21 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
22 | import java.nio.charset.Charset
23 | import scala.language.implicitConversions
24 |
25 | class ErrorDecoder( charset : Charset ) extends MessageDecoder {
26 |
27 | def decode(buffer: ByteBuf): ServerMessage = {
28 |
29 | new ErrorMessage(
30 | buffer.readShort(),
31 | buffer.readFixedString( 6, charset ),
32 | buffer.readUntilEOF(charset)
33 | )
34 |
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/ClientMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.client
18 |
19 | import com.github.mauricio.async.db.KindedMessage
20 |
21 | object ClientMessage {
22 |
23 | final val ClientProtocolVersion = 0x09 // COM_STATISTICS
24 | final val Quit = 0x01 // COM_QUIT
25 | final val Query = 0x03 // COM_QUERY
26 | final val PreparedStatementPrepare = 0x16 // COM_STMT_PREPARE
27 | final val PreparedStatementExecute = 0x17 // COM_STMT_EXECUTE
28 | final val PreparedStatementSendLongData = 0x18 // COM_STMT_SEND_LONG_DATA
29 | final val AuthSwitchResponse = 0xfe // AuthSwitchRequest
30 |
31 | }
32 |
33 | class ClientMessage ( val kind : Int ) extends KindedMessage
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/client/HandshakeResponseMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.message.client
18 |
19 | import java.nio.charset.Charset
20 |
21 | case class HandshakeResponseMessage(
22 | username: String,
23 | charset: Charset,
24 | seed: Array[Byte],
25 | authenticationMethod: String,
26 | password: Option[String] = None,
27 | database: Option[String] = None
28 | )
29 | extends ClientMessage(ClientMessage.ClientProtocolVersion)
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/NotificationResponseParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 db-async-common
3 | *
4 | * The db-async-common project licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import language.implicitConversions
20 | import java.nio.charset.Charset
21 | import io.netty.buffer.ByteBuf
22 | import com.github.mauricio.async.db.postgresql.messages.backend.{NotificationResponse, ServerMessage}
23 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
24 |
25 | class NotificationResponseParser( charset : Charset ) extends MessageParser {
26 |
27 | def parseMessage(buffer: ByteBuf): ServerMessage = {
28 | new NotificationResponse( buffer.readInt(), buffer.readCString(charset), buffer.readCString(charset) )
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/db-async-common/src/test/scala/com/github/mauricio/async/db/pool/DummyTimeoutScheduler.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.pool
18 |
19 | import java.util.concurrent.atomic.AtomicInteger
20 | import com.github.mauricio.async.db.util.{NettyUtils, ExecutorServiceUtils}
21 | import io.netty.channel.EventLoopGroup
22 |
23 | /**
24 | * Implementation of TimeoutScheduler used for testing
25 | */
26 | class DummyTimeoutScheduler extends TimeoutScheduler {
27 | implicit val internalPool = ExecutorServiceUtils.CachedExecutionContext
28 | private val timeOuts = new AtomicInteger
29 | override def onTimeout = timeOuts.incrementAndGet
30 | def timeoutCount = timeOuts.get()
31 | def eventLoopGroup : EventLoopGroup = NettyUtils.DefaultEventLoopGroup
32 | }
33 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/StringEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
21 | import com.github.mauricio.async.db.util.ChannelWrapper.bufferToWrapper
22 | import com.github.mauricio.async.db.util.Log
23 | import java.nio.charset.Charset
24 |
25 | object StringEncoder {
26 | final val log = Log.get[StringEncoder]
27 | }
28 |
29 | class StringEncoder( charset : Charset ) extends BinaryEncoder {
30 |
31 | def encode(value: Any, buffer: ByteBuf) {
32 | buffer.writeLenghtEncodedString(value.toString, charset)
33 | }
34 |
35 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_VARCHAR
36 |
37 | }
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/column/ByteArrayColumnDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.column
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.column.ColumnDecoder
21 | import java.nio.charset.Charset
22 | import com.github.mauricio.async.db.general.ColumnData
23 |
24 | object ByteArrayColumnDecoder extends ColumnDecoder {
25 |
26 | override def decode(kind: ColumnData , value: ByteBuf, charset: Charset): Any = {
27 | val bytes = new Array[Byte](value.readableBytes())
28 | value.readBytes(bytes)
29 | bytes
30 | }
31 |
32 | def decode(value: String): Any = {
33 | throw new UnsupportedOperationException("This method should never be called for byte arrays")
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/exceptions/InsufficientParametersException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.exceptions
18 |
19 | /**
20 | *
21 | * Raised when the user gives more or less parameters than the query takes. Each parameter is a ?
22 | * (question mark) in the query string. The count of ? should be the same as the count of items in the provided
23 | * sequence of parameters.
24 | *
25 | * @param expected the expected count of parameters
26 | * @param given the collection given
27 | */
28 | class InsufficientParametersException( expected : Int, given : Seq[Any] )
29 | extends DatabaseException(
30 | "The query contains %s parameters but you gave it %s (%s)".format(expected, given.length, given.mkString(",")
31 | )
32 | )
33 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/encoder/LocalDateEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.binary.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import org.joda.time.LocalDate
21 | import com.github.mauricio.async.db.exceptions.DateEncoderNotAvailableException
22 | import com.github.mauricio.async.db.mysql.column.ColumnTypes
23 |
24 | object LocalDateEncoder extends BinaryEncoder {
25 | def encode(value: Any, buffer: ByteBuf) {
26 | val date = value.asInstanceOf[LocalDate]
27 |
28 | buffer.writeByte(4)
29 | buffer.writeShort(date.getYear)
30 | buffer.writeByte(date.getMonthOfYear)
31 | buffer.writeByte(date.getDayOfMonth)
32 |
33 | }
34 |
35 | def encodesTo: Int = ColumnTypes.FIELD_TYPE_DATE
36 | }
37 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/MySQLHandlerDelegate.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.codec
18 |
19 | import com.github.mauricio.async.db.ResultSet
20 | import com.github.mauricio.async.db.mysql.message.server._
21 | import io.netty.channel.ChannelHandlerContext
22 |
23 | trait MySQLHandlerDelegate {
24 |
25 | def onHandshake( message : HandshakeMessage )
26 | def onError( message : ErrorMessage )
27 | def onOk( message : OkMessage )
28 | def onEOF( message : EOFMessage )
29 | def exceptionCaught( exception : Throwable )
30 | def connected( ctx : ChannelHandlerContext )
31 | def onResultSet( resultSet : ResultSet, message : EOFMessage )
32 | def switchAuthentication( message : AuthenticationSwitchRequest )
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/codec/PostgreSQLConnectionDelegate.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.codec
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend._
20 |
21 | trait PostgreSQLConnectionDelegate {
22 |
23 | def onAuthenticationResponse(message: AuthenticationMessage)
24 | def onCommandComplete( message : CommandCompleteMessage )
25 | def onDataRow( message : DataRowMessage )
26 | def onError( message : ErrorMessage )
27 | def onError( throwable : Throwable )
28 | def onParameterStatus( message : ParameterStatusMessage )
29 | def onReadyForQuery()
30 | def onRowDescription(message : RowDescriptionMessage)
31 | def onNotificationResponse(message : NotificationResponse )
32 |
33 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/messages/frontend/PreparedStatementMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.messages.frontend
18 |
19 | import com.github.mauricio.async.db.column.ColumnEncoderRegistry
20 |
21 | class PreparedStatementMessage(
22 | val statementId: Int,
23 | kind: Byte,
24 | val query: String,
25 | val values: Seq[Any],
26 | encoderRegistry: ColumnEncoderRegistry
27 | )
28 | extends ClientMessage(kind) {
29 |
30 | val valueTypes: Seq[Int] = values.map {
31 | value =>
32 | encoderRegistry.kindOf(value)
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/DataRowParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{DataRowMessage, ServerMessage}
20 | import io.netty.buffer.ByteBuf
21 |
22 | object DataRowParser extends MessageParser {
23 |
24 | def parseMessage(buffer: ByteBuf): ServerMessage = {
25 |
26 | val row = new Array[ByteBuf](buffer.readShort())
27 |
28 | 0.until(row.length).foreach {
29 | column =>
30 | val length = buffer.readInt()
31 |
32 | row(column) = if (length == -1) {
33 | null
34 | } else {
35 | buffer.readBytes(length)
36 | }
37 | }
38 |
39 | new DataRowMessage(row)
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/PostgreSQLSSLConnectionSpec.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.postgresql
2 |
3 | import org.specs2.mutable.Specification
4 | import com.github.mauricio.async.db.SSLConfiguration.Mode
5 | import javax.net.ssl.SSLHandshakeException
6 |
7 | class PostgreSQLSSLConnectionSpec extends Specification with DatabaseTestHelper {
8 |
9 | "ssl handler" should {
10 |
11 | "connect to the database in ssl without verifying CA" in {
12 |
13 | withSSLHandler(Mode.Require, "127.0.0.1", None) { handler =>
14 | handler.isReadyForQuery must beTrue
15 | }
16 |
17 | }
18 |
19 | "connect to the database in ssl verifying CA" in {
20 |
21 | withSSLHandler(Mode.VerifyCA, "127.0.0.1") { handler =>
22 | handler.isReadyForQuery must beTrue
23 | }
24 |
25 | }
26 |
27 | "connect to the database in ssl verifying CA and hostname" in {
28 |
29 | withSSLHandler(Mode.VerifyFull) { handler =>
30 | handler.isReadyForQuery must beTrue
31 | }
32 |
33 | }
34 |
35 | "throws exception when CA verification fails" in {
36 |
37 | withSSLHandler(Mode.VerifyCA, rootCert = None) { handler =>
38 | } must throwA[SSLHandshakeException]
39 |
40 | }
41 |
42 | "throws exception when hostname verification fails" in {
43 |
44 | withSSLHandler(Mode.VerifyFull, "127.0.0.1") { handler =>
45 | } must throwA[SSLHandshakeException]
46 |
47 | }
48 |
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/QueryMessageEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.client.{QueryMessage, ClientMessage}
21 | import com.github.mauricio.async.db.util.ByteBufferUtils
22 | import java.nio.charset.Charset
23 |
24 | class QueryMessageEncoder( charset : Charset ) extends MessageEncoder {
25 |
26 | def encode(message: ClientMessage): ByteBuf = {
27 |
28 | val m = message.asInstanceOf[QueryMessage]
29 | val encodedQuery = m.query.getBytes( charset )
30 | val buffer = ByteBufferUtils.packetBuffer(4 + 1 + encodedQuery.length )
31 | buffer.writeByte( ClientMessage.Query )
32 | buffer.writeBytes( encodedQuery )
33 |
34 | buffer
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/db-async-common/src/main/scala/com/github/mauricio/async/db/pool/PartitionedConnectionPool.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.pool;
2 |
3 | import com.github.mauricio.async.db.util.ExecutorServiceUtils
4 | import com.github.mauricio.async.db.{ QueryResult, Connection }
5 | import scala.concurrent.{ ExecutionContext, Future }
6 |
7 | class PartitionedConnectionPool[T <: Connection](
8 | factory: ObjectFactory[T],
9 | configuration: PoolConfiguration,
10 | numberOfPartitions: Int,
11 | executionContext: ExecutionContext = ExecutorServiceUtils.CachedExecutionContext)
12 | extends PartitionedAsyncObjectPool[T](factory, configuration, numberOfPartitions)
13 | with Connection {
14 |
15 | def disconnect: Future[Connection] = if (this.isConnected) {
16 | this.close.map(item => this)(executionContext)
17 | } else {
18 | Future.successful(this)
19 | }
20 |
21 | def connect: Future[Connection] = Future.successful(this)
22 |
23 | def isConnected: Boolean = !this.isClosed
24 |
25 | def sendQuery(query: String): Future[QueryResult] =
26 | this.use(_.sendQuery(query))(executionContext)
27 |
28 | def sendPreparedStatement(query: String, values: Seq[Any] = List()): Future[QueryResult] =
29 | this.use(_.sendPreparedStatement(query, values))(executionContext)
30 |
31 | override def inTransaction[A](f: Connection => Future[A])(implicit context: ExecutionContext = executionContext): Future[A] =
32 | this.use(_.inTransaction[A](f)(context))(executionContext)
33 | }
34 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/encoder/PreparedStatementPrepareEncoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.encoder
18 |
19 | import io.netty.buffer.ByteBuf
20 | import com.github.mauricio.async.db.mysql.message.client.{PreparedStatementPrepareMessage, ClientMessage}
21 | import com.github.mauricio.async.db.util.ByteBufferUtils
22 | import java.nio.charset.Charset
23 |
24 | class PreparedStatementPrepareEncoder( charset : Charset ) extends MessageEncoder {
25 |
26 | def encode(message: ClientMessage): ByteBuf = {
27 | val m = message.asInstanceOf[PreparedStatementPrepareMessage]
28 | val statement = m.statement.getBytes(charset)
29 | val buffer = ByteBufferUtils.packetBuffer( 4 + 1 + statement.size)
30 | buffer.writeByte( m.kind )
31 | buffer.writeBytes( statement )
32 |
33 | buffer
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/parsers/ParserKSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend.{ServerMessage, ProcessData}
20 | import org.specs2.mutable.Specification
21 | import io.netty.buffer.Unpooled
22 |
23 | class ParserKSpec extends Specification {
24 |
25 | val parser = BackendKeyDataParser
26 |
27 | "parserk" should {
28 |
29 | "correctly parse the message" in {
30 |
31 | val buffer = Unpooled.buffer()
32 | buffer.writeInt(10)
33 | buffer.writeInt(20)
34 |
35 | val data = parser.parseMessage(buffer).asInstanceOf[ProcessData]
36 |
37 | data.kind === ServerMessage.BackendKeyData
38 | data.processId === 10
39 | data.secretKey === 20
40 |
41 | }
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/column/TimeDecoder.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.mysql.column
18 |
19 | import com.github.mauricio.async.db.column.ColumnDecoder
20 | import scala.concurrent.duration._
21 |
22 | object TimeDecoder extends ColumnDecoder {
23 |
24 | final val Hour = 1.hour.toMillis
25 |
26 | override def decode(value: String): Duration = {
27 |
28 | val pieces = value.split(':')
29 |
30 | val secondsAndMillis = pieces(2).split('.')
31 |
32 | val parts = if ( secondsAndMillis.length == 2 ) {
33 | (secondsAndMillis(0).toInt,secondsAndMillis(1).toInt)
34 | } else {
35 | (secondsAndMillis(0).toInt,0)
36 | }
37 |
38 | val hours = pieces(0).toInt
39 | val minutes = pieces(1).toInt
40 |
41 | hours.hours + minutes.minutes + parts._1.seconds + parts._2.millis
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/message/server/ServerMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | *
16 | */
17 |
18 | package com.github.mauricio.async.db.mysql.message.server
19 |
20 | import com.github.mauricio.async.db.KindedMessage
21 |
22 | object ServerMessage {
23 |
24 | final val ServerProtocolVersion = 10
25 | final val Error = -1
26 | final val Ok = 0
27 | final val EOF = -2
28 |
29 | // these messages don't actually exist
30 | // but we use them to simplify the switch statements
31 | final val ColumnDefinition = 100
32 | final val ColumnDefinitionFinished = 101
33 | final val ParamProcessingFinished = 102
34 | final val ParamAndColumnProcessingFinished = 103
35 | final val Row = 104
36 | final val BinaryRow = 105
37 | final val PreparedStatementPrepareResponse = 106
38 |
39 | }
40 |
41 | class ServerMessage( val kind : Int ) extends KindedMessage
42 |
--------------------------------------------------------------------------------
/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/codec/SendLongDataEncoder.scala:
--------------------------------------------------------------------------------
1 | package com.github.mauricio.async.db.mysql.codec
2 |
3 | import com.github.mauricio.async.db.mysql.message.client.{ClientMessage, SendLongDataMessage}
4 | import com.github.mauricio.async.db.util.{ByteBufferUtils, Log}
5 | import io.netty.buffer.Unpooled
6 | import io.netty.channel.ChannelHandlerContext
7 | import io.netty.handler.codec.MessageToMessageEncoder
8 |
9 | object SendLongDataEncoder {
10 | val log = Log.get[SendLongDataEncoder]
11 |
12 | val LONG_THRESHOLD = 1023
13 | }
14 |
15 | class SendLongDataEncoder
16 | extends MessageToMessageEncoder[SendLongDataMessage](classOf[SendLongDataMessage]) {
17 |
18 | import com.github.mauricio.async.db.mysql.codec.SendLongDataEncoder.log
19 |
20 | def encode(ctx: ChannelHandlerContext, message: SendLongDataMessage, out: java.util.List[Object]): Unit = {
21 | if ( log.isTraceEnabled ) {
22 | log.trace(s"Writing message ${message.toString}")
23 | }
24 |
25 | val sequence = 0
26 |
27 | val headerBuffer = ByteBufferUtils.mysqlBuffer(3 + 1 + 1 + 4 + 2)
28 | ByteBufferUtils.write3BytesInt(headerBuffer, 1 + 4 + 2 + message.value.readableBytes())
29 | headerBuffer.writeByte(sequence)
30 |
31 | headerBuffer.writeByte(ClientMessage.PreparedStatementSendLongData)
32 | headerBuffer.writeBytes(message.statementId)
33 | headerBuffer.writeShort(message.paramId)
34 |
35 | val result = Unpooled.wrappedBuffer(headerBuffer, message.value)
36 |
37 | out.add(result)
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/parsers/ReturningMessageParser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Maurício Linhares
3 | *
4 | * Maurício Linhares licenses this file to you under the Apache License,
5 | * version 2.0 (the "License"); you may not use this file except in compliance
6 | * with the License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package com.github.mauricio.async.db.postgresql.parsers
18 |
19 | import com.github.mauricio.async.db.postgresql.messages.backend._
20 | import io.netty.buffer.ByteBuf
21 |
22 | object ReturningMessageParser {
23 |
24 | val BindCompleteMessageParser = new ReturningMessageParser(BindComplete)
25 | val CloseCompleteMessageParser = new ReturningMessageParser(CloseComplete)
26 | val EmptyQueryStringMessageParser = new ReturningMessageParser(EmptyQueryString)
27 | val NoDataMessageParser = new ReturningMessageParser(NoData)
28 | val ParseCompleteMessageParser = new ReturningMessageParser(ParseComplete)
29 |
30 | }
31 |
32 | class ReturningMessageParser(val message: ServerMessage) extends MessageParser {
33 |
34 | def parseMessage(buffer: ByteBuf): ServerMessage = this.message
35 |
36 | }
37 |
--------------------------------------------------------------------------------