You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2003/05/20 23:01:44 UTC
cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils DynaRowSetTestCase.java
rdonkin 2003/05/20 14:01:44
Modified: beanutils/src/java/org/apache/commons/beanutils
RowSetDynaClass.java
beanutils/src/test/org/apache/commons/beanutils
DynaRowSetTestCase.java
Log:
Enhancement #19763 - this allows only a limited number of rows to be cached in the dyna class. Submitted by Gemes Tibor.
Revision Changes Path
1.5 +72 -17 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/RowSetDynaClass.java
Index: RowSetDynaClass.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/RowSetDynaClass.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RowSetDynaClass.java 13 Mar 2003 18:45:38 -0000 1.4
+++ RowSetDynaClass.java 20 May 2003 21:01:44 -0000 1.5
@@ -113,6 +113,22 @@
public class RowSetDynaClass extends JDBCDynaClass implements DynaClass, Serializable {
+ // ----------------------------------------------------- Instance variables
+
+ /**
+ * <p>Limits the size of the returned list. The call to
+ * <code>getRows()</code> will return at most limit number of rows.
+ * If less than or equal to 0, does not limit the size of the result.
+ */
+ protected int limit = -1;
+
+ /**
+ * <p>The list of {@link DynaBean}s representing the contents of
+ * the original <code>ResultSet</code> on which this
+ * {@link RowSetDynaClass} was based.</p>
+ */
+ protected List rows = new ArrayList();
+
// ----------------------------------------------------------- Constructors
@@ -130,11 +146,57 @@
*/
public RowSetDynaClass(ResultSet resultSet) throws SQLException {
- this(resultSet, true);
+ this(resultSet, true, -1);
}
+ /**
+ * <p>Construct a new {@link RowSetDynaClass} for the specified
+ * <code>ResultSet</code>. The property names corresponding
+ * to column names in the result set will be lower cased.</p>
+ *
+ * If <code>limit</code> is not less than 0, max <code>limit</code>
+ * number of rows will be copied into the list.
+ *
+ * @param resultSet The result set to be wrapped
+ * @param limit The maximum for the size of the result.
+ *
+ * @exception NullPointerException if <code>resultSet</code>
+ * is <code>null</code>
+ * @exception SQLException if the metadata for this result set
+ * cannot be introspected
+ */
+ public RowSetDynaClass(ResultSet resultSet, int limit) throws SQLException {
+
+ this(resultSet, true, limit);
+
+ }
+
+
+ /**
+ * <p>Construct a new {@link RowSetDynaClass} for the specified
+ * <code>ResultSet</code>. The property names corresponding
+ * to the column names in the result set will be lower cased or not,
+ * depending on the specified <code>lowerCase</code> value.</p>
+ *
+ * If <code>limit</code> is not less than 0, max <code>limit</code>
+ * number of rows will be copied into the resultset.
+ *
+ *
+ * @param resultSet The result set to be wrapped
+ * @param lowerCase Should property names be lower cased?
+ *
+ * @exception NullPointerException if <code>resultSet</code>
+ * is <code>null</code>
+ * @exception SQLException if the metadata for this result set
+ * cannot be introspected
+ */
+ public RowSetDynaClass(ResultSet resultSet, boolean lowerCase)
+ throws SQLException {
+ this(resultSet, lowerCase, -1);
+ }
+
/**
* <p>Construct a new {@link RowSetDynaClass} for the specified
* <code>ResultSet</code>. The property names corresponding
@@ -156,27 +218,19 @@
* @exception SQLException if the metadata for this result set
* cannot be introspected
*/
- public RowSetDynaClass(ResultSet resultSet, boolean lowerCase)
- throws SQLException {
+ public RowSetDynaClass(ResultSet resultSet, boolean lowerCase, int limit)
+ throws SQLException {
if (resultSet == null) {
throw new NullPointerException();
}
this.lowerCase = lowerCase;
+ this.limit = limit;
introspect(resultSet);
copy(resultSet);
}
-
- /**
- * <p>The list of {@link DynaBean}s representing the contents of
- * the original <code>ResultSet</code> on which this
- * {@link RowSetDynaClass} was based.</p>
- */
- protected List rows = new ArrayList();
-
-
/**
* <p>Return a <code>List</code> containing the {@link DynaBean}s that
* represent the contents of each <code>Row</code> from the
@@ -211,7 +265,8 @@
*/
protected void copy(ResultSet resultSet) throws SQLException {
- while (resultSet.next()) {
+ int cnt = 0;
+ while (resultSet.next() && (limit < 0 || cnt++ < limit) ) {
DynaBean bean = new BasicDynaBean(this);
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getName();
1.2 +13 -5 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaRowSetTestCase.java
Index: DynaRowSetTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaRowSetTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynaRowSetTestCase.java 5 Jan 2003 05:33:05 -0000 1.1
+++ DynaRowSetTestCase.java 20 May 2003 21:01:44 -0000 1.2
@@ -280,5 +280,13 @@
}
-
+ public void testLimitedRows() throws Exception {
+
+ // created one with low limit
+ RowSetDynaClass limitedDynaClass = new RowSetDynaClass(new TestResultSet(), 3);
+ List rows = limitedDynaClass.getRows();
+ assertNotNull("list exists", rows);
+ assertEquals("limited row count", 3, rows.size());
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org