The JSDataSourceNode class facilitates interaction with data source nodes within a Servoy solution model. It enables the creation, retrieval, and management of calculations and foundset methods associated with a data source. * This class is tied to an IApplication instance and a specified data source, allowing dynamic manipulation of related objects.
## Core Functionality
The class provides methods for retrieving and managing calculations and foundset methods. Calculations can be created using JavaScript code, * with the ability to specify types and validate names. Similarly, foundset methods can be dynamically defined and linked to the data source. Both calculations and methods support retrieval, enumeration, and removal, enhancing the flexibility of database scripting.
## Additional Features
The JSDataSourceNode ensures persistence management by integrating with the Servoy framework’s FlattenedSolution and TableNode objects. It supports cloning of script providers and handles runtime exceptions gracefully, ensuring stability. It also provides utility methods like hashCode, equals, and toString for seamless object management in Java environments.
Methods Summarized
Type
Name
Summary
Get an existing calculation for the datasource node.
Gets all the calculations for the datasource node.
Get the data source for this node.
Get an existing foundset method for the datasource node.
Gets all the foundset methods for the datasource node.
Creates a new calculation for the given code, the type will be the column where it could be build on (if name is a column name), else it will default to JSVariable.
Creates a new calculation for the given code and the type, if it builds on a column (name is a column name) then type will be ignored.
Creates a new foundset method with the specified code.
Removes the calculation specified by name.
Removes the foundset method specified by name.
Methods Detailed
getCalculation(name)
Get an existing calculation for the datasource node.
var method =solutionModel.getDataSourceNode("db:/example_data/orders").newMethod("function doubleSize() { return 2*getSize(); }");application.output('Doubled orders for this customer: '+customers_to_orders.doubleSize())
getMethods()
Gets all the foundset methods for the datasource node.
var method =solutionModel.getDataSourceNode("db:/example_data/orders").newMethod("function doubleSize() { return 2*getSize(); }");application.output('Doubled orders for this customer: '+customers_to_orders.doubleSize())
newCalculation(code)
Creates a new calculation for the given code, the type will be the column where it could be build on (if name is a column name), else it will default to JSVariable.TEXT;
Parameters
Stringcode The code of the calculation, this must be a full function declaration.
var method =solutionModel.getDataSourceNode("db:/example_data/orders").newMethod("function doubleSize() { return 2*getSize(); }");application.output('Doubled orders for this customer: '+customers_to_orders.doubleSize())
removeCalculation(name)
Removes the calculation specified by name.
Parameters
Stringname the name of the calculation to be removed
Returns:Boolean true if the removal was successful, false otherwise
Sample
var calc1 =solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation1() { return 123; }",JSVariable.INTEGER);var calc2 =solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation2() { return '20'; }");var c =solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");application.output("Name: "+c.getName() +", Stored: "+c.isStored());solutionModel.getDataSourceNode("db:/example_data/customers").removeCalculation("myCalculation1");c =solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");if (c !=null) {application.output("myCalculation could not be removed.");}var allCalcs =solutionModel.getDataSourceNode("db:/example_data/customers").getCalculations();for (var i =0; i <allCalcs.length; i++) {application.output(allCalcs[i]);}