330 Craig L Russell 2010-09-21
Add deletePersistent(Class cls, Object key)
modified:
clusterj-api/src/main/java/com/mysql/clusterj/Session.java
clusterj-core/src/main/java/com/mysql/clusterj/core/SessionImpl.java
clusterj-test/src/main/java/testsuite/clusterj/DeleteInsertTest.java
clusterj-test/src/main/java/testsuite/clusterj/MultiplePKTest.java
329 Craig L Russell 2010-09-21
Add session.newInstance(Class cls, Object key)
modified:
clusterj-api/src/main/java/com/mysql/clusterj/Session.java
clusterj-core/src/main/java/com/mysql/clusterj/core/SessionImpl.java
clusterj-core/src/main/java/com/mysql/clusterj/core/spi/DomainTypeHandler.java
clusterj-test/src/main/java/testsuite/clusterj/AbstractClusterJModelTest.java
clusterj-test/src/main/java/testsuite/clusterj/domaintypehandler/CrazyDomainTypeHandlerFactoryImpl.java
=== modified file 'clusterj-api/src/main/java/com/mysql/clusterj/Session.java'
--- a/clusterj-api/src/main/java/com/mysql/clusterj/Session.java 2010-09-21 20:47:06 +0000
+++ b/clusterj-api/src/main/java/com/mysql/clusterj/Session.java 2010-09-22 00:09:11 +0000
@@ -90,6 +90,15 @@ public interface Session {
*/
Iterable<?> makePersistentAll(Iterable<?> instances);
+ /** Delete an instance of a class from the database given its primary key.
+ * For single-column keys, the key parameter is a wrapper (e.g. Integer).
+ * For multi-column keys, the key parameter is an Object[] in which
+ * elements correspond to the primary keys in order as defined in the schema.
+ * @param cls the class
+ * @param key the primary key
+ */
+ public <T> void deletePersistent(Class<T> cls, Object key);
+
/** Delete the instance from the database. Only the id field is used
* to determine which instance is to be deleted.
* If the instance does not exist in the database, an exception is thrown.
=== modified file 'clusterj-core/src/main/java/com/mysql/clusterj/core/SessionImpl.java'
--- a/clusterj-core/src/main/java/com/mysql/clusterj/core/SessionImpl.java 2010-09-21 20:47:06 +0000
+++ b/clusterj-core/src/main/java/com/mysql/clusterj/core/SessionImpl.java 2010-09-22 00:09:11 +0000
@@ -322,6 +322,19 @@ public class SessionImpl implements Sess
return result;
}
+ /** Delete an instance of a class from the database given its primary key.
+ * For single-column keys, the key parameter is a wrapper (e.g. Integer).
+ * For multi-column keys, the key parameter is an Object[] in which
+ * elements correspond to the primary keys in order as defined in the schema.
+ * @param cls the class
+ * @param key the primary key
+ */
+ public <T> void deletePersistent(Class<T> cls, Object key) {
+ DomainTypeHandler<T> domainTypeHandler = getDomainTypeHandler(cls);
+ ValueHandler keyValueHandler = domainTypeHandler.createKeyValueHandler(key);
+ delete(domainTypeHandler, keyValueHandler);
+ }
+
/** Remove an instance from the database. Only the key field(s)
* are used to identify the instance.
*
=== modified file 'clusterj-test/src/main/java/testsuite/clusterj/DeleteInsertTest.java'
--- a/clusterj-test/src/main/java/testsuite/clusterj/DeleteInsertTest.java 2009-10-27 09:44:31 +0000
+++ b/clusterj-test/src/main/java/testsuite/clusterj/DeleteInsertTest.java 2010-09-22 00:09:11 +0000
@@ -35,7 +35,7 @@ public class DeleteInsertTest extends Ab
int count = 0;
for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
tx.begin();
- session.deletePersistent(employees.get(i));
+ session.deletePersistent(Employee.class, i);
try {
tx.commit();
++count;
=== modified file 'clusterj-test/src/main/java/testsuite/clusterj/MultiplePKTest.java'
--- a/clusterj-test/src/main/java/testsuite/clusterj/MultiplePKTest.java 2009-12-01 23:55:49 +0000
+++ b/clusterj-test/src/main/java/testsuite/clusterj/MultiplePKTest.java 2010-09-22 00:09:11 +0000
@@ -431,17 +431,7 @@ public class MultiplePKTest extends Abst
for (int i = 0; i < NUMBER_OF_INSTANCES; ++i) {
dn2idPK[1] = getA1for(NUMBER_OF_INSTANCES, i);
dn2idPK[3] = "employeenumber=100000" + i;
- Dn2id d = session.find(Dn2id.class, dn2idPK);
- // verify eid after update
- long expected = i + NUMBER_OF_INSTANCES;
- long actual = d.getEid();
- if (expected != actual) {
- error("Failed to find dn2id " + i
- + " expected eid " + expected
- + " actual eid " + actual);
- }
- // now delete the instance
- session.deletePersistent(d);
+ session.deletePersistent(Dn2id.class, dn2idPK);
}
tx.commit();
}
Attachment: [text/bzr-bundle] bzr/craig.russell@oracle.com-20100922000911-9s45xpn1r35f5be5.bundle
| Thread |
|---|
| • bzr push into clusterj branch (Craig.Russell:329 to 330) | Craig L Russell | 22 Sep |