#At https://bazaar.launchpad.net/~ndb-bindings/ndb-bindings/trunk
439 Monty Taylor 2008-06-30
Added code to allow for interpreted increment and decrement of columns.
added:
java/com/mysql/cluster/ndbj/NdbAtomicOperation.java
java/com/mysql/cluster/ndbj/NdbAtomicOperationImpl.java
java/testsuite/ndbj/IncrementTest.java
modified:
interface/ndbapi/NdbOperation.i
interface/ndbapi/NdbScanOperation.i
interface/ndbapi/NdbTransaction.i
java/Makefile.am
java/com/mysql/cluster/ndbj/NdbOperationFactory.java
java/swig/NdbTransaction.i
java/testsuite/ndbj/AllTests.java
ndbpp/libndbpp.h
ndbpp/util.cpp
=== modified file 'interface/ndbapi/NdbOperation.i'
--- a/interface/ndbapi/NdbOperation.i 2008-06-30 13:29:41 +0000
+++ b/interface/ndbapi/NdbOperation.i 2008-06-30 17:05:21 +0000
@@ -109,6 +109,24 @@ public:
virtual voidint deleteTuple();
+ %rename(increment) incValue(const char* anAttrName, Uint32 aValue);
+ %rename(increment) incValue(const char* anAttrName, Uint64 aValue);
+ %rename(increment) incValue(Uint32 anAttrId, Uint32 aValue);
+ %rename(increment) incValue(Uint32 anAttrId, Uint64 aValue);
+ %rename(decrement) subValue(const char* anAttrName, Uint32 aValue);
+ %rename(decrement) subValue(const char* anAttrName, Uint64 aValue);
+ %rename(decrement) subValue(Uint32 anAttrId, Uint32 aValue);
+ %rename(decrement) subValue(Uint32 anAttrId, Uint64 aValue);
+ voidint incValue(const char* anAttrName, Uint32 aValue);
+ voidint incValue(const char* anAttrName, Uint64 aValue);
+ voidint incValue(Uint32 anAttrId, Uint32 aValue);
+ voidint incValue(Uint32 anAttrId, Uint64 aValue);
+ voidint subValue(const char* anAttrName, Uint32 aValue);
+ voidint subValue(const char* anAttrName, Uint64 aValue);
+ voidint subValue(Uint32 anAttrId, Uint32 aValue);
+ voidint subValue(Uint32 anAttrId, Uint64 aValue);
+
+
%ndbnoexception;
};
@@ -523,52 +541,8 @@ public:
return getColumnId(self,columnName);
}
- voidint branchColEq(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_eq(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColNe(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_ne(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColLt(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_lt(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColLe(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_le(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColGt(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_gt(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColGe(Uint32 ColId, Int64 val, Uint32 len,
- bool nopad, Uint32 Label) {
- return self->branch_col_ge(ColId, (void *) &val, len, nopad, Label);
- }
- voidint branchColLikeString(Uint32 ColId,
- const char* anInputString, size_t len,
- bool nopad, Uint32 Label) {
- return self->branch_col_like(ColId, (void *)anInputString, (Uint32)len,
- nopad, Label);
- };
- voidint branchColNotLikeString(Uint32 ColId,
- const char* anInputString, size_t len,
- bool nopad, Uint32 Label) {
- return self->branch_col_notlike(ColId, (void *)anInputString, (Uint32)len,
- nopad, Label);
- };
- voidint branchColLikeBytes(Uint32 ColId, const char* BYTE, size_t len,
- bool nopad, Uint32 Label) {
- return self->branch_col_like(ColId, (void *)BYTE, (Uint32)len,
- nopad, Label);
- };
- voidint branchColNotLikeBytes(Uint32 ColId, const char* BYTE, size_t len,
- bool nopad, Uint32 Label) {
- return self->branch_col_notlike(ColId, (void *)BYTE, (Uint32)len,
- nopad, Label);
- };
+
+
%ndbnoexception;
=== modified file 'interface/ndbapi/NdbScanOperation.i'
--- a/interface/ndbapi/NdbScanOperation.i 2008-04-19 18:53:30 +0000
+++ b/interface/ndbapi/NdbScanOperation.i 2008-06-30 17:05:21 +0000
@@ -96,5 +96,52 @@ public:
NdbScanFilter * getNdbScanFilter() {
return new NdbScanFilter(self);
}
+
+ %ndbexception("NdbApiException") {
+ $action
+ if (result==-1) {
+ NdbError err = arg1->getNdbError();
+ NDB_exception_err(NdbApiException,err.message,err);
+ }
+ }
+
+ voidint increment(NdbDictColumn * theColumn, Uint32 aValue)
+ {
+ return interpretedIncrement(self, theColumn->getAttrId(), (Uint64)aValue);
+ }
+ voidint increment(NdbDictColumn * theColumn, Uint64 aValue)
+ {
+ return interpretedIncrement(self, theColumn->getAttrId(), aValue);
+ }
+ voidint increment(const char* aColumnName, Uint32 aValue)
+ {
+ return interpretedIncrement(self, getColumnId(self, aColumnName),
+ (Uint64)aValue);
+ }
+ voidint increment(const char* aColumnName, Uint64 aValue)
+ {
+ return interpretedIncrement(self, getColumnId(self, aColumnName), aValue);
+ }
+
+ voidint decrement(NdbDictColumn * theColumn, Uint32 aValue)
+ {
+ return interpretedDecrement(self, theColumn->getAttrId(), (Uint64)aValue);
+ }
+ voidint decrement(NdbDictColumn * theColumn, Uint64 aValue)
+ {
+ return interpretedDecrement(self, theColumn->getAttrId(), aValue);
+ }
+ voidint decrement(const char* aColumnName, Uint32 aValue)
+ {
+ return interpretedDecrement(self, getColumnId(self, aColumnName),
+ (Uint64)aValue);
+ }
+ voidint decrement(const char* aColumnName, Uint64 aValue)
+ {
+ return interpretedDecrement(self, getColumnId(self, aColumnName),
+ aValue);
+ }
+
%ndbnoexception
- }
+
+};
=== modified file 'interface/ndbapi/NdbTransaction.i'
--- a/interface/ndbapi/NdbTransaction.i 2008-06-30 14:48:57 +0000
+++ b/interface/ndbapi/NdbTransaction.i 2008-06-30 17:05:21 +0000
@@ -520,6 +520,26 @@ public:
return theOp;
}
+ NdbOperation * getAtomicUpdateOperation(const class NdbDictTable* aTable)
+ {
+ NdbOperation * theOp = self->getNdbOperation(aTable);
+ if (theOp != NULL)
+ {
+ theOp->interpretedUpdateTuple();
+ }
+ return theOp;
+ }
+
+ NdbOperation* getAtomicUpdateOperation(const char* aTableName)
+ {
+ NdbOperation * theOp = self->getNdbOperation(aTableName);
+ if (theOp != NULL)
+ {
+ theOp->interpretedUpdateTuple();
+ }
+ return theOp;
+ }
+
%ndbexception("NdbApiException") {
$action
if (result==(Uint64)-1) {
=== modified file 'java/Makefile.am'
--- a/java/Makefile.am 2008-06-30 13:29:41 +0000
+++ b/java/Makefile.am 2008-06-30 17:05:21 +0000
@@ -180,6 +180,8 @@ NDBAPI_JAVA_SRC = $(package_srcdir)/ndbj
${package_srcdir}/ndbj/NodeShutdown.java \
${package_srcdir}/ndbj/SchemaObjectExists.java \
${package_srcdir}/ndbj/InternalTemporary.java \
+ ${package_srcdir}/ndbj/NdbAtomicOperation.java \
+ ${package_srcdir}/ndbj/NdbAtomicOperationImpl.java \
${package_srcdir}/ndbj/NdbBaseOperationSet.java \
${package_srcdir}/ndbj/NdbBaseOperationEquals.java \
${package_srcdir}/ndbj/NdbBaseOperationEqualsImpl.java \
@@ -259,6 +261,8 @@ NDBAPI_JAVA_CLASSES = $(package_builddir
${package_builddir}/ndbj/SchemaError.class \
${package_builddir}/ndbj/NdbApiPermanentException.class \
${package_builddir}/ndbj/NdbApiTemporaryException.class \
+ ${package_builddir}/ndbj/NdbAtomicOperation.class \
+ ${package_builddir}/ndbj/NdbAtomicOperationImpl.class \
${package_builddir}/ndbj/NdbBaseOperationSet.class \
${package_builddir}/ndbj/NdbBaseOperationEquals.class \
${package_builddir}/ndbj/NdbBaseOperationEqualsImpl.class \
=== added file 'java/com/mysql/cluster/ndbj/NdbAtomicOperation.java'
--- a/java/com/mysql/cluster/ndbj/NdbAtomicOperation.java 1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbAtomicOperation.java 2008-06-30 17:05:21 +0000
@@ -0,0 +1,17 @@
+package com.mysql.cluster.ndbj;
+
+import java.math.BigInteger;
+
+public interface NdbAtomicOperation extends NdbBaseOperationEquals {
+
+ public void increment(NdbColumn theColumn, long aValue) throws NdbApiException;
+ public void increment(NdbColumn theColumn, BigInteger aValue) throws NdbApiException;
+ public void increment(String aColumnName, long aValue) throws NdbApiException;
+ public void increment(String aColumnName, BigInteger aValue) throws NdbApiException;
+
+ public void decrement(NdbColumn theColumn, long aValue) throws NdbApiException;
+ public void decrement(NdbColumn theColumn, BigInteger aValue) throws NdbApiException;
+ public void decrement(String aColumnName, long aValue) throws NdbApiException;
+ public void decrement(String aColumnName, BigInteger aValue) throws NdbApiException;
+}
+
=== added file 'java/com/mysql/cluster/ndbj/NdbAtomicOperationImpl.java'
--- a/java/com/mysql/cluster/ndbj/NdbAtomicOperationImpl.java 1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbAtomicOperationImpl.java 2008-06-30 17:05:21 +0000
@@ -0,0 +1,268 @@
+package com.mysql.cluster.ndbj;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+public class NdbAtomicOperationImpl implements NdbAtomicOperation {
+
+ NdbOperationImpl theOp = null;
+
+ protected NdbAtomicOperationImpl(NdbOperationImpl op) {
+ theOp = op;
+ }
+
+ public void decrement(NdbColumn theColumn, BigInteger aValue) throws NdbApiException {
+ theOp.decrement(NdbColumn.getCPtr(theColumn), aValue);
+ }
+
+ public void decrement(NdbColumn theColumn, long aValue) throws NdbApiException {
+ theOp.decrement(NdbColumn.getCPtr(theColumn), aValue);
+ }
+
+ public void decrement(String aColumnName, BigInteger aValue) throws NdbApiException {
+ theOp.decrement(aColumnName, aValue);
+ }
+
+ public void decrement(String aColumnName, long aValue) throws NdbApiException {
+ theOp.decrement(aColumnName, aValue);
+ }
+
+ public void equal(long columnId, BigInteger val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(long columnId, byte[] val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(long columnId, int val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(long columnId, long val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(long columnId, String val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(long columnId, Timestamp val) throws NdbApiException {
+ theOp.equal(columnId, val);
+ }
+
+ public void equal(String columnName, BigInteger val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equal(String columnName, byte[] val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equal(String columnName, int val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equal(String columnName, long val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equal(String columnName, String val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equal(String columnName, Timestamp val) throws NdbApiException {
+ theOp.equal(columnName, val);
+ }
+
+ public void equalBytes(long anAttrId, byte[] BYTE) throws NdbApiException {
+ theOp.equalBytes(anAttrId, BYTE);
+ }
+
+ public void equalBytes(NdbColumn theColumn, byte[] BYTE) throws NdbApiException {
+ theOp.equalBytes(theColumn, BYTE);
+ }
+
+ public void equalBytes(String anAttrName, byte[] BYTE) throws NdbApiException {
+ theOp.equalBytes(anAttrName, BYTE);
+ }
+
+ public void equalDatetime(long anAttrId, Calendar anInputDateTime) throws NdbApiException {
+ theOp.equalDatetime(anAttrId, anInputDateTime);
+ }
+
+ public void equalDatetime(NdbColumn theColumn, Calendar anInputDateTime) throws NdbApiException {
+ theOp.equalDatetime(theColumn, anInputDateTime);
+ }
+
+ public void equalDatetime(String anAttrName, Calendar anInputDateTime) throws NdbApiException {
+ theOp.equalDatetime(anAttrName, anInputDateTime);
+ }
+
+ public void equalDecimal(long anAttrId, BigDecimal decVal) throws NdbApiException {
+ theOp.equalDecimal(anAttrId, decVal);
+ }
+
+ public void equalDecimal(NdbColumn theColumn, BigDecimal decVal) throws NdbApiException {
+ theOp.equalDecimal(theColumn, decVal);
+ }
+
+ public void equalDecimal(String anAttrName, BigDecimal decVal) throws NdbApiException {
+ theOp.equalDecimal(anAttrName, decVal);
+ }
+
+ public void equalInt(long anAttrId, int aValue) throws NdbApiException {
+ theOp.equalInt(anAttrId, aValue);
+ }
+
+ public void equalInt(NdbColumn theColumn, int theValue) throws NdbApiException {
+ theOp.equalInt(theColumn, theValue);
+ }
+
+ public void equalInt(String anAttrName, int aValue) throws NdbApiException {
+ theOp.equalInt(anAttrName, aValue);
+ }
+
+ public void equalLong(long anAttrId, long aValue) throws NdbApiException {
+ theOp.equalLong(anAttrId, aValue);
+ }
+
+ public void equalLong(NdbColumn theColumn, long theValue) throws NdbApiException {
+ theOp.equalLong(theColumn, theValue);
+ }
+
+ public void equalLong(String anAttrName, long aValue) throws NdbApiException {
+ theOp.equalLong(anAttrName, aValue);
+ }
+
+ public void equalNull(long anAttrId) throws NdbApiException {
+ theOp.equalNull(anAttrId);
+ }
+
+ public void equalNull(NdbColumn theColumn) throws NdbApiException {
+ theOp.equalNull(theColumn);
+ }
+
+ public void equalNull(String anAttrName) throws NdbApiException {
+ theOp.equalNull(anAttrName);
+ }
+
+ public boolean equals(Object obj) {
+ return theOp.equals(obj);
+ }
+
+ public void equalShort(long anAttrId, short theValue) throws NdbApiException {
+ theOp.equalShort(anAttrId, theValue);
+ }
+
+ public void equalShort(NdbColumn theColumn, short theValue) throws NdbApiException {
+ theOp.equalShort(theColumn, theValue);
+ }
+
+ public void equalShort(String anAttrName, short theValue) throws NdbApiException {
+ theOp.equalShort(anAttrName, theValue);
+ }
+
+ public void equalString(long anAttrId, String anInputString) throws NdbApiException {
+ theOp.equalString(anAttrId, anInputString);
+ }
+
+ public void equalString(String anAttrName, String anInputString) throws NdbApiException {
+ theOp.equalString(anAttrName, anInputString);
+ }
+
+ public void equalTimestamp(long anAttrId, Timestamp anInputTimestamp) throws NdbApiException {
+ theOp.equalTimestamp(anAttrId, anInputTimestamp);
+ }
+
+ public void equalTimestamp(NdbColumn theColumn, Timestamp anInputTimestamp) throws NdbApiException {
+ theOp.equalTimestamp(theColumn, anInputTimestamp);
+ }
+
+ public void equalTimestamp(String anAttrName, Timestamp anInputTimestamp) throws NdbApiException {
+ theOp.equalTimestamp(anAttrName, anInputTimestamp);
+ }
+
+ public void equalUint(long anAttrId, long aValue) throws NdbApiException {
+ theOp.equalUint(anAttrId, aValue);
+ }
+
+ public void equalUint(NdbColumn theColumn, long theValue) throws NdbApiException {
+ theOp.equalUint(theColumn, theValue);
+ }
+
+ public void equalUint(String anAttrName, long aValue) throws NdbApiException {
+ theOp.equalUint(anAttrName, aValue);
+ }
+
+ public void equalUlong(long anAttrId, BigInteger aValue) throws NdbApiException {
+ theOp.equalUlong(anAttrId, aValue);
+ }
+
+ public void equalUlong(NdbColumn theColumn, BigInteger theValue) throws NdbApiException {
+ theOp.equalUlong(theColumn, theValue);
+ }
+
+ public void equalUlong(String anAttrName, BigInteger aValue) throws NdbApiException {
+ theOp.equalUlong(anAttrName, aValue);
+ }
+
+ public void getBlob(long columnId, int length) throws NdbApiException {
+ theOp.getBlob(columnId, length);
+ }
+
+ public void getBlob(long columnId) throws NdbApiException {
+ theOp.getBlob(columnId);
+ }
+
+ public void getBlob(String columnName, int length) throws NdbApiException {
+ theOp.getBlob(columnName, length);
+ }
+
+ public void getBlob(String columnName) throws NdbApiException {
+ theOp.getBlob(columnName);
+ }
+
+ public NdbBlobImpl getBlobHandle(long anAttrId) throws NdbApiException {
+ return theOp.getBlobHandle(anAttrId);
+ }
+
+ public NdbBlobImpl getBlobHandle(String anAttrName) throws NdbApiException {
+ return theOp.getBlobHandle(anAttrName);
+ }
+
+ public void getValue(long columnId) throws NdbApiException {
+ theOp.getValue(columnId);
+ }
+
+ public void getValue(NdbColumn theColumn) throws NdbApiException {
+ theOp.getValue(theColumn);
+ }
+
+ public void getValue(String columnName) throws NdbApiException {
+ theOp.getValue(columnName);
+ }
+
+ public void increment(NdbColumn theColumn, BigInteger aValue) throws NdbApiException {
+ theOp.increment(NdbColumn.getCPtr(theColumn), aValue);
+ }
+
+ public void increment(NdbColumn theColumn, long aValue) throws NdbApiException {
+ theOp.increment(NdbColumn.getCPtr(theColumn), aValue);
+ }
+
+ public void increment(String aColumnName, BigInteger aValue) throws NdbApiException {
+ theOp.increment(aColumnName, aValue);
+ }
+
+ public void increment(String aColumnName, long aValue) throws NdbApiException {
+ theOp.increment(aColumnName, aValue);
+ }
+
+ public NdbResultSet resultData() {
+ return theOp.resultData();
+ }
+
+}
=== modified file 'java/com/mysql/cluster/ndbj/NdbOperationFactory.java'
--- a/java/com/mysql/cluster/ndbj/NdbOperationFactory.java 2008-06-20 02:03:30 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbOperationFactory.java 2008-06-30 17:05:21 +0000
@@ -588,4 +588,8 @@ public interface NdbOperationFactory {
int batch)
throws NdbApiException;
+ public NdbAtomicOperation getAtomicUpdateOperation(NdbTable aTable) throws NdbApiException;
+
+ public NdbAtomicOperation getAtomicUpdateOperation(String aTableName) throws NdbApiException;
+
}
=== modified file 'java/swig/NdbTransaction.i'
--- a/java/swig/NdbTransaction.i 2008-06-10 12:37:51 +0000
+++ b/java/swig/NdbTransaction.i 2008-06-30 17:05:21 +0000
@@ -28,6 +28,20 @@ import java.util.HashMap;
%typemap(javabase) NdbTransaction "NdbJtaTransaction";
%rename(realClose) NdbTransaction::close;
+
+%typemap(jstype) NdbOperation * getAtomicUpdateOperation "NdbAtomicOperation";
+%typemap(javaout) NdbOperation * getAtomicUpdateOperation {
+ long cPtr = $jnicall;
+ if (cPtr == 0) {
+ return null;
+ }
+
+ $javaclassname theOperation = new $javaclassname(cPtr, $owner);
+ createdOperations.put(new Long(cPtr),
+ theOperation);
+ return new NdbAtomicOperationImpl(theOperation);
+
+ }
%typemap(javaout) NdbOperation * getNextCompletedOperation {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner);
=== modified file 'java/testsuite/ndbj/AllTests.java'
--- a/java/testsuite/ndbj/AllTests.java 2008-06-30 13:54:09 +0000
+++ b/java/testsuite/ndbj/AllTests.java 2008-06-30 17:05:21 +0000
@@ -61,6 +61,7 @@ public class AllTests {
suite.addTestSuite(NdbBlobTest.class);
suite.addTestSuite(NdbScanFilterTest.class);
suite.addTestSuite(MultipleAsyncTest.class);
+ suite.addTestSuite(IncrementTest.class);
//$JUnit-END$
return suite;
}
=== added file 'java/testsuite/ndbj/IncrementTest.java'
--- a/java/testsuite/ndbj/IncrementTest.java 1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/IncrementTest.java 2008-06-30 17:05:21 +0000
@@ -0,0 +1,82 @@
+/* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
+ *
+ * ndb-bindings: Bindings for the NDB API
+ * Copyright (C) 2008 MySQL
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package testsuite.ndbj;
+
+import testsuite.BaseNdbjTestCase;
+
+import com.mysql.cluster.ndbj.NdbApiException;
+import com.mysql.cluster.ndbj.NdbAtomicOperation;
+import com.mysql.cluster.ndbj.NdbOperation;
+import com.mysql.cluster.ndbj.NdbResultSet;
+import com.mysql.cluster.ndbj.NdbOperation.AbortOption;
+import com.mysql.cluster.ndbj.NdbOperation.LockMode;
+import com.mysql.cluster.ndbj.NdbTransaction.ExecType;
+
+import java.sql.SQLException;
+
+public class IncrementTest extends BaseNdbjTestCase {
+ private static final String tablename = "t_increment";
+
+ public IncrementTest(String arg0) {
+ super(arg0);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ this.createTable(tablename, "(id int, name varchar(32), age int unsigned not null, primary key(id)) engine=ndbcluster");
+ }
+
+ /**
+ * Simple test for inserting a string with NdbOperation.
+ */
+ public void testSimpleIncrement() throws NdbApiException,SQLException {
+ trans = ndb.startTransaction();
+ NdbOperation op = trans.getInsertOperation(tablename);
+ op.equalInt("id", 1);
+ op.setString("name", "Monty");
+ op.setInt("age", 30);
+ trans.execute(ExecType.Commit,AbortOption.AbortOnError,true);
+ trans.close();
+
+ trans = ndb.startTransaction();
+ NdbAtomicOperation aOp = trans.getAtomicUpdateOperation(tablename);
+ aOp.equalInt("id", 1);
+ aOp.increment("age", 2);
+ trans.executeCommit();
+ trans.close();
+
+ trans = ndb.startTransaction();
+ op = trans.getSelectOperation(tablename, LockMode.LM_Read);
+ op.equalInt("id", 1);
+ op.getValue("age");
+
+ NdbResultSet r = op.resultData();
+ trans.execute(ExecType.Commit, AbortOption.AbortOnError, true);
+
+ r.next();
+ assertEquals(32,r.getInt("age"));
+ }
+
+
+}
=== modified file 'ndbpp/libndbpp.h'
--- a/ndbpp/libndbpp.h 2008-06-30 12:32:14 +0000
+++ b/ndbpp/libndbpp.h 2008-06-30 17:05:21 +0000
@@ -147,4 +147,7 @@ NdbDateTime * createNdbDateTime(const Nd
Int64 selectCount(Ndb * theNdb, const char * tbl);
Uint64 selectCountBig(Ndb * theNdb, const char * tbl, bool &selectCountError);
+int interpretedIncrement(NdbOperation * theOp, Uint32 anAttrId, Uint64 aValue);
+int interpretedDecrement(NdbOperation * theOp, Uint32 anAttrId, Uint64 aValue);
+
#endif
=== modified file 'ndbpp/util.cpp'
--- a/ndbpp/util.cpp 2008-06-30 12:33:00 +0000
+++ b/ndbpp/util.cpp 2008-06-30 17:05:21 +0000
@@ -307,3 +307,40 @@ Uint64 selectCountBig(Ndb * theNdb, cons
};
+int interpretedIncrement(NdbScanOperation * theOp,
+ Uint32 anAttrId, Uint64 aValue)
+{
+
+ /* Letting API allocate the space for this, since we don't
+ have a place to hold on to any */
+ NdbInterpretedCode code(theOp->getTable());
+
+ if ((code.add_val(anAttrId, aValue) != 0) ||
+ (code.interpret_exit_ok() != 0) ||
+ (code.finalise() != 0))
+ {
+ return -1;
+ }
+
+ return theOp->setInterpretedCode(&code);
+
+}
+
+int interpretedDecrement(NdbScanOperation * theOp,
+ Uint32 anAttrId, Uint64 aValue)
+{
+
+ /* Letting API allocate the space for this, since we don't
+ have a place to hold on to any */
+ NdbInterpretedCode code(theOp->getTable());
+
+ if ((code.sub_val(anAttrId, aValue) != 0) ||
+ (code.interpret_exit_ok() != 0) ||
+ (code.finalise() != 0))
+ {
+ return -1;
+ }
+
+ return theOp->setInterpretedCode(&code);
+
+}
| Thread |
|---|
| • bzr commit into NDB/Bindings:trunk branch (monty:439) | Monty Taylor | 30 Jun |