Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.iapi.store.access
Class RowUtil  view RowUtil download RowUtil.java

java.lang.Object
  extended byorg.apache.derby.iapi.store.access.RowUtil

public class RowUtil
extends java.lang.Object

A set of static utility methods to work with rows.

A row or partial row is described by two or three parameters.

  1. DataValueDescriptor[] row - an array of objects, one per column.
  2. FormatableBitSet validColumns - an indication of which objects in row map to which columns
These objects can describe a complete row or a partial row. A partial row is one where a sub-set (e.g. columns 0, 4 and 7) of the columns are supplied for update, or requested to be fetched on a read. Here's an example of code to set up a partial column list to fetch the 0th (type FOO), 4th (type BAR), and 7th (type MMM) columns from a row with 10 columns, note that the format for a partial row changed from a "packed" representation in the 3.0 release to a "sparse" representation in later releases:

  // allocate/initialize the row 
  DataValueDescriptor row = new DataValueDescriptor[10]
  row[0] = new FOO();
  row[4] = new BAR();
  row[7] = new MMM();

  // allocate/initialize the bit set 
  FormatableBitSet FormatableBitSet = new FormatableBitSet(10);

  FormatableBitSet.set(0);
  FormatableBitSet.set(4);
  FormatableBitSet.set(7);
  

Column mapping
When validColumns is null:
  • The number of columns is given by row.length
  • Column N maps to row[N], where column numbers start at zero.

When validColumns is not null, then
  • The number of requested columns is given by the number of bits set in validColumns.
  • Column N is not in the partial row if validColumns.isSet(N) returns false.
  • Column N is in the partial row if validColumns.isSet(N) returns true.
  • If column N is in the partial row then it maps to row[N]. If N >= row.length then the column is taken as non existent for an insert or update, and not fetched on a fetch.
If row.length is greater than the number of columns indicated by validColumns the extra entries are ignored.


Field Summary
static org.apache.derby.iapi.types.DataValueDescriptor[] EMPTY_ROW
          An object that can be used on a fetch to indicate no fields need to be fetched.
static org.apache.derby.iapi.services.io.FormatableBitSet EMPTY_ROW_BITSET
          An object that can be used on a fetch as a FormatableBitSet to indicate no fields need to be fetched.
static org.apache.derby.iapi.store.raw.FetchDescriptor EMPTY_ROW_FETCH_DESCRIPTOR
          An object that can be used on a fetch as a FormatableBitSet to indicate no fields need to be fetched.
static org.apache.derby.iapi.store.raw.FetchDescriptor[] ROWUTIL_FETCH_DESCRIPTOR_CONSTANTS
           
 
Constructor Summary
private RowUtil()
           
 
Method Summary
static int columnOutOfRange(org.apache.derby.iapi.types.DataValueDescriptor[] row, org.apache.derby.iapi.services.io.FormatableBitSet columnList, int maxColumns)
          Return the column number of the first column out of range, or a number less than zero if all columns are in range.
static org.apache.derby.iapi.types.DataValueDescriptor getColumn(org.apache.derby.iapi.types.DataValueDescriptor[] row, org.apache.derby.iapi.services.io.FormatableBitSet columnList, int columnId)
          Get the object for a column identifer (0 based) from a complete or partial row.
static java.lang.Object getColumn(java.lang.Object[] row, org.apache.derby.iapi.services.io.FormatableBitSet columnList, int columnId)
           
static org.apache.derby.iapi.store.raw.FetchDescriptor getFetchDescriptorConstant(int single_column_number)
          Return a FetchDescriptor which describes a single column set.
static int getNumberOfColumns(int maxColumnNumber, org.apache.derby.iapi.services.io.FormatableBitSet columnList)
          Get the number of columns represented by a FormatableBitSet.
static org.apache.derby.iapi.services.io.FormatableBitSet getQualifierBitSet(Qualifier[][] qualifiers)
          Get a FormatableBitSet representing all the columns represented in a qualifier list.
static boolean isRowEmpty(org.apache.derby.iapi.types.DataValueDescriptor[] row, org.apache.derby.iapi.services.io.FormatableBitSet columnList)
          See if a row actually contains no columns.
static org.apache.derby.iapi.services.loader.InstanceGetter[] newClassInfoTemplate(org.apache.derby.iapi.services.io.FormatableBitSet column_list, int[] format_ids)
          Generate a row of InstanceGetter objects to be used to generate "empty" rows.
static org.apache.derby.iapi.types.DataValueDescriptor[] newRowFromClassInfoTemplate(org.apache.derby.iapi.services.loader.InstanceGetter[] classinfo_template)
          Generate an "empty" row from an array of classInfo objects.
private static void newRowFromClassInfoTemplateError()
           
static int nextColumn(java.lang.Object[] row, org.apache.derby.iapi.services.io.FormatableBitSet columnList, int startColumn)
          Get the next valid column after or including start column.
static boolean qualifyRow(java.lang.Object[] row, Qualifier[][] qual_list)
          Process the qualifier list on the row, return true if it qualifies.
static java.lang.String toString(java.util.Hashtable hash_table)
          return string version of a HashTable returned from a FetchSet.
static java.lang.String toString(java.lang.Object[] row)
          return string version of row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ROW

public static final org.apache.derby.iapi.types.DataValueDescriptor[] EMPTY_ROW
An object that can be used on a fetch to indicate no fields need to be fetched.


EMPTY_ROW_BITSET

