List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 23 2007 5:13am
Subject:Rev 191: Added the throwing exceptions that contain an NdbError. Haven't put these everywhere - but the guts work. in http://bazaar.launchpad.net/~ndb...
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 191
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Mon 2007-10-22 22:12:33 -0700
message:
  Added the throwing exceptions that contain an NdbError. Haven't put these everywhere -
but the guts work.
modified:
  java/com/mysql/cluster/mgmj/MgmApiException.java
mgmapiexception.java-20070914094439-b3vmm9orpa86yan5-1
  java/com/mysql/cluster/ndbj/BlobUndefinedException.java
blobundefinedexcepti-20070428054022-qvbhak1i97y86t1c-1
  java/com/mysql/cluster/ndbj/MgmApiException.java
mgmapiexception.java-20070528224344-z863qm98ai16jr9x-1
  java/com/mysql/cluster/ndbj/NdbApiException.java
ndbapiexception.java-20070428054022-qvbhak1i97y86t1c-2
  java/com/mysql/cluster/ndbj/NdbApiPermanentException.java
ndbapipermanentexcep-20070428054022-qvbhak1i97y86t1c-3
  java/com/mysql/cluster/ndbj/NdbApiTemporaryException.java
ndbapitemporaryexcep-20070428054022-qvbhak1i97y86t1c-5
  java/com/mysql/cluster/ndbj/NdbApiTimeStampOutOfBoundsException.java
ndbapitimestampoutof-20070428054022-qvbhak1i97y86t1c-6
  java/com/mysql/cluster/ndbj/NdbApiUserErrorPermanentException.java
ndbapiusererrorperma-20070428054022-qvbhak1i97y86t1c-7
  java/com/mysql/cluster/ndbj/NdbClusterConnectionPermanentException.java
ndbclusterconnection-20070428054022-qvbhak1i97y86t1c-8
  java/com/mysql/cluster/ndbj/NdbClusterConnectionTemporaryException.java
ndbclusterconnection-20070428054022-qvbhak1i97y86t1c-9
  java/ndbj.i                    ndbj.i-20070913223244-5938mztpztyn9sry-1
  java/testsuite/ndbj/Latin1InsertReadTest.java
latin1insertreadtest-20070517181935-98huwjarzuh25b30-48
  swig/NdbOperation.i            ndboperation.i-20070228021421-qkr4cbpxymyqdrf3-3
  swig/NdbTransaction.i          ndbtransaction.i-20070227184716-ecjyhh3jgvmye4de-7
