tfischer2005/01/11 09:13:00
Modified:src/rttest/org/apache/torque Tag: TORQUE_3_1_BRANCH
DataTest.java
Added: src/java/org/apache/torque/util Tag: TORQUE_3_1_BRANCH
CountHelper.java
Log:
Added a helper class which eases counting of datasets in a table.
The CountHelper class has been submitted by Martin Goulet, and I have
introduced some changes which are approved by Martin.
See TRQS265 in scarab for Martin's last version.
Also added a test case for the class.
Submitted by: (CountHelper.java) [EMAIL PROTECTED]
Revision ChangesPath
No revision
No revision
1.1.2.1 +141 -0
db-torque/src/java/org/apache/torque/util/Attic/CountHelper.java
No revision
No revision
1.8.2.8 +61 -2 db-torque/src/rttest/org/apache/torque/DataTest.java
Index: DataTest.java
===
RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DataTest.java,v
retrieving revision 1.8.2.7
retrieving revision 1.8.2.8
diff -u -r1.8.2.7 -r1.8.2.8
--- DataTest.java 29 Dec 2004 20:45:01 - 1.8.2.7
+++ DataTest.java 11 Jan 2005 17:13:00 - 1.8.2.8
@@ -37,6 +37,7 @@
import org.apache.torque.test.MultiPkPeer;
import org.apache.torque.test.NullValueTable;
import org.apache.torque.util.BasePeer;
+import org.apache.torque.util.CountHelper;
import org.apache.torque.util.Criteria;
import com.workingdogs.village.Record;
@@ -901,8 +902,66 @@
+ : + e.getMessage());
}
}
+
-
+/**
+ * Tests the CountHelper class
+ */
+public void testCountHelper()
+{
+try
+{
+cleanBookstore();
+Author author = new Author();
+author.setName(Name);
+author.save();
+
+author = new Author();
+author.setName(Name2);
+author.save();
+
+author = new Author();
+author.setName(Name);
+author.save();
+
+Criteria criteria = new Criteria();
+int count = new CountHelper().count(
+criteria,
+null,
+AuthorPeer.AUTHOR_ID);
+
+if (count != 3) {
+fail(counted + count + datasets, should be 3 );
+}
+
+criteria = new Criteria();
+criteria.setDistinct();
+count = new CountHelper().count(criteria, null, AuthorPeer.NAME);
+
+if (count != 2) {
+fail(counted + count + distinct datasets, should be 2
);
+}
+
+criteria = new Criteria();
+criteria.add(AuthorPeer.NAME, Name2);
+count = new CountHelper().count(criteria);
+
+if (count != 1) {
+fail(counted + count + datasets with name Name2,
+ + should be 1 );
+}
+
+}
+catch( Exception e)
+{
+e.printStackTrace();
+fail(Exception caught :
+ + e.getClass().getName()
+ + : + e.getMessage());
+}
+}
+
+
/**
* Strips the schema and table name from a fully qualified colum name
* This is useful for creating Query with aliases, as the constants
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]