List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:May 4 2007 8:50pm
Subject:Rev 97: Fixed Java custom exceptions (thanks jbalint) in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptions
View as plain text  
------------------------------------------------------------
revno: 97
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: exceptions
timestamp: Fri 2007-05-04 13:45:38 -0700
message:
  Fixed Java custom exceptions (thanks jbalint)
  Fixed configure to only require high versions of swig when building php.
  Turned off building php by default.
modified:
  acinclude.m4                   acinclude.m4-20070228020914-u2pk759xg7thauwf-8
  configure.in                   configure.in-20070228020914-u2pk759xg7thauwf-13
  csharp/MySql.Data.dll          mysql.data.dll-20070502041820-zgr1aeh272ptdpwv-1
  csharp/test.cs                
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-csharp%2ftest.cs
  java/ndbapi.i                  ndbapi.i-20070130002924-gcvhapmvh0lu1pkd-3
  java/test.java                 test.java-20070130002924-gcvhapmvh0lu1pkd-4
  swig/NdbClusterConnection.i    ndb_cluster_connecti-20070228021421-qkr4cbpxymyqdrf3-6
  swig/NdbFactory.i              ndbfactory.i-20070427052328-bwn5ewzrbigsg9v5-1
  swig/NdbIndexOperation.i       ndbindexoperation.i-20070426125056-cdc2fzutv5osp12a-1
  swig/NdbOperation.i            ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3
  swig/NdbScanOperation.i        ndbscanoperation.i-20070228021421-qkr4cbpxymyqdrf3-5
  swig/NdbTransaction.i          ndbtransaction.i-20070227184716-ecjyhh3jgvmye4de-7