public static final org.apache.derby.iapi.services.io.FormatableBitSet EMPTY_ROW_BITSET
An object that can be used on a fetch as a FormatableBitSet to indicate no fields need to be fetched.


EMPTY_ROW_FETCH_DESCRIPTOR

public static final org.apache.derby.iapi.store.raw.FetchDescriptor EMPTY_ROW_FETCH_DESCRIPTOR
An object that can be used on a fetch as a FormatableBitSet to indicate no fields need to be fetched.


ROWUTIL_FETCH_DESCRIPTOR_CONSTANTS

public static final org.apache.derby.iapi.store.raw.FetchDescriptor[] ROWUTIL_FETCH_DESCRIPTOR_CONSTANTS
Constructor Detail

RowUtil

private RowUtil()
Method Detail

getColumn

public static org.apache.derby.iapi.types.DataValueDescriptor getColumn(org.apache.derby.iapi.types.DataValueDescriptor[] row,
                                                                        org.apache.derby.iapi.services.io.FormatableBitSet columnList,
                                                                        int columnId)
Get the object for a column identifer (0 based) from a complete or partial row.


getColumn

public static java.lang.Object getColumn(java.lang.Object[] row,
                                         org.apache.derby.iapi.services.io.FormatableBitSet columnList,
                                         int columnId)

getQualifierBitSet

public static org.apache.derby.iapi.services.io.FormatableBitSet getQualifierBitSet(Qualifier[][] qualifiers)
Get a FormatableBitSet representing all the columns represented in a qualifier list.


getNumberOfColumns

public static int getNumberOfColumns(int maxColumnNumber,
                                     org.apache.derby.iapi.services.io.FormatableBitSet columnList)
Get the number of columns represented by a FormatableBitSet.

This is simply a count of the number of bits set in the FormatableBitSet.


isRowEmpty

public static boolean isRowEmpty(org.apache.derby.iapi.types.DataValueDescriptor[] row,
                                 org.apache.derby.iapi.services.io.FormatableBitSet columnList)
See if a row actually contains no columns. Returns true if row is null, row.length is null, or columnList is not null but has not bits set.


columnOutOfRange

public static int columnOutOfRange(org.apache.derby.iapi.types.DataValueDescriptor[] row,
                                   org.apache.derby.iapi.services.io.FormatableBitSet columnList,
                                   int maxColumns)
Return the column number of the first column out of range, or a number less than zero if all columns are in range.


nextColumn

public static int nextColumn(java.lang.Object[] row,
                             org.apache.derby.iapi.services.io.FormatableBitSet columnList,
                             int startColumn)
Get the next valid column after or including start column. Returns -1 if no valid columns exist after startColumn


getFetchDescriptorConstant

public static final org.apache.derby.iapi.store.raw.FetchDescriptor getFetchDescriptorConstant(int single_column_number)
Return a FetchDescriptor which describes a single column set.

This routine returns one of a set of constant FetchDescriptor's, and should not be altered by the caller.


newClassInfoTemplate

public static org.apache.derby.iapi.services.loader.InstanceGetter[] newClassInfoTemplate(org.apache.derby.iapi.services.io.FormatableBitSet column_list,
                                                                                          int[] format_ids)
                                                                                   throws org.apache.derby.iapi.error.StandardException
Generate a row of InstanceGetter objects to be used to generate "empty" rows.

Generate an array of InstanceGetter objects which will be used to make repeated calls to newRowFromClassInfoTemplate(), to repeatedly and efficiently generate new rows. This is important for certain applications like the sorter and fetchSet which generate large numbers of "new" empty rows.


newRowFromClassInfoTemplateError

private static void newRowFromClassInfoTemplateError()

newRowFromClassInfoTemplate

public static org.apache.derby.iapi.types.DataValueDescriptor[] newRowFromClassInfoTemplate(org.apache.derby.iapi.services.loader.InstanceGetter[] classinfo_template)
                                                                                     throws org.apache.derby.iapi.error.StandardException
Generate an "empty" row from an array of classInfo objects.

Generate an array of new'd objects by using the getNewInstance() method on each of the InstanceGetter objects. It is more efficient to allocate new objects based on this "cache'd" InstanceGetter object than to call the Monitor to generate a new class from a format id.


toString

public static java.lang.String toString(java.lang.Object[] row)
return string version of row.

For debugging only.


toString

public static java.lang.String toString(java.util.Hashtable hash_table)
return string version of a HashTable returned from a FetchSet.


qualifyRow

public static final boolean qualifyRow(java.lang.Object[] row,
                                       Qualifier[][] qual_list)
                                throws org.apache.derby.iapi.error.StandardException
Process the qualifier list on the row, return true if it qualifies.

A two dimensional array is to be used to pass around a AND's and OR's in conjunctive normal form. The top slot of the 2 dimensional array is optimized for the more frequent where no OR's are present. The first array slot is always a list of AND's to be treated as described above for single dimensional AND qualifier arrays. The subsequent slots are to be treated as AND'd arrays or OR's. Thus the 2 dimensional array qual[][] argument is to be treated as the following, note if qual.length = 1 then only the first array is valid and it is and an array of and clauses: (qual[0][0] and qual[0][0] ... and qual[0][qual[0].length - 1]) and (qual[1][0] or qual[1][1] ... or qual[1][qual[1].length - 1]) and (qual[2][0] or qual[2][1] ... or qual[2][qual[2].length - 1]) ... and (qual[qual.length - 1][0] or qual[1][1] ... or qual[1][2])