Search in sources :

Example 51 with RepositoryException

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

the class JSCalculation method setVariableType.

@JSSetter
public void setVariableType(int type) {
    if (isStored())
        throw new RuntimeException("Can't alter variable type of the stored calculation " + scriptCalculation.getName());
    checkModification();
    scriptCalculation.setTypeAndCheck(type, application);
    TableScope tableScope;
    try {
        tableScope = (TableScope) application.getScriptEngine().getTableScope(scriptCalculation.getTable());
        if (tableScope != null) {
            tableScope.put(scriptCalculation, scriptCalculation);
            ((FoundSetManager) application.getFoundSetManager()).flushSQLSheet(scriptCalculation.getTable().getDataSource());
        }
    } catch (RepositoryException e) {
        Debug.error(e);
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TableScope(com.servoy.j2db.scripting.TableScope) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSSetter(org.mozilla.javascript.annotations.JSSetter)

Example 52 with RepositoryException

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

Example 53 with RepositoryException

use of com.servoy.j2db.persistence.RepositoryException 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 54 with RepositoryException

use of com.servoy.j2db.persistence.RepositoryException 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);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 55 with RepositoryException

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

the class RemoteActiveSolutionHandler method loadLoginSolutionAndModules.

@Override
public Solution[] loadLoginSolutionAndModules(final SolutionMetaData mainSolutionDef) throws RepositoryException, RemoteException {
    final SolutionMetaData[] loginSolutionDefinitions = getApplicationServer().getLoginSolutionDefinitions(mainSolutionDef);
    if (loginSolutionDefinitions == null) {
        throw new RepositoryException("Could not load login solution");
    }
    final Solution[] solutions = new Solution[loginSolutionDefinitions.length];
    if (loginSolutionDefinitions.length > 0) {
        ThrowingRunnable<RepositoryException, RemoteException> r = new ThrowingRunnable<RepositoryException, RemoteException>() {

            @Override
            public void run() {
                try {
                    int[] sol_ids = new int[loginSolutionDefinitions.length];
                    for (int i = 0; i < sol_ids.length; i++) {
                        sol_ids[i] = loginSolutionDefinitions[i].getRootObjectId();
                    }
                    long[] asus = getApplicationServer().getActiveRootObjectsLastModified(sol_ids);
                    ConcurrentMap<String, IServer> sps = getRepository().getServerProxies(loginSolutionDefinitions);
                    for (int i = 0; i < loginSolutionDefinitions.length; i++) {
                        Solution s = loadCachedSolution(loginSolutionDefinitions[i], asus[i], sps);
                        if (s == null) {
                            // do full load
                            s = getApplicationServer().getLoginSolution(mainSolutionDef, loginSolutionDefinitions[i]);
                        }
                        if (s != null) {
                            if (s.getRepository() == null) {
                                // transient
                                s.setRepository(getRepository());
                            }
                            loadedActiveSolutionUpdateSequences.put(new Integer(s.getSolutionID()), new Long(asus[i]));
                            s.setServerProxies(sps);
                        }
                        solutions[i] = s;
                    }
                } catch (RepositoryException eo) {
                    e1 = eo;
                } catch (RemoteException et) {
                    e2 = et;
                }
            }
        };
        UIUtils.runWhileDispatchingEvents(r, getServiceProvider());
    }
    return solutions;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ThrowingRunnable(com.servoy.j2db.util.UIUtils.ThrowingRunnable) RemoteException(java.rmi.RemoteException) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

RepositoryException (com.servoy.j2db.persistence.RepositoryException)116 RemoteException (java.rmi.RemoteException)45 QuerySelect (com.servoy.j2db.query.QuerySelect)25 ITable (com.servoy.j2db.persistence.ITable)22 JSFunction (org.mozilla.javascript.annotations.JSFunction)22 ServoyException (com.servoy.j2db.util.ServoyException)21 Column (com.servoy.j2db.persistence.Column)19 ArrayList (java.util.ArrayList)19 BaseQueryTable (com.servoy.base.query.BaseQueryTable)16 Table (com.servoy.j2db.persistence.Table)16 QueryTable (com.servoy.j2db.query.QueryTable)16 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Point (java.awt.Point)14 IDataProvider (com.servoy.j2db.persistence.IDataProvider)13 QueryColumn (com.servoy.j2db.query.QueryColumn)13 IColumn (com.servoy.j2db.persistence.IColumn)12 ApplicationException (com.servoy.j2db.ApplicationException)11 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)10 SafeArrayList (com.servoy.j2db.util.SafeArrayList)10 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)8