use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.
the class JSCalculation method checkModification.
private void checkModification() {
if (!isCopy) {
try {
TableNode tableNode = application.getFlattenedSolution().getSolutionCopyTableNode(parent.getDataSource());
ScriptCalculation sc = tableNode.getScriptCalculation(scriptCalculation.getName());
if (sc == null) {
sc = (ScriptCalculation) scriptCalculation.clonePersist(tableNode);
scriptCalculation = sc;
}
isCopy = true;
} catch (RepositoryException e) {
Debug.error(e);
throw new RuntimeException("Can't alter ScriptCalculation " + scriptCalculation.getName() + ", clone failed", e);
}
}
}
use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.
the class JSDataSourceNode method newMethod.
/**
* Creates a new foundset method with the specified code.
*
* @sample
* 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())
*
* @param code the specified code for the foundset method
*
* @return a JSMethod object
*/
@JSFunction
public JSMethod newMethod(String code) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
if (tablenode == null)
throw new RuntimeException("Couldnt create method for datasource: " + dataSource);
String name = JSMethod.parseName(code);
ScriptMethod method = tablenode.createNewFoundsetMethod(new ScriptNameValidator(fs), name, null);
method.setDeclaration(code);
((FoundSetManager) application.getFoundSetManager()).reloadFoundsetMethod(dataSource, method);
return new JSMethod(this, method, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.
the class JSDataSourceNode method getScriptCopy.
@SuppressWarnings("unchecked")
public <T extends IScriptProvider> T getScriptCopy(T script) throws RepositoryException {
TableNode tableNode = application.getFlattenedSolution().getSolutionCopyTableNode(dataSource);
T sc = AbstractBase.selectByName(new TypeIterator<T>(tableNode.getAllObjects(), script.getTypeID()), script.getName());
if (sc == null) {
sc = (T) ((ICloneable) script).clonePersist(tableNode);
}
return sc;
}
use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.
the class JSDataSourceNode method newCalculation.
/**
* 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.
*
* @param code The code of the calculation, this must be a full function declaration.
* @param type The type of the calculation, one of the JSVariable types.
*
* @sample
* var calc = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation() { return 123; }", JSVariable.INTEGER);
* var calc2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation2() { return '20'; }");
* var calc3 = solutionModel.getDataSourceNode("db:/example_data/employees").newCalculation("function myCalculation3() { return 'Hello World!'; }", JSVariable.TEXT);
*
* var c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation");
* application.output("Name: " + c.getName() + ", Stored: " + c.isStored());
*
* var allCalcs = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculations();
* for (var i = 0; i < allCalcs.length; i++) {
* application.output(allCalcs[i]);
* }
*/
@JSFunction
public JSCalculation newCalculation(String code, int type) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
String name = JSMethod.parseName(code);
ScriptCalculation scriptCalculation = tablenode.createNewScriptCalculation(new ScriptNameValidator(fs), name, null, fs.getTable(dataSource));
scriptCalculation.setDeclaration(code);
scriptCalculation.setTypeAndCheck(type, application);
TableScope tableScope = (TableScope) application.getScriptEngine().getTableScope(scriptCalculation.getTable());
if (tableScope != null) {
tableScope.put(scriptCalculation, scriptCalculation);
((FoundSetManager) application.getFoundSetManager()).flushSQLSheet(dataSource);
}
return new JSCalculation(this, scriptCalculation, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.
the class JSDataSourceNode method removeMethod.
/**
* Removes the foundset method specified by name.
*
* @sample
* var method1 = solutionModel.getDataSourceNode("db:/example_data/customers").newMethod("function myFoundsetMethod1() { return 123; }");
* var method2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myFoundsetMethod2() { return '20'; }");
*
* var m = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod("myFoundsetMethod1");
* application.output("Name: " + m.getName());
*
* solutionModel.getDataSourceNode("db:/example_data/customers").removeMethod("myFoundsetMethod1");
* m = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myFoundsetMethod1");
* if (m != null) { application.output("myFoundsetMethod1 could not be removed."); }
*
* var allMethods = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod();
* for (var i = 0; i < allMethods; i++)
* {
* application.output(allMethods[i]);
* }
*
* @param name the name of the method to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeMethod(String name) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
ScriptMethod sc = tablenode.getFoundsetMethod(name);
if (sc != null) {
tablenode.removeChild(sc);
return true;
}
// it is a design time method, therefore we "hide" it
sc = fs.getFoundsetMethod(name, dataSource);
if (sc != null) {
fs.addToRemovedPersists(sc);
if (application.getFormManager() instanceof FormManager)
((FormManager) application.getFormManager()).fillScriptMenu();
return true;
}
// not found
return false;
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
Aggregations