From: Monty Taylor Date: September 13 2007 8:08pm Subject: Rev 145: Added test for OrderedIndexScan. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge List-Archive: http://lists.mysql.com/ndb-connectors/162 Message-Id: At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge ------------------------------------------------------------ revno: 145 revision-id: mtaylor@stripped parent: mtaylor@stripped committer: Monty Taylor branch nick: ndbjmerge timestamp: Thu 2007-09-13 13:06:16 -0700 message: Added test for OrderedIndexScan. Added readTuples() implementations. TODO: Either wrap the internal version of this too, or implement a replacement in Java. Commented out some mgmapi work that isn't done yet. added: java/testsuite/ndbj/OrderedIndexScanTest.java orderedindexscantest-20070913200612-yxpzo7ji93xk863r-1 modified: java/com/mysql/cluster/errors/NdbApiException.java ndbapiexception.java-20070428054022-qvbhak1i97y86t1c-2 java/com/mysql/cluster/ndbj/NdbIndexScanOperation.java ndbindexscanoperatio-20070517181935-98huwjarzuh25b30-17 java/com/mysql/cluster/ndbj/NdbIndexScanOperationImpl.java ndbindexscanoperatio-20070517181935-98huwjarzuh25b30-18 java/mgmapi.i mgmapi.i-20070415064013-80k9rsqzumm2kjaf-1 swig/NdbLogevent.i ndblogevent.i-20070906065931-8drgzkovsy4cdn0b-1 === added file 'java/testsuite/ndbj/OrderedIndexScanTest.java' --- a/java/testsuite/ndbj/OrderedIndexScanTest.java 1970-01-01 00:00:00 +0000 +++ b/java/testsuite/ndbj/OrderedIndexScanTest.java 2007-09-13 20:06:16 +0000 @@ -0,0 +1,110 @@ +package testsuite.ndbj; + +import java.math.BigInteger; + +import testsuite.BaseNdbjTestCase; + +import com.mysql.cluster.errors.NdbApiException; +import com.mysql.cluster.ndbj.NdbOperation; +import com.mysql.cluster.ndbj.NdbTransaction; +import com.mysql.cluster.ndbj.NdbIndexScanOperation; +import com.mysql.cluster.ndbj.NdbResultSet; + +public class OrderedIndexScanTest extends BaseNdbjTestCase { + + protected String col1="id"; + protected String col2="name"; + protected String theTableName="t_oi_scan"; + protected static final int SELECT_COUNT=12000; + + public static void main(String[] args) { + junit.textui.TestRunner.run(OrderedIndexScanTest.class); + } + + public OrderedIndexScanTest(String arg0) { + super(arg0); + } + + public void setUp() throws Exception { + super.setUp(); + this.createTable(theTableName, + "(a integer, b integer, c integer, primary key(a,b)) engine=ndbcluster" + ); + this.stmt.executeUpdate("insert into t_oi_scan values (1,1,1)"); + this.stmt.executeUpdate("insert into t_oi_scan values (1,2,1)"); + this.stmt.executeUpdate("insert into t_oi_scan values (1,3,1)"); + this.stmt.executeUpdate("insert into t_oi_scan values (1,4,1)"); + this.stmt.executeUpdate("insert into t_oi_scan values (1,5,1)"); + } + + public void tearDown() throws Exception { + //super.tearDown(); + } + + /* + * Test method for 'com.mysql.ndbapi.Ndb.destroy()' + */ +// public void testInsertAndReadAndUpdateAndReadAndDeleteAndRead() { +// // TODO Auto-generated method stub +// } + + public void testOIScan() { + + + try { + + trans = ndb.startTransaction(); + + NdbIndexScanOperation iop= + trans.getNdbIndexScanOperation("PRIMARY", theTableName); + + iop.readTuples(NdbOperation.LockMode.LM_CommittedRead); + //iop.readTuples(NdbOperation.LockMode.LM_CommittedRead, 0,0,false,false,false /*readRangeNo set to true to be able to read "many" ranges in one scan op*/); + + + /* System.out.println("foo"); + /* + iop.equal(0,1); + */ + System.out.println(NdbIndexScanOperation.BoundType.BoundEQ); + iop.setBound(0, + NdbIndexScanOperation.BoundType.BoundEQ, + 1); + + long bound_no=0; + iop.endOfBound(bound_no); + + + iop.getValue("a"); + iop.getValue("b"); + + NdbResultSet rs = iop.resultData(); + trans.execute(NdbTransaction.ExecType.NoCommit, + NdbTransaction.AbortOption.AbortOnError, + true); + + + + while(rs.next()) + { + System.out.println("a=" + rs.getInt("a") + + " b=" + rs.getInt("b")); + } + + + assertTrue(true); + + + } + catch (NdbApiException e) { + System.out.println("Caught NdbApiException:\t" + e.getMessage() + e.getCode()); + assertTrue(false); + } + finally { + if (trans!=null) + trans.close(); + } + + } + +} === modified file 'java/com/mysql/cluster/errors/NdbApiException.java' --- a/java/com/mysql/cluster/errors/NdbApiException.java 2007-05-21 00:08:02 +0000 +++ b/java/com/mysql/cluster/errors/NdbApiException.java 2007-09-13 20:06:16 +0000 @@ -1,6 +1,8 @@ package com.mysql.cluster.errors; import com.mysql.cluster.ndbapi.NdbError; +import com.mysql.cluster.ndbapi.NdbError.Classification; +import com.mysql.cluster.ndbapi.NdbError.Status; /** * A NdbApiException is the base checked exception class of the NDB/J API Exception hierarchy. @@ -62,4 +64,34 @@ return toString(); } + + /** + * @return + * @see com.mysql.cluster.ndbapi.NdbError#getClassification() + */ + public Classification getClassification() { + return errRef.getClassification(); + } + + + /** + * @return + * @see com.mysql.cluster.ndbapi.NdbError#getCode() + */ + public int getCode() { + if (errRef == null) { + return -1; + } + return errRef.getCode(); + } + + + /** + * @return + * @see com.mysql.cluster.ndbapi.NdbError#getStatus() + */ + public Status getStatus() { + return errRef.getStatus(); + } + } === modified file 'java/com/mysql/cluster/ndbj/NdbIndexScanOperation.java' --- a/java/com/mysql/cluster/ndbj/NdbIndexScanOperation.java 2007-05-23 01:05:32 +0000 +++ b/java/com/mysql/cluster/ndbj/NdbIndexScanOperation.java 2007-09-13 20:06:16 +0000 @@ -3,6 +3,7 @@ import java.util.Calendar; import com.mysql.cluster.errors.NdbApiException; +import com.mysql.cluster.ndbj.NdbBaseOperation.LockMode; /** * This interface describes operations that can be performed on an INDEX in a @@ -90,7 +91,22 @@ } }; + public abstract void readTuples(LockMode lock_mode, long scan_flags, long parallel, long batch) + throws NdbApiException; + + public abstract void readTuples(LockMode lock_mode, long scan_flags, long parallel) + throws NdbApiException; + + public abstract void readTuples(LockMode lock_mode, long scan_flags) + throws NdbApiException; + + public abstract void readTuples(LockMode lock_mode) + throws NdbApiException; + + public abstract void readTuples() + throws NdbApiException; /** + TODO: Make this version of the method * An index scan operation to read many tuples. * * @param lockMode @@ -100,12 +116,13 @@ * @param orderDesc * @param readRangeNo * @throws NdbApiException - */ + public abstract void readTuples(LockMode lockMode, int batch, int parallel, boolean orderBy, boolean orderDesc, boolean readRangeNo) throws NdbApiException; - +*/ /** + TODO: Make this version of the method * * @param lockMode * LM_Read Read with shared lock LM_Exclusive Read with exclusive @@ -122,11 +139,11 @@ * @param keyInfo * @throws NdbApiException * if the object has been closed or if readTuples failed. - */ + public abstract void readTuples(LockMode lockMode, int batch, int parallel, boolean orderBy, boolean orderDesc, boolean readRangeNo, boolean keyInfo) throws NdbApiException; - +*/ /** * * @param columnId @@ -278,5 +295,8 @@ */ public void setBound(long anAttrId, BoundType type, float val) throws NdbApiException; - + + + public int endOfBound(long range_no) + throws NdbApiException; } \ No newline at end of file === modified file 'java/com/mysql/cluster/ndbj/NdbIndexScanOperationImpl.java' --- a/java/com/mysql/cluster/ndbj/NdbIndexScanOperationImpl.java 2007-05-23 01:05:32 +0000 +++ b/java/com/mysql/cluster/ndbj/NdbIndexScanOperationImpl.java 2007-09-13 20:06:16 +0000 @@ -212,30 +212,61 @@ return scanOpRef.getSorted(); } - /* - * (non-Javadoc) - * - * @see com.mysql.cluster.ndbj.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbj.NdbBaseOperation.LockMode, - * int, int, boolean, boolean, boolean) - */ - public void readTuples(LockMode lockMode, int batch, int parallel, - boolean orderBy, boolean orderDesc, boolean readRangeNo) - throws NdbApiException { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see com.mysql.cluster.ndbj.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbj.NdbBaseOperation.LockMode, - * int, int, boolean, boolean, boolean, boolean) - */ - public void readTuples(LockMode lockMode, int batch, int parallel, - boolean orderBy, boolean orderDesc, boolean readRangeNo, - boolean keyInfo) throws NdbApiException { - // TODO Auto-generated method stub - + + + /** + * @return + * @throws NdbApiException + * @see com.mysql.cluster.ndbapi.NdbIndexScanOperation#readTuples() + */ + public void readTuples() throws NdbApiException { + scanOpRef.readTuples(); + } + + /** + * @param lock_mode + * @param scan_flags + * @param parallel + * @param batch + * @return + * @throws NdbApiException + * @see com.mysql.cluster.ndbapi.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode, long, long, long) + */ + public void readTuples(LockMode lock_mode, long scan_flags, long parallel, long batch) throws NdbApiException { + scanOpRef.readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode.swigToEnum(lock_mode.type), scan_flags, parallel, batch); + } + + /** + * @param lock_mode + * @param scan_flags + * @param parallel + * @return + * @throws NdbApiException + * @see com.mysql.cluster.ndbapi.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode, long, long) + */ + public void readTuples(LockMode lock_mode, long scan_flags, long parallel) throws NdbApiException { + scanOpRef.readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode.swigToEnum(lock_mode.type), scan_flags, parallel); + } + + /** + * @param lock_mode + * @param scan_flags + * @return + * @throws NdbApiException + * @see com.mysql.cluster.ndbapi.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode, long) + */ + public void readTuples(LockMode lock_mode, long scan_flags) throws NdbApiException { + scanOpRef.readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode.swigToEnum(lock_mode.type), scan_flags); + } + + /** + * @param lock_mode + * @return + * @throws NdbApiException + * @see com.mysql.cluster.ndbapi.NdbIndexScanOperation#readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode) + */ + public void readTuples(LockMode lock_mode) throws NdbApiException { + scanOpRef.readTuples(com.mysql.cluster.ndbapi.NdbOperation.LockMode.swigToEnum(lock_mode.type)); } /** === modified file 'java/mgmapi.i' --- a/java/mgmapi.i 2007-09-06 06:59:43 +0000 +++ b/java/mgmapi.i 2007-09-13 20:06:16 +0000 @@ -48,4 +48,3 @@ %include "NdbMgmReply.i" %include "NdbLogevent.i" %include "NdbMgmLogeventHandle.i" - === modified file 'swig/NdbLogevent.i' --- a/swig/NdbLogevent.i 2007-09-06 06:59:43 +0000 +++ b/swig/NdbLogevent.i 2007-09-13 20:06:16 +0000 @@ -17,6 +17,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/** Log event specific data for for corresponding NDB_LE_ log event */ +class ConnectedEvent { +public: + unsigned node; +}; + /** * The NdbLogevent @@ -48,24 +54,14 @@ /** Node ID of the node that reported the log event */ unsigned source_nodeid; - union { - /* CONNECT */ - /** Log event specific data for for corresponding NDB_LE_ log event */ - struct { - unsigned node; - } Connected; - - /** Log event specific data for for corresponding NDB_LE_ log event */ - struct { - unsigned node; - } Disconnected; - - /** Log event specific data for for corresponding NDB_LE_ log event */ - struct { - unsigned node; - } CommunicationClosed; - - }; - -}; +}; + +%extend ndb_logevent { + + ConnectedEvent getConnectedEvent { + return $self->ConnectedEvent; + } +}; + +