Skip to content

Commit 2174247

Browse files
committed
Implementing changes in the bolt-connection
1 parent 33f9cf3 commit 2174247

File tree

15 files changed

+386
-83
lines changed

15 files changed

+386
-83
lines changed

packages/bolt-connection/src/connection-provider/connection-provider-pooled.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
8282
*/
8383
_createConnection ({ auth }, address, release) {
8484
return this._createChannelConnection(address).then(connection => {
85-
connection._release = () => {
85+
connection.release = () => {
8686
return release(address, connection)
8787
}
8888
this._openConnections[connection.id] = connection
@@ -160,7 +160,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
160160
await connection.resetAndFlush()
161161
}
162162
} finally {
163-
await connection._release()
163+
await connection.release()
164164
}
165165
return serverInfo
166166
}
@@ -191,7 +191,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
191191
}
192192
throw error
193193
} finally {
194-
await Promise.all(connectionsToRelease.map(conn => conn._release()))
194+
await Promise.all(connectionsToRelease.map(conn => conn.release()))
195195
}
196196
}
197197

@@ -201,7 +201,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
201201
connection._sticky = connectionWithSameCredentials && !connection.supportsReAuth
202202

203203
if (shouldCreateStickyConnection || connection._sticky) {
204-
await connection._release()
204+
await connection.release()
205205
throw newError('Driver is connected to a database that does not support user switch.')
206206
}
207207
}

packages/bolt-connection/src/connection/connection-channel.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ export default class ChannelConnection extends Connection {
156156
}
157157
}
158158

159+
beginTransaction (config) {
160+
return this._protocol.beginTransaction(config)
161+
}
162+
163+
run (query, parameters, config) {
164+
return this._protocol.run(query, parameters, config)
165+
}
166+
167+
commitTransaction (config) {
168+
return this._protocol.commitTransaction(config)
169+
}
170+
171+
rollbackTransaction (config) {
172+
return this._protocol.rollbackTransaction(config)
173+
}
174+
175+
getProtocolVersion () {
176+
return this._protocol.version
177+
}
178+
159179
get authToken () {
160180
return this._authToken
161181
}

packages/bolt-connection/src/connection/connection-delegate.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ export default class DelegateConnection extends Connection {
3535
this._delegate = delegate
3636
}
3737

38+
beginTransaction (config) {
39+
return this._delegate.beginTransaction(config)
40+
}
41+
42+
run (query, param, config) {
43+
return this._delegate.run(query, param, config)
44+
}
45+
46+
commitTransaction (config) {
47+
return this._delegate.commitTransaction(config)
48+
}
49+
50+
rollbackTransaction (config) {
51+
return this._delegate.rollbackTransaction(config)
52+
}
53+
54+
getProtocolVersion () {
55+
return this._delegate.getProtocolVersion()
56+
}
57+
3858
get id () {
3959
return this._delegate.id
4060
}
@@ -103,11 +123,11 @@ export default class DelegateConnection extends Connection {
103123
return this._delegate.close()
104124
}
105125

106-
_release () {
126+
release () {
107127
if (this._originalErrorHandler) {
108128
this._delegate._errorHandler = this._originalErrorHandler
109129
}
110130

111-
return this._delegate._release()
131+
return this._delegate.release()
112132
}
113133
}

packages/bolt-connection/src/connection/connection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
*/
1919
// eslint-disable-next-line no-unused-vars
2020
import { ResultStreamObserver, BoltProtocol } from '../bolt'
21+
import { Connection as CoreConnection } from 'neo4j-driver-core'
2122

