Database Manager
Return Types
SQL_ACTION_TYPES,JSColumn,JSDataSet,JSFoundSetUpdater,JSRecordMarker,JSRecordMarkers,JSRecord,JSFoundSet,JSTable,QBSelect,QBColumn,QBCase,QBCaseWhen,QBColumn,QBColumns,QBCondition,QBColumn,QBGroupBy,QBJoin,QBJoins,QBLogicalCondition,QBLogicalCondition,QBResult,QBColumn,QBSort,QBSorts,QBTableClause,QBPart,QBParameter,QBParameters,QBFunctions,QUERY_COLUMN_TYPES,JSFoundSet,JSRecord,JSTableFilter,
Property Summary
Type | Name | Summary |
---|---|---|
Enable/disable the foundset behaviour to keep selection to the first row always, even if updates from other clients are received that add new records before the current first record.. | ||
Enable/disable the automatic prefetching of related foundsets for sibling records.. | ||
Enable/disable the default null validator for non null columns, makes it possible to do the checks later on when saving, when for example autosave is disabled.. |
Methods Summary
Type | Name | Summary |
---|---|---|
Request lock(s) for a foundset, can be a normal or related foundset.. | ||
Request lock(s) for a foundset, can be a normal or related foundset.. | ||
Adds a filter based on a query to all the foundsets based on a table.. | ||
Adds a filter based on a query to all the foundsets based on a table.. | ||
Adds a filter to all the foundsets based on a table.. | ||
Adds a filter to all the foundsets based on a table.. | ||
Adds a filter to all the foundsets based on a table.. | ||
Adds a filter to all the foundsets based on a table.. | ||
void | Add tracking info used in the log table.. | |
Returns true if a transaction is committed; rollback if commit fails.. | ||
Returns true if a transaction is committed; rollback if commit fails.. | ||
Returns true if a transaction is committed; rollback if commit fails.. | ||
Creates a foundset that combines all the records of the specified one-to-many relation seen from the given parent/primary foundset.. | ||
Creates a foundset that combines all the records of the specified one-to-many relation seen from the given parent/primary foundset.. | ||
Converts the argument to a JSDataSet, possible use in controller.. | ||
Converts the argument to a JSDataSet, possible use in controller.. | ||
Converts the argument to a JSDataSet, possible use in controller.. | ||
Converts the argument to a JSDataSet, possible use in controller.. | ||
Converts the argument to a JSDataSet, possible use in controller.. | ||
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names).. | ||
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names).. | ||
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names).. | ||
Performs a query and saves the result in a datasource.. | ||
Performs a query and saves the result in a datasource.. | ||
Performs a query and saves the result in a datasource.. | ||
Performs a query and saves the result in a datasource.. | ||
Performs a sql query on the specified server, saves the the result in a datasource.. | ||
Performs a sql query on the specified server, saves the the result in a datasource.. | ||
Performs a sql query on the specified server, saves the the result in a datasource.. | ||
Returns an empty dataset object.. | ||
Returns an empty dataset object.. | ||
Returns an empty dataset object.. | ||
Create a QueryBuilder object for a datasource.. | ||
Create a QueryBuilder object for a datasource with given table alias.. | ||
Create a table filter that can be applied to all the foundsets based on a table.. | ||
Create a table filter that can be applied to all the foundsets based on a table.. | ||
Create a table filter that can be applied to all the foundsets based on a table.. | ||
Check wether a data source exists.. | ||
void | This method differences for recalculate() that it only works on a datasource rows/records that are loaded in memory.. | |
void | This method differences for recalculate() that it only works on a datasource rows/records that are loaded in memory.. | |
Returns true or false if autosave is enabled or disabled.. | ||
Retrieves a list with names of all database servers that have property DataModelCloneFrom equal to the server name parameter.. | ||
Performs a sql query with a query builder object.. | ||
Performs a sql query with a query builder object.. | ||
Performs a sql query on the specified server, returns the result in a dataset.. | ||
Returns the datasource corresponding to the given server/table.. | ||
Returns the server name from the datasource, or null if not a database datasource.. | ||
Returns the table name from the datasource, or null if not a database datasource.. | ||
Returns the database product name as supplied by the driver for a server.. | ||
Returns an array of edited records with outstanding (unsaved) data.. | ||
Returns an array of edited records with outstanding (unsaved) data.. | ||
Returns an array of edited records with outstanding (unsaved) data.. | ||
Returns an array of edited records with outstanding (unsaved) data for a datasource with a filter.. | ||
Returns an array of records that fail after a save.. | ||
Returns an array of records that fail after a save.. | ||
Returns a foundset object for a specified pk base query.. | ||
Returns a foundset object for a specified datasource or server and tablename.. | ||
Returns a foundset object for a specified datasource or server and tablename.. | ||
Returns the total number of records in a foundset.. | ||
Returns a JSFoundsetUpdater object that can be used to update all or a specific number of rows in the specified foundset.. | ||
Gets the next sequence for a column which has a sequence defined in its column dataprovider properties.. | ||
Returns an array with all the server names used in the solution.. | ||
Returns the JSTable object from which more info can be obtained (like columns).. | ||
Returns the JSTable object from which more info can be obtained (like columns).. | ||
Returns the JSTable object from which more info can be obtained (like columns).. | ||
Returns the JSTable object from which more info can be obtained (like columns).. | ||
Returns the total number of records(rows) in a table.. | ||
Returns a two dimensional array object containing the table filter information currently applied to the servers tables.. | ||
Returns a two dimensional array object containing the table filter information currently applied to the servers tables.. | ||
Returns an array of all table names for a specified server.. | ||
Returns a ViewFoundSet that was created by getViewFoundSet(name,query,register) with the registerd boolean "true".. | ||
Returns a foundset object for a specified query.. | ||
Returns a foundset object for a specified query.. | ||
Returns an array of all view names for a specified server.. | ||
Returns true if the current client has any or the specified lock(s) acquired.. | ||
Returns true if the current client has any or the specified lock(s) acquired.. | ||
Returns true if the argument (foundSet / record) has at least one row that was not yet saved in the database.. | ||
Returns true if the argument (foundSet / record) has at least one row that was not yet saved in the database.. | ||
Returns true if the specified foundset, on a specific index or in any of its records, or the specified record has changes or is new unsaved record.. | ||
Returns true if the specified foundset, on a specific index or in any of its records, or the specified record has changes or is new unsaved record.. | ||
Returns true if the (related)foundset exists and has records.. | ||
Returns true if the (related)foundset exists and has records.. | ||
Returns true if there is an transaction active for this client.. | ||
Merge records from the same foundset, updates entire datamodel (via foreign type on columns) with destination record pk, deletes source record.. | ||
Merge records from the same foundset, updates entire datamodel (via foreign type on columns) with destination record pk, deletes source record.. | ||
void | Can be used to recalculate a specified record or all rows in the specified foundset.. | |
Flushes the client data cache and requeries the data for a record (based on the record index) in a foundset or all records in the foundset.. | ||
Release all current locks the client has (optionally limited to named locks).. | ||
Release all current locks the client has (optionally limited to named locks).. | ||
Free resources allocated for a previously created data source.. | ||
Removes a previously defined table filter.. | ||
void | Reverts outstanding (not saved) in memory changes from edited records.. | |
void | Reverts outstanding (not saved) in memory changes from edited records.. | |
void | Rollback a transaction started by databaseManager.. | |
void | Rollback a transaction started by databaseManager.. | |
void | Rollback a transaction started by databaseManager.. | |
Saves all outstanding (unsaved) data and exits the current record.. | ||
Saves all outstanding (unsaved) data and exits the current record.. | ||
Saves all outstanding (unsaved) data and exits the current record.. | ||
Saves all outstanding (unsaved) data and exits the current record.. | ||
Set autosave, if false then no saves will happen by the ui (not including deletes!).. | ||
void | Turnoff the initial form foundset record loading, set this in the solution open method.. | |
Apply multiples table filters to all the foundsets that arte affected by the filters.. | ||
void | Start a database transaction.. | |
Switches a named server to another named server with the same datamodel (recommended to be used in an onOpen method for a solution).. | ||
Validates the given record, it runs first the method that is attached to the entity event "onValidate".. | ||
Validates the given record, it runs first the method that is attached to the entity event "onValidate".. |
Properties Details
alwaysFollowPkSelection
Enable/disable the foundset behaviour to keep selection to the first row always, even if updates from other clients are received that add new records before the current first record.
If set to false [default], a foundset with selection on first record will keep the selected index to 1, but may change the selected record when a new record is received from another client. If set to true, the selected index may change but the selected record will be kept if possible.
Returns Boolean
Sample
disableRelatedSiblingsPrefetch
Enable/disable the automatic prefetching of related foundsets for sibling records.
For example, when orders from a record in a customer foundset are retrieved, already the orders of a few sibling records are also prefetched. This is the default behaviour and in most situations this better for performance in user interfaces.
In some situations performance can be better if this property is set to false to prevent queries for data that is never used.
Returns Boolean
Sample
nullColumnValidatorEnabled
Enable/disable the default null validator for non null columns, makes it possible to do the checks later on when saving, when for example autosave is disabled.
Returns Boolean
Sample
Methods Details
acquireLock(foundset, recordIndex)
Request lock(s) for a foundset, can be a normal or related foundset. The record_index can be -1 to lock all rows, 0 to lock the current row, or a specific row of > 0 Optionally name the lock(s) so that it can be referenced it in releaseAllLocks()
By default this call doesn't try to lock records in the database itself. But the locks are tracked in the Servoy Server itself. If you need database locking because of others applications that can also read the table or you use the Broadcaster plugin for more then 1 servoy server on the same database, you need to set the property 'servoy.record.lock.lockInDB' in the servoy.properties file to true. This will try to do a 'select for update no wait' on databases that supports this. This can only be used together with a transaction, so before you aquire the lock a transaction must be started so the database lock is held on to the transaction connection.
Do not change the record data before that, because aquirelock will make sure with a select from the database that it really has the latest data. If there are changes to columns that you changed before calling aquireLock these changes will be reverted, so you don't change something again that you didn't see really the value of first.
returns true if the lock could be acquired.
Parameters JSFoundSet foundset The JSFoundset to get the lock for Number recordIndex The record index which should be locked.
Returns Boolean true if the lock could be acquired.
Sample
acquireLock(foundset, recordIndex, lockName)
Request lock(s) for a foundset, can be a normal or related foundset. The record_index can be -1 to lock all rows, 0 to lock the current row, or a specific row of > 0 Optionally name the lock(s) so that it can be referenced it in releaseAllLocks()
By default this call doesn't try to lock records in the database itself. But the locks are tracked in the Servoy Server itself. If you need database locking because of others applications that can also read the table or you use the Broadcaster plugin for more then 1 servoy server on the same database, you need to set the property 'servoy.record.lock.lockInDB' in the servoy.properties file to true. This will try to do a 'select for update no wait' on databases that supports this. This can only be used together with a transaction, so before you aquire the lock a transaction must be started so the database lock is held on to the transaction connection.
Do not change the record data before that, because aquirelock will make sure with a select from the database that it really has the latest data. If there are changes to columns that you changed before calling aquireLock these changes will be reverted, so you don't change something again that you didn't see really the value of first.
returns true if the lock could be acquired.
Parameters JSFoundSet foundset The JSFoundset to get the lock for Number recordIndex The record index which should be locked. String lockName The name of the lock.
Returns Boolean true if the lock could be acquired.
Sample
addTableFilterParam(query)
Adds a filter based on a query to all the foundsets based on a table.
Filters on tables touched in the query will not be applied to the query filter. For example, when a table filter exists on the order_details table, a query filter with a join from orders to order_details will be applied to queries on the orders table, but the filter condition on the orders_details table will not be included.
returns true if the table filter could be applied.
Parameters QBSelect query condition to filter on.
Returns Boolean true if the table filter could be applied.
Sample
addTableFilterParam(query, filterName)
Adds a filter based on a query to all the foundsets based on a table.
Filters on tables touched in the query will not be applied to the query filter. For example, when a table filter exists on the order_details table, a query filter with a join from orders to order_details will be applied to queries on the orders table, but the filter condition on the orders_details table will not be included.
returns true if the table filter could be applied.
Parameters QBSelect query condition to filter on. String filterName The specified name of the database table filter.
Returns Boolean true if the table filter could be applied.
Sample
addTableFilterParam(datasource, dataprovider, operator, value)
Adds a filter to all the foundsets based on a table. Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied. returns true if the table filter could be applied.
Parameters String datasource The datasource String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query. Object value The specified filter value.
Returns Boolean true if the table filter could be applied.
Sample
addTableFilterParam(datasource, dataprovider, operator, value, filterName)
Adds a filter to all the foundsets based on a table. Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied. returns true if the table filter could be applied.
Parameters String datasource The datasource String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query. Object value The specified filter value. String filterName The specified name of the database table filter.
Returns Boolean true if the table filter could be applied.
Sample
addTableFilterParam(serverName, tableName, dataprovider, operator, value)
Adds a filter to all the foundsets based on a table. Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied. returns true if the table filter could be applied.
Parameters String serverName The name of the database server connection for the specified table name. String tableName The name of the specified table. String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query. Object value The specified filter value.
Returns Boolean true if the table filter could be applied.
Sample
addTableFilterParam(serverName, tableName, dataprovider, operator, value, filterName)
Adds a filter to all the foundsets based on a table. Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied. returns true if the table filter could be applied.
Parameters String serverName The name of the database server connection for the specified table name. String tableName The name of the specified table. String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query.. Object value The specified filter value. String filterName The specified name of the database table filter.
Returns Boolean true if the table filter could be applied.
Sample
addTrackingInfo(columnName, value)
Add tracking info used in the log table. When tracking is enabled and a new row is inserted in the log table, if it has a column named 'columnName', its value will be set with 'value'
Parameters String columnName The name of the column in the log table, used for tracking info Object value The value to be set when inserting a new row in the log table, for the 'columnName' column
Returns void
Sample
commitTransaction()
Returns true if a transaction is committed; rollback if commit fails. Saves all edited records and commits the data.
Returns Boolean if the transaction could be committed.
Sample
commitTransaction(saveFirst)
Returns true if a transaction is committed; rollback if commit fails.
Parameters Boolean saveFirst save edited records to the database first (default true)
Returns Boolean if the transaction could be committed.
Sample
commitTransaction(saveFirst, revertSavedRecords)
Returns true if a transaction is committed; rollback if commit fails.
Parameters Boolean saveFirst save edited records to the database first (default true) Boolean revertSavedRecords if a commit fails and a rollback is done, the when given false the records are not reverted to the database state (and are in edited records again)
Returns Boolean if the transaction could be committed.
Sample
convertFoundSet(foundset, related)
Creates a foundset that combines all the records of the specified one-to-many relation seen from the given parent/primary foundset. The created foundset will not contain records that have not been saved in the database, because the records in the foundset will be the result of a select query to the database.
Parameters JSFoundSet foundset The JSFoundset to convert. JSFoundSet related can be a one-to-many relation object or the name of a one-to-many relation
Returns JSFoundSet The converted JSFoundset.
Sample
convertFoundSet(foundset, related)
Creates a foundset that combines all the records of the specified one-to-many relation seen from the given parent/primary foundset. The created foundset will not contain records that have not been saved in the database, because the records in the foundset will be the result of a select query to the database.
Parameters JSFoundSet foundset The JSFoundset to convert. String related the name of a one-to-many relation
Returns JSFoundSet The converted JSFoundset.
Sample
convertToDataSet(foundset)
Converts the argument to a JSDataSet, possible use in controller.loadRecords(dataset). The optional array of dataprovider names is used (only) to add the specified dataprovider names as columns to the dataset.
Parameters JSFoundSet foundset The foundset to be converted.
Returns JSDataSet JSDataSet with the data.
Sample
convertToDataSet(foundset, dataproviderNames)
Converts the argument to a JSDataSet, possible use in controller.loadRecords(dataset). The optional array of dataprovider names is used (only) to add the specified dataprovider names as columns to the dataset.
Parameters JSFoundSet foundset The foundset to be converted. Array dataproviderNames Array with column names.
Returns JSDataSet JSDataSet with the data.
Sample
convertToDataSet(values)
Converts the argument to a JSDataSet, possible use in controller.loadRecords(dataset). The optional array of dataprovider names is used (only) to add the specified dataprovider names as columns to the dataset.
Parameters Array values The values array.
Returns JSDataSet JSDataSet with the data.
Sample
convertToDataSet(values, dataproviderNames)
Converts the argument to a JSDataSet, possible use in controller.loadRecords(dataset). The optional array of dataprovider names is used (only) to add the specified dataprovider names as columns to the dataset.
Parameters Array values The values array. Array dataproviderNames The property names array.
Returns JSDataSet JSDataSet with the data.
Sample
convertToDataSet(ids)
Converts the argument to a JSDataSet, possible use in controller.loadRecords(dataset). The optional array of dataprovider names is used (only) to add the specified dataprovider names as columns to the dataset.
Parameters String ids Concatenated values to be put into dataset.
Returns JSDataSet JSDataSet with the data.
Sample
copyMatchingFields(source, destination)
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names). The matching requires the properties and getter functions of the source to match those of the destination; for the getter functions, the 'get' will be removed and the remaining name will be converted to lowercase before attempting to match. Returns true if no error occurred.
NOTE: This function could be used to store a copy of records in an archive table. Use the getRecord() function to get the record as an object. Before trying this example, please make sure that the foundsets have some records loaded:
Parameters Object source The source record or (java/javascript)object to be copied. JSRecord destination The destination record to copy to.
Returns Boolean true if no errors happened.
Sample
copyMatchingFields(source, destination, overwrite)
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names). The matching requires the properties and getter functions of the source to match those of the destination; for the getter functions, the 'get' will be removed and the remaining name will be converted to lowercase before attempting to match. Returns true if no error occurred.
NOTE: This function could be used to store a copy of records in an archive table. Use the getRecord() function to get the record as an object. Before trying this example, please make sure that the foundsets have some records loaded:
Parameters Object source The source record or (java/javascript)object to be copied. JSRecord destination The destination record to copy to. Boolean overwrite Boolean values to overwrite all values. If overwrite is false/not provided, then the non empty values are not overwritten in the destination record.
Returns Boolean true if no errors happened.
Sample
copyMatchingFields(source, destination, names)
Copies all matching non empty columns (if overwrite boolean is given all columns except pk/ident, if array then all columns except pk and array names). The matching requires the properties and getter functions of the source to match those of the destination; for the getter functions, the 'get' will be removed and the remaining name will be converted to lowercase before attempting to match. Returns true if no error occurred.
NOTE: This function could be used to store a copy of records in an archive table. Use the getRecord() function to get the record as an object. Before trying this example, please make sure that the foundsets have some records loaded:
Parameters Object source The source record or (java/javascript)object to be copied. JSRecord destination The destination record to copy to. Array names The property names that shouldn't be overriden.
Returns Boolean true if no errors happened.
Sample
createDataSourceByQuery(name, query, useTableFilters, max_returned_rows, types, pkNames)
Performs a query and saves the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name Data source name QBSelect query The query builder to be executed. Boolean useTableFilters use table filters (default true). Number max_returned_rows The maximum number of rows returned by the query. Array types The column types, when null the types are inferred from the query. Array pkNames array of pk names, when null a hidden pk-column will be added
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, query, max_returned_rows)
Performs a query and saves the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name data source name QBSelect query The query builder to be executed. Number max_returned_rows The maximum number of rows returned by the query.
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, query, max_returned_rows, types)
Performs a query and saves the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
Using this variation of createDataSourceByQuery any Tablefilter on the involved tables will be taken into account.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name Data source name QBSelect query The query builder to be executed. Number max_returned_rows The maximum number of rows returned by the query. Array types The column types
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, query, max_returned_rows, types, pkNames)
Performs a query and saves the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
Using this variation of createDataSourceByQuery any Tablefilter on the involved tables will be taken into account.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name Data source name QBSelect query The query builder to be executed. Number max_returned_rows The maximum number of rows returned by the query. Array types The column types Array pkNames array of pk names, when null a hidden pk-column will be added
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, server_name, sql_query, arguments, max_returned_rows)
Performs a sql query on the specified server, saves the the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
Using this variation of createDataSourceByQuery any Tablefilter on the involved tables will be disregarded.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name data source name String server_name The name of the server where the query should be executed. String sql_query The custom sql, must start with 'select', 'call', 'with' or 'declare'. Array arguments Specified arguments or null if there are no arguments. Number max_returned_rows The maximum number of rows returned by the query.
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, server_name, sql_query, arguments, max_returned_rows, types)
Performs a sql query on the specified server, saves the the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
Using this variation of createDataSourceByQuery any Tablefilter on the involved tables will be disregarded.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name data source name String server_name The name of the server where the query should be executed. String sql_query The custom sql, must start with 'select', 'call', 'with' or 'declare'. Array arguments Specified arguments or null if there are no arguments. Number max_returned_rows The maximum number of rows returned by the query. Array types The column types
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createDataSourceByQuery(name, server_name, sql_query, arguments, max_returned_rows, columnTypes, pkNames)
Performs a sql query on the specified server, saves the the result in a datasource. Will throw an exception if anything went wrong when executing the query. Column types in the datasource are inferred from the query result or can be explicitly specified.
Using this variation of createDataSourceByQuery any Tablefilter on the involved tables will be disregarded.
A datasource can be reused if the data has the same signature (column names and types). A new createDataSourceByQuery() call will clear the datasource contents from a previous call and insert the current data.
Parameters String name data source name String server_name The name of the server where the query should be executed. String sql_query The custom sql, must start with 'select', 'call', 'with' or 'declare'. Array arguments Specified arguments or null if there are no arguments. Number max_returned_rows The maximum number of rows returned by the query. Object columnTypes The column types Array pkNames array of pk names, when null a hidden pk-column will be added
Returns String datasource containing the results of the query or null if the parameters are wrong.
Sample
createEmptyDataSet()
Returns an empty dataset object.
Returns JSDataSet An empty JSDataSet with the initial sizes.
Sample
createEmptyDataSet(rowCount, columnCount)
Returns an empty dataset object.
Parameters Number rowCount The number of rows in the DataSet object. Number columnCount Number of columns.
Returns JSDataSet An empty JSDataSet with the initial sizes.
Sample
createEmptyDataSet(rowCount, columnNames)
Returns an empty dataset object.
Parameters Number rowCount ; Array columnNames ;
Returns JSDataSet An empty JSDataSet with the initial sizes.
Sample
createSelect(dataSource)
Create a QueryBuilder object for a datasource.
Parameters String dataSource The data source to build a query for.
Returns QBSelect query builder
Sample
createSelect(dataSource, tableAlias)
Create a QueryBuilder object for a datasource with given table alias. The alias can be used inside custom queries to bind to the outer table.
Parameters String dataSource The data source to build a query for. String tableAlias The alias for the main table.
Returns QBSelect query builder
Sample
createTableFilterParam(query)
Create a table filter that can be applied to all the foundsets based on a table. Multiple filters can be applied at the same time using databaseManager.setTableFilters().
Filters on tables touched in the query will not be applied to the query filter. For example, when a table filter exists on the order_details table, a query filter with a join from orders to order_details will be applied to queries on the orders table, but the filter condition on the orders_details table will not be included.
Parameters QBSelect query condition to filter on.
Returns JSTableFilter table filter.
Sample
createTableFilterParam(datasource, dataprovider, operator, value)
Create a table filter that can be applied to all the foundsets based on a table. Multiple filters can be applied at the same time using databaseManager.setTableFilters().
Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied.
Parameters String datasource The datasource String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query. Object value The specified filter value.
Returns JSTableFilter table filter.
Sample
createTableFilterParam(serverName, tableName, dataprovider, operator, value)
Create a table filter that can be applied to all the foundsets based on a table. Multiple filters can be applied at the same time using databaseManager.setTableFilters().
Note: if null is provided as the tablename the filter will be applied on all tables with the dataprovider name. A dataprovider can have multiple filters defined, they will all be applied.
Parameters String serverName The name of the database server connection for the specified table name. String tableName The name of the specified table. String dataprovider A specified dataprovider column name. String operator One of "=, <, >, >=, <=, !=, LIKE, or IN" optionally augmented with modifiers "#" (ignore case) or "^||" (or-is-null), prefix with "sql:" to allow the value to be interpreted as a custom query. Object value The specified filter value.
Returns JSTableFilter table filter.
Sample
dataSourceExists(dataSource)
Check wether a data source exists. This function can be used for any type of data source (db-based, in-memory).
Parameters String dataSource the datasource string to check.
Returns Boolean boolean exists
Sample
flushCalculations(datasource, onlyUnstored)
This method differences for recalculate() that it only works on a datasource rows/records that are loaded in memory. It will not cause extra rows of that datasource to be loaded in memory (except if a calc itself would do that)
if onlyUnstored is true, then only unstored calculations will be flushed. (so also not causing any saves to the database)
Parameters String datasource The datasource to flush all calculations of Boolean onlyUnstored to only go over the unstore cals of this datasource
Returns void
Sample
flushCalculations(datasource, onlyUnstored, calcnames)
This method differences for recalculate() that it only works on a datasource rows/records that are loaded in memory. It will not cause extra rows of that datasource to be loaded in memory (except if a calc itself would do that)
if onlyUnstored is true, then only unstored calculations will be flushed. (so also not causing any saves to the database)
Parameters String datasource The datasource to flush all calculations of Boolean onlyUnstored to only go over the unstore cals of this datasource Array calcnames A string array of calculation names that need to be flushed, if null then all unstored (or all depending on the boolean)
Returns void
Sample
getAutoSave()
Returns true or false if autosave is enabled or disabled.
Returns Boolean true if autosave if enabled.
Sample
getDataModelClonesFrom(serverName)
Retrieves a list with names of all database servers that have property DataModelCloneFrom equal to the server name parameter.
Parameters String serverName ;
Returns Array
Sample
getDataSetByQuery(query, useTableFilters, max_returned_rows)
Performs a sql query with a query builder object. Will throw an exception if anything did go wrong when executing the query.
Parameters QBSelect query QBSelect query. Boolean useTableFilters use table filters (default true). Number max_returned_rows The maximum number of rows returned by the query.
Returns JSDataSet The JSDataSet containing the results of the query.
Sample
getDataSetByQuery(query, max_returned_rows)
Performs a sql query with a query builder object. Will throw an exception if anything did go wrong when executing the query.
Using this variation of getDataSetByQuery any Tablefilter on the involved tables will be taken into account.
Parameters QBSelect query QBSelect query. Number max_returned_rows The maximum number of rows returned by the query.
Returns JSDataSet The JSDataSet containing the results of the query.
Sample
getDataSetByQuery(server_name, sql_query, arguments, max_returned_rows)
Performs a sql query on the specified server, returns the result in a dataset. Will throw an exception if query is not a select statement or anything did go wrong when executing the query.
Using this variation of getDataSetByQuery any Tablefilter on the involved tables will be disregarded.
Parameters String server_name The name of the server where the query should be executed. String sql_query The custom sql, must start with 'select', 'call', 'with' or 'declare'. Array arguments Specified arguments or null if there are no arguments. Number max_returned_rows The maximum number of rows returned by the query.
Returns JSDataSet The JSDataSet containing the results of the query.
Sample
getDataSource(serverName, tableName)
Returns the datasource corresponding to the given server/table.
Parameters String serverName The name of the table's server. String tableName The table's name.
Returns String The datasource of the given table/server.
Sample
getDataSourceServerName(dataSource)
Returns the server name from the datasource, or null if not a database datasource.
Parameters String dataSource The datasource string to get the server name from.
Returns String The servername of the datasource.
Sample
getDataSourceTableName(dataSource)
Returns the table name from the datasource, or null if not a database datasource.
Parameters String dataSource The datasource string to get the tablename from.
Returns String The tablename of the datasource.
Sample
getDatabaseProductName(serverName)
Returns the database product name as supplied by the driver for a server.
NOTE: For more detail on named server connections, see the chapter on Database Connections, beginning with the Introduction to database connections in the Servoy Developer User's Guide.
Parameters String serverName The specified name of the database server connection.
Returns String A database product name.
Sample
getEditedRecords()
Returns an array of edited records with outstanding (unsaved) data.
This is different form JSRecord.isEditing() because this call actually checks if there are changes between the current record data and the stored data in the database. If there are no changes then the record is removed from the edited records list (so after this call JSRecord.isEditing() can return false when it returned true just before this call)
NOTE: To return a dataset of outstanding (unsaved) edited data for each record, see JSRecord.getChangedData(); NOTE2: The fields focus may be lost in user interface in order to determine the edits.
Returns Array Array of outstanding/unsaved JSRecords.
Sample
getEditedRecords(foundset)
Returns an array of edited records with outstanding (unsaved) data.
NOTE: To return a dataset of outstanding (unsaved) edited data for each record, see JSRecord.getChangedData(); NOTE2: The fields focus may be lost in user interface in order to determine the edits.
Parameters JSFoundSet foundset return edited records in the foundset only.
Returns Array Array of outstanding/unsaved JSRecords.
Sample
getEditedRecords(datasource)
Returns an array of edited records with outstanding (unsaved) data.
Parameters String datasource the datasource for which to get the edited records
Returns Array Array of outstanding/unsaved JSRecords
Sample
getEditedRecords(datasource, filter)
Returns an array of edited records with outstanding (unsaved) data for a datasource with a filter.
Parameters String datasource the datasource for which to get the edited records Object filter criteria against which the edited record must match to be included
Returns Array Array of outstanding/unsaved JSRecords
Sample
getFailedRecords()
Returns an array of records that fail after a save.
Returns Array Array of failed JSRecords
Sample
getFailedRecords(foundset)
Returns an array of records that fail after a save.
Parameters JSFoundSet foundset return failed records in the foundset only.
Returns Array Array of failed JSRecords
Sample
getFoundSet(query)
Returns a foundset object for a specified pk base query. This creates a filtered "view" on top of the database table based on that query.
This foundset is different then when doing foundset.loadRecords(query) or datasources.db.server.table.loadRecords(query) because this is generated as a "view" Which means that the foundset will always have this query as its base, even when doing foundset.loadAllRecords() afterwards. Because this query is set as its "creation query" JSFoundset.loadRecords(query) does set that query on the current foundset as a a "search" condition. which will be removed when doing a loadAllRecords().
So doing a clear() on a foundse created by this call will just add a "search" condition that results in no records found ( 1 = 2) and then loadAllRecords() will go back to this query. But in a foundset.loadRecord(query) then clear() will overwrite the "search" condition which is the given query so the query will be lost after that so loadAllRecords() will go back to all records in the table)
Parameters QBSelect query The query to get the JSFoundset for.
Returns JSFoundSet A new JSFoundset with that query as its base query.
Sample
getFoundSet(dataSource)
Returns a foundset object for a specified datasource or server and tablename. Alternative method: datasources.db.server_name.table_name.getFoundSet() or datasources.mem['ds'].getFoundSet()
Parameters String dataSource The datasource to get a JSFoundset for.
Returns JSFoundSet A new JSFoundset for that datasource.
Sample
getFoundSet(serverName, tableName)
Returns a foundset object for a specified datasource or server and tablename.
Parameters String serverName The servername to get a JSFoundset for. String tableName The tablename for that server
Returns JSFoundSet A new JSFoundset for that datasource.
Sample
getFoundSetCount(foundset)
Returns the total number of records in a foundset.
NOTE: This can be an expensive operation (time-wise) if your resultset is large.
Parameters JSFoundSet foundset The JSFoundset to get the count for.
Returns Number the foundset count
Sample
getFoundSetUpdater(foundset)
Returns a JSFoundsetUpdater object that can be used to update all or a specific number of rows in the specified foundset.
Parameters JSFoundSet foundset The foundset to update.
Returns JSFoundSetUpdater The JSFoundsetUpdater for the specified JSFoundset.
Sample
getNextSequence(dataSource, columnName)
Gets the next sequence for a column which has a sequence defined in its column dataprovider properties.
NOTE: For more infomation on configuring the sequence for a column, see the section Auto enter options for a column from the Dataproviders chapter in the Servoy Developer User's Guide.
Parameters String dataSource The datasource that points to the table which has the column with the sequence, or the name of the server where the table can be found. If the name of the server is specified, then a second optional parameter specifying the name of the table must be used. If the datasource is specified, then the name of the table is not needed as the second argument. String columnName The name of the column that has a sequence defined in its properties.
Returns Object The next sequence for the column, null if there was no sequence for that column or if there is no column with the given name.
Sample
getServerNames()
Returns an array with all the server names used in the solution.
NOTE: For more detail on named server connections, see the chapter on Database Connections, beginning with the Introduction to database connections in the Servoy Developer User's Guide.
Returns Array An Array of servernames.
Sample
getTable(foundset)
Returns the JSTable object from which more info can be obtained (like columns). The parameter can be a JSFoundset,JSRecord,datasource string or server/tablename combination.
Parameters JSFoundSet foundset The foundset where the JSTable can be get from.
Returns JSTable the JSTable get from the input.
Sample
getTable(record)
Returns the JSTable object from which more info can be obtained (like columns). The parameter can be a JSFoundset,JSRecord,datasource string or server/tablename combination.
Parameters JSRecord record The record where the table can be get from.
Returns JSTable the JSTable get from the input.
Sample
getTable(dataSource)
Returns the JSTable object from which more info can be obtained (like columns). The parameter can be a JSFoundset,JSRecord,datasource string or server/tablename combination.
Parameters String dataSource The datasource where the table can be get from.
Returns JSTable the JSTable get from the input.
Sample
getTable(serverName, tableName)
Returns the JSTable object from which more info can be obtained (like columns). The parameter can be a JSFoundset,JSRecord,datasource string or server/tablename combination.
Parameters String serverName Server name. String tableName Table name.
Returns JSTable the JSTable get from the input.
Sample
getTableCount(dataSource)
Returns the total number of records(rows) in a table.
NOTE: This can be an expensive operation (time-wise) if your resultset is large
Parameters Object dataSource Data where a server table can be get from. Can be a foundset, a datasource name or a JSTable.
Returns Number the total table count.
Sample
getTableFilterParams(serverName)
Returns a two dimensional array object containing the table filter information currently applied to the servers tables. For column-based table filters, a row of 5 fields per filter are returned. The "columns" of a row from this array are: tablename, dataprovider, operator, value, filtername
For query-based filters, a row of 2 fields per filter are returned. The "columns" of a row from this array are: query, filtername
Parameters String serverName The name of the database server connection.
Returns Array Two dimensional array.
Sample
getTableFilterParams(serverName, filterName)
Returns a two dimensional array object containing the table filter information currently applied to the servers tables. For column-based table filters, a row of 5 fields per filter are returned. The "columns" of a row from this array are: tablename, dataprovider, operator, value, filtername
For query-based filters, a row of 2 fields per filter are returned. The "columns" of a row from this array are: query, filtername
Parameters String serverName The name of the database server connection. String filterName The filter name for which to get the array.
Returns Array Two dimensional array.
Sample
getTableNames(serverName)
Returns an array of all table names for a specified server.
Parameters String serverName The server name to get the table names from.
Returns Array An Array with the tables names of that server.
Sample
getViewFoundSet(name)
Returns a ViewFoundSet that was created by getViewFoundSet(name,query,register) with the registerd boolean "true". So it is registered and remembered by the system to use in Forms. You can't get ViewFoundSet back that are not registered to the system, those are not remembered.
Parameters String name The name to lookup a ViewFoundSet for
Returns JSFoundSet A new ViewFoundSet for that query.
Sample
getViewFoundSet(name, query)
Returns a foundset object for a specified query. This just creates one without keeping any reference to it, you have to use the getViewFoundSet(name,query,true) for registering it to the system. ViewFoundSets are different then normal foundsets because they have a lot less methods, stuff like newRecord/deleteRecord don't work.
If you query the pk with the columns that you display for the main or join tables then those columns can be updated and through ViewFoundSet#save(ViewRecord) they can be saved. If there are changes in ViewRecords of this ViewFoundSet then databroadcast configurations that need to load new data won't do the query right away (only after the save) Also loading more (the next chunksize) will not be done. This is because the ViewRecord on an index can be completely changed. We can't track those.
Also databroadcast can be enabled by calling one of the ViewFoundSet#enableDatabroadcastFor(QBTableClause) to listen for that specific table (main or joins). Flags can be used to control what exactly should be monitored, some don't cost a lot of overhead others have to do a full re-query to see the changes.
Parameters String name The name given to this foundset (will create a datasource url like view:[name]) QBSelect query The query to get the ViewFoundSet for.
Returns JSFoundSet A new ViewFoundSet for that query.
Sample
getViewFoundSet(name, query, register)
Returns a foundset object for a specified query. If the boolean register is true then the system will register it to the system so it can be used in Forms. Also getViewFoundSet(name) will then return that instance. ViewFoundSets are different then normal foundsets because they have a lot less methods, stuff like newRecord/deleteRecord don't work.
If you query the pk with the columns that you display for the main or join tables then those columns can be updated and through ViewFoundSet#save(ViewRecord) they can be saved. If there are changes in ViewRecords of this ViewFoundSet then databroadcast configurations that need to load new data won't do the query right away (only after the save) Also loading more (the next chunksize) will not be done. This is because the ViewRecord on an index can be completely changed. We can't track those.
Also databroadcast can be enabled by calling one of the ViewFoundSet#enableDatabroadcastFor(QBTableClause) to listen for that specific table (main or joins). Flags can be used to control what exactly should be monitored, some don't cost a lot of overhead others have to do a full re-query to see the changes.
if the register boolean is true, then the given ViewFoundSet is registered to the system so it is picked up by forms that have this datasource (see viewFoundset.getDatasource() for the actual datasource string) assigned. The form's foundset will then have a much more limited API, so a lot of things can't be done with it - e.g. newRecord() or deleteRecords(). Also records can be updated in memory, so they are not fully read-only, but the developer is responsible for saving these changes to a persisted store. See also viewFoundset.save(...).
If the solution doesn't need this ViewFoundSet anymore and you did use register is true, please use ViewFoundSet.dispose() to clear and remove it from the system, because otherwise this register call will keep/hold this foundset in memory (for that datasource string to work) forever.
Parameters String name The name given to this foundset (will create a datasource url like view:[name]) QBSelect query The query to get the ViewFoundSet for. Boolean register Register the created ViewFoundSet to the system so it can be used by forms.
Returns JSFoundSet A new JSFoundset for that query.
Sample
getViewNames(serverName)
Returns an array of all view names for a specified server.
Parameters String serverName The server name to get the view names from.
Returns Array An Array with the view names of that server.
Sample
hasLocks()
Returns true if the current client has any or the specified lock(s) acquired.
Returns Boolean true if the current client has locks or the lock.
Sample
hasLocks(lockName)
Returns true if the current client has any or the specified lock(s) acquired.
Parameters String lockName The lock name to check.
Returns Boolean true if the current client has locks or the lock.
Sample
hasNewRecords(foundset)
Returns true if the argument (foundSet / record) has at least one row that was not yet saved in the database.
Parameters JSFoundSet foundset The JSFoundset to test.
Returns Boolean true if the JSFoundset has new records or JSRecord is a new record.
Sample
hasNewRecords(foundset, index)
Returns true if the argument (foundSet / record) has at least one row that was not yet saved in the database.
Parameters JSFoundSet foundset The JSFoundset to test. Number index The record index in the foundset to test (not specified means has the foundset any new records)
Returns Boolean true if the JSFoundset has new records or JSRecord is a new record.
Sample
hasRecordChanges(foundset)
Returns true if the specified foundset, on a specific index or in any of its records, or the specified record has changes or is new unsaved record.
NOTE: The fields focus may be lost in user interface in order to determine the edits.
Parameters JSFoundSet foundset The JSFoundset to test if it has changes.
Returns Boolean true if there are changes in the JSFoundset or JSRecord.
Sample
hasRecordChanges(foundset, index)
Returns true if the specified foundset, on a specific index or in any of its records, or the specified record has changes or is new unsaved record.
NOTE: The fields focus may be lost in user interface in order to determine the edits.
Parameters JSFoundSet foundset The JSFoundset to test if it has changes. Number index The record index in the foundset to test (not specified means has the foundset any changed records)
Returns Boolean true if there are changes in the JSFoundset or JSRecord.
Sample
hasRecords(foundset)
Returns true if the (related)foundset exists and has records.
Parameters JSFoundSet foundset A JSFoundset to test.
Returns Boolean true if the foundset/relation has records.
Sample
hasRecords(record, relationString)
Returns true if the (related)foundset exists and has records.
Parameters JSRecord record A JSRecord to test. String relationString The relation name.
Returns Boolean true if the foundset/relation has records.
Sample
hasTransaction()
Returns true if there is an transaction active for this client.
Returns Boolean true if the client has a transaction.
Sample
mergeRecords(sourceRecord, combinedDestinationRecord)
Merge records from the same foundset, updates entire datamodel (via foreign type on columns) with destination record pk, deletes source record. Do use a transaction!
This function is very handy in situations where duplicate data exists. It allows you to merge the two records and move all related records in one go. Say the source_record is "Ikea" and the combined_destination_record is "IKEA", the "Ikea" record is deleted and all records related to it (think of contacts and orders, for instance) will be related to the "IKEA" record.
The function takes an optional array of column names. If provided, the data in the named columns will be copied from source_record to combined_destination_record.
Note that it is essential for both records to originate from the same foundset, as shown in the sample code.
Parameters JSRecord sourceRecord The source JSRecord to copy from. JSRecord combinedDestinationRecord The target/destination JSRecord to copy into.
Returns Boolean true if the records could me merged.
Sample
mergeRecords(sourceRecord, combinedDestinationRecord, columnNames)
Merge records from the same foundset, updates entire datamodel (via foreign type on columns) with destination record pk, deletes source record. Do use a transaction!
This function is very handy in situations where duplicate data exists. It allows you to merge the two records and move all related records in one go. Say the source_record is "Ikea" and the combined_destination_record is "IKEA", the "Ikea" record is deleted and all records related to it (think of contacts and orders, for instance) will be related to the "IKEA" record.
The function takes an optional array of column names. If provided, the data in the named columns will be copied from source_record to combined_destination_record.
Note that it is essential for both records to originate from the same foundset, as shown in the sample code.
Parameters JSRecord sourceRecord The source JSRecord to copy from. JSRecord combinedDestinationRecord The target/destination JSRecord to copy into. Array columnNames The column names array that should be copied.
Returns Boolean true if the records could me merged.
Sample
recalculate(foundsetOrRecord)
Can be used to recalculate a specified record or all rows in the specified foundset. May be necessary when data is changed from outside of servoy, or when there is data changed inside servoy but records with calculations depending on that data where not loaded so not updated and you need to update the stored calculation values because you are depending on that with queries or aggregates.
Parameters Object foundsetOrRecord JSFoundset or JSRecord to recalculate.
Returns void
Sample
refreshRecordFromDatabase(foundset, index)
Flushes the client data cache and requeries the data for a record (based on the record index) in a foundset or all records in the foundset. Used where a program external to Servoy has modified the database record. Giving 0 as the index will just refresh he selected record.
If the index is -1 then this method will refresh all the records of the datasource of the foundset, it does this by flusing all the records and the row data of the full datasource So everything is reloaded fully fresh when the foundsets will requery for there data. WARNING: Don't hold any references to JSRecord objects from before this call with -1 index. Those records objects are all in an invalid state because of the underlying data flush.
Parameters Object foundset The JSFoundset to refresh Number index The index of the JSRecord that must be refreshed (or -1 for all).
Returns Boolean true if the refresh was done.
Sample
releaseAllLocks()
Release all current locks the client has (optionally limited to named locks). return true if the locks are released.
Returns Boolean true if all locks or the lock is released.
Sample
releaseAllLocks(lockName)
Release all current locks the client has (optionally limited to named locks). return true if the locks are released.
Parameters String lockName The lock name to release.
Returns Boolean true if all locks or the lock is released.
Sample
removeDataSource(uri)
Free resources allocated for a previously created data source. NOTE: make sure this datasource is not using anymore in forms or components! because the inmemory table and the foundset build on that table are all just removed.
Normally this will be automatically done if a client is removed/shutdown, but if constantly new stuff is created or you don't need it anymore from what the client currently is using or seeing, then removing this will clean up memory.
Parameters String uri ;
Returns Boolean
Sample
removeTableFilterParam(serverName, filterName)
Removes a previously defined table filter.
Parameters String serverName The name of the database server connection. String filterName The name of the filter that should be removed.
Returns Boolean true if the filter could be removed.
Sample
revertEditedRecords()
Reverts outstanding (not saved) in memory changes from edited records. Can specify a record or foundset as parameter to rollback. Best used in combination with the function databaseManager.setAutoSave() This does not include deletes, they do not honor the autosafe false flag so they cant be rollbacked by this call.
Returns void
Sample
revertEditedRecords(foundset)
Reverts outstanding (not saved) in memory changes from edited records. Can specify a record or foundset as parameter to rollback. Best used in combination with the function databaseManager.setAutoSave() This does not include deletes, they do not honor the autosafe false flag so they cant be rollbacked by this call.
Parameters JSFoundSet foundset A JSFoundset to revert.
Returns void
Sample
rollbackTransaction()
Rollback a transaction started by databaseManager.startTransaction(). Note that when autosave is false, revertEditedRecords() will not handle deleted records, while rollbackTransaction() does. Also, rollbackEditedRecords() is called before rolling back the transaction see rollbackTransaction(boolean) to control that behavior and saved records within the transactions are restored to the database values, so user input is lost, to control this see rollbackTransaction(boolean,boolean)
Returns void
Sample
rollbackTransaction(rollbackEdited)
Rollback a transaction started by databaseManager.startTransaction(). Note that when autosave is false, revertEditedRecords() will not handle deleted records, while rollbackTransaction() does. Also, saved records within the transactions are restored to the database values, so user input is lost, to controll this see rollbackTransaction(boolean,boolean)
Parameters Boolean rollbackEdited call rollbackEditedRecords() before rolling back the transaction
Returns void
Sample
rollbackTransaction(rollbackEdited, revertSavedRecords)
Rollback a transaction started by databaseManager.startTransaction(). Note that when autosave is false, revertEditedRecords() will not handle deleted records, while rollbackTransaction() does.
Parameters Boolean rollbackEdited call rollbackEditedRecords() before rolling back the transaction Boolean revertSavedRecords if false then all records in the transaction do keep the user input and are back in the edited records list. Note that if the pks of such a record are no longer used by it's foundset (find/search or load by query or ...) it will just be rolled-back as it can't be put in editing records list.
Returns void
Sample
saveData()
Saves all outstanding (unsaved) data and exits the current record.
Optionally, by specifying a record or foundset, can save a single record or all records from foundset instead of all the data. Since Servoy 8.3 saveData with null parameter does not call saveData() as fallback, it just returns false.
NOTE: The fields focus may be lost in user interface in order to determine the edits. saveData() called from table events (like afterRecordInsert) is only partially supported depending on how first saveData() (that triggers the event) is called. If first saveData() is called with no arguments, all saveData() from table events are returning immediately with true value and records will be saved as part of first save. If first saveData() is called with record(s) as arguments, saveData() from table event will try to save record(s) from arguments that are different than those in first call. saveData() with no arguments inside table events will always return true without saving anything.
NOTE: When saveData() is called within a transaction, records after a record that fails with some sql-exception will not be saved, but moved to the failed records. record.exception.getErrorCode() will return ServoyException.MUST_ROLLBACK for these records.
Returns Boolean true if the save was done without an error.
Sample
saveData(foundset)
Saves all outstanding (unsaved) data and exits the current record.
Optionally, by specifying a record or foundset, can save a single record or all records from foundset instead of all the data. Since Servoy 8.3 saveData with null parameter does not call saveData() as fallback, it just returns false.
NOTE: The fields focus may be lost in user interface in order to determine the edits. saveData() called from table events (like afterRecordInsert) is only partially supported depending on how first saveData() (that triggers the event) is called. If first saveData() is called with no arguments, all saveData() from table events are returning immediately with true value and records will be saved as part of first save. If first saveData() is called with record(s) as arguments, saveData() from table event will try to save record(s) from arguments that are different than those in first call. saveData() with no arguments inside table events will always return true without saving anything.
NOTE: When saveData() is called within a transaction, records after a record that fails with some sql-exception will not be saved, but moved to the failed records. record.exception.getErrorCode() will return ServoyException.MUST_ROLLBACK for these records.
Parameters JSFoundSet foundset The JSFoundset to save.
Returns Boolean true if the save was done without an error.
Sample
saveData(record)
Saves all outstanding (unsaved) data and exits the current record.
Optionally, by specifying a record or foundset, can save a single record or all records from foundset instead of all the data. Since Servoy 8.3 saveData with null parameter does not call saveData() as fallback, it just returns false.
NOTE: The fields focus may be lost in user interface in order to determine the edits. saveData() called from table events (like afterRecordInsert) is only partially supported depending on how first saveData() (that triggers the event) is called. If first saveData() is called with no arguments, all saveData() from table events are returning immediately with true value and records will be saved as part of first save. If first saveData() is called with record(s) as arguments, saveData() from table event will try to save record(s) from arguments that are different than those in first call. saveData() with no arguments inside table events will always return true without saving anything.
NOTE: When saveData() is called within a transaction, records after a record that fails with some sql-exception will not be saved, but moved to the failed records. record.exception.getErrorCode() will return ServoyException.MUST_ROLLBACK for these records.
Parameters JSRecord record The JSRecord to save.
Returns Boolean true if the save was done without an error.
Sample
saveData(records)
Saves all outstanding (unsaved) data and exits the current record.
Optionally, by specifying a record or foundset, can save a single record or all records from foundset instead of all the data. Since Servoy 8.3 saveData with null parameter does not call saveData() as fallback, it just returns false.
NOTE: The fields focus may be lost in user interface in order to determine the edits. saveData() called from table events (like afterRecordInsert) is only partially supported depending on how first saveData() (that triggers the event) is called. If first saveData() is called with no arguments, all saveData() from table events are returning immediately with true value and records will be saved as part of first save. If first saveData() is called with record(s) as arguments, saveData() from table event will try to save record(s) from arguments that are different than those in first call. saveData() with no arguments inside table events will always return true without saving anything.
NOTE: When saveData() is called within a transaction, records after a record that fails with some sql-exception will not be saved, but moved to the failed records. record.exception.getErrorCode() will return ServoyException.MUST_ROLLBACK for these records.
Parameters Array records The array of JSRecord to save.
Returns Boolean true if the save was done without an error.
Sample
setAutoSave(autoSave)
Set autosave, if false then no saves will happen by the ui (not including deletes!). Until you call databaseManager.saveData() or setAutoSave(true)
If you also want to be able to rollback deletes then you have to use databaseManager.startTransaction(). Because even if autosave is false deletes of records will be done.
Parameters Boolean autoSave Boolean to enable or disable autosave.
Returns Boolean false if the current edited record could not be saved.
Sample
setCreateEmptyFormFoundsets()
Turnoff the initial form foundset record loading, set this in the solution open method. Simular to calling foundset.clear() in the form's onload event.
NOTE: When the foundset record loading is turned off, controller.find or controller.loadAllRecords must be called to display the records
Returns void
Sample
setTableFilters(filterName, tableFilters)
Apply multiples table filters to all the foundsets that arte affected by the filters. After all filters have been applied / updated, foundset changes will be applied in the client.
The filters that have been applied with the same filter name will be removed and replaced with the new set of filters.
Parameters String filterName The name of the filter that should be removed. Array tableFilters list of filters to be applied.
Returns Boolean true if the table filters could be applied.
Sample
startTransaction()
Start a database transaction. If you want to avoid round trips to the server or avoid the possibility of blocking other clients because of your pending changes, you can use databaseManager.setAutoSave(false/true) and databaseManager.rollbackEditedRecords().
startTransaction, commit/rollbackTransacton() does support rollback of record deletes which autoSave = false doesn't support.
Returns void
Sample
switchServer(sourceName, destinationName)
Switches a named server to another named server with the same datamodel (recommended to be used in an onOpen method for a solution). return true if successful. Note that this only works if source and destination server are of the same database type.
Parameters String sourceName The name of the source database server connection String destinationName The name of the destination database server connection.
Returns Boolean true if the switch could be done.
Sample
validate(record)
Validates the given record, it runs first the method that is attached to the entity event "onValidate". Then it will call also the entity events "onInsert" or "onUpdate" depending if the record is new or an update. All those methods do get a parameter JSRecordMarkers where the problems can be reported against.
All columns are then also null/empty checked and if they are and the Column is marked as "not null" an error will be added with the message key "servoy.record.error.null.not.allowed" for that column.
All changed columns are length checked and if the record values is bigger then what the database column can handle and error will be added with the message key "servoy.record.error.columnSizeTooSmall" for that column. Then all the column validators will be run over all the changed columns, The validators will also get the same JSRecordMarkers to report problems to. So the global method validator now also has more parameters then just the value.
These 3 validations (null, length and column validators) are not by default done any more on change of the dataprovider itself. This is controlled by the servoy property "servoy.execute.column.validators.only.on.validate_and_save" which can also be seen at the TableEditor column validators page.
An extra state object can be given that will also be passed around if you want to have more state in the validation objects (like giving some ui state so the entity methods know where you come from)
It will return a JSRecordMarkers when the record had validation problems
Parameters JSRecord record The record to validate.
Returns JSRecordMarkers Returns a JSRecordMarkers if the record has validation problems
Sample
validate(record, customObject)
Validates the given record, it runs first the method that is attached to the entity event "onValidate". Then it will call also the entity events "onInsert" or "onUpdate" depending if the record is new or an update. All those methods do get a parameter JSRecordMarkers where the problems can be reported against.
All columns are then also null/empty checked and if they are and the Column is marked as "not null" an error will be added with the message key "servoy.record.error.null.not.allowed" for that column.
All changed columns are length checked and if the record values is bigger then what the database column can handle and error will be added with the message key "servoy.record.error.columnSizeTooSmall" for that column. Then all the column validators will be run over all the changed columns, The validators will also get the same JSRecordMarkers to report problems to. So the global method validator now also has more parameters then just the value.
These 3 validations (null, length and column validators) are not by default done any more on change of the dataprovider itself. This is controlled by the servoy property "servoy.execute.column.validators.only.on.validate_and_save" which can also be seen at the TableEditor column validators page.
An extra state object can be given that will also be passed around if you want to have more state in the validation objects (like giving some ui state so the entity methods know where you come from)
It will return a JSRecordMarkers when the record had validation problems
Parameters JSRecord record The record to validate. Object customObject The extra customObject that is passed on the the validation methods.
Returns JSRecordMarkers
Sample
Last updated