2828
2929NOT_SET = _NOT_SET # required for passing timeout to Session.execute
3030
31+ cluster = None
32+ session = None
33+
3134# connections registry
3235DEFAULT_CONNECTION = '_default_'
3336_connections = {}
@@ -79,6 +82,7 @@ def __init__(self, name, hosts, consistency=None,
7982
8083 def setup (self ):
8184 """Setup the connection"""
85+ global cluster , session
8286
8387 if 'username' in self .cluster_options or 'password' in self .cluster_options :
8488 raise CQLEngineException ("Username & Password are now handled by using the native driver's auth_provider" )
@@ -99,6 +103,10 @@ def setup(self):
99103 if self .consistency is not None :
100104 self .session .default_consistency_level = self .consistency
101105
106+ if DEFAULT_CONNECTION in _connections and _connections [DEFAULT_CONNECTION ] == self :
107+ cluster = _connections [DEFAULT_CONNECTION ].cluster
108+ session = _connections [DEFAULT_CONNECTION ].session
109+
102110 self .setup_session ()
103111
104112 def setup_session (self ):
@@ -135,32 +143,38 @@ def register_connection(name, hosts, consistency=None, lazy_connect=False,
135143 _connections [name ] = conn
136144
137145 if default :
138- _connections [ DEFAULT_CONNECTION ] = conn
146+ set_default_connection ( name )
139147
140148 conn .setup ()
141149 return conn
142150
143151
144152def unregister_connection (name ):
153+ global cluster , session
145154
146155 if name not in _connections :
147156 return
148157
149158 if DEFAULT_CONNECTION in _connections and _connections [name ] == _connections [DEFAULT_CONNECTION ]:
150159 del _connections [DEFAULT_CONNECTION ]
160+ cluster = None
161+ session = None
151162 log .warning ("Unregistering default connection '{0}'. Use set_default_connection to set a new one." .format (name ))
152163
153164 log .debug ("Connection '{0}' has been removed from the registry." .format (name ))
154165 del _connections [name ]
155166
156167
157168def set_default_connection (name ):
169+ global cluster , session
158170
159171 if name not in _connections :
160172 raise CQLEngineException ("Connection '{0}' doesn't exist." .format (name ))
161173
162174 log .debug ("Connection '{0}' has been set as default." .format (name ))
163175 _connections [DEFAULT_CONNECTION ] = _connections [name ]
176+ cluster = _connections [name ].cluster
177+ session = _connections [name ].session
164178
165179
166180def get_connection (name = None ):
0 commit comments