=== modified file 'java/com/mysql/cluster/mgmj/MgmApiException.java'
--- a/java/com/mysql/cluster/mgmj/MgmApiException.java	2007-09-17 02:16:25 +0000
+++ b/java/com/mysql/cluster/mgmj/MgmApiException.java	2007-10-23 05:12:33 +0000
@@ -5,7 +5,7 @@
 public class MgmApiException extends com.mysql.cluster.ndbj.NdbApiException {
 
 
-	public MgmApiException(NdbError error) {
+	public MgmApiException(long error) {
 		super(error);
 	}
 

=== modified file 'java/com/mysql/cluster/ndbj/BlobUndefinedException.java'
--- a/java/com/mysql/cluster/ndbj/BlobUndefinedException.java	2007-10-02 22:56:43 +0000
+++ b/java/com/mysql/cluster/ndbj/BlobUndefinedException.java	2007-10-23 05:12:33 +0000
@@ -9,7 +9,7 @@
 
 	protected static final long serialVersionUID = 1L;
 	
-	public BlobUndefinedException(NdbError error) {
+	public BlobUndefinedException(long error) {
 		super(error);
 	}
 

=== modified file 'java/com/mysql/cluster/ndbj/MgmApiException.java'
--- a/java/com/mysql/cluster/ndbj/MgmApiException.java	2007-10-01 19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/MgmApiException.java	2007-10-23 05:12:33 +0000
@@ -5,7 +5,7 @@
 
 	protected static final long serialVersionUID = 1L;
 	
-	public MgmApiException(NdbError error) {
+	public MgmApiException(long error) {
 		super(error);
 	}
 

=== modified file 'java/com/mysql/cluster/ndbj/NdbApiException.java'
--- a/java/com/mysql/cluster/ndbj/NdbApiException.java	2007-10-01 19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbApiException.java	2007-10-23 05:12:33 +0000
@@ -25,11 +25,12 @@
      * NdbError object.
      * @param error
      */
-    public NdbApiException(NdbError error)
+    public NdbApiException(long errPtr)
 	{
-    	super(error.getMessage());
-    	this.errRef=error;
-	    message=error.getMessage();
+    	super();
+    	errRef = new NdbError(errPtr,true);
+    	this.message=errRef.getMessage();
+;
 	}
 
 
@@ -45,15 +46,18 @@
 	    this.errRef=null;
 	}
 
+    public NdbError getErrorObj() { 
+    	return this.errRef;
+    }
     /**
      * @return String a stringified message describing the cause of the exception.
      */
     public String toString() {
-    	if (errRef == null) { 
+    	//if (errRef == null) { 
     		return message;
-    	}
-        return "ERROR: " + errRef.getCode() + " Message: " + message
-        + " Classification: " + errRef.getClassification();
+    	//}
+        //return "ERROR: " + errRef.getCode() + " Message: " + message
+        //+ " Classification: " + errRef.getClassification();
     }
 
     /**
@@ -69,7 +73,10 @@
 	 * @see com.mysql.cluster.ndbj.NdbError#getClassification()
 	 */
 	public Classification getClassification() {
-		return errRef.getClassification();
+		if (errRef != null) { 
+			return errRef.getClassification();
+		}
+		return null;
 	}
 
 

=== modified file 'java/com/mysql/cluster/ndbj/NdbApiPermanentException.java'
--- a/java/com/mysql/cluster/ndbj/NdbApiPermanentException.java	2007-10-01 19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbApiPermanentException.java	2007-10-23 05:12:33 +0000
@@ -14,7 +14,7 @@
 	/**
 	 * @param error
 	 */
-	public NdbApiPermanentException(NdbError error) {
+	public NdbApiPermanentException(long error) {
 		super(error);
 	}
 

=== modified file 'java/com/mysql/cluster/ndbj/NdbApiTemporaryException.java'
--- a/java/com/mysql/cluster/ndbj/NdbApiTemporaryException.java	2007-10-01 19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbApiTemporaryException.java	2007-10-23 05:12:33 +0000
@@ -35,7 +35,7 @@
 	/**
 	 * @param error
 	 */
-	public NdbApiTemporaryException(NdbError error) {
+	public NdbApiTemporaryException(long error) {
 		super(error);
 	}
 

=== modified file 'java/com/mysql/cluster/ndbj/NdbApiTimeStampOutOfBoundsException.java'
--- a/java/com/mysql/cluster/ndbj/NdbApiTimeStampOutOfBoundsException.java	2007-10-01
19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbApiTimeStampOutOfBoundsException.java	2007-10-23
05:12:33 +0000
@@ -17,7 +17,7 @@
 	/**
 	 * @param error
 	 */
-	public NdbApiTimeStampOutOfBoundsException(NdbError error) {
+	public NdbApiTimeStampOutOfBoundsException(long error) {
 		super(error);
 	}
 	/**

=== modified file 'java/com/mysql/cluster/ndbj/NdbApiUserErrorPermanentException.java'
--- a/java/com/mysql/cluster/ndbj/NdbApiUserErrorPermanentException.java	2007-10-01
19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbApiUserErrorPermanentException.java	2007-10-23
05:12:33 +0000
@@ -15,7 +15,7 @@
 	/**
 	 * @param error
 	 */
-	public NdbApiUserErrorPermanentException(NdbError error) {
+	public NdbApiUserErrorPermanentException(long error) {
 		super(error);
 	}
 

=== modified file
'java/com/mysql/cluster/ndbj/NdbClusterConnectionPermanentException.java'
--- a/java/com/mysql/cluster/ndbj/NdbClusterConnectionPermanentException.java	2007-10-01
19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbClusterConnectionPermanentException.java	2007-10-23
05:12:33 +0000
@@ -15,7 +15,7 @@
 	 * 
 	 * @param error
 	 */
-	public NdbClusterConnectionPermanentException(NdbError error) {
+	public NdbClusterConnectionPermanentException(long error) {
 		super(error);
 	}
 

=== modified file
'java/com/mysql/cluster/ndbj/NdbClusterConnectionTemporaryException.java'
--- a/java/com/mysql/cluster/ndbj/NdbClusterConnectionTemporaryException.java	2007-10-01
19:55:09 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbClusterConnectionTemporaryException.java	2007-10-23
05:12:33 +0000
@@ -32,7 +32,7 @@
 	 *
 	 * @param error
 	 */
-	public NdbClusterConnectionTemporaryException(NdbError error) {
+	public NdbClusterConnectionTemporaryException(long error) {
 		super(error);
 	}
 

=== modified file 'java/ndbj.i'
--- a/java/ndbj.i	2007-10-23 01:41:19 +0000
+++ b/java/ndbj.i	2007-10-23 05:12:33 +0000
@@ -98,6 +98,7 @@
 }
 
 #define NDB_exception(excp, msg) { ndb_throw_exception(jenv, #excp,msg);  } 
+#define NDB_exception_err(excp, msg, err) { ndb_throw_exception(jenv, #excp,msg, err);  }

 
 void ndb_throw_exception(JNIEnv *jenv, const char * excp, const char *msg) { 
   const char * prefix = "com/mysql/cluster/ndbj/";
@@ -110,7 +111,32 @@
   free(exception);
 
   jenv->ThrowNew(clazz,msg);
-}
+  jenv->DeleteLocalRef(clazz);
+}
+
+void ndb_throw_exception(JNIEnv *jenv, const char * excp, const char *msg, NdbError &
err) { 
+  const char * prefix = "com/mysql/cluster/ndbj/";
+  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);
+  free(exception);
+
+  jlong errPtr = 0; 
+  NdbError * result = new NdbError(err);
+  errPtr = (jlong)result;
+  
+  jmethodID method = jenv->GetMethodID(clazz,"<init>","(J)V");
+  jthrowable excpObj = (jthrowable)jenv->NewObject(clazz,method,errPtr);
+
+  jenv->Throw(excpObj);
+
+  jenv->DeleteLocalRef(clazz);
+  jenv->DeleteLocalRef(excpObj);
+}
+
  %}
 
 

=== modified file 'java/testsuite/ndbj/Latin1InsertReadTest.java'
--- a/java/testsuite/ndbj/Latin1InsertReadTest.java	2007-09-17 01:09:47 +0000
+++ b/java/testsuite/ndbj/Latin1InsertReadTest.java	2007-10-23 05:12:33 +0000
@@ -64,7 +64,7 @@
 					NdbOperation op = trans.getNdbOperation(tablename);
 					op.insertTuple();
 					if (i != 0)
-						op.equal(col1, Integer.toString(i));
+						op.equal("bob", Integer.toString(i));
 					else
 						op.equal(col1,col2Val);
 					op.setString(col2, col2Val);
@@ -81,16 +81,19 @@
 				System.out
 						.println("Temporary error. Retrying insert. Num Retries == "
 								+ numRetries + " error msg:" + e.getMessage());
+				System.out.println(e.getMessage());
 			} catch (NdbApiException e) {
 				System.out.println("Caught NdbApiException in Insert:\t"
 						+ e.getMessage());
+
+				System.out.println(e.getErrorObj().getMessage());
 				assertTrue(false);
 				done = true;
 			} finally {
 				if (trans != null)
 					trans.close();
 			}
-		}
+	}
 
 		try {
 			System.out.println("Reading the inserted rows");

=== modified file 'swig/NdbOperation.i'
--- a/swig/NdbOperation.i	2007-10-23 01:41:19 +0000
+++ b/swig/NdbOperation.i	2007-10-23 05:12:33 +0000
@@ -209,7 +209,7 @@
     $action
       if (result == NULL) { 
         NdbError err = arg1->getNdbError();
-	NDB_exception(NdbApiException,err.message);
+	NDB_exception_err(NdbApiException,err.message,err);
       }
   }
 
@@ -220,7 +220,7 @@
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
-        NDB_exception(NdbApiException,err.message);
+        NDB_exception_err(NdbApiException,err.message,err);
       }
   }
 
