23
23
from warnings import warn
24
24
25
25
from neo4j .data import DataDehydrator
26
- from neo4j .exceptions import (
27
- Neo4jError ,
28
- ServiceUnavailable ,
29
- SessionExpired ,
30
- )
26
+ from neo4j .io import ConnectionErrorHandler
31
27
from neo4j .work .summary import ResultSummary
32
28
33
29
34
- class _ConnectionErrorHandler :
35
- """
36
- Wrapper class for handling connection errors.
37
-
38
- The class will wrap each method to invoke a callback if the method raises
39
- SessionExpired or ServiceUnavailable.
40
- The error will be re-raised after the callback.
41
- """
42
-
43
- def __init__ (self , connection , on_error ):
44
- """
45
- :param connection the connection object to warp
46
- :type connection Bolt
47
- :param on_error the function to be called when a method of
48
- connection raises of of the caught errors.
49
- :type on_error callable
50
- """
51
- self .connection = connection
52
- self .on_error = on_error
53
-
54
- def __getattr__ (self , item ):
55
- connection_attr = getattr (self .connection , item )
56
- if not callable (connection_attr ):
57
- return connection_attr
58
-
59
- def outer (func ):
60
- def inner (* args , ** kwargs ):
61
- try :
62
- func (* args , ** kwargs )
63
- except (Neo4jError , ServiceUnavailable , SessionExpired ) as exc :
64
- self .on_error (exc )
65
- raise
66
- return inner
67
-
68
- return outer (connection_attr )
69
-
70
-
71
30
class Result :
72
31
"""A handler for the result of Cypher query execution. Instances
73
32
of this class are typically constructed and returned by
@@ -76,7 +35,7 @@ class Result:
76
35
77
36
def __init__ (self , connection , hydrant , fetch_size , on_closed ,
78
37
on_error ):
79
- self ._connection = _ConnectionErrorHandler (connection , on_error )
38
+ self ._connection = ConnectionErrorHandler (connection , on_error )
80
39
self ._hydrant = hydrant
81
40
self ._on_closed = on_closed
82
41
self ._metadata = None
@@ -98,7 +57,7 @@ def __init__(self, connection, hydrant, fetch_size, on_closed,
98
57
99
58
@property
100
59
def _qid (self ):
101
- if self ._raw_qid == self ._connection .connection . most_recent_qid :
60
+ if self ._raw_qid == self ._connection .most_recent_qid :
102
61
return - 1
103
62
else :
104
63
return self ._raw_qid
@@ -127,7 +86,7 @@ def on_attached(metadata):
127
86
# For auto-commit there is no qid and Bolt 3 does not support qid
128
87
self ._raw_qid = metadata .get ("qid" , - 1 )
129
88
if self ._raw_qid != - 1 :
130
- self ._connection .connection . most_recent_qid = self ._raw_qid
89
+ self ._connection .most_recent_qid = self ._raw_qid
131
90
self ._keys = metadata .get ("fields" )
132
91
self ._attached = True
133
92
0 commit comments