Business Components

oracle.jbo
Class ViewCriteria

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--oracle.jbo.ViewCriteria
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, NavigatableRowIterator, RowIterator, java.io.Serializable

public class ViewCriteria
extends java.util.Vector
implements NavigatableRowIterator

A list of row criteria for a View Object's WHERE clause.

The lengths of the ViewCriteriaRows in the list must all match the number of attributes in the View Object.

The following example of a user-defined function, demoCriteria uses several methods in the ViewCriteria and ViewCriteriaRow classes to create and populate criteria rows and to demonstrate "query-by-example". The printViewObject is a helper function that executes the View Object query and prints the results to the screen.

     public static void demoCriteria(ApplicationModule appMod) {

     // Create and populate criteria rows to support query-by-example.
       ViewObject empView = appMod.createViewObject("emp", "d2e.EmpView");
       ViewCriteria vc = empView.createViewCriteria();
       ViewCriteriaRow vcRow = vc.createViewCriteriaRow();

     // ViewCriteriaRow attribute name is case-sensitive.
     // ViewCriteriaRow attribute value requires operator and value.
     // Note also single-quotes around string value.
       vcRow.setAttribute("Job", "= 'MANAGER'");
       vc.addElement(vcRow);

       vcRow = vc.createViewCriteriaRow();
       vcRow.setAttribute("Sal", "> 2500");

       vc.addElement(vcRow);
       empView.applyViewCriteria(vc);

     // Multiple rows are OR-ed in WHERE clause.
       System.out.println("Demo View Criteria");

     //Should print employees that are MANAGER or have Sal > 2500
       QueryDemo.printViewObject(empView);
   }

     public static void printViewObject(ViewObject vo)   {
       // Execute the query, print results to the screen.
       vo.executeQuery();
       while (vo.hasNext()) {
          Row row = vo.next();\
          String rowDataStr = "";

        // How many attributes (columns) is the View Object using?
          int numAttrs = vo.getAttributeCount();

       // Column numbers start with 0, not 1.
          for (int columnNo = 0; columnNo < numAttrs; columnNo++) {

          // See also Row.getAttribute(String name).
            Object attrData = row.getAttribute(columnNo);
            rowDataStr += (attrData + "\t");
          }
          System.out.println(rowDataStr);
       }
    }
 

Since:
JDeveloper 3.0
See Also:
Serialized Form

Field Summary
TypeField
protected  com.sun.java.util.collections.ArrayList listeners
           
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Fields inherited from interface oracle.jbo.RowIterator
ITER_MODE_LAST_PAGE_FULL, ITER_MODE_LAST_PAGE_PARTIAL, SLOT_BEFORE_FIRST, SLOT_BEYOND_LAST, SLOT_DELETED, SLOT_VALID
 
Constructor Summary
ViewCriteria(ViewObject viewObject)
          Creates an empty view criteria object.
 
Method Summary
TypeMethod
 void addListener(java.lang.Object target)
          Adds a subscriber (listener) to be notified of RowSetListener events generated by this row set iterator.
 Key createKey(AttributeList nvp)
          Given a list of name-value pairs, creates a Key object that matches the key structure for the ViewObject for this RowItertor.
 Row createRow()
          Creates a new Row object, but does not insert it into the row set.
 ViewCriteriaRow createViewCriteriaRow()
          Creates a new criteria row as a ViewCriteriaRow object.
 java.util.Enumeration enumerateRowsInRange()
          Gets an Enumeration interface for the row set.
 Row[] findByEntity(int eRowHandle, int maxNumOfRows)
          Finds and returns view rows that use the entity row, identified by the entity row handle, eRowHandle.
 Row[] findByKey(Key key, int maxNumOfRows)
          Finds and returns view rows that match the specified key.
 Row first()
          Designates the first row of the row set as the current row.
 Row[] getAllRowsInRange()
          Extracts the rows in the range.
 int getAttributeIndexOf(java.lang.String name)
          Finds the column associated with an attribute name.
 Row getCurrentRow()
          Accesses the current row.
 int getCurrentRowIndex()
          Gets the absolute index (not range index) of the current row.
 int getCurrentRowSlot()
          Gets the slot status of the current row.
 int getFetchedRowCount()
          Counts the number of rows currently fetched in the row set.
 int getIterMode()
          Gets the current iteration mode.