@@ -379,7 +379,7 @@
     $action
       if (result==NULL) { 
         NdbError err = arg1->getNdbError();
-        NDB_exception(NdbApiException,err.message);
+        NDB_exception_err(NdbApiException,err.message,err);
       }
   }
 
@@ -406,7 +406,7 @@
     $action
       if (result==-1) { 
         NdbError err = arg1->getNdbError();
-        NDB_exception(NdbApiException,err.message);
+        NDB_exception_err(NdbApiException,err.message,err);
       }
   }
 

=== modified file 'swig/NdbTransaction.i'
--- a/swig/NdbTransaction.i	2007-10-05 19:46:08 +0000
+++ b/swig/NdbTransaction.i	2007-10-23 05:12:33 +0000
@@ -65,13 +65,13 @@
         NdbError err = arg1->getNdbError();
         switch (err.status) { 
           case NdbError::TemporaryError:
-            NDB_exception(NdbApiTemporaryException,err.message);
+            NDB_exception_err(NdbApiTemporaryException,err.message,err);
             break;
           case NdbError::PermanentError:
-            NDB_exception(NdbApiPermanentException,err.message);
+            NDB_exception_err(NdbApiPermanentException,err.message,err);
             break; 
           default: 
-            NDB_exception(NdbApiException,err.message);
+            NDB_exception_err(NdbApiException,err.message,err);
             break;
         } 
       }

Thread
Rev 191: Added the throwing exceptions that contain an NdbError. Haven't put these everywhere - but the guts work. in http://bazaar.launchpad.net/~ndb...Monty Taylor23 Oct