List:Commits« Previous MessageNext Message »
From:Monty Taylor Date:August 19 2008 7:00am
Subject:bzr commit into NDB/Bindings:trunk branch (monty:449)
View as plain text  
#At https://bazaar.launchpad.net/~ndb-bindings/ndb-bindings/trunk

  449 Monty Taylor	2008-08-18
      Add ref count array for Ndb object creation.
      Change how we tag object creation and deletion for Ndb and NdbClusterConnection
      Rename close() to realClose()... next step, get people to start using delete() 
      instead in Java.
      Ndb.close()/Ndb.delete() should now get rid of the c++ object immediately and 
      remove the Java jni pointer reference. However, not calling it will just cause
      the object to get reaped when NdbClusterConnection gets GC'd. We _might_ still
      have a race condition here, in which case we'll want to remove the %newobject from createNdb() and make Ndb.close() bypass the swigMemOwn bit. But lets see.
modified:
  interface/ndbapi/Ndb.i
  interface/ndbapi/NdbClusterConnection.i
  java/swig/Ndb.i
  java/swig/NdbClusterConnection.i

=== modified file 'interface/ndbapi/Ndb.i'
--- a/interface/ndbapi/Ndb.i	2008-08-04 21:10:14 +0000
+++ b/interface/ndbapi/Ndb.i	2008-08-19 06:56:32 +0000
@@ -349,7 +349,7 @@ public:
 
   %ndbnoexception;
 
-  void close() {
+  void realClose() {
     if (self)
       delete self;
   }

=== modified file 'interface/ndbapi/NdbClusterConnection.i'
--- a/interface/ndbapi/NdbClusterConnection.i	2008-06-19 18:53:28 +0000
+++ b/interface/ndbapi/NdbClusterConnection.i	2008-08-19 06:56:32 +0000
@@ -19,6 +19,10 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+%newobject Ndb_cluster_connection::create;
+%newobject Ndb_cluster_connection::realCreateNdb;
+%delobject Ndb_cluster_connection::close;
+
 class Ndb_cluster_connection {
 
 
@@ -104,9 +108,6 @@ public:
 
 };
 
-%newobject Ndb_cluster_connection::createNdb;
-%delobject Ndb_cluster_connection::close;
-
 %extend Ndb_cluster_connection {
 
   %ndbexception("NdbApiPermanentException,"
@@ -126,28 +127,9 @@ public:
 
   %ndbnoexception;
 
-  void close() {
-    delete self;
-  }
-
-  void deleteAllNdbObjects() {
-
-    const Ndb * tmpNdb = NULL;
-
-    self->lock_ndb_objects();
-
-    tmpNdb = self->get_next_ndb_object(NULL);
-    while (tmpNdb != NULL) {
-      const Ndb * delNdb = tmpNdb;
-      tmpNdb = self->get_next_ndb_object(tmpNdb);
-      delete delNdb;
-    }
-
-    tmpNdb = NULL;
-
-    // Leave Ndb objects locked until we delete the mutex
-    delete self;
-
+  void realClose() {
+    if (self != NULL)
+      delete self; 
   }
 
 public:
@@ -165,7 +147,7 @@ public:
     }
   }
 
-  Ndb* createNdb(const char* aCatalogName, Int32 maxThreads = 4) {
+  Ndb* realCreateNdb(const char* aCatalogName, Int32 maxThreads = 4) {
     Ndb * theNdb = new Ndb(self,aCatalogName);
     if (theNdb!=NULL) {
       int ret = theNdb->init(maxThreads);

=== modified file 'java/swig/Ndb.i'
--- a/java/swig/Ndb.i	2008-07-10 22:55:07 +0000
+++ b/java/swig/Ndb.i	2008-08-19 06:56:32 +0000
@@ -37,6 +37,11 @@
 %rename(realDropEventOperation) Ndb::dropEventOperation;
 
 %typemap(javacode) Ndb %{
+  public void close()
+  {
+    this.realClose();
+    this.swigCPtr = 0;
+  }
   public void dropEventOperation(NdbEventOperation eventOp)
     throws NdbApiException
   {

=== modified file 'java/swig/NdbClusterConnection.i'
--- a/java/swig/NdbClusterConnection.i	2008-06-10 16:11:08 +0000
+++ b/java/swig/NdbClusterConnection.i	2008-08-19 06:56:32 +0000
@@ -25,11 +25,38 @@
 
 %javamethodmodifiers Ndb_cluster_connection::deleteAllNdbObjects "protected";
 
-%typemap(javafinalize) Ndb_cluster_connection %{
-protected void finalize() {
-  deleteAllNdbObjects();
-  delete();
-}
+%typemap(javaimports) Ndb_cluster_connection %{
+import java.util.ArrayList;
+import java.util.List;
+%}
+
+%typemap(javacode) Ndb_cluster_connection %{
+
+  public void close()
+  {
+    this.delete();
+  }
+
+  private List<NdbImpl> theNdbs = null;
+
+  public Ndb createNdb(String aCatalogName, int maxThreads) throws NdbApiException {
+    if (theNdbs==null)
+      theNdbs = new ArrayList<NdbImpl>();
+    NdbImpl theNewNdb = realCreateNdb(aCatalogName, maxThreads);
+    if (theNewNdb != null )
+      theNdbs.add(theNewNdb);
+    theNdbs.add(theNewNdb);
+    return theNewNdb;
+  }
+  public Ndb createNdb(String aCatalogName) throws NdbApiException {
+    if (theNdbs==null)
+      theNdbs = new ArrayList<NdbImpl>();
+    NdbImpl theNewNdb = realCreateNdb(aCatalogName);
+    if (theNewNdb != null )
+      theNdbs.add(theNewNdb);
+    theNdbs.add(theNewNdb);
+    return theNewNdb;
+  }
 %}
 
 %include "ndbapi/NdbClusterConnection.i"

Thread
bzr commit into NDB/Bindings:trunk branch (monty:449) Monty Taylor19 Aug