protected  com.sun.java.util.collections.ArrayList getListenersList()
           
 int getRangeIndexOf(Row row)
          Get the index of the given row relative to the beginning of the range.
 int getRangeSize()
          Gets the size of the row set range.
 int getRangeStart()
          Gets the absolute index of the first row in the row set range.
 Row getRow(Key key)
          Accesses a row through a unique key.
 Row getRowAtRangeIndex(int index)
          Accesses a row through its index in the row set.
 int getRowCount()
          Counts the total number of rows in the row set.
 int getRowCountInRange()
          Gets the size of the row set range.
 ViewObject getViewObject()
          Gets the View Object that owns the view criteria.
 boolean hasNext()
          Tests for the existence of a row after the current row.
 boolean hasPrevious()
          Tests for the existence of a row before the current row.
 void insertRow(Row row)
          Adds a row to the row set, before the current row.
 void insertRowAtRangeIndex(int index, Row row)
          Adds a row to the row set at the given index.
 boolean isRangeAtBottom()
          Tests if the row set range is at the end of the result set.
 boolean isRangeAtTop()
          Tests if the row set range is at the beginning of the result set.
 Row last()
          Designates the last row of the row set as the current row.
 Row next()
          Steps forward, designating the next row as the current row.
 Row previous()
          Steps backward, designating the previous row as the current row.
 void removeCurrentRow()
          Removes the current Row object from the row set.
 void removeListener(java.lang.Object target)
          Removes a subscriber (listener) for RowSetListener events generated by this row set iterator.
 void reset()
          Clears the "current row" designation and places the iterator in the slot before the first row.
 int scrollRange(int amount)
          Moves the row set range up or down a given number of rows.
 int scrollRangeTo(Row row, int index)
          Scrolls the range to place a given row at a given row set index.
 boolean setCurrentRow(Row row)
          Designates a given row as the current row.
 boolean setCurrentRowAtRangeIndex(int index)
          Designates a given index as the current row.
 void setIterMode(int mode)
          Sets the iteration mode for this Row Iterator.
 int setRangeSize(int size)
          Modifies the size of the row set range.
 int setRangeStart(int start)
          Moves the row set range.
 void setRowValidation(boolean flag)
          Sets the validation flag on this iterator.
 void trimNoDataRows()
           
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

listeners

protected com.sun.java.util.collections.ArrayList listeners
Constructor Detail

ViewCriteria

public ViewCriteria(ViewObject viewObject)
Creates an empty view criteria object.
Parameters:
viewObject - the owner of the ViewCriteria.
Method Detail

getViewObject

public ViewObject getViewObject()
Gets the View Object that owns the view criteria.
Returns:
the ViewObject that contains the ViewCriteria.

getAttributeIndexOf

public int getAttributeIndexOf(java.lang.String name)
Finds the column associated with an attribute name.
Parameters:
name - the column name.
Returns:
a column index.

createViewCriteriaRow

public ViewCriteriaRow createViewCriteriaRow()
Creates a new criteria row as a ViewCriteriaRow object. A ViewCriteriaRow object is an array for WHERE clause criteria.
Returns:
a ViewCriteriaRow, an array for WHERE clause criteria.
See Also:
ViewCriteriaRow

next

public Row next()
Steps forward, designating the next row as the current row.
Specified by:
next in interface RowIterator
Returns:
a Row object, or null if there is no next row.

previous

public Row previous()
Steps backward, designating the previous row as the current row.
Specified by:
previous in interface RowIterator
Returns:
a Row object, or null if there is no previous row.

first

public Row first()
Designates the first row of the row set as the current row.
Specified by:
first in interface RowIterator
Returns:
a Row object, or null if the row set is empty.

