List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:July 3 2007 6:04pm
Subject:Rev 138: Added ndbj.BaseCallback so that NDB/J callbacks don't have to reference ndbapi. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors...
View as plain text  
------------------------------------------------------------
revno: 138
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Tue 2007-07-03 11:04:19 -0700
message:
  Added ndbj.BaseCallback so that NDB/J callbacks don't have to reference ndbapi.
added:
  java/com/mysql/cluster/ndbj/BaseCallback.java
basecallback.java-20070703180415-vgaf7h8unl6b2jg2-1
modified:
  java/com/mysql/cluster/ndbj/NdbFactory.java
ndbfactory.java-20070517181935-98huwjarzuh25b30-13
  java/com/mysql/cluster/ndbj/NdbScanOperationImpl.java
ndbscanoperationimpl-20070517181935-98huwjarzuh25b30-26
  java/com/mysql/cluster/ndbj/NdbTransactionImpl.java
ndbtransactionimpl.j-20070517181935-98huwjarzuh25b30-28
  java/com/mysql/cluster/ndbj/examples/TestBaseCallback.java
testbasecallback.jav-20070703002120-jsnz1ul38pp1h3w3-2
=== added file 'java/com/mysql/cluster/ndbj/BaseCallback.java'
--- a/java/com/mysql/cluster/ndbj/BaseCallback.java	1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/ndbj/BaseCallback.java	2007-07-03 18:04:19 +0000
@@ -0,0 +1,38 @@
+package com.mysql.cluster.ndbj;
+
+import com.mysql.cluster.errors.*;
+
+public class BaseCallback extends com.mysql.cluster.ndbapi.BaseCallback {
+
+	private Ndb myNdb = null;  
+	
+	public BaseCallback() { 
+		super(); 
+	}
+	
+	public BaseCallback(Ndb theNdb) {
+		super();
+		this.myNdb = theNdb;
+	}
+	
+	public final void callback(int res, com.mysql.cluster.ndbapi.NdbTransaction trans) {
+		// TODO: need to get a throws from the C++ basecallback
+		NdbTransaction ndbjTrans = null; 
+		try { 
+			if (this.myNdb == null) { 
+				ndbjTrans = NdbFactory.createTransaction(trans);
+			} else { 
+				ndbjTrans = NdbFactory.createTransaction(myNdb,trans);
+			}
+		} catch (NdbApiException e) {
+			// TODO: What's a sensible thing to do here if we can't re-throw? 
+			ndbjTrans = null;
+		}
+		if (ndbjTrans != null) 
+			this.callback(res, ndbjTrans);
+	}
+	
+	public void callback(int res, NdbTransaction trans) { 
+		System.out.println("In the NDB/J default callback. Transaction:" + trans);
+	}
+}

=== modified file 'java/com/mysql/cluster/ndbj/NdbFactory.java'
--- a/java/com/mysql/cluster/ndbj/NdbFactory.java	2007-05-21 23:00:16 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbFactory.java	2007-07-03 18:04:19 +0000
@@ -293,6 +293,32 @@
         return trans;
     }
 
+    static NdbTransaction createTransaction(
+    		Ndb theNdb, 
+    		com.mysql.cluster.ndbapi.NdbTransaction transRef)
+    throws NdbApiException
+    {
+        NdbTransaction trans=null;
+        if (MODE.equals("development")) {
+            trans = new NdbTransactionImpl(((NdbImpl)theNdb).ndbRef, transRef);
+        }
+        if (MODE.equals("production")) {
+
+        }
+        return trans;
+    }
+    static NdbTransaction createTransaction(
+    		com.mysql.cluster.ndbapi.NdbTransaction transRef) 
+    throws NdbApiException
+    {
+    	NdbTransaction trans = null; 
+    	if (MODE.equals("development")) {
+    		trans = new NdbTransactionImpl(transRef);
+    	} else if (MODE.equals("production")) {
+    	
+    	}
+    	return trans;
+    }
     /**
      * Used internally by NDB/J.
      * @param trans

=== modified file 'java/com/mysql/cluster/ndbj/NdbScanOperationImpl.java'
--- a/java/com/mysql/cluster/ndbj/NdbScanOperationImpl.java	2007-07-03 00:21:23 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbScanOperationImpl.java	2007-07-03 18:04:19 +0000
@@ -1,7 +1,6 @@
 package com.mysql.cluster.ndbj;
 
 import com.mysql.cluster.errors.*;
-import com.mysql.cluster.ndbapi.NdbOperation.LockMode;
 
 import java.util.ArrayList;
 

=== modified file 'java/com/mysql/cluster/ndbj/NdbTransactionImpl.java'
--- a/java/com/mysql/cluster/ndbj/NdbTransactionImpl.java	2007-07-03 00:21:23 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbTransactionImpl.java	2007-07-03 18:04:19 +0000
@@ -2,7 +2,9 @@
 
 import com.mysql.cluster.errors.*;
 import com.mysql.cluster.ndbapi.*;
+import com.mysql.cluster.ndbapi.BaseCallback;
 import com.mysql.cluster.ndbapi.NdbError;
+
 import java.math.BigInteger;
 
 import java.util.ArrayList;
@@ -46,6 +48,8 @@
  * @see com.mysql.cluster.ndbj.NdbIndexScanOperation
  */
 class NdbTransactionImpl extends NdbBaseImpl implements NdbTransaction {
+
+
 	/**
 	 * List of Blob object used by the Transaction
 	 */
@@ -89,6 +93,14 @@
 		transExecutionState = NdbTransaction.ExecutionState.STARTED;
 	}
 
