@@ -13,62 +13,20 @@ import '../result_set.dart';
1313import  '../statement.dart' ;
1414import  'bindings.dart' ;
1515import  'exception.dart' ;
16- import  'finalizer.dart' ;
1716import  'statement.dart' ;
1817import  'utils.dart' ;
1918
20- /// Contains the state of a database needed for finalization. 
21- /// 
22- /// This is extracted into separate object so that it can be used as a 
23- /// finalization token. It will get disposed when the main database is no longer 
24- /// reachable without being closed. 
25- final  class  FinalizableDatabase  extends  FinalizablePart  {
26-   final  RawSqliteBindings  bindings;
27-   final  RawSqliteDatabase  database;
28- 
29-   final  List <FinalizableStatement > _statements =  [];
30-   final  List <void  Function ()> dartCleanup =  [];
31- 
32-   FinalizableDatabase (this .bindings, this .database);
33- 
34-   @override 
35-   void  dispose () {
36-     for  (final  stmt in  _statements) {
37-       stmt.dispose ();
38-     }
39- 
40-     for  (final  cleanup in  dartCleanup.toList ()) {
41-       cleanup ();
42-     }
43- 
44-     final  code =  database.sqlite3_close_v2 ();
45-     SqliteException ?  exception;
46-     if  (code !=  SqlError .SQLITE_OK ) {
47-       exception =  createExceptionRaw (
48-         bindings,
49-         database,
50-         code,
51-         operation:  'closing database' ,
52-       );
53-     }
54- 
55-     if  (exception !=  null ) {
56-       throw  exception;
57-     }
58-   }
59- }
60- 
6119base  class  DatabaseImplementation  implements  CommonDatabase  {
6220  final  RawSqliteBindings  bindings;
21+   // Note: Implementations of this have platform-specific finalizers on them. 
6322  final  RawSqliteDatabase  database;
6423
65-   final  FinalizableDatabase  finalizable;
66- 
6724  _StreamHandlers <SqliteUpdate , void  Function ()>?  _updates;
6825  _StreamHandlers <void , void  Function ()>?  _rollbacks;
6926  _StreamHandlers <void , VoidPredicate >?  _commits;
7027
71-   var  _isClosed =  false ;
28+   @internal 
29+   var  isClosed =  false ;
7230
7331  @override 
7432  DatabaseConfig  get  config =>  DatabaseConfigImplementation (this );
@@ -91,24 +49,15 @@ base class DatabaseImplementation implements CommonDatabase {
9149    execute ('PRAGMA user_version = $value ;' );
9250  }
9351
94-   DatabaseImplementation (this .bindings, this .database)
95-     :  finalizable =  FinalizableDatabase (bindings, database) {
96-     disposeFinalizer.attach (this , finalizable, detach:  this );
97-   }
52+   DatabaseImplementation (this .bindings, this .database);
9853
9954  @visibleForOverriding 
10055  StatementImplementation  wrapStatement (String  sql, RawSqliteStatement  stmt) {
10156    return  StatementImplementation (sql, this , stmt);
10257  }
10358
104-   void  handleFinalized (StatementImplementation  stmt) {
105-     if  (! _isClosed) {
106-       finalizable._statements.remove (stmt.finalizable);
107-     }
108-   }
109- 
11059  void  _ensureOpen () {
111-     if  (_isClosed ) {
60+     if  (isClosed ) {
11261      throw  StateError ('This database has already been closed' );
11362    }
11463  }
@@ -289,10 +238,9 @@ base class DatabaseImplementation implements CommonDatabase {
289238
290239  @override 
291240  void  dispose () {
292-     if  (_isClosed ) return ;
241+     if  (isClosed ) return ;
293242
294-     disposeFinalizer.detach (this );
295-     _isClosed =  true ;
243+     isClosed =  true ;
296244
297245    _updates? .close ();
298246    _commits? .close ();
@@ -302,7 +250,20 @@ base class DatabaseImplementation implements CommonDatabase {
302250    database.sqlite3_commit_hook (null );
303251    database.sqlite3_rollback_hook (null );
304252
305-     finalizable.dispose ();
253+     final  code =  database.sqlite3_close_v2 ();
254+     SqliteException ?  exception;
255+     if  (code !=  SqlError .SQLITE_OK ) {
256+       exception =  createExceptionRaw (
257+         bindings,
258+         database,
259+         code,
260+         operation:  'closing database' ,
261+       );
262+     }
263+ 
264+     if  (exception !=  null ) {
265+       throw  exception;
266+     }
306267  }
307268
308269  @override 
@@ -447,11 +408,6 @@ base class DatabaseImplementation implements CommonDatabase {
447408    }
448409
449410    compiler.close ();
450- 
451-     for  (final  created in  createdStatements) {
452-       finalizable._statements.add (created.finalizable);
453-     }
454- 
455411    return  createdStatements;
456412  }
457413
@@ -661,7 +617,7 @@ final class _StreamHandlers<T, SyncCallback> {
661617
662618  Stream <T > _generateStream (bool  dispatchSynchronously) {
663619    return  Stream .multi ((newListener) {
664-       if  (_database._isClosed ) {
620+       if  (_database.isClosed ) {
665621        newListener.close ();
666622        return ;
667623      }
@@ -713,7 +669,7 @@ final class _StreamHandlers<T, SyncCallback> {
713669  void  _removeAsyncListener (MultiStreamController <T > listener, bool  sync ) {
714670    _asyncListeners.remove ((controller:  listener, sync :  sync ));
715671
716-     if  (! hasListener &&  ! _database._isClosed ) {
672+     if  (! hasListener &&  ! _database.isClosed ) {
717673      _unregister ();
718674    }
719675  }
0 commit comments