Skip to content

Commit

Permalink
Use BEConnection interface where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
lisael committed Oct 7, 2016
1 parent 74c29fc commit 39d8d57
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
22 changes: 11 additions & 11 deletions pg/connection/conversation.pony
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ use "pg"

trait Conversation

be apply(c: _Connection)
be apply(c: BEConnection tag)
be message(m: ServerMessage val)


actor _NullConversation is Conversation
let _conn: _Connection
let _conn: BEConnection tag

new create(c: _Connection) => _conn = c
be apply(c: _Connection) => None
new create(c: BEConnection tag) => _conn = c
be apply(c: BEConnection tag) => None
be message(m: ServerMessage val) =>
_conn.handle_message(m)


actor _AuthConversation is Conversation
let _pool: ConnectionManager
let _params: Array[(String, String)] val
let _conn: _Connection
new create(p: ConnectionManager, c: _Connection, params: Array[(String, String)] val) =>
let _conn: BEConnection tag
new create(p: ConnectionManager, c: BEConnection tag, params: Array[(String, String)] val) =>
_pool=p
_conn=c
_params=params

be log(msg: String) =>
_pool.log(msg)

be apply(c: _Connection) =>
be apply(c: BEConnection tag) =>
let data = recover val
let msg = StartupMessage(_params)
msg.done()
Expand Down Expand Up @@ -149,19 +149,19 @@ actor ExecuteConversation is Conversation

actor QueryConversation is Conversation
let query: String val
let _conn: _Connection
let _conn: BEConnection tag
let _handler: ResultCB val
var _rows: (Rows val | Rows trn ) = recover trn Rows end
var _tuple_desc: (TupleDescription val | None) = None

new create(c: _Connection, q: String, h: ResultCB val) =>
new create(c: BEConnection tag, q: String, h: ResultCB val) =>
query = q
_conn = c
_handler = h

be log(msg: String) => _conn.log(msg)

be apply(c: _Connection) =>
be apply(c: BEConnection tag) =>
c.writev(recover val QueryMessage(query).done() end)

be call_back() =>
Expand Down Expand Up @@ -196,7 +196,7 @@ actor TerminateConversation is Conversation

be log(msg: String) => _conn.log(msg)

be apply(c: _Connection) =>
be apply(c: BEConnection tag) =>
c.writev(recover val TerminateMessage.done() end)

be message(m: ServerMessage val)=>
Expand Down
4 changes: 2 additions & 2 deletions pg/connection/listener.pony
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class PGParseError is ParseEvent


actor Listener
let _conn: _Connection
let _conn: BEConnection tag
var r: Reader iso = Reader // current reader
var _ctype: U8 = 0 // current type (keep it if the data is chuncked)
var _clen: USize = 0 // current message len (as given by server)

new create(c: _Connection) =>
new create(c: BEConnection tag) =>
_conn = c

be received(data: Array[U8] iso) =>
Expand Down
8 changes: 6 additions & 2 deletions pg/connection/manager.pony
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ use "promises"
use "pg"

actor ConnectionManager
let _connections: Array[_Connection] = Array[_Connection tag]
let _connections: Array[BEConnection tag] = Array[BEConnection tag]
let _params: Array[(String, String)] val
let _host: String
let _service: String
let _user: String
let _passwd_provider: PasswordProvider tag
var _password: (String | None) = None
let _max_size: USize

new create(host: String,
service: String,
user: String,
passwd_provider: PasswordProvider tag,
params: Array[Param] val) =>
params: Array[Param] val,
pool_size: USize = 1
) =>
_params = params
_host = host
_service = service
_passwd_provider = passwd_provider
_user = user
_max_size = pool_size

be log(msg: String) =>
None
Expand Down
1 change: 1 addition & 0 deletions pg/connection/tcp.pony
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface BEConnection
be next()
be schedule(conv: Conversation tag)
be terminate()
be received(s: ServerMessage val)
be do_terminate()
be cursor(query: String, notify: CursorNotify iso) => None

Expand Down

0 comments on commit 39d8d57

Please sign in to comment.