22-
export default class Connection {
23+
export default class Connection extends CoreConnection {
2324
/**
2425
* @param {ConnectionErrorHandler} errorHandler the error handler
2526
*/
2627
constructor (errorHandler) {
28+
super()
2729
this._errorHandler = errorHandler
2830
}
2931

packages/bolt-connection/test/connection-provider/connection-provider-direct.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe('constructor', () => {
289289

290290
const connection = await create({}, server0, release)
291291

292-
const released = connection._release()
292+
const released = connection.release()
293293

294294
expect(released).toBe(releaseResult)
295295
expect(release).toHaveBeenCalledWith(server0, connection)
@@ -546,7 +546,7 @@ describe('user-switching', () => {
546546

547547
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
548548
expect(poolAcquire).toHaveBeenCalledWith({ auth: acquireAuth }, address)
549-
expect(connection._release).toHaveBeenCalled()
549+
expect(connection.release).toHaveBeenCalled()
550550
expect(connection._sticky).toEqual(isStickyConn)
551551
})
552552
})
@@ -599,15 +599,15 @@ describe('.verifyConnectivityAndGetServerInfo()', () => {
599599

600600
await connectionProvider.verifyConnectivityAndGetServerInfo()
601601

602-
expect(seenConnections[0]._release).toHaveBeenCalledTimes(1)
602+
expect(seenConnections[0].release).toHaveBeenCalledTimes(1)
603603
})
604604

605605
it('should resetAndFlush and then release the connection', async () => {
606606
const { connectionProvider, seenConnections, resetAndFlush } = setup()
607607

608608
await connectionProvider.verifyConnectivityAndGetServerInfo()
609609

610-
expect(seenConnections[0]._release.mock.invocationCallOrder[0])
610+
expect(seenConnections[0].release.mock.invocationCallOrder[0])
611611
.toBeGreaterThan(resetAndFlush.mock.invocationCallOrder[0])
612612
})
613613

@@ -636,7 +636,7 @@ describe('.verifyConnectivityAndGetServerInfo()', () => {
636636
await connectionProvider.verifyConnectivityAndGetServerInfo()
637637
} catch (e) {
638638
} finally {
639-
expect(seenConnections[0]._release).toHaveBeenCalledTimes(1)
639+
expect(seenConnections[0].release).toHaveBeenCalledTimes(1)
640640
}
641641
})
642642

@@ -692,7 +692,7 @@ describe('.verifyConnectivityAndGetServerInfo()', () => {
692692
}
693693
connection.resetAndFlush = resetAndFlush
694694
if (releaseMock) {
695-
connection._release = releaseMock
695+
connection.release = releaseMock
696696
}
697697
seenConnections.push(connection)
698698
return connection
@@ -782,7 +782,7 @@ class FakeConnection extends Connection {
782782
super(null)
783783

784784
this._address = address
785-
this._release = jest.fn(() => release(address, this))
785+
this.release = jest.fn(() => release(address, this))
786786
this._server = server
787787
this._authToken = auth
788788
this._closed = false

packages/bolt-connection/test/connection-provider/connection-provider-routing.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,8 +2834,8 @@ describe.each([
28342834

28352835
expect(connections.length).toBe(1)
28362836
expect(connections[0].resetAndFlush).toHaveBeenCalled()
2837-
expect(connections[0]._release).toHaveBeenCalled()
2838-
expect(connections[0]._release.mock.invocationCallOrder[0])
2837+
expect(connections[0].release).toHaveBeenCalled()
2838+
expect(connections[0].release.mock.invocationCallOrder[0])
28392839
.toBeGreaterThan(connections[0].resetAndFlush.mock.invocationCallOrder[0])
28402840
})
28412841

@@ -2856,7 +2856,7 @@ describe.each([
28562856

28572857
// extra checks
28582858
expect(connections.length).toBe(1)
2859-
expect(connections[0]._release).toHaveBeenCalled()
2859+
expect(connections[0].release).toHaveBeenCalled()
28602860
})
28612861

28622862
it('should not acquire, resetAndFlush and release connections for sever with the other access mode', async () => {
@@ -2900,7 +2900,7 @@ describe.each([
29002900

29012901
expect(connections.length).toBe(1)
29022902
expect(connections[0].resetAndFlush).toHaveBeenCalled()
2903-
expect(connections[0]._release).toHaveBeenCalled()
2903+
expect(connections[0].release).toHaveBeenCalled()
29042904
}
29052905
}
29062906
})
@@ -2956,8 +2956,8 @@ describe.each([
29562956

29572957
expect(connections.length).toBe(1)
29582958
expect(connections[0].resetAndFlush).toHaveBeenCalled()
2959-
expect(connections[0]._release).toHaveBeenCalled()
2960-
expect(connections[0]._release.mock.invocationCallOrder[0])
2959+
expect(connections[0].release).toHaveBeenCalled()
2960+
expect(connections[0].release.mock.invocationCallOrder[0])
29612961
.toBeGreaterThan(connections[0].resetAndFlush.mock.invocationCallOrder[0])
29622962
}
29632963
}
@@ -2979,7 +2979,7 @@ describe.each([
29792979

29802980
expect(connections.length).toBe(1)
29812981
expect(connections[0].resetAndFlush).toHaveBeenCalled()
2982-
expect(connections[0]._release).toHaveBeenCalled()
2982+
expect(connections[0].release).toHaveBeenCalled()
29832983
}
29842984
}
29852985
})
@@ -3054,7 +3054,7 @@ describe.each([
30543054
connection.resetAndFlush = resetAndFlush
30553055
}
30563056
if (releaseMock) {
3057-
connection._release = releaseMock
3057+
connection.release = releaseMock
30583058
}
30593059
seenConnectionsPerAddress.get(address).push(connection)
30603060
return connection
@@ -3193,7 +3193,7 @@ describe.each([
31933193

31943194
const connection = await create({}, server0, release)
31953195

3196-
const released = connection._release()
3196+
const released = connection.release()
31973197

31983198
expect(released).toBe(releaseResult)
31993199
expect(release).toHaveBeenCalledWith(server0, connection)
@@ -3460,7 +3460,7 @@ describe.each([
34603460

34613461
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
34623462
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server3)
3463-
expect(connection._release).toHaveBeenCalled()
3463+
expect(connection.release).toHaveBeenCalled()
34643464
expect(connection._sticky).toEqual(isStickyConn)
34653465
})
34663466

@@ -3502,7 +3502,7 @@ describe.each([
35023502

35033503
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
35043504
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server1)
3505-
expect(connection._release).toHaveBeenCalled()
3505+
expect(connection.release).toHaveBeenCalled()
35063506
expect(connection._sticky).toEqual(isStickyConn)
35073507
})
35083508

@@ -3546,7 +3546,7 @@ describe.each([
35463546

35473547
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
35483548
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server0)
3549-
expect(connection._release).toHaveBeenCalled()
3549+
expect(connection.release).toHaveBeenCalled()
35503550
expect(connection._sticky).toEqual(isStickyConn)
35513551
})
35523552

@@ -3575,7 +3575,7 @@ describe.each([
35753575

35763576
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
35773577
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server0)
3578-
expect(connection._release).toHaveBeenCalled()
3578+
expect(connection.release).toHaveBeenCalled()
35793579
expect(connection._sticky).toEqual(isStickyConn)
35803580
})
35813581
})
@@ -3903,7 +3903,7 @@ class FakeConnection extends Connection {
39033903
this._version = version
39043904
this._protocolVersion = protocolVersion
39053905
this.release = release
3906-
this._release = jest.fn(() => release(address, this))
3906+
this.release = jest.fn(() => release(address, this))
39073907
this.resetAndFlush = jest.fn(() => Promise.resolve())
39083908
this._server = server
39093909
this._authToken = authToken

0 commit comments

Comments
 (0)