------------------------------------------------------------
revno: 94
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: exceptions
timestamp: Wed 2007-05-02 14:31:41 -0700
message:
Added a global placeholder for RuntimeError in NdbException enum
Added custom exceptions to Ruby (wow, ruby is good at that)
Changed ruby build to use -autorename so that naming conventions match Ruby
standards. This means methods like createNdbClusterConnection are now
create_ndb_cluster_connection in Ruby.
Updated ruby test file to catch a thrown exception and use the new naming.
modified:
ruby/Makefile.am makefile.am-20070228212451-7arjxk90dkwcn5xr-2
ruby/ndbapi.i ndb.i-20070228212451-7arjxk90dkwcn5xr-3
ruby/test.rb test.rb-20070228212451-7arjxk90dkwcn5xr-4
swig/globals.i globals.i-20070228021421-qkr4cbpxymyqdrf3-7
=== modified file 'ruby/Makefile.am'
--- a/ruby/Makefile.am 2007-04-15 09:56:16 +0000
+++ b/ruby/Makefile.am 2007-05-02 21:31:41 +0000
@@ -4,12 +4,12 @@
rubyarch_DATA=mysql/cluster/ndbapi.so mysql/cluster/mgmapi.so
CLEANFILES=*.db test-out.rdf core* \
- $(rubyarch_DATA)
+ $(rubyarch_DATA) ndbapi.cpp
SWIG_OPTS=-I$(srcdir) -I$(SWIG_DIR) @MYSQL_INCLUDES@
%.cpp: %.i $(SWIG_SOURCES)
- $(SWIG) -c++ -ruby $(SWIG_OPTS) -o $@ $<
+ $(SWIG) -c++ -ruby -autorename $(SWIG_OPTS) -o $@ $<
$(srcdir)/%.o: $(srcdir)/%.cpp
$(CXX) $(SWIG_OPTS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)
$(AM_CFLAGS) $(STANDARD_CFLAGS) -fPIC -DPIC -I$(rubyarchdir) $< -c -o $@
=== modified file 'ruby/ndbapi.i'
--- a/ruby/ndbapi.i 2007-04-27 05:23:30 +0000
+++ b/ruby/ndbapi.i 2007-05-02 21:31:41 +0000
@@ -19,6 +19,74 @@
%module ndbapi
%include "globals.i"
+
+%{
+
+#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;
+}
+
+
+ %}
+
%include "NdbFactory.i"
%include "NdbClusterConnection.i"
%include "Ndb.i"
=== modified file 'ruby/test.rb'
--- a/ruby/test.rb 2007-04-15 09:56:16 +0000
+++ b/ruby/test.rb 2007-05-02 21:31:41 +0000
@@ -9,11 +9,18 @@
puts "Connecting to cluster"
-connection=Ndbapi::Ndb_cluster_connection.new
-
-connection.connect(5,3,1)
-
-connection.wait_until_ready(30, 30)
+#connection=Ndbapi::NdbFactory.createNdbClusterConnection()
+connection=Ndbapi::NdbFactory.create_ndb_cluster_connection("127.0.0.1")
+
+begin
+ connection.connect(1,1,1)
+ connection.wait_until_ready(30, 30)
+
+rescue NdbApiException => e
+ puts "ERROR:" + e
+ exit
+end
+
myNdb = Ndbapi::Ndb.new(connection,"test")
@@ -21,17 +28,17 @@
puts "running tests"
-myTransaction = myNdb.startTransaction
+myTransaction = myNdb.start_transaction
-myOperation = myTransaction.getNdbOperation("mytablename")
-myOperation.insertTuple
-auto_id = myNdb.getAutoIncrementValue("mytablename",BATCH_SIZE)
+myOperation = myTransaction.get_ndb_operation("mytablename")
+myOperation.insert_tuple
+auto_id = myNdb.get_auto_increment_value("mytablename",BATCH_SIZE)
puts "Inserting" , auto_id
myOperation.equal("ATTR1",auto_id)
-myOperation.setValue("ATTR2",1234)
+myOperation.set_value("ATTR2",1234)
myTransaction.execute(Ndbapi::Commit)
-myNdb.closeTransaction(myTransaction)
+myTransaction.close
=== modified file 'swig/globals.i'
--- a/swig/globals.i 2007-05-02 02:56:57 +0000
+++ b/swig/globals.i 2007-05-02 21:31:41 +0000
@@ -7,6 +7,7 @@
#include <NdbApi.hpp>
enum NdbException {
+ BaseRuntimeError,
NdbApiException,
BlobUndefinedException,
NdbApiPermanentException,
| Thread |
|---|
| • Rev 94: Added a global placeholder for RuntimeError in NdbException enum in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptions | Monty Taylor | 2 May |