=== modified file 'acinclude.m4'
--- a/acinclude.m4	2007-04-26 15:30:02 +0000
+++ b/acinclude.m4	2007-05-04 20:45:38 +0000
@@ -5,7 +5,7 @@
 AC_DEFUN([WITH_PHP], [
 
   AC_ARG_WITH(php,  [  --with-php=PATH	path to php_config binary],
-    with_php=$withval, withval="yes")
+    with_php=$withval, withval="no")
 
   if test "X$withval" != "Xno" ; then 
     if test "X$withval" != "Xyes" ; then 
@@ -13,6 +13,8 @@
     else
       AC_CHECK_PROGS(PHP_CONFIG, [ php-config  php-config5 ])
     fi
+  else 
+    with_php="no"
   fi
 
 if test "X$PHP_CONFIG" != "X"; then 

=== modified file 'configure.in'
--- a/configure.in	2007-05-02 05:05:05 +0000
+++ b/configure.in	2007-05-04 20:45:38 +0000
@@ -9,18 +9,29 @@
   CFLAGS="-O0 -g -Wall"
 fi 
 
+WITH_PHP()
+
 #AC_CHECK_PROGS(SWIG,swig)
-AC_PROG_SWIG(1.3.31)
+if test "$with_php" = "no" ; then 
+  AC_PROG_SWIG(1.3.28)
+  if test "x$SWIG" == "x"  ; then 
+    AC_MSG_ERROR([Couldn't find swig.])
+  fi
+else
+  AC_PROG_SWIG(1.3.32)
+  if test "x$SWIG" == "x"  ; then 
+    AC_MSG_ERROR([php support requires at least swig version 1.3.32])
+    AC_MSG_ERROR([Couldn't find swig.])
+  fi
+fi 
+
+
 AC_CHECK_PROGS(MONO,mono)
 AC_CHECK_PROGS(MCS,gmcs)
 SWIG_ENABLE_CXX
 AC_CANONICAL_HOST
 ACX_PTHREAD()
 
-if test "x$SWIG" == "x"  ; then 
-AC_MSG_ERROR([Couldn't find swig.])
-fi
-
 WITH_MYSQL()
 
 AC_PROG_LIBTOOL()
@@ -42,7 +53,6 @@
 
 WITH_RUBY()
 
-WITH_PHP()
   
 SWIG_SOURCES="\${top_srcdir}/swig/globals.i \
               \${top_srcdir}/swig/Mgm.i \

=== modified file 'csharp/MySql.Data.dll'
Binary files a/csharp/MySql.Data.dll	2007-05-02 05:05:05 +0000 and
b/csharp/MySql.Data.dll	2007-05-04 20:45:38 +0000 differ
=== modified file 'csharp/test.cs'
--- a/csharp/test.cs	2007-05-02 05:05:05 +0000
+++ b/csharp/test.cs	2007-05-04 20:45:38 +0000
@@ -38,22 +38,25 @@
     int BATCH_SIZE=1000;
     
     MySqlConnection conn = new MySqlConnection();
-    conn.ConnectionString = "Server=127.0.0.1;User Id=root;Password=;Connection
Timeout=15;";
+    conn.ConnectionString = "Server=127.0.0.1;User Id=root;Password=;Connection
Timeout=15;Database=test";
     conn.Open();
     
     Console.WriteLine("Creating schema");
     
     MySqlCommand cur = conn.CreateCommand();
     
-    
-    cur.CommandText="CREATE DATABASE if not exists test";
-    cur.ExecuteNonQuery();
-    
-    conn.ChangeDatabase("test");
+    Console.WriteLine("createCommand");
+    
+    //cur.CommandText="CREATE DATABASE if not exists test";
+    //cur.ExecuteNonQuery();
+    
+    //conn.ChangeDatabase("test");
     
     try { 
       cur.CommandText = "DROP table if exists mytablename";
+      Console.WriteLine("drop table");
       cur.ExecuteNonQuery();
+      Console.WriteLine("execute");
     }
     catch (MySqlException e) { 
       Console.WriteLine(e.Message);  

=== modified file 'java/ndbapi.i'
--- a/java/ndbapi.i	2007-05-03 03:28:55 +0000
+++ b/java/ndbapi.i	2007-05-04 20:45:38 +0000
@@ -41,7 +41,6 @@
   asynch_callback_t * callback_data = (asynch_callback_t *)aObject;
 
   JNIEnv *env = callback_data->env; 
-  jobject obj = callback_data->obj;
 
   jclass callablecls = env->GetObjectClass((callback_data->obj));
 
@@ -59,12 +58,12 @@
 
 void ndb_throw_exception(JNIEnv *jenv, const char * excp, const char *msg) { 
   const char * prefix = "com/mysql/cluster/ndbapi/";
-  char * exception = (char *)malloc(strlen(excp)+strlen(prefix));
+  char * exception = (char *)malloc(strlen(excp)+strlen(prefix)+1);
   strcpy(exception,prefix);
   strcat(exception,excp);
 
-  jclass clazz = jenv->FindClass("java/lang/RuntimeException");
-  //jclass clazz = jenv->FindClass(exception);
+  //jclass clazz = jenv->FindClass("java/lang/RuntimeException");
+  jclass clazz = jenv->FindClass(exception);
   jenv->ThrowNew(clazz,msg);
 }
  %}
@@ -101,7 +100,7 @@
 %include "NdbFactory.i"
 
 //%javaexception("com.mysql.cluster.ndbapi.NdbApiException")
Ndb_cluster_connection::connect;
-%javaexception("java.lang.RuntimeException") Ndb_cluster_connection::connect;
+//%javaexception("java.lang.RuntimeException") Ndb_cluster_connection::connect;
 //%javaexception("com.mysql.cluster.ndbapi.NdbApiException")
Ndb_cluster_connection::wait_until_ready;
 
 %include "NdbClusterConnection.i"

=== modified file 'java/test.java'
--- a/java/test.java	2007-05-03 03:28:55 +0000
+++ b/java/test.java	2007-05-04 20:45:38 +0000
@@ -76,17 +76,23 @@
      **************************************************************/
 
     System.out.println("connecting to cluster");
+  try { 
 
     NdbClusterConnection connection = NdbFactory.createNdbClusterConnection();
 
     try {
+
       connection.connect(1,1,1);
       /*if (connection.connect(1,1,1)==-1) { 
         throw new NdbApiException("Couldn't connect");
       }*/
-    } catch (Exception e) { 
-
-      System.out.println("Caught generic exception");
+    } catch (NdbClusterConnectionPermanentException e) { 
+      
+      System.out.println("Caught Permanenet exception");
+      e.printStackTrace();
+      System.exit(-1);
+   } catch (NdbApiException e) { 
+      System.out.println("Caught generic NdbApiException");
       e.printStackTrace();
       System.exit(-1);
    }
@@ -246,7 +252,11 @@
     System.out.println("NDBAPI Execution time for " + num_iter + ": ");
     System.out.println("   "+(endTime.getTime() - beginTime.getTime())+"ms");
     s.close();
-    
+  } catch (NdbApiException e) { 
+    System.out.println("Caught a fatal error"); 
+    e.printStackTrace();
+    System.exit(-1);    
+  }
 
   }
 }

=== modified file 'swig/NdbClusterConnection.i'
--- a/swig/NdbClusterConnection.i	2007-05-02 02:56:57 +0000
+++ b/swig/NdbClusterConnection.i	2007-05-04 20:45:38 +0000
@@ -29,7 +29,11 @@
 
   void set_name(const char* name); 
 
+#if defined(SWIGJAVA)
+  %javaexception("NdbApiException,NdbClusterConnectionPermanentException") {
+#else
   %exception { 
+#endif
     $action
       if (result) { 
 	const char * msg = "Connect to management server failed"; 
@@ -57,7 +61,11 @@
   }
   int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
 
-  %exception { 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
+  %exception {
+#endif
     $action
       if (result) { 
         const char * msg = "Cluster was not ready";
@@ -72,7 +80,11 @@
 
 %extend Ndb_cluster_connection {
 public:
-  %exception getNdb { 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") getNdb {
+#else
+  %exception getNdb {
+#endif
     $action
       if (result==NULL) { 
 	NDB_exception(NdbApiException,"Couldn't allocate an Ndb object");

=== modified file 'swig/NdbFactory.i'
--- a/swig/NdbFactory.i	2007-05-02 02:56:57 +0000
+++ b/swig/NdbFactory.i	2007-05-04 20:45:38 +0000
@@ -49,7 +49,11 @@
   NdbFactory();
   ~NdbFactory();
 public:
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception {
+#endif
     $action
       if (result==NULL) {
         NDB_exception(NdbApiException,"Couldn't allocate NdbClusterConnection");

=== modified file 'swig/NdbIndexOperation.i'
--- a/swig/NdbIndexOperation.i	2007-05-01 22:50:04 +0000
+++ b/swig/NdbIndexOperation.i	2007-05-04 20:45:38 +0000
@@ -17,7 +17,11 @@
 {
 public:
 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
@@ -35,7 +39,11 @@
   int interpretedUpdateTuple();
   int interpretedDeleteTuple();
   
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==0) { 
         NdbError err = arg1->getNdbError();

=== modified file 'swig/NdbOperation.i'
--- a/swig/NdbOperation.i	2007-05-01 22:50:04 +0000
+++ b/swig/NdbOperation.i	2007-05-04 20:45:38 +0000
@@ -17,6 +17,7 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+/*
 %{
     #include <my_time.h>
 
@@ -108,7 +109,7 @@
         }
     }
 %}
-
+*/
 class NdbOperation {
 
   friend class Ndb;
@@ -146,7 +147,11 @@
   void setPartitionHash(const Uint64 *, Uint32 len);
   Uint32 getPartitionId() const;
 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { 
+#endif
     $action
       if (result == NULL) { 
         NdbError err = arg1->getNdbError();
@@ -160,7 +165,11 @@
   virtual NdbBlob* getBlobHandle(const char* anAttrName);
   virtual NdbBlob* getBlobHandle(Uint32 anAttrId);
 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
@@ -298,7 +307,12 @@
   int  equal(Uint32 anAttrId, Int64 aValue);	
   int  equal(Uint32 anAttrId, Uint64 aValue);
 
+#if defined(SWIGJAVA)
+  %javaexception;
+#else
   %exception; // clear exception handler
+#endif
+
 
 protected:
   NdbOperation(Ndb* aNdb, Type aType = PrimaryKeyAccess);	
@@ -319,7 +333,11 @@
     return self->getValue(col,NULL);
   }
 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
@@ -333,6 +351,7 @@
   int equalNull(Uint32 anAttrId) {
       return self->equal(anAttrId, (char*)0);
   }
+/*
   %cstring_input_binary(const char *aString, size_t len);
   int equalString(const char* anAttrName, const char* aString, size_t len) {
       bufMethodPtr m=&NdbOperation::equal;
@@ -345,6 +364,12 @@
       uint64MethodPtr um=&NdbOperation::setValue;
       return callNdbOperationBufMethod(*self, m, um, anAttrName, aString, len);
   }
+*/
+#if defined(SWIGJAVA)
+  %javaexception;
+#else
   %exception; // clear exception handler
+#endif
+
 
 };

=== modified file 'swig/NdbScanOperation.i'
--- a/swig/NdbScanOperation.i	2007-05-04 18:32:14 +0000
+++ b/swig/NdbScanOperation.i	2007-05-04 20:45:38 +0000
@@ -27,9 +27,11 @@
 
 public:
 
-  const NdbError & getNdbError() const;
-
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
@@ -44,7 +46,11 @@
   int deleteCurrentTuple(NdbTransaction* takeOverTransaction);
   int restart(bool forceSend = false);
 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
   %exception { // this applies to everything until we clear it
+#endif
     $action
       if (result==0) { 
         NdbError err = arg1->getNdbError();
@@ -59,7 +65,14 @@
   NdbOperation* updateCurrentTuple();
   NdbOperation*	updateCurrentTuple(NdbTransaction* updateTrans);
 
-  %exception;
+#if defined(SWIGJAVA)
+  %nojavaexception;
+#else
+  %noexception;
+#endif
+
+
+  const NdbError & getNdbError() const;
 
   void close(bool forceSend = false, bool releaseOp = false);
 };
@@ -72,4 +85,3 @@
 
 };
 
-%exception; 

=== modified file 'swig/NdbTransaction.i'
--- a/swig/NdbTransaction.i	2007-05-02 02:56:57 +0000
+++ b/swig/NdbTransaction.i	2007-05-04 20:45:38 +0000
@@ -28,7 +28,11 @@
 
   const NdbError & getNdbError() const;
 
-  %exception { 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
+  %exception {
+#endif
     $action
       if (result==NULL) { 
         NdbError err = arg1->getNdbError();
@@ -45,7 +49,11 @@
   NdbScanOperation* getNdbScanOperation(const char* aTableName);
   NdbOperation*	getNdbErrorOperation();
 
-  %exception { 
+#if defined(SWIGJAVA)
+  %javaexception("com.mysql.cluster.ndbapi.NdbApiException") {
+#else
+  %exception {
+#endif
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
@@ -59,7 +67,12 @@
   int getNdbErrorLine();
   
 
-  %exception;
+#if defined(SWIGJAVA)
+  %nojavaexception;
+#else
+  %noexception;
+#endif
+
   void executeAsynchPrepare(ExecType          execType,
                             NdbAsynchCallback callback,
                             void*             anyObject,

Thread
Rev 97: Fixed Java custom exceptions (thanks jbalint) in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptionsMonty Taylor4 May