Skip to content

Commit b7a98c4

Browse files
committed
Missing files...=/
1 parent c9e1667 commit b7a98c4

File tree

4 files changed

+305
-0
lines changed

4 files changed

+305
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import Transaction from './transaction'
21+
22+
/**
23+
* Represents a transaction that is managed by the transaction executor.
24+
*
25+
* @public
26+
*/
27+
class ManagedTransaction extends Transaction {
28+
29+
/**
30+
* Commits the transaction and returns the result.
31+
*
32+
* After committing the transaction can no longer be used.
33+
*
34+
* @deprecated Commit should be done by returning from the transaction work.
35+
*
36+
* @returns {Promise<void>} An empty promise if committed successfully or error if any error happened during commit.
37+
*/
38+
commit(): Promise<void> {
39+
return super.commit()
40+
}
41+
42+
/**
43+
* Rollbacks the transaction.
44+
*
45+
* After rolling back, the transaction can no longer be used.
46+
*
47+
* @deprecated Rollback should be done by throwing or returning a rejected promise from the transaction work.
48+
*
49+
* @returns {Promise<void>} An empty promise if rolled back successfully or error if any error happened during
50+
* rollback.
51+
*/
52+
rollback(): Promise<void> {
53+
return super.rollback()
54+
}
55+
56+
/**
57+
* Closes the transaction
58+
*
59+
* This method will roll back the transaction if it is not already committed or rolled back.
60+
*
61+
* @deprecated Close should not be done in transaction work. See {@link ManagedTransaction#commit} and {@link ManagedTransaction#rollback}
62+
*
63+
* @returns {Promise<void>} An empty promise if closed successfully or error if any error happened during
64+
*/
65+
close(): Promise<void> {
66+
return super.close()
67+
}
68+
}
69+
70+
export default ManagedTransaction
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import RxTransaction from './transaction-rx'
21+
22+
/**
23+
* Represents a RX transaction that is managed by the transaction executor.
24+
*
25+
* @public
26+
*/
27+
class RxManagedTransaction extends RxTransaction {
28+
/**
29+
* Commits the transaction.
30+
*
31+
* @public
32+
* @deprecated Commit should be done by returning from the transaction work.
33+
* @returns {Observable} - An empty observable
34+
*/
35+
commit () {
36+
return super.commit()
37+
}
38+
39+
/**
40+
* Rolls back the transaction.
41+
*
42+
* @public
43+
* @deprecated Rollback should be done by throwing or returning a rejected promise from the transaction work.
44+
* @returns {Observable} - An empty observable
45+
*/
46+
rollback () {
47+
return super.rollback()
48+
}
49+
50+
/**
51+
* Closes the transaction
52+
*
53+
* This method will roll back the transaction if it is not already committed or rolled back.
54+
* @deprecated Close should not be done in transaction work. See {@link RxManagedTransaction#commit} and {@link RxManagedTransaction#rollback}
55+
* @returns {Observable} - An empty observable
56+
*/
57+
close () {
58+
return super.close()
59+
}
60+
}
61+
62+
export default RxManagedTransaction
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import RxManagedTransaction from '../../src/transaction-managed-rx'
20+
21+
describe('#unit', () => {
22+
describe('.commit()', () => {
23+
it('should delegate to the original Transaction', async () => {
24+
const txc = {
25+
commit: jasmine.createSpy('commit').and.returnValue(Promise.resolve())
26+
}
27+
28+
const transaction = new RxManagedTransaction(txc)
29+
30+
await transaction.commit().toPromise()
31+
32+
expect(txc.commit).toHaveBeenCalled()
33+
})
34+
35+
it('should fail if to the original Transaction.close call fails', async () => {
36+
const expectedError = new Error('expected')
37+
const txc = {
38+
commit: jasmine
39+
.createSpy('commit')
40+
.and.returnValue(Promise.reject(expectedError))
41+
}
42+
43+
const transaction = new RxManagedTransaction(txc)
44+
45+
try {
46+
await transaction.commit().toPromise()
47+
fail('should have thrown')
48+
} catch (error) {
49+
expect(error).toBe(expectedError)
50+
}
51+
})
52+
})
53+
54+
describe('.rollback()', () => {
55+
it('should delegate to the original Transaction', async () => {
56+
const txc = {
57+
rollback: jasmine
58+
.createSpy('rollback')
59+
.and.returnValue(Promise.resolve())
60+
}
61+
62+
const transaction = new RxManagedTransaction(txc)
63+
64+
await transaction.rollback().toPromise()
65+
66+
expect(txc.rollback).toHaveBeenCalled()
67+
})
68+
69+
it('should fail if to the original Transaction.close call fails', async () => {
70+
const expectedError = new Error('expected')
71+
const txc = {
72+
rollback: jasmine
73+
.createSpy('rollback')
74+
.and.returnValue(Promise.reject(expectedError))
75+
}
76+
77+
const transaction = new RxManagedTransaction(txc)
78+
79+
try {
80+
await transaction.rollback().toPromise()
81+
fail('should have thrown')
82+
} catch (error) {
83+
expect(error).toBe(expectedError)
84+
}
85+
})
86+
})
87+
88+
describe('.close()', () => {
89+
it('should delegate to the original Transaction', async () => {
90+
const txc = {
91+
close: jasmine.createSpy('close').and.returnValue(Promise.resolve())
92+
}
93+
94+
const transaction = new RxManagedTransaction(txc)
95+
96+
await transaction.close().toPromise()
97+
98+
expect(txc.close).toHaveBeenCalled()
99+
})
100+
101+
it('should fail if to the original Transaction.close call fails', async () => {
102+
const expectedError = new Error('expected')
103+
const txc = {
104+
close: jasmine
105+
.createSpy('close')
106+
.and.returnValue(Promise.reject(expectedError))
107+
}
108+
109+
const transaction = new RxManagedTransaction(txc)
110+
111+
try {
112+
await transaction.close().toPromise()
113+
fail('should have thrown')
114+
} catch (error) {
115+
expect(error).toBe(expectedError)
116+
}
117+
})
118+
})
119+
})
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import { Observable } from 'rxjs'
20+
import { Parameters } from './query-runner'
21+
import RxResult from './result-rx'
22+
23+
declare interface RxManagedTransaction {
24+
run(query: string, parameters?: Parameters): RxResult
25+
26+
/**
27+
* Commits the transaction.
28+
*
29+
* @public
30+
* @deprecated Commit should be done by returning from the transaction work.
31+
* @returns {Observable} - An empty observable
32+
*/
33+
commit(): Observable<any>
34+
35+
/**
36+
* Rolls back the transaction.
37+
*
38+
* @public
39+
* @deprecated Rollback should be done by throwing or returning a rejected promise from the transaction work.
40+
* @returns {Observable} - An empty observable
41+
*/
42+
rollback(): Observable<any>
43+
44+
/**
45+
* Closes the transaction
46+
*
47+
* This method will roll back the transaction if it is not already committed or rolled back.
48+
* @deprecated Close should not be done in transaction work. See {@link RxManagedTransaction#commit} and {@link RxManagedTransaction#rollback}
49+
* @returns {Observable} - An empty observable
50+
*/
51+
close(): Observable<any>
52+
}
53+
54+
export default RxManagedTransaction

0 commit comments

Comments
 (0)