@@ -23,10 +23,6 @@ final DatabaseTracker tracker = DatabaseTracker();
2323/// this is necessary. 
2424class  DatabaseTracker  {
2525  final  Database  _db;
26-   bool  _isDisposed =  false ;
27- 
28-   /// Whether this [DatabaseTracker]  has been disposed. 
29-    bool  get  isDisposed =>  _isDisposed;
3026
3127  /// Creates a new tracker with necessary tables. 
3228   DatabaseTracker ()
@@ -42,35 +38,24 @@ CREATE TABLE IF NOT EXISTS open_connections(
4238    ''' );
4339  }
4440
45-   /// Tracks the [openedDb] . The [path]  argument can be used to track 
46-   /// the path of that database, if it's bound to a file. 
47-   /// 
48-   /// Throws a [StateError]  if this tracker has already been disposed. 
41+   /// Tracks the [openedDb] . The [path]  argument can be used to track the path 
42+   /// of that database, if it's bound to a file. 
4943   void  markOpened (String  path, Database  openedDb) {
50-     _checkIfDisposed ();
51- 
5244    final  stmt =  _db.prepare ('INSERT INTO open_connections VALUES (?, ?)' );
5345    stmt.execute ([openedDb.handle.address, path]);
5446    stmt.dispose ();
5547  }
5648
5749  /// Marks the database [db]  as closed. 
58-   /// 
59-   /// Throws a [StateError]  if this tracker has already been disposed. 
6050   void  markClosed (Database  db) {
61-     _checkIfDisposed ();
62- 
6351    final  ptr =  db.handle.address;
6452    _db.execute ('DELETE FROM open_connections WHERE database_pointer = $ptr ' );
6553  }
6654
67-   /// Closes all tracked database connections that are still open. 
68-   /// 
69-   /// Throws a [StateError]  if this tracker has already been disposed. 
55+   /// Closes tracked database connections. 
7056   void  closeExisting () {
71-     _checkIfDisposed ();
72- 
7357    _db.execute ('BEGIN;' );
58+ 
7459    try  {
7560      final  results = 
7661          _db.select ('SELECT database_pointer FROM open_connections' );
@@ -85,30 +70,4 @@ CREATE TABLE IF NOT EXISTS open_connections(
8570      _db.execute ('COMMIT;' );
8671    }
8772  }
88- 
89-   /// Releases all open database handles managed by this tracker and 
90-   /// closes the internal in-memory database. 
91-   /// 
92-   /// After calling this method, this instance should no longer be used. 
93-   /// Any further calls to public methods will throw a [StateError] . 
94-    void  dispose () {
95-     if  (_isDisposed) {
96-       return ;
97-     }
98- 
99-     // Safely close any tracked connections 
100-     closeExisting ();
101- 
102-     _db.dispose ();
103-     _isDisposed =  true ;
104-   }
105- 
106-   /// Checks if this tracker has been disposed and throws a [StateError]  if so. 
107-    void  _checkIfDisposed () {
108-     if  (_isDisposed) {
109-       throw  StateError (
110-         'DatabaseTracker has already been disposed and can no longer be used.' ,
111-       );
112-     }
113-   }
11473}
0 commit comments