2222class SpannerAdminApi (api .TableReadApi ):
2323 """Manages table schema information on Spanner."""
2424
25- _connection = None
2625 _connection_info = None
26+ _spanner_connection = None
2727
2828 @classmethod
2929 def connect (cls ,
@@ -34,32 +34,35 @@ def connect(cls,
3434 create_ddl = None ):
3535 """Connects to the specified database, optionally creating tables."""
3636 connection_info = (project , instance , database , credentials )
37- if cls ._connection is not None and connection_info == cls ._connection_info :
38- return
37+ if cls ._spanner_connection is not None :
38+ if connection_info == cls ._connection_info :
39+ return
40+ cls .hangup ()
3941
4042 client = spanner .Client (project = project , credentials = credentials )
4143 instance = client .instance (instance )
4244
4345 if create_ddl is not None :
44- cls ._connection = instance .database (database , ddl_statements = create_ddl )
46+ cls ._spanner_connection = instance .database (
47+ database , ddl_statements = create_ddl )
4548 operation = cls ._connection .create ()
4649 operation .result ()
4750 else :
48- cls ._connection = instance .database (database )
51+ cls ._spanner_connection = instance .database (database )
4952
5053 cls ._connection_info = connection_info
5154
5255 @classmethod
53- def _database_connection (cls ):
54- assert cls ._connection is not None
55- return cls ._connection
56+ def _connection (cls ):
57+ assert cls ._spanner_connection is not None
58+ return cls ._spanner_connection
5659
5760 @classmethod
5861 def hangup (cls ):
59- cls ._connection = None
62+ cls ._spanner_connection = None
6063 cls ._connection_info = None
6164
6265 @classmethod
6366 def update_schema (cls , change ):
64- operation = cls ._database_connection ().update_ddl ([change ])
67+ operation = cls ._connection ().update_ddl ([change ])
6568 operation .result ()
0 commit comments