Child pages
  • ViewFoundSet
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Refresh page Apr 26, 2024 13:50

Supported Clients
SmartClient WebClient NGClient

Constants Summary
Number MONITOR_AGGREGATES Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for aggregates that are in the results of the given datasource.
Number MONITOR_COLUMNS Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource.
Number MONITOR_DELETES Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for deletes on the given table/datasource.
Number MONITOR_DELETES_FOR_PRIMAIRY_TABLE Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for deletes on the given table/datasource which should be the primary/main table of this query.
Number MONITOR_INSERT Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for inserts on the given table/datasource.
Number MONITOR_JOIN_CONDITIONS Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource in the join statement Like order_lines.
Number MONITOR_WHERE_CONDITIONS Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource that are used in the where statement.

Property Summary
Boolean multiSelect Returns true if this foundset is in multiselect mode and false if it's in single-select mode.
void setMultiSelect Puts this foundset in multi-select or single-select mode.

Methods Summary
void enableDatabroadcastFor(queryTable) Databroadcast can be enabled per select table of a query, the select table can be the main QBSelect or on of it QBJoins By default this monitors only the column values that are in the result of the QBSelect, you can only enable this default monitoring for a table if for that table also the PK is selected in the results.
void enableDatabroadcastFor(queryTable, flags) Enable the databroadcast for a specific table of the QBSelect or QBJoin with flags for looking for join or where criteria or deletes/inserts.
Object forEach(callback) Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
Object forEach(callback, thisObject) Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
String getDataSource() The datasource this foundset is build on
QBSelect getQuery() Get the cloned query that created this ViewFoundSset (modifying this QBSelect will not change the foundset).
JSRecord getRecord(row)
JSRecord getSelectedRecord()
Number getSize() Get the size of present cached row identifiers (primary keys)
void loadAllRecords() This will reload the current set of ViewRecords in this foundset, resetting the chunk size back to the start (default 200).
Number save() Saves all records in the view foundset that have changes.
Number save(record) Saved a specific record of this foundset.
void sort(recordComparisonFunction) Sorts the foundset based on the given record comparator function.

Constants Details

MONITOR_AGGREGATES

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for aggregates that are in the results of the given datasource.
 This means that when there are updates on that specific column where the aggregate is on  or deletes, inserts on give datasource, a full requery will happen to refresh the aggregate.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_COLUMNS

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource.
This is used by default  if you just use enableDatabroadcastFor() without flags.  If you use the one with the flags you need to give this one if you just
 want to listen to column changes that are in the result for a given datasource and pk.
 This constants needs to have the pk's selected for the given datasource (should be in the results)

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_DELETES

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for deletes on the given table/datasource.
This will always result in a full query to detect changes whenever an delete  on that table happens.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_DELETES_FOR_PRIMAIRY_TABLE

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for deletes on the given table/datasource which should be the primary/main table of this query.
If a delete comes in for this table, then we will only remove the records from the ViewFoundSet that do have this primary key in its value. So no need to do a full query.
So this will only work if the query shows order_lines for the order_lines table, not for the products table that is joined to get the product_name.
Only 1 of the 2 monitors for deletes should be registered for a table/datasource.
This constants needs to have the pk's selected for the given datasource (should be in the results)

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_INSERT

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen for inserts on the given table/datasource.
This will always result in a full query to detect changes whenever an insert on that table happens.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_JOIN_CONDITIONS

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource in the join statement
Like order_lines.productid that has a join to orders and is displaying the productname.
If a change in such a join condition (like order_lines.productid in the sample above) is seen then the query will be fired again to detect changes.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

MONITOR_WHERE_CONDITIONS

Constant for the flags in #enableDatabroadcastFor(QBTableClause,int) to listen also for column changes of the given table/datasource that are used in the where statement.
Like order_lines.unit_price > 100. If a change is seen on that datasource on such a column used in the where a full query will be fired again to detect changes.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

Property Details

multiSelect

Returns true if this foundset is in multiselect mode and false if it's in single-select mode.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

setMultiSelect

Puts this foundset in multi-select or single-select mode. If this foundset is shown in a form, this call can be
ignored as the form decides the foundset's multiselect.

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

Methods Details

enableDatabroadcastFor(queryTable)

Databroadcast can be enabled per select table of a query, the select table can be the main QBSelect or on of it QBJoins
By default this monitors only the column values that are in the result of the QBSelect, you can only enable this default monitoring for a table if for that table also the PK is selected in the results.

