Search in sources :

Example 1 with TableNode

use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.

the class FlattenedSolution method getAllDataProvidersForTable.

public Map<String, IDataProvider> getAllDataProvidersForTable(ITable table) throws RepositoryException {
    if (table == null)
        return null;
    synchronized (this) {
        if (allProvidersForTable == null)
            allProvidersForTable = new ConcurrentHashMap<ITable, Map<String, IDataProvider>>(64, 0.9f, 16);
    }
    Map<String, IDataProvider> dataProvidersMap = allProvidersForTable.get(table);
    if (dataProvidersMap == null) {
        dataProvidersMap = new HashMap<String, IDataProvider>(16, 0.9f);
        // 1) first the columns
        Iterator<Column> columns = table.getColumns().iterator();
        while (columns.hasNext()) {
            Column col = columns.next();
            ColumnInfo ci = col.getColumnInfo();
            if (ci != null && ci.isExcluded()) {
                continue;
            }
            dataProvidersMap.put(col.getDataProviderID(), col);
        }
        // 2) last the scriptcalculations and aggregates so the overlap the columns in case of stored calcs
        Iterator<TableNode> tableNodes = getTableNodes(table);
        while (tableNodes.hasNext()) {
            TableNode tableNode = tableNodes.next();
            if (tableNode != null) {
                Iterator<IPersist> it2 = tableNode.getAllObjects();
                while (it2.hasNext()) {
                    IPersist persist = it2.next();
                    if (persist instanceof IDataProvider) {
                        dataProvidersMap.put(((IDataProvider) persist).getDataProviderID(), (IDataProvider) persist);
                    }
                }
            }
        }
        Map<String, IDataProvider> currentValue = allProvidersForTable.putIfAbsent(table, dataProvidersMap);
        if (currentValue != null)
            dataProvidersMap = currentValue;
    }
    return dataProvidersMap;
}
Also used : QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IPersist(com.servoy.j2db.persistence.IPersist) TableNode(com.servoy.j2db.persistence.TableNode) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 2 with TableNode

use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, String uuidOrName, IJSParent<?> parent, String propertyName) {
    if (uuidOrName != null) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(uuidOrName);
        ;
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof TableNode && parent instanceof JSDataSourceNode) {
                scriptParent = (JSDataSourceNode) parent;
            } else if (scriptMethod.getParent() instanceof Solution) {
                // global
                scriptParent = null;
            } else {
                // form method
                scriptParent = getJSFormParent(parent);
                if (scriptMethod.getParent() != scriptParent.getSupportChild() && scriptParent.getSupportChild() instanceof Form) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm((Form) scriptParent.getSupportChild(), false);
                }
            }
            List<Object> arguments = persist.getFlattenedMethodArguments(propertyName);
            if (arguments == null || arguments.size() == 0) {
                return new JSMethod(scriptParent, scriptMethod, application, false);
            } else {
                return new JSMethodWithArguments(application, scriptParent, scriptMethod, false, arguments.toArray());
            }
        }
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) TableNode(com.servoy.j2db.persistence.TableNode) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 3 with TableNode

use of com.servoy.j2db.persistence.TableNode in project servoy-client by Servoy.

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, int methodid, IJSParent<?> parent, String propertyName) {
    if (methodid > 0) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = null;
        if (parent instanceof JSForm) {
            // form method
            scriptMethod = ((JSForm) parent).getSupportChild().getScriptMethod(methodid);
            if (scriptMethod == null) {
                Form f = ((JSForm) parent).getSupportChild();
                while (f != null && f.getExtendsID() > 0 && scriptMethod == null) {
                    f = application.getFlattenedSolution().getForm(f.getExtendsID());
                    if (f != null)
                        scriptMethod = f.getScriptMethod(methodid);
                }
                if (scriptMethod != null) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm(f, false);
                }
            }
        }
        if (scriptMethod == null) {
            // foundset method
            if (parent instanceof JSDataSourceNode) {
                scriptMethod = ((JSDataSourceNode) parent).getSupportChild().getFoundsetMethod(methodid);
            } else if (parent instanceof JSForm && ((JSForm) parent).getForm().getDataSource() != null) {
                Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(((JSForm) parent).getForm().getDataSource(), false);
                scriptMethod = AbstractBase.selectById(foundsetMethods, methodid);
                if (scriptMethod != null) {
                    scriptParent = new JSDataSourceNode(application, ((JSForm) parent).getForm().getDataSource());
                }
            }
        }
        if (scriptMethod == null) {
            // global method
            scriptMethod = application.getFlattenedSolution().getScriptMethod(methodid);
        }
        if (scriptMethod != null) {
            if (scriptParent == null) {
                if (scriptMethod.getParent() instanceof TableNode && parent instanceof JSDataSourceNode) {
                    scriptParent = (JSDataSourceNode) parent;
                } else if (scriptMethod.getParent() instanceof Solution) {
                    // global
                    scriptParent = null;
                } else {
                    // form method
                    scriptParent = getJSFormParent(parent);
                }
            }
            List<Object> arguments = persist.getFlattenedMethodArguments(propertyName);
            if (arguments == null || arguments.size() == 0) {
                return new JSMethod(scriptParent, scriptMethod, application, false);
            } else {
                return new JSMethodWithArguments(application, scriptParent, scriptMethod, false, arguments.toArray());
            }
        }
    } else if (methodid == 0 && BaseComponent.isCommandProperty(propertyName)) {
        return (JSMethod) ISMDefaults.COMMAND_DEFAULT;
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) Iterator(java.util.Iterator) TableNode(com.servoy.j2db.persistence.TableNode) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 4 with TableNode

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);
    }
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TableScope(com.servoy.j2db.scripting.TableScope) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 5 with TableNode

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;
}
Also used : ICloneable(com.servoy.j2db.persistence.ICloneable) TableNode(com.servoy.j2db.persistence.TableNode)

Aggregations

TableNode (com.servoy.j2db.persistence.TableNode)18 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)9 FlattenedSolution (com.servoy.j2db.FlattenedSolution)8 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)6 Solution (com.servoy.j2db.persistence.Solution)6 Form (com.servoy.j2db.persistence.Form)5 IPersist (com.servoy.j2db.persistence.IPersist)4 JSFunction (org.mozilla.javascript.annotations.JSFunction)4 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)3 ServoyException (com.servoy.j2db.util.ServoyException)3 ArrayList (java.util.ArrayList)3 BaseColumnType (com.servoy.base.query.BaseColumnType)2 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)2 ApplicationException (com.servoy.j2db.ApplicationException)2 Column (com.servoy.j2db.persistence.Column)2 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 IScriptProvider (com.servoy.j2db.persistence.IScriptProvider)2 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)2