com.javaranch.db
Class DBResults

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--com.javaranch.db.DBResults
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class DBResults
extends java.util.ArrayList

Returned from DBFacade and Jenny generated classes. A DBResults object contains all of the results returned from the database completely in memory - there are no connections that would need to be closed. All of the data in a DBResults object is a string. The original DBResults object contained all objects. It was determined that almost all of the casting was to String. By making this change, it does seem that a great deal of code became much easier to read. Example:

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DBResults()
           
 
Method Summary
 java.lang.String get(int row, int column)
           
 int getColumnCount()
           
 java.lang.String[] getRow(int row)
          Will return null if there is no such row.
 int[] toIntArray()
          Extract the first column into an int array.
 KeyValuePair[] toKeyValuePairArray()
           
 NameIDPair[] toNameIDPairArray()
          The columns must be in the order of "name" and then "id".
 java.lang.String[] toStringArray()
          Extract the first column into a String array.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

DBResults

public DBResults()
Method Detail

getRow

public java.lang.String[] getRow(int row)
Will return null if there is no such row.


getColumnCount

public int getColumnCount()
Returns:
the number of columns found in the first row (and probably all rows). If there are zero rows, zero will be returned.

get

public java.lang.String get(int row,
                            int column)
Returns:
the data found in the cell as a string.

toStringArray

public java.lang.String[] toStringArray()
Extract the first column into a String array.

Returns:
an array of length zero if the results have a size of zero.

toNameIDPairArray

public NameIDPair[] toNameIDPairArray()
The columns must be in the order of "name" and then "id". "firstname", "lastname" and then "id" would work too. There are many times that you want to get a list of names with ID's for use in a short menu. The name is displayed to the user and the ID is used as the key in case the user selects that item. Example:

Returns:
an array of length zero if the results have a size of zero.

toKeyValuePairArray

public KeyValuePair[] toKeyValuePairArray()

toIntArray

public int[] toIntArray()
Extract the first column into an int array. This is used for cases where you need to keep track of all of the records in a table that meet a certain criteria, but keeping the whole record would consume too much memory.

Returns:
an array of length zero if the results have a size of zero.


Copyright ©2004 Paul Wheaton All Rights Reserved