4185 Craig L Russell 2011-05-09
Support autotransaction for delete by query
modified:
storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/query/QueryDomainTypeImpl.java
storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractClusterJTest.java
storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractQueryTest.java
storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/DeleteQueryAllPrimitivesTest.java
4184 Craig L Russell 2011-05-09
Update */pom.xml to 7.1.14
modified:
storage/ndb/clusterj/clusterj-api/pom.xml
storage/ndb/clusterj/clusterj-bindings/pom.xml
storage/ndb/clusterj/clusterj-core/pom.xml
storage/ndb/clusterj/clusterj-jdbc/pom.xml
storage/ndb/clusterj/clusterj-jpatest/pom.xml
storage/ndb/clusterj/clusterj-openjpa/pom.xml
storage/ndb/clusterj/clusterj-test/pom.xml
storage/ndb/clusterj/clusterj-tie/pom.xml
storage/ndb/clusterj/pom.xml
=== modified file 'storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/query/QueryDomainTypeImpl.java'
--- a/storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/query/QueryDomainTypeImpl.java 2011-03-22 01:48:09 +0000
+++ b/storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/query/QueryDomainTypeImpl.java 2011-05-10 01:19:27 +0000
@@ -292,78 +292,93 @@ public class QueryDomainTypeImpl<T> impl
int result = 0;
int errorCode = 0;
Index storeIndex;
+ session.startAutoTransaction();
- switch (scanType) {
+ try {
+ switch (scanType) {
- case PRIMARY_KEY: {
- // perform a delete by primary key operation
- Operation op = session.getDeleteOperation(domainTypeHandler.getStoreTable());
- // set key values into the operation
- index.operationSetKeys(context, op);
- // execute the delete operation
- session.executeNoCommit(false, true);
- errorCode = op.errorCode();
- // a non-zero result means the row was not deleted
- result = (errorCode == 0?1:0);
- break;
- }
-
- case UNIQUE_KEY: {
- storeIndex = index.getStoreIndex();
- if (logger.isDetailEnabled()) logger.detail("Using delete by unique key " + index.getIndexName());
- // perform a delete by unique key operation
- IndexOperation op = session.getUniqueIndexDeleteOperation(storeIndex, domainTypeHandler.getStoreTable());
- // set the keys of the indexName into the operation
- where.operationEqual(context, op);
- // execute the delete operation
- session.executeNoCommit(false, true);
- errorCode = op.errorCode();
- // a non-zero result means the row was not deleted
- result = (errorCode == 0?1:0);
- break;
- }
+ case PRIMARY_KEY: {
+ // perform a delete by primary key operation
+ if (logger.isDetailEnabled()) logger.detail("Using delete by primary key.");
+ Operation op = session.getDeleteOperation(domainTypeHandler.getStoreTable());
+ // set key values into the operation
+ index.operationSetKeys(context, op);
+ // execute the delete operation
+ session.executeNoCommit(false, true);
+ errorCode = op.errorCode();
+ // a non-zero result means the row was not deleted
+ result = (errorCode == 0?1:0);
+ break;
+ }
- case INDEX_SCAN: {
- storeIndex = index.getStoreIndex();
- if (logger.isDetailEnabled()) logger.detail("Using delete by index scan with index " + index.getIndexName());
- // perform an index scan operation
- IndexScanOperation op = session.getIndexScanDeleteOperation(storeIndex, domainTypeHandler.getStoreTable());
- // set the expected columns into the operation
- domainTypeHandler.operationGetValues(op);
- // set the bounds into the operation
- index.operationSetBounds(context, op);
- // set additional filter conditions
- where.filterCmpValue(context, op);
- // execute the scan operation
- session.executeNoCommit();
- // delete results of the scan; don't abort if no row found
- result = session.deletePersistentAll(op, false);
- break;
- }
+ case UNIQUE_KEY: {
+ storeIndex = index.getStoreIndex();
+ if (logger.isDetailEnabled()) logger.detail(
+ "Using delete by unique key " + index.getIndexName());
+ // perform a delete by unique key operation
+ IndexOperation op = session.getUniqueIndexDeleteOperation(storeIndex,
+ domainTypeHandler.getStoreTable());
+ // set the keys of the indexName into the operation
+ where.operationEqual(context, op);
+ // execute the delete operation
+ session.executeNoCommit(false, true);
+ errorCode = op.errorCode();
+ // a non-zero result means the row was not deleted
+ result = (errorCode == 0?1:0);
+ break;
+ }
- case TABLE_SCAN: {
- if (logger.isDetailEnabled()) logger.detail("Using delete by table scan");
- // perform a table scan operation
- ScanOperation op = session.getTableScanDeleteOperation(domainTypeHandler.getStoreTable());
- // set the expected columns into the operation
- domainTypeHandler.operationGetValues(op);
- // set the bounds into the operation
- if (where != null) {
+ case INDEX_SCAN: {
+ storeIndex = index.getStoreIndex();
+ if (logger.isDetailEnabled()) logger.detail(
+ "Using delete by index scan with index " + index.getIndexName());
+ // perform an index scan operation
+ IndexScanOperation op = session.getIndexScanDeleteOperation(storeIndex,
+ domainTypeHandler.getStoreTable());
+ // set the expected columns into the operation
+ domainTypeHandler.operationGetValues(op);
+ // set the bounds into the operation
+ index.operationSetBounds(context, op);
+ // set additional filter conditions
where.filterCmpValue(context, op);
+ // execute the scan operation
+ session.executeNoCommit();
+ // delete results of the scan; don't abort if no row found
+ result = session.deletePersistentAll(op, false);
+ break;
}
- // execute the scan operation
- session.executeNoCommit();
- // delete results of the scan; don't abort if no row found
- result = session.deletePersistentAll(op, false);
- break;
- }
- default:
- throw new ClusterJFatalInternalException(
- local.message("ERR_Illegal_Scan_Type", scanType));
- }
- context.deleteFilters();
- return result;
+ case TABLE_SCAN: {
+ if (logger.isDetailEnabled()) logger.detail("Using delete by table scan");
+ // perform a table scan operation
+ ScanOperation op = session.getTableScanDeleteOperation(domainTypeHandler.getStoreTable());
+ // set the expected columns into the operation
+ domainTypeHandler.operationGetValues(op);
+ // set the bounds into the operation
+ if (where != null) {
+ where.filterCmpValue(context, op);
+ }
+ // execute the scan operation
+ session.executeNoCommit();
+ // delete results of the scan; don't abort if no row found
+ result = session.deletePersistentAll(op, false);
+ break;
+ }
+
+ default:
+ throw new ClusterJFatalInternalException(
+ local.message("ERR_Illegal_Scan_Type", scanType));
+ }
+ context.deleteFilters();
+ session.endAutoTransaction();
+ return result;
+ } catch (ClusterJException e) {
+ session.failAutoTransaction();
+ throw e;
+ } catch (Exception e) {
+ session.failAutoTransaction();
+ throw new ClusterJException(local.message("ERR_Exception_On_Query"), e);
+ }
}
protected CandidateIndexImpl[] createCandidateIndexes() {
=== modified file 'storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractClusterJTest.java'
--- a/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractClusterJTest.java 2011-02-22 05:33:17 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractClusterJTest.java 2011-05-10 01:19:27 +0000
@@ -40,6 +40,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -184,6 +185,28 @@ public abstract class AbstractClusterJTe
}
}
+ protected void errorIfNotEqual(String message, int[] expected, int[] actual) {
+ if (expected == null && actual == null) {
+ return;
+ }
+ int i;
+ if (expected.length == actual.length) {
+ for (i = 0; i < expected.length; ++i) {
+ if (expected[i] != actual[i]) {
+ break;
+ }
+ }
+ if (i == expected.length) {
+ return;
+ }
+ }
+ initializeErrorMessages();
+ errorMessages.append(message + NL);
+ errorMessages.append(
+ "Expected: " + ((expected==null)?"null":Arrays.toString(expected))
+ + " actual: " + ((actual==null)?"null":Arrays.toString(actual)) + NL);
+ }
+
protected void errorIfEqual(String message, Object expected, Object actual) {
if (expected == null && actual != null) {
return;
=== modified file 'storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractQueryTest.java'
--- a/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractQueryTest.java 2011-03-22 01:48:09 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/AbstractQueryTest.java 2011-05-10 01:19:27 +0000
@@ -59,8 +59,11 @@ abstract public class AbstractQueryTest
/** The QueryHolder for this test */
protected QueryHolder holder;
+ private boolean autotransaction;
+
@Override
public void localSetUp() {
+ setAutotransaction(false);
createSessionFactory();
session = sessionFactory.getSession();
tx = session.currentTransaction();
@@ -80,6 +83,10 @@ abstract public class AbstractQueryTest
addTearDownClasses(instanceType);
}
+ protected void setAutotransaction(boolean b) {
+ autotransaction = b;
+ }
+
protected boolean getCleanupAfterTest() {
return true;
}
@@ -334,7 +341,9 @@ abstract public class AbstractQueryTest
public void deleteEqualQuery(String propertyName, String expectedIndex,
Object parameterValue, int expected) {
- tx.begin();
+ if (!autotransaction) {
+ tx.begin();
+ }
QueryHolder holder = new QueryHolder(instanceType, propertyName, expectedIndex);
// specify the where clause
holder.dobj.where(holder.equal);
@@ -344,7 +353,9 @@ abstract public class AbstractQueryTest
holder.setParameterEqual(parameterValue);
// get the results
holder.checkDeletePersistentAll(propertyName + " delete equal", expected);
- tx.commit();
+ if (!autotransaction) {
+ tx.commit();
+ }
}
public void equalOrEqualQuery(String propertyName, Object parameterValue1,
@@ -564,8 +575,9 @@ abstract public class AbstractQueryTest
public void deleteGreaterThanAndLessThanQuery(String propertyName, String expectedIndex,
Object parameterLowerValue, Object parameterUpperValue,
int expected) {
-
- tx.begin();
+ if (!autotransaction) {
+ tx.begin();
+ }
QueryHolder holder = new QueryHolder(instanceType, propertyName, expectedIndex);
// set the where clause into the query
holder.dobj.where(holder.greaterThanAndLessThan);
@@ -576,7 +588,9 @@ abstract public class AbstractQueryTest
holder.setParameterLower(parameterLowerValue);
// get the results
holder.checkDeletePersistentAll(propertyName + " delete lessThanAndGreaterThan", expected);
- tx.commit();
+ if (!autotransaction) {
+ tx.commit();
+ }
}
public void greaterEqualAndLessThanQuery(String propertyName, String expectedIndex,
=== modified file 'storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/DeleteQueryAllPrimitivesTest.java'
--- a/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/DeleteQueryAllPrimitivesTest.java 2011-02-01 00:03:49 +0000
+++ b/storage/ndb/clusterj/clusterj-test/src/main/java/testsuite/clusterj/DeleteQueryAllPrimitivesTest.java 2011-05-10 01:19:27 +0000
@@ -116,4 +116,52 @@ create table allprimitives (
failOnError();
}
+ public void testDeleteEqualByPrimaryKeyAutotransaction() {
+ setAutotransaction(true);
+ deleteEqualQuery("id", "PRIMARY", 8, 1);
+ deleteEqualQuery("id", "PRIMARY", 8, 0);
+ equalQuery("id", "PRIMARY", 8);
+ failOnError();
+ }
+
+ public void testDeleteEqualByUniqueKeyAutotransaction() {
+ setAutotransaction(true);
+ deleteEqualQuery("int_not_null_hash", "idx_int_not_null_hash", 8, 1);
+ deleteEqualQuery("int_not_null_hash", "idx_int_not_null_hash", 8, 0);
+ equalQuery("int_not_null_hash", "idx_int_not_null_hash", 8);
+ failOnError();
+ }
+
+ public void testDeleteEqualByBtreeIndexAutotransaction() {
+ setAutotransaction(true);
+ deleteEqualQuery("int_not_null_btree", "idx_int_not_null_btree", 8, 1);
+ deleteEqualQuery("int_not_null_btree", "idx_int_not_null_btree", 8, 0);
+ equalQuery("int_not_null_btree", "idx_int_not_null_btree", 8);
+ failOnError();
+ }
+
+ public void testDeleteEqualByTableScanAutotransaction() {
+ setAutotransaction(true);
+ deleteEqualQuery("int_not_null_none", "none", 8, 1);
+ deleteEqualQuery("int_not_null_none", "none", 8, 0);
+ equalQuery("int_not_null_none", "none", 8);
+ failOnError();
+ }
+
+ public void testDeleteRangeByBtreeIndexAutotransaction() {
+ setAutotransaction(true);
+ deleteGreaterThanAndLessThanQuery("int_not_null_btree", "idx_int_not_null_btree", 4, 7, 2);
+ deleteGreaterThanAndLessThanQuery("int_not_null_btree", "idx_int_not_null_btree", 4, 7, 0);
+ betweenQuery("int_not_null_btree", "idx_int_not_null_btree", 3, 8, 3, 4, 7, 8);
+ failOnError();
+ }
+
+ public void testDeleteRangeByTableScanAutotransaction() {
+ setAutotransaction(true);
+ deleteGreaterThanAndLessThanQuery("int_not_null_none", "none", 4, 7, 2);
+ deleteGreaterThanAndLessThanQuery("int_not_null_none", "none", 4, 7, 0);
+ betweenQuery("int_not_null_btree", "idx_int_not_null_btree", 3, 8, 3, 4, 7, 8);
+ failOnError();
+ }
+
}
Attachment: [text/bzr-bundle] bzr/craig.russell@oracle.com-20110510011927-b7cdsgkqz9dqks03.bundle
| Thread |
|---|
| • bzr push into mysql-5.1-telco-7.1 branch (Craig.Russell:4184 to 4185) | Craig L Russell | 10 May |