last

public Row last()
Designates the last row of the row set as the current row.
Specified by:
last in interface RowIterator
Returns:
a Row object, or null if the row set is empty.

reset

public void reset()
Clears the "current row" designation and places the iterator in the slot before the first row.

A subsequent invocation of next() will cause the first row to become the current row.

Specified by:
reset in interface RowIterator

hasNext

public boolean hasNext()
Tests for the existence of a row after the current row.
Specified by:
hasNext in interface RowIterator
Returns:
true if there is next row.

hasPrevious

public boolean hasPrevious()
Tests for the existence of a row before the current row.
Specified by:
hasPrevious in interface RowIterator
Returns:
true if there is previous row.

getFetchedRowCount

public int getFetchedRowCount()
Counts the number of rows currently fetched in the row set.
Specified by:
getFetchedRowCount in interface RowIterator
Returns:
the number of fetched rows.

getRowCount

public int getRowCount()
Counts the total number of rows in the row set.
Specified by:
getRowCount in interface RowIterator
Returns:
the number of rows.

getRowAtRangeIndex

public Row getRowAtRangeIndex(int index)
Accesses a row through its index in the row set.
Specified by:
getRowAtRangeIndex in interface RowIterator
Parameters:
index - an integer in the range 0 to getRangeSize() - 1.
Returns:
a Row object, or null if the index is out of range.

getCurrentRow

public Row getCurrentRow()
Accesses the current row.
Specified by:
getCurrentRow in interface RowIterator
Returns:
the Row object designated as the current row.

getCurrentRowIndex

public int getCurrentRowIndex()
Gets the absolute index (not range index) of the current row.
Specified by:
getCurrentRowIndex in interface RowIterator
Returns:
a row index.

getCurrentRowSlot

public int getCurrentRowSlot()
Gets the slot status of the current row.
Specified by:
getCurrentRowSlot in interface RowIterator
Returns:
one of the class constants prefixed by SLOT_.

setCurrentRow

public boolean setCurrentRow(Row row)
Designates a given row as the current row.
Specified by:
setCurrentRow in interface RowIterator
Parameters:
row - the new current row.
Returns:
true if the operation succeeded.

createRow

public Row createRow()
Creates a new Row object, but does not insert it into the row set.
Specified by:
createRow in interface RowIterator
Returns:
a new Row object.

insertRow

public void insertRow(Row row)
Adds a row to the row set, before the current row. This method sets the current row to the row just inserted. With respect to eventing, this method call will generate two events (of oracle.jbo.RowSetListener): rowInserted, followed by navigated.
Specified by:
insertRow in interface RowIterator
Parameters:
row - the Row object to be added.

removeCurrentRow

public void removeCurrentRow()
Removes the current Row object from the row set.
Specified by:
removeCurrentRow in interface RowIterator

setRangeSize

public int setRangeSize(int size)
Modifies the size of the row set range.

This method takes effect when the next set of data is fetched. For an example usage of setRangeSize, see setRangeStart.

Specified by:
setRangeSize in interface RowIterator
Parameters:
size - the new number of rows in the row set range. Size of 0 is treated same as 1. Size < -1 is treated same as -1.
Returns:
the new size of the range.
See Also:
setRangeStart(int start)

getRangeSize

public int getRangeSize()
Gets the size of the row set range.
Specified by:
getRangeSize in interface RowIterator
Returns:
the number of rows in the range.

getRangeStart

public int getRangeStart()
Gets the absolute index of the first row in the row set range.

The absolute index is 0-based, and is the row's index relative to the entire result set.

Specified by:
getRangeStart in interface RowIterator
Returns:
an index.

setRangeStart

public int setRangeStart(int start)
Moves the row set range.

Note that the index is 0-based. When you call setRangeStart(1), the range start will be positioned at the second table row.

Another behavior of setRangeStart (and also setRangeSize) is that it tries to position the range, so as to fill up the range as much as possible. For example, assume you have View Object vo focused on a table with four rows (A, B, C, D), and you execute the following code:

     vo.setRangeStart(4);
     vo.setRangeSize(3);
     Row[] rows = vo.getAllRowsInRange();
 

In this case, rows contains the last 3 rows (B, C, D). When you call setRangeStart(4), it will try to position you at row 4. Since the index is 0-based, it finds that there is no row. Since the default range size is 1, it will position you to the last row (row index 3).

Then, when you call getRangeSize(3), it tries to fill up the range from the bottom. This is why you get (B, C, D).

Specified by:
setRangeStart in interface RowIterator
Parameters:
start - the absolute index of the new first row in the row set range.

scrollRange

public int scrollRange(int amount)
Moves the row set range up or down a given number of rows.
Specified by:
scrollRange in interface RowIterator
Parameters:
amount - the number of rows to scroll. A negative value scrolls upward.
Returns:
the number of rows actually scrolled.

scrollRangeTo

public int scrollRangeTo(Row row,
                         int index)
Scrolls the range to place a given row at a given row set index.
Specified by:
scrollRangeTo in interface RowIterator
Parameters:
row - the row.
index - the row's new index.
Returns:
the actual number of rows scrolled. A negative number indicates that the scroll was scrolled upward.

setCurrentRowAtRangeIndex

public boolean setCurrentRowAtRangeIndex(int index)
Designates a given index as the current row.
Specified by:
setCurrentRowAtRangeIndex in interface RowIterator
Parameters:
index - the index of the new current row.
Returns:
true if the operation succeeded.

insertRowAtRangeIndex

public void insertRowAtRangeIndex(int index,
                                  Row row)
Adds a row to the row set at the given index. The index is relative to the range, i.e., index of 0 would mean to insert before the first row of the range. Allowed values for index is 0 to range size. If index equals range size, the row is inserted right after the last row in the range. This method call does not alter the current position of the iterator, nor does it affect the range position.
Specified by:
insertRowAtRangeIndex in interface RowIterator
Parameters:
index - the point where row is to be added.
row - the Row object to be added.

getRangeIndexOf

public int getRangeIndexOf(Row row)
Get the index of the given row relative to the beginning of the range.
Specified by:
getRangeIndexOf in interface RowIterator
Parameters:
row - a Row object. or -1 if the row is not in range.
Returns:
the index of row,

getRowCountInRange

public int getRowCountInRange()
Gets the size of the row set range.
Specified by:
getRowCountInRange in interface RowIterator
Returns:
the number of rows in the range.

isRangeAtBottom

public boolean isRangeAtBottom()
Tests if the row set range is at the end of the result set.
Specified by:
isRangeAtBottom in interface RowIterator
Returns:
true if the last row of the range is the last row of the result set.

isRangeAtTop

public boolean isRangeAtTop()
Tests if the row set range is at the beginning of the result set.
Specified by:
isRangeAtTop in interface RowIterator
Returns:
true if the first row of the range is the first row of the result set.

enumerateRowsInRange

public java.util.Enumeration enumerateRowsInRange()
Gets an Enumeration interface for the row set.
Specified by:
enumerateRowsInRange in interface RowIterator
Returns:
an Enumeration interface.

getAllRowsInRange

public Row[] getAllRowsInRange()
Extracts the rows in the range.
Specified by:
getAllRowsInRange in interface RowIterator
Returns:
an array of Row objects. The size if the array is setViewSize().

getRow

public Row getRow(Key key)
Accesses a row through a unique key.
Specified by:
getRow in interface RowIterator
Parameters:
key - a key.
Returns:
the Row object matching the key.

findByKey

public Row[] findByKey(Key key,
                       int maxNumOfRows)
Finds and returns view rows that match the specified key.

See ViewObjectImpl#findByKey(key, int) for details.

You do not have to specify all of the keys, but you do have to correctly specify the positions of the keys that you do want. For example, assume that you have 3 Entity Objects in the View Object, and each Entity Object key is 2 parts. If you want to specify only the key attributes for Entity Object 1 and Entity Object 3, you need:

    Object [] keyValues = new Object[6]; // IMPORTANT that length is *6*
    keyValues[0] = eo1_keypart1; // first Entity Object, key part 1
    keyValues[1] = eo1_keypart2; // first Entity Object, key part 2
    keyValues[4] = eo3_keypart1; // third Entity Object, key part 1
    keyValues[5] = eo3_keypart2; // third Entity Object, key part 2
    Key key = new Key(keyValues);
 
Specified by:
findByKey in interface RowIterator
Parameters:
key - the key to match.
maxNumOfRows - the maximum size of the array to return, or -1 to return all rows.
Returns:
an array of rows matching the key.
See Also:
ViewObjectImpl.findByKey(Key, int)

createKey

public Key createKey(AttributeList nvp)
Given a list of name-value pairs, creates a Key object that matches the key structure for the ViewObject for this RowItertor. This Key object could be used as a valid argument to findByKey. This Key will have null values for attributes expected in the key structure for this ViewObject, but not found in the given set of name-value pairs.
Specified by:
createKey in interface RowIterator

findByEntity

public Row[] findByEntity(int eRowHandle,
                          int maxNumOfRows)
Finds and returns view rows that use the entity row, identified by the entity row handle, eRowHandle.

Specified by:
findByEntity in interface RowIterator
Parameters:
eRowHandle - the entity row handle.
maxNumOfRows - the maximum size of the row array to return, or -1 to return all rows.
Returns:
an array of view rows that use the entity row.

setRowValidation

public void setRowValidation(boolean flag)
Sets the validation flag on this iterator. By default a RowIterator validates the current row when navigating to another row. This method can be used to turn this row-validation off by passing 'false' as parameter.
Specified by:
setRowValidation in interface RowIterator
Parameters:
flag - Whether to turn row validation off or not.
Throws:
InvalidOperException - is thrown if this iterator is the default iterator of a ViewObject or a RowSet.

getIterMode

public int getIterMode()
Description copied from interface: RowIterator
Gets the current iteration mode. See Iteration Modes above for details on iteration mode which controls how the range behaves when it reaches the end of the Row Set.
Specified by:
getIterMode in interface RowIterator
Following copied from interface: oracle.jbo.RowIterator
Returns:
ITER_MODE_LAST_PAGE_PARTIAL if the iteration mode is "partial-last-page", ITER_MODE_LAST_PAGE_FULL if it is "full-last-page".

setIterMode

public void setIterMode(int mode)
Description copied from interface: RowIterator
Sets the iteration mode for this Row Iterator. See Iteration Modes above for details on iteration mode which controls how the range behaves when it reaches the end of the Row Set.
Specified by:
setIterMode in interface RowIterator
Following copied from interface: oracle.jbo.RowIterator
Parameters:
mode - should be ITER_MODE_LAST_PAGE_PARTIAL if the iteration mode is to be "partial-last-page", ITER_MODE_LAST_PAGE_FULL if it is to be "full-last-page".

getListenersList

protected com.sun.java.util.collections.ArrayList getListenersList()

addListener

public void addListener(java.lang.Object target)
Description copied from interface: NavigatableRowIterator
Adds a subscriber (listener) to be notified of RowSetListener events generated by this row set iterator.
Specified by:
addListener in interface NavigatableRowIterator
Following copied from interface: oracle.jbo.NavigatableRowIterator
Parameters:
listener - the subscriber to be added. It should implement RowSetListener.

removeListener

public void removeListener(java.lang.Object target)
Description copied from interface: NavigatableRowIterator
Removes a subscriber (listener) for RowSetListener events generated by this row set iterator.
Specified by:
removeListener in interface NavigatableRowIterator
Following copied from interface: oracle.jbo.NavigatableRowIterator
Parameters:
listener - the subscriber to be removed.

trimNoDataRows

public void trimNoDataRows()

Business Components