Package com.mysql.cluster.ndbj

Examples of com.mysql.cluster.ndbj.NdbScanOperation


    protected int delByScan(NdbTable table) throws NdbApiException {
        beginTransaction();

        // get a full table scan operation with exclusive locks
        final NdbScanOperation op
            = tx.getSelectScanOperation(table, LockMode.LM_Exclusive);
        assert op != null;

        // start the scan; don't commit yet
        executeOperations();

        // delete all rows in a given scan
        int count = 0;
        int stat;
        final boolean allowFetch = true; // request new batches when exhausted
        while ((stat = op.nextResult(allowFetch)) == 0) {
            // delete all tuples within a batch
            do {
                op.deleteCurrentTuple();
                count++;

                // XXX execute the operation now if in non-batching mode
                //if (!batch)
                //    executeOperations();
          } while ((stat = op.nextResult(!allowFetch)) == 0);

            if (stat == 1) {
                // no more batches
                break;
            }
            if (stat == 2) {
                // end of current batch, fetch next
                // XXX not documented: return value != 0 v throwing exception
                // YYY Monty: should always throw exception -> void method
                int s = tx.execute(ExecType.NoCommit, AbortOption.AbortOnError);
                if (s != 0)
                    throw new RuntimeException("s == " + s);
                continue;
            }
            throw new RuntimeException("stat == " + stat);
        }
        if (stat != 1)
            throw new RuntimeException("stat == " + stat);

        // close the scan
        op.close();

        commitTransaction();
        closeTransaction();
        return count;
    }
View Full Code Here

TOP

Related Classes of com.mysql.cluster.ndbj.NdbScanOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.