List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:September 19 2007 9:55am
Subject:Rev 159: Added NDB_exception info to mgmapi.i for ruby. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 159
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Wed 2007-09-19 11:54:56 +0200
message:
  Added NDB_exception info to mgmapi.i for ruby.
modified:
  ruby/mgmapi.i                  mgmapi.i-20070415091411-plc5gtpiwg93c2lx-1
  ruby/test.rb                   test.rb-20070228212451-7arjxk90dkwcn5xr-4
  ruby/testreaddt.rb             testreaddt.rb-20070521223831-70qncxglgiscqe0a-1
=== modified file 'ruby/mgmapi.i'
--- a/ruby/mgmapi.i	2007-07-25 17:20:31 +0000
+++ b/ruby/mgmapi.i	2007-09-19 09:54:56 +0000
@@ -38,6 +38,72 @@
   $1[i]=0;
 }
 
+%{ 
+
+#define NDB_exception(code,msg) do { ndb_raise_exception(code, msg); SWIG_fail; }
while(0);
+
+#define getExceptionMethod(excptype,eparent) \
+  SWIGINTERN VALUE \
+get ## excptype () { \
+  static int init ## excptype = 0 ; \
+  static VALUE rb_e ## excptype ; \
+  VALUE rb_eparent = ndb_get_exception (eparent); \
+  if (! init ## excptype ) { \
+    init ## excptype = 1; \
+    rb_e ## excptype = rb_define_class(#excptype , rb_eparent); \
+  } \
+  return rb_e ## excptype ; \
+}
+VALUE ndb_get_exception(NdbException excpcode);
+
+getExceptionMethod(NdbApiException,BaseRuntimeError);
+getExceptionMethod(NdbApiRuntimeException,NdbApiException);
+getExceptionMethod(NdbApiPermanentException,NdbApiException);
+getExceptionMethod(NdbApiTemporaryException,NdbApiException);
+getExceptionMethod(NdbApiUserErrorPermanentException,NdbApiPermanentException);
+getExceptionMethod(NdbClusterConnectionPermanentException,NdbApiPermanentException);
+getExceptionMethod(NdbClusterConnectionTemporaryException,NdbApiTemporaryException);
+getExceptionMethod(NdbApiTimeStampOutOfBoundsException,NdbApiException);
+getExceptionMethod(BlobUndefinedException,NdbApiException);
+getExceptionMethod(NoSuchColumnException,NdbApiException);
+getExceptionMethod(NoSuchIndexException,NdbApiException);
+getExceptionMethod(NoSuchTableException,NdbApiException);
+
+void ndb_raise_exception(NdbException excpcode, const char * msg) {
+  rb_raise(ndb_get_exception(excpcode),msg);
+}
+
+#define CASE_exception(excp) case excp : exception = get ## excp (); break;
+
+VALUE ndb_get_exception(NdbException excpcode) { 
+
+ VALUE exception;
+
+ switch (excpcode) {
+    case BaseRuntimeError:
+      exception = rb_eRuntimeError;
+      break;
+    CASE_exception(NdbApiException)
+    CASE_exception(BlobUndefinedException)
+    CASE_exception(NdbApiPermanentException)
+    CASE_exception(NdbApiRuntimeException)
+    CASE_exception(NdbApiTemporaryException)
+    CASE_exception(NdbApiTimeStampOutOfBoundsException)
+    CASE_exception(NdbApiUserErrorPermanentException)
+    CASE_exception(NdbClusterConnectionPermanentException)
+    CASE_exception(NdbClusterConnectionTemporaryException)
+    CASE_exception(NoSuchColumnException)
+    CASE_exception(NoSuchIndexException)
+    CASE_exception(NoSuchTableException)
+    default:
+      exception = rb_eRuntimeError;
+      break;
+  }
+  return exception;
+}
+
+%}
+
 //%apply ndb_logevent *OUTPUT { ndb_logevent *dst };
 
 %include "NdbMgm.i"

=== modified file 'ruby/test.rb'
--- a/ruby/test.rb	2007-06-25 16:54:09 +0000
+++ b/ruby/test.rb	2007-09-19 09:54:56 +0000
@@ -15,7 +15,7 @@
   connection.connect(1,1,1)
   connection.wait_until_ready(30, 30)
   
-rescue Ndbapi::NdbApiException => e
+rescue NdbApiException => e
   puts "ERROR:" + e
   exit 
 end
@@ -35,8 +35,15 @@
 
 puts "Inserting" , auto_id
 
-myOperation.equalInt32("ATTR1",auto_id)
-myOperation.set_string("ATTR2","monty")
+begin
+  
+  myOperation.equalInt32("ATTR1",auto_id)
+  myOperation.set_int("ATTR2",10)
+
+rescue NdbApiException => e
+  puts "ERROR:" + e
+  exit
+end
 
 myTransaction.execute(Ndbapi::Commit)
 

=== modified file 'ruby/testreaddt.rb'
--- a/ruby/testreaddt.rb	2007-07-25 17:20:31 +0000
+++ b/ruby/testreaddt.rb	2007-09-19 09:54:56 +0000
@@ -32,7 +32,7 @@
 
 puts "Reading" , insertid
 
-myOperation.equal("id",insertid)
+myOperation.equalInt32("id",insertid)
 ra=myOperation.get_value("ts")
 
 myTransaction.execute(Ndbapi::Commit)

Thread
Rev 159: Added NDB_exception info to mgmapi.i for ruby. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor19 Sep