+	NdbTransactionImpl(com.mysql.cluster.ndbapi.NdbTransaction transRef)
+			throws NdbApiException {
+		super();
+		this.ndbRef = null;
+		this.transRef=transRef;
+		ndbBlobArray = new ArrayList<NdbBlob>(DEFAULT_NUM_BLOBS);
+		transExecutionState = NdbTransaction.ExecutionState.STARTED;
+	}
 	/**
 	 * The transaction stores a listt of Blob objects for the transactions
 	 * 
@@ -142,12 +154,21 @@
 	 * @see com.mysql.cluster.ndbj.NdbTransaction#getNdbIndexOperation(java.lang.String,
 	 *      java.lang.String)
 	 */
+	public NdbIndexOperation getNdbIndexOperation(Ndb myNdb, String indexName, String
tableName) 
+	throws NdbApiException
+	{
+		com.mysql.cluster.ndbapi.NdbIndexOperation opRef =
transRef.getNdbIndexOperation(((NdbImpl)myNdb).ndbRef, indexName, tableName);
+		return NdbFactory.createNdbIndexOperation(this,opRef);
+	}
+	
 	public NdbIndexOperation getNdbIndexOperation(String indexName,
 			String tableName) throws NdbApiException {
 		isValid();
 		isStringNullOrEmpty(tableName);
 		isStringNullOrEmpty(indexName);
-
+		if (ndbRef == null) { 
+			throw new RuntimeException("null ndbRef");
+		}
 		com.mysql.cluster.ndbapi.NdbIndexOperation opRef =
transRef.getNdbIndexOperation(ndbRef, indexName, tableName);
 		return NdbFactory.createNdbIndexOperation(this,opRef);
 	}
@@ -158,6 +179,13 @@
 	 * @see com.mysql.cluster.ndbj.NdbTransaction#getNdbIndexScanOperation(java.lang.String,
 	 *      java.lang.String)
 	 */
+	public NdbIndexScanOperation getNdbIndexScanOperation(Ndb myNdb, String indexName,
String tableName) 
+	throws NdbApiException
+	{
+		com.mysql.cluster.ndbapi.NdbIndexScanOperation opRef =
transRef.getNdbIndexScanOperation(((NdbImpl)myNdb).ndbRef, indexName, tableName);
+		return NdbFactory.createNdbIndexScanOperation(this,tableName, indexName,opRef);
+	}
+	
 	public NdbIndexScanOperation getNdbIndexScanOperation(String indexName,
 			String tableName) throws NdbApiException {
 		isValid();

=== modified file 'java/com/mysql/cluster/ndbj/examples/TestBaseCallback.java'
--- a/java/com/mysql/cluster/ndbj/examples/TestBaseCallback.java	2007-07-03 00:41:04 +0000
+++ b/java/com/mysql/cluster/ndbj/examples/TestBaseCallback.java	2007-07-03 18:04:19 +0000
@@ -3,7 +3,7 @@
 import com.mysql.cluster.ndbj.*;
 import com.mysql.cluster.errors.*;
 
-class TestBaseCallback extends com.mysql.cluster.ndbapi.BaseCallback { 
+class TestBaseCallback extends BaseCallback { 
 
   NdbResultSet myRs; 
   Ndb myNdb; 
@@ -13,7 +13,7 @@
     this.myNdb=theNdb; 
   }
 
-  public void callback(int result, com.mysql.cluster.ndbapi.NdbTransaction myTrans) { 
+  public void callback(int result, NdbTransaction myTrans) { 
     //System.out.println("result " + result + " value: " + this.myRs.getInt("ATTR));
     try { 
     	System.out.println("value " + this.myRs.getInt("ATTR2"));

Thread
Rev 138: Added ndbj.BaseCallback so that NDB/J callbacks don't have to reference ndbapi. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors...Monty Taylor3 Jul