you can use #enableDatabroadcastFor(QBTableClause,int) to specify what should be monitored more besides pure column values per pk.
Those have impact on performance because for the most part if we see a hit then a full query is done to see if there are changes.

Parameters

QBTableClause queryTable The QBSelect or QBJoin of a full query where this foundset should listenn for data changes.

Supported Clients

SmartClient,WebClient,NGClient

Sample

var select = datasources.db.example_data.order_details.createSelect();
 var join = select.joins.add("db:/example_data/products");
 join.on.add(select.columns.productid.eq(join.columns.productid));
 select.result.add(); // add colums of the select or join
 var vf = databaseManager.getViewFoundSet("myorders",select)
 vf.enableDatabroadcastFor(select);
 vf.enableDatabroadcastFor(join);

enableDatabroadcastFor(queryTable, flags)

Enable the databroadcast for a specific table of the QBSelect or QBJoin with  flags for looking for join or where criteria or deletes/inserts.
These  flags can be a performance hit because the query needs to be executed again to see if there are any changes.
For certain flags #MONITOR_COLUMNS and #MONITOR_DELETES_FOR_PRIMAIRY_TABLE the pk for that table must be in the results.

Parameters

QBTableClause queryTable The QBSelect or QBJoin of a full query where this foundset should listenn for data changes.
Number flags One or more of the ViewFoundSet.XXX flags added to each other.

Supported Clients

SmartClient,WebClient,NGClient

Sample

var select = datasources.db.example_data.order_details.createSelect();
 var join = select.joins.add("db:/example_data/products");
 join.on.add(select.columns.productid.eq(join.columns.productid));
 select.result.add(); // add colums of the select or join
 var vf = databaseManager.getViewFoundSet("myorders",select)
 // monitor for the main table the join conditions (orders->product, when product id changes in the orders table) and requery the table on insert events, delete directly the record if a pk delete happens.
 vf.enableDatabroadcastFor(select,,ViewFoundSet.MONITOR_JOIN_CONDITIONS | ViewFoundSet.MONITOR_INSERT | ViewFoundSet.MONITOR_DELETES_FOR_PRIMAIRY_TABLE);
 vf.enableDatabroadcastFor(join);

forEach(callback)

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned.
If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function.
If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating.
When an exception is thrown from the callback function, the iteraion over the foundset will be stopped.

Parameters

Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

forEach(callback, thisObject)

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned.
If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function.
If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating.
When an exception is thrown from the callback function, the iteraion over the foundset will be stopped.

Parameters

Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.
Object thisObject What the this object should be in the callback function (default it is the foundset)

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

getDataSource()

The datasource this foundset is build on

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

getQuery()

Get the cloned query that created this ViewFoundSset (modifying this QBSelect will not change the foundset).
The ViewFoundSets main query can't be altered after creation; you need to make a new ViewFoundSet for that (it can have the same datasource name).

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

var q = foundset.getQuery()
q.where.add(q.columns.x.eq(100))
var newVF = databaseManager.getViewFoundset("name", q);

getRecord(row)

Parameters

Number row ;

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

getSelectedRecord()

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

getSize()

Get the size of present cached row identifiers (primary keys)

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

loadAllRecords()

This will reload the current set of ViewRecords in this foundset, resetting the chunk size back to the start (default 200).
All edited records will be discarded! So this can be seen as a full clean up of this ViewFoundSet.

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

save()

Saves all records in the view foundset that have changes.
You can only save columns from a table if the pks of that table are also selected by the view foundset's query.

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

save(record)

Saved a specific record of this foundset.
You can only save columns from a table if also the pk is selected of that table

Parameters

JSRecord record ;

Returns

Supported Clients

SmartClient,WebClient,NGClient

Sample

 

sort(recordComparisonFunction)

Sorts the foundset based on the given record comparator function.
Tries to preserve selection based on primary key. If first record is selected or cannot select old record it will select first record after sort.
The comparator function is called to compare
two records, that are passed as arguments, and
it will return -1/0/1 if the first record is less/equal/greater
then the second record.

The function based sorting does not work with printing.
It is just a temporary in-memory sort.

NOTE: starting with 7.2 release this function doesn't save the data anymore

Parameters

Function recordComparisonFunction record comparator function

Supported Clients

SmartClient,WebClient,NGClient

Sample

%%prefix%%foundset.sort(mySortFunction);

function mySortFunction(r1, r2)
{
	var o = 0;
	if(r1.id < r2.id)
	{
		o = -1;
	}
	else if(r1.id > r2.id)
	{
		o = 1;
	}
	return o;
}

  • No labels