List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:August 1 2007 4:44pm
Subject:Rev 135: Added Johan's getBytes() method with a few changes. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 135
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Wed 2007-08-01 09:44:14 -0700
message:
  Added Johan's getBytes() method with a few changes. 
modified:
  java/ndbapi.i                  ndbapi.i-20070130002924-gcvhapmvh0lu1pkd-3
  swig/NdbRecAttr.i              ndbrecattr.i-20070228021421-qkr4cbpxymyqdrf3-4
  swig/ndbglobals.i              globals.i-20070228021421-qkr4cbpxymyqdrf3-7
=== modified file 'java/ndbapi.i'
--- a/java/ndbapi.i	2007-07-12 20:28:26 +0000
+++ b/java/ndbapi.i	2007-08-01 16:44:14 +0000
@@ -88,7 +88,7 @@
 %typemap(jstype) asynch_callback_t * "INdbCallable"
 %typemap(javain) asynch_callback_t * "(Object)$javainput"
 
-%typemap(javaimports) NdbFactory, Ndb, Ndb_cluster_connection, NdbTransaction,
NdbOperation, NdbIndexOperation, NdbScanOperation, NdbIndexScanOperation, NdbBlob,
NdbDictDictionary, NdbDictColumn, NdbDictIndex, NdbDictTable, NdbDictObject,
NdbScanFilter, NdbEvent, NdbEventOperation "import com.mysql.cluster.errors.*;"
+%typemap(javaimports) NdbFactory, Ndb, Ndb_cluster_connection, NdbTransaction,
NdbOperation, NdbIndexOperation, NdbScanOperation, NdbIndexScanOperation, NdbBlob,
NdbDictDictionary, NdbDictColumn, NdbDictIndex, NdbDictTable, NdbDictObject,
NdbScanFilter, NdbEvent, NdbEventOperation, NdbRecAttr "import
com.mysql.cluster.errors.*;"
 %pragma(java) moduleimports="import com.mysql.cluster.errors.*;"
 %pragma(java) jniclassimports="import com.mysql.cluster.errors.*;"
 
@@ -104,6 +104,11 @@
 %typemap(javain) NdbTimestamp "$javainput.getTime()/1000"
 %typemap(javaout) NdbTimestamp { return new java.sql.Timestamp($jnicall); }
 
+%typemap(jni) BYTES "jbyteArray"
+%typemap(jtype) BYTES "byte[]"
+%typemap(jstype) BYTES "byte[]"
+%typemap(javaout) BYTES { return $jnicall; } 
+
 %typemap(in) (MYSQL_TIME *) { 
    MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME));
    static jclass calendar_class = jenv->FindClass("java/util/Calendar");
@@ -144,6 +149,13 @@
 
  }
 
+%typemap(out) (BYTES)  { 
+ 
+ $result = jenv->NewByteArray($1.theLength); 
+ jenv->SetByteArrayRegion($result,0,$1.theLength,(const jbyte*) $1.theString);
+ 
+} 
+
 %typemap(freearg) (MYSQL_TIME *) {
   free((MYSQL_TIME *) $1);
  }

=== modified file 'swig/NdbRecAttr.i'
--- a/swig/NdbRecAttr.i	2007-07-25 17:20:31 +0000
+++ b/swig/NdbRecAttr.i	2007-08-01 16:44:14 +0000
@@ -78,13 +78,63 @@
     return y;
   }
 
+  %ndbexception("NdbApiException") {
+    $action
+      if ( (result.theString == NULL) || (result.theLength == -1) )  { 
+	NDB_exception(NdbApiException,"Error fetching data");
+      }
+  }
+
+  BYTES getBytes() { 
+    NdbDictionary::Column::Type colType = self->getType();
+    BYTES output; 
+    output.theString=NULL;
+    output.theLength=-1;
+
+    char* rec = self->aRef();
+
+    if(colType == NdbDictionary::Column::Longvarbinary)
+      {
+	output.theLength=(int)uint2korr(rec);
+        output.theString = &rec[2];
+/*
+	jbyteArray bArray = env->NewByteArray(len); 
+	env->SetByteArrayRegion(bArray,0,len,(const jbyte*) &self->aRef()[2]);
+	return bArray; */
+      } 
+    else if(colType == NdbDictionary::Column::Varbinary)
+    {
+
+      output.theLength = (int) (rec[0]);
+      output.theString = &rec[1];
+      /*jbyteArray bArray = env->NewByteArray(len); 
+      env->SetByteArrayRegion(bArray,0,len,(const jbyte*) &self->aRef()[1]);
+      return bArray; */
+    }
+    else if( colType == NdbDictionary::Column::Binary)
+    {
+      output.theLength = strlen(rec)-1;
+      output.theString = &rec[0]; 
+     /* jbyteArray bArray = env->NewByteArray(i); 
+      env->SetByteArrayRegion(bArray,0,i,(const jbyte*) &self->aRef()[0]);
+      return bArray; */
+    }
+    return output; 
+  }
+
+  %ndbexception("NdbApiException") {
+    $action
+      if (result == NULL) { 
+	NDB_exception(NdbApiException,"Error fetching data");
+      }
+  }
+
   const char* getString() { 
     NdbDictionary::Column::Type colType = self->getType();
 
     char* ref = self->aRef();
 
-    if(colType == NdbDictionary::Column::Longvarchar ||
-       colType == NdbDictionary::Column::Longvarbinary)
+    if(colType == NdbDictionary::Column::Longvarchar) 
       {
         int len=(int)uint2korr(ref);
         char * buff = (char *)malloc((len+1)*sizeof(char *));
@@ -94,8 +144,7 @@
         buff[len+1]='\0';
         return buff;
       } 
-    else if(colType == NdbDictionary::Column::Varchar ||
-	    colType == NdbDictionary::Column::Varbinary)
+    else if(colType == NdbDictionary::Column::Varchar)
     {
       short len = (short) (unsigned char) (ref[0]);
       char * buff = (char *)malloc((len+1)*sizeof(char *));
@@ -104,8 +153,7 @@
       buff[len+1]='\0';
       return buff;
     }
-    else if(colType == NdbDictionary::Column::Char ||
-	    colType == NdbDictionary::Column::Binary)
+    else if(colType == NdbDictionary::Column::Char) 
     {
       
       int len=strlen(ref);
@@ -125,6 +173,8 @@
     }
     return NULL;
   }
+
+
   NdbTimestamp getTimestamp() { 
     return (NdbTimestamp)(self->u_32_value());
   }

=== modified file 'swig/ndbglobals.i'
--- a/swig/ndbglobals.i	2007-07-26 18:58:43 +0000
+++ b/swig/ndbglobals.i	2007-08-01 16:44:14 +0000
@@ -50,7 +50,10 @@
 typedef NdbDictionary::Index NdbDictIndex;
 typedef NdbDictionary::Dictionary NdbDictDictionary;
 typedef NdbDictionary::Event NdbDictEvent;
-
+typedef struct st_byte { 
+  char * theString; 
+  int theLength; 
+} BYTES; 
 %}
 
 typedef char my_bool;

Thread
Rev 135: Added Johan's getBytes() method with a few changes. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor1 Aug