Accessors for class IliDataSource

Properties

Methods

Callbacks

Description

The IliDataSource class defines a gadget that holds an IliTable object and that can manage a set of "data source aware" gadgets located in one or more panels (containers). Each of these gadgets is connected to a column of the table. Note that there is one exception. The IliTableGadget can connect to a data source but it is not connected to a particular column. In addition, the data source acts like a cursor in the table, because at any point in time it is positioned on a particular row of the table. Methods are provided that enable the data source to move to the next or previous row, and so on.
Among the most important properties of a data source are:
Each time the current row index of a data source is changed to a new value, the data source row buffer is updated with a copy of the values found in the designated table row. If the new current row does not designate a valid row in the table, the row buffer is updated with null values. The data source's inputModified property is also set to false.
At this time any data source aware gadgets that are connected to the data source are updated according to the row buffer.
The user can then edit the values displayed in the data source aware gadgets or, alternatively, the row buffer can be modified by a Rogue Wave Views Script function (running on behalf of a callback). The data source's inputModified property is set to true at this time. Any new values edited by the user in the data source aware gadgets are copied to their corresponding position in the row buffer.
Later, the user can call the validate method. This will trigger some system-defined and some application-defined checks on the contents of the row buffer. (See the ValidateRow, PrepareInsert, and PrepareUpdate callbacks for more information.) If the checks succeed, either a new row is inserted in the table or the table row is updated from the data source row buffer depending on whether the current row is the insert row or not. The inputModified property is set to false. If the checks fail, any appropriate error messages are shown to the user, and the data source remains in the same state as just before the validation attempt. The inputModified property is still true and the row buffer still holds the values that resulted from the user editing the gadgets. As an alternative to using the validate method, the user may call the cancel method. In this case, the contents of the row buffer are dismissed. The row buffer is updated from the existing table row or with null values if the new current row index does not designate a valid row in the table. Any data source aware gadgets are then updated with values from the row buffer. The inputModified property is set to false. The data source has a data source column for each table column of the managed table. These data source columns belong to class IliDataSourceColumn. They can be obtained by calling one of the getColumn or getColumnAt methods. They also become properties of the data source and can be directly accessed as such using the dot notation. Each data source column contains a value property that holds the row buffer's value for the corresponding table column. The following example computes a total price and stores it in a data source's row buffer:
     dataSource.gotoRow(0);
     writeln(dataSource.inputModified); // prints "false"

     var qty = dataSource.QTY.value;
     var itemPrice = dataSource.ITEM_PRICE.value;
     dataSource.TOTAL_PRICE.value = qty * itemPrice;

     writeln(dataSource.inputModified); // prints "true"

Errors

There are many situations where you may want to manage errors in relation to a data source:
To generate errors, see the ValidateRow callback, the addError method, and the addErrorMessage method. Catching and reporting errors is done by standard Rogue Wave Views Data Access gadgets such as the IliDbNavigator or the IliTableGadget. For example, if you validate a data source by clicking on the Validate button in a DbNavigator, the DbNavigator gadget takes care of catching any errors and reporting them. The same is true if you edit the data through a table gadget. If you want to add a menu item that does some specific work with the data source, you need to use the addErrorSink, removeErrorSink, and reportErrors methods if you want errors to be shown. As an example, assume you have a button in a panel and you need to code its callback so that it scans all rows in a data source and deletes rows having a negative balance. You want to catch any errors that may occur and display a dialog box showing these errors when you are finished. Here is how it can be done:
     function RemoveSomeRows(btn) {
        var ds = IliRepository.ACCOUNT_DS;
	
        // install an error sink
        var errors = new IliErrorList;
        ds.addErrorSink(errors);
	
        // do whatever needs to be done with the data-source
        ds.gotoRow(0);
        while (ds.currentRow < ds.rowsCount) {
          if (ds.BALANCE.value < 0) 
            ds.deleteCurrentRow();
        }

        // display errors if any
        ds.removeErrorSink(errors);
        ds.reportErrors(errors);
   
        // we return true if there were no errors
        return (errors.errorsCount == 0);
     }

Callbacks

There are a number of callbacks that can be used to customize a data source. Be aware that these callbacks are called in very specific contexts that are explained in the description for each callback. Consequently, great care should be taken not to call, directly or indirectly, methods that would completely change the context in which the callback was called. For instance, one should not call the gotoRow method from inside a ValidateRow callback since it is assumed that the row validation is not yet finished at this stage. When the state of a data source can be changed in a particular way, the description of the callback mentions it. For instance, the ValidateRow callback may change values in the row buffer before the row is sent to the underlying table.

TypeNameDescriptionNotes
BooleanautoRowLockingEnabledContains true if the data source automatically calls refreshAndLockRow on the underlying table as soon as an attempt is made to modify an existing row. This is useful when using IliSQLTable objects in order to implement the "pessimistic concurrency control policy". (See IliSQLTable::concurrencyControl for more information.) Initially, this property is false.
BooleanautoSelectEnabledWhen this property is true, the data source automatically calls the select method if a given event occurs. The table of a data source may have parameters defined. Some of these parameters may have been mapped on another data source. It can be said that a data source depends on other data sources through the parameters of its table. Therefore, if the autoSelectEnabled property is true, the data source will call the select method whenever one of the data sources on which it depends undergoes a current row change. Initially, this property is set to false.
IntcolumnsCountContains the number of columns in the table.read-only
IntcurrentRowContains the position (counting from 0) of the current row. It contains -1 if the data source is not positioned on any row and a value equal to the value of the rowsCount property if it is positioned on the insert row.
IntdeletedRowContains the row position that is to be deleted.read-only
IntfetchedRowContains the row position that is fetched.read-only
BooleaninputModifiedContains true when the current row has been modified by the user and these changes have not yet been validated.read-only
BooleaninsertEnabledContains true if new rows can be inserted in the table through the data source. Initially, this property is set to true.
BooleanreadOnlyThis property is true if the data source is read-only.
IntrowsCountContains the number of rows in the table.read-only
IliTabletableContains the table object managed by the data source.read-only
StringtablePropertyManagerNameContains the name of the table property manager used by the data source or null if the default table property manager is used. Initially, this property is null.
BooleanuseTablePropertiesContains true if the data source uses table properties. Initially, this property is true.
VoidaddError(String message)Forwards an application error message to all the error sinks that have been added with the addErrorSink function.
VoidaddErrorMessage(IliErrorMessage message)Forwards an application error message to all the error sinks that have been added with the addErrorSink function.
VoidaddErrorSink(Object sink)Adds an error sink to the data source. When an error occurs, it will be forwarded to this error sink. The sink parameter can be either:
  • An IliErrorList object

         var errList = new IliErrorList
         ds.addErrorSink(errList);
    

  • An IliObserver object whose func property contains a Rogue Wave Views Script function having the following signature: fct(IliErrorMessage msg)

         function OnError(errorMsg) {
            writeln(errorMsg.prettyMessage);
         }
         ds.addErrorSink(new IliObserver(OnError));
    
BooleanapplyQueryMode()Applies the query that the user specified while in query mode. The original data source table is restored and its select method is called. This method returns true if successful. Any errors that occur will be reported to the user by calling the reportErrors method.
BooleanapplyQueryModeSilently()This method is similar to the applyQueryMode method except that errors will not be reported to the user.
Voidcancel()Cancels any user input awaiting validation. The contents of the row buffer are discarded, the current row is read back from the table and its values are copied into the data source's row buffer, and the inputModified property is set to false. The CancelEdits callback is called.
VoidcancelQueryMode()Cancels query mode by restoring the original data source table.
Voidclear()Calls table.clearRows. Any pending user input is first canceled by this method.
BooleandeleteCurrentRow()Deletes the current row of the data source as long as the current row is an actual row. It returns true if successful. Before the row deletion, the PrepareDelete callback is called, which can prevent any further processing of the deletion by calling the dontDeleteRow method.
VoiddontDeleteRow()Called from the PrepareDeleteRow callback. It stops the deletion of the row whose position is given by the deletedRow property. The addError method should be called to provide the user with a descriptive error message.
VoiddontValidateRow()Called from either the ValidateRow, PrepareUpdate, or PrepareInsert callbacks. It stops the row validation from proceeding. The addError method should be called to provide the user with a descriptive error message.
IliDataSourceColumngetColumn(String colname)Returns the description of the column named colname. Note that the columns become properties of the data source so that the following expressions are equivalent:
     dataSource.getColumn("NAME")
     dataSource.NAME

IliDataSourceColumngetColumnAt(Int colno)Returns the description of the column positioned at colno.
BooleangotoFirst()Changes the current row of the data source to the first row of the table after validating any pending user input. It returns true if successful.
BooleangotoLast()Changes the current row of the data source to the insert row if insertion is allowed or to the last row if not. Any pending user input is first validated by this method. It returns true if successful.
BooleangotoNext()Changes the current row of the data source to the next row, after validating any pending user input. If the current row is the last row of the table and if insertion is allowed, the current row changes to the insert row. It returns true if successful.
BooleangotoPrevious()Changes the current row of the data source to the previous row (as long as the current row is not the first row). Any pending user input is first validated by this method. It returns true if successful.
BooleangotoRow(Int rowno)Changes the current row of the data source to the row designated by rowno. If rowno equals -1, the data source will not be positioned on any row. If rowno equals the value of the rowsCount property, the current row will change to the insert row. Any pending user input is first validated by this method. It returns true if successful.
BooleanisCurrentRowNull()Returns true if the row buffer contains null for each row.
BooleanisInQueryMode()Returns true if the data source is currently in query mode.
BooleanisOnInsertRow()Returns true if the current row is the insert row.
BooleanisQueryModeSupported()Returns true if the data source table supports query mode.
BooleanrefreshAndLockCurrentRow(Boolean keepCurrentChanges)This method does the same thing as the refreshCurrentRow method. In addition, if the remote database supports it, the remote row that corresponds to the current row is locked so that other users cannot modify or delete it as long as the lock is held. See the descriptions of the IliTable::refreshAndLockRow method and the IliSQLTable class for more information on row locking.
This method returns true if successful.
BooleanrefreshCurrentRow(Boolean keepCurrentChanges)If the underlying table is a two-tier table, this method re-reads the current row's values from the remote database. If the optional keepCurrentChanges parameter is given the value true, any columns of the data source that contain changes awaiting validation will not be re-read. Only unchanged columns will be updated. If keepCurrentChanges is false or if it is omitted, all columns are updated without regard to the "modified" state. With a one-tier table, this method does nothing. This method returns true if successful.
VoidremoveErrorSink(Object sink)Removes an error sink.
VoidreportErrors(IliErrorList errorList)Reports the errors that are in the error list.
Booleanselect()Calls table.select() and then moves to the first row of the table. Any pending user input is canceled by this method. It returns true if successful.
BooleanstartInsert()Changes the current row of the data source to the insert row if insertion is allowed. Any pending user input is canceled by this method. It returns true if successful.
BooleanswitchToQueryMode()If query mode is supported, this method changes the data-source's table to a special memory table dedicated to contain query conditions. It returns true if successful.
Booleanvalidate()Validates the current row returning true if successful. Validation is carried out in the following manner:
  • If the row buffer of the data source is unmodified, validation succeeds immediately.

  • Otherwise, system defined constraints are checked on the current row buffer. If these constraints are not satisfied, validation fails.

  • The ValidateRow callback is called. It checks any application defined constraints and if these are not satisfied, it calls the dontValidateRow method. In this case, validation fails.

  • One of the PrepareInsert or PrepareUpdate callbacks is called depending on whether the current row is the insert row.

  • A new row is then inserted into the underlying table depending on whether the current row is the insert row. If successful, one of the QuitInsertMode or QuitUpdateMode callback is called and true is returned.

If successful, the current row is read back from the table, its values are copied into the data source's row buffer, and the inputModified property is set to false.
If this method fails, it shows any error messages to the user by calling the reportErrors method.
BooleanvalidateSilently()Performs validation in the same manner as the validate method but does not show error messages to the user.
CallbackCancelEditsCalled just after the edits in the current row have been cancelled.
CallbackDeleteRowCalled just before a row in the underlying table is deleted. The index of the row that is to be deleted can be obtained by looking at the deletedRow property.
CallbackEnterInsertModeCalled just after the current row buffer becomes modified when the current row is the insert row.
CallbackEnterModifiedStateCalled just after the data source changes its state from "not-modified" to "modified". This typically happens when the end user starts modifying a field connected to the data source or when the setValue member function is called.
This callback can be used to check that it is possible to enter the modified state at the present time. If not, it calls the cancel member function.
Note that it would not be possible to use the EnterUpdateMode or EnterInsertMode callbacks for this purpose since they are called before the state of the data source changes (and hence calling cancel would not have any effect in this case).
CallbackEnterRowCalled just after a new row is entered.
CallbackEnterUpdateModeCalled just after the current row buffer becomes modified when the current row is not the insert row.
CallbackFetchRowCalled just after a new row has been retrieved from a remote database and cached in the underlying table. The index of the row that has just been fetched can be obtained by looking at the fetchedRow property.
Here is an example of a FetchRow callback:
     var counter = 0;
     function OnFetchRow(ds) {
        var column = ds.COUNTER.tableColumn;
        column.setInCache(ds.fetchedRow, 
                          ++counter);
     }

Note how it uses the setInCache method of class IliTableColumn to store a value in the local row cache of the table object.
CallbackPrepareDeleteRowCalled when the user attempts to delete a row through the data source. The index of the row that is to be deleted can be obtained by looking at the deletedRow property.
The row deletion can be prevented by calling the dontDeleteRow method. In addition, the addErrorMessage member function may be called to describe the reason for the failure.
Here is an example of a PrepareDeleteRow callback:
     function OnPrepareDeleteRow(ds) {
        if (ds.deletedRow == 0) {
          ds.dontDeleteRow();
          ds.addError("Leaf node cannot be deleted.");
        }
     }
CallbackPrepareInsertCalled when an attempt is made to validate the current row when the current row is not the insert row. This callback is called in addition to the ValidateRow callback. The row validation can be prevented by calling the dontValidateRow method. In this case, the addErrorMessage method should also be called to provide an error message to the user. Alternatively, it is possible to change some of the values in the current row before it is inserted in the underlying table.
CallbackPrepareUpdateCalled when an attempt is made to validate the current row when the current row is not the insert row. This callback is called in addition to the ValidateRow callback. The row validation can be prevented by calling the dontValidateRow method. In this case, the addErrorMessage method should also be called to provide an error message to the user. Alternatively, it is possible to change some of the values in the current row before it is updated in the underlying table.
CallbackQuitInsertModeCalled just after the current row has been successfully validated when the current row is the insert row.
CallbackQuitRowCalled just before the selection moves out of a row.
CallbackQuitUpdateModeCalled just after the current row has been successfully validated when the current row is not the insert row.
CallbackValidateRowCalled when an attempt is made to validate the current row. The row validation can be prevented by calling the dontValidateRow method. In this case, the addErrorMessage method should also be called to provide an error message to the user. Alternatively, it is possible to change some of the values in the current row before it is transmitted to the underlying table. This callback is called when an existing row is being updated or when a new row is being inserted.
Here is an example of a ValidateRow callback:
     function OnValidateRow(ds) {
        var capacity = ds.CAPACITY.value;
        var volume = ds.VOLUME.value;
        if (volume > capacity) {
           ds.dontValidateRow();
           ds.addError("Volume must be less than Capacity");
        }
        else {
           ds.LASTMODIF.value = new Date();
        }
     }