Search in sources :

Example 46 with Solution

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

the class PersistIndexCache method getPersistIndex.

public static IPersistIndex getPersistIndex(Solution solution, Solution[] modules) {
    boolean isCloned = solution.getRuntimeProperty(AbstractBase.Cloned) != null && solution.getRuntimeProperty(AbstractBase.Cloned).booleanValue();
    IPersistIndex index = isCloned ? null : persistIndexCache.get(solution.getUUID());
    if (index == null) {
        List<Solution> solutions = new ArrayList<>();
        solutions.add(solution);
        if (modules != null) {
            for (Solution mod : modules) {
                solutions.add(mod);
            }
        }
        index = new PersistIndex(solutions).createIndex();
        if (!isCloned) {
            IPersistIndex alreadyCreated = persistIndexCache.putIfAbsent(solution.getUUID(), index);
            if (alreadyCreated != null)
                index = alreadyCreated;
            LOG.debug("Persist Index Cache entry created for " + solution + " with modules " + (modules != null ? Arrays.asList(modules) : Collections.emptyList()));
        }
    }
    return index;
}
Also used : ArrayList(java.util.ArrayList) Solution(com.servoy.j2db.persistence.Solution)

Example 47 with Solution

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

the class WebClient method onBeginRequest.

public void onBeginRequest(WebClientSession webClientSession) {
    Solution solution = getSolution();
    if (solution != null) {
        synchronized (onBeginRequestLock) {
            long solutionLastModifiedTime = webClientSession.getSolutionLastModifiedTime(solution);
            if (solutionLastModifiedTime != -1 && solutionLastModifiedTime != solution.getLastModifiedTime()) {
                if (isClosing() || isShutDown()) {
                    if (((WebRequest) RequestCycle.get().getRequest()).isAjax())
                        throw new AbortException();
                    else
                        throw new RestartResponseException(Application.get().getHomePage());
                }
                refreshI18NMessages(true);
                ((IScriptSupport) getScriptEngine()).reload();
                ((WebFormManager) getFormManager()).reload();
                MainPage page = (MainPage) ((WebFormManager) getFormManager()).getMainContainer(null);
                throw new RestartResponseException(page);
            }
            executeEvents();
        }
    }
}
Also used : WebRequest(org.apache.wicket.protocol.http.WebRequest) RestartResponseException(org.apache.wicket.RestartResponseException) IScriptSupport(com.servoy.j2db.scripting.IScriptSupport) Solution(com.servoy.j2db.persistence.Solution) AbortException(org.apache.wicket.AbortException)

Example 48 with Solution

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

the class TemplateGenerator method getFormHTMLAndCSS.

public static Pair<String, String> getFormHTMLAndCSS(int solution_id, int form_id) throws RepositoryException, RemoteException {
    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
    Solution solution = (Solution) repository.getActiveRootObject(solution_id);
    Form form = solution.getForm(form_id);
    IServiceProvider sp = null;
    if (WebClientSession.get() != null) {
        sp = WebClientSession.get().getWebClient();
    }
    return getFormHTMLAndCSS(solution, form, sp, form.getName());
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IRepository(com.servoy.j2db.persistence.IRepository) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 49 with Solution

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

the class DebugClientHandler method executeMethod.

/**
 * @param persist
 * @param elementName
 */
public void executeMethod(final ISupportChilds persist, final String scopeName, final String methodname) {
    final IApplication serviceProvider = getDebugReadyClient();
    if (serviceProvider != null) {
        final Runnable run = new Runnable() {

            public void run() {
                if (persist instanceof Solution) {
                    try {
                        serviceProvider.getScriptEngine().getScopesScope().executeGlobalFunction(scopeName, methodname, null, false, false);
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                } else if (persist instanceof Form) {
                    try {
                        IFormController fp = serviceProvider.getFormManager().leaseFormPanel(((Form) persist).getName());
                        if (fp != null) {
                            fp.initForJSUsage();
                            fp.setView(fp.getView());
                            fp.executeOnLoadMethod();
                            fp.executeFunction(methodname, null, false, null, false, null);
                        }
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                }
            }
        };
        if (serviceProvider == getDebugHeadlessClient() || serviceProvider == getDebugAuthenticator()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    serviceProvider.invokeLater(run);
                }
            });
        } else if (serviceProvider == getDebugWebClient()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    RequestCycle rc = null;
                    try {
                        // fake a request as much as possible
                        WebClientsApplication fakeApplication = ((WebClient) serviceProvider).getFakeApplication();
                        Application.set(fakeApplication);
                        rc = new WebRequestCycle(fakeApplication, new EmptyRequest(), new WebResponse());
                        serviceProvider.invokeAndWait(run);
                    } finally {
                        Application.unset();
                        rc.detach();
                    }
                }
            });
        } else {
            serviceProvider.invokeLater(run);
        }
    }
}
Also used : WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) IApplication(com.servoy.j2db.IApplication) WebResponse(org.apache.wicket.protocol.http.WebResponse) Form(com.servoy.j2db.persistence.Form) WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) RequestCycle(org.apache.wicket.RequestCycle) EmptyRequest(com.servoy.j2db.server.headlessclient.EmptyRequest) IFormController(com.servoy.j2db.IFormController) WebClientsApplication(com.servoy.j2db.server.headlessclient.WebClientsApplication) WebClient(com.servoy.j2db.server.headlessclient.WebClient) IDebugWebClient(com.servoy.j2db.IDebugWebClient) Solution(com.servoy.j2db.persistence.Solution) CoreException(org.eclipse.core.runtime.CoreException)

Example 50 with Solution

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

the class DebugUtils method getScopesAndFormsToReload.

public static Set<IFormController>[] getScopesAndFormsToReload(final ClientState clientState, Collection<IPersist> changes) {
    Set<IFormController> scopesToReload = new HashSet<IFormController>();
    final Set<IFormController> formsToReload = new HashSet<IFormController>();
    final SpecProviderState specProviderState = WebComponentSpecProvider.getSpecProviderState();
    final Set<Form> formsUpdated = new HashSet<Form>();
    for (IPersist persist : changes) {
        clientState.getFlattenedSolution().updatePersistInSolutionCopy(persist);
        if (persist instanceof ScriptMethod) {
            if (persist.getParent() instanceof Form) {
                Form form = (Form) persist.getParent();
                List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
                for (IFormController formController : cachedFormControllers) {
                    scopesToReload.add(formController);
                }
            } else if (persist.getParent() instanceof Solution) {
                LazyCompilationScope scope = clientState.getScriptEngine().getScopesScope().getGlobalScope(((ScriptMethod) persist).getScopeName());
                scope.remove((IScriptProvider) persist);
                scope.put((IScriptProvider) persist, (IScriptProvider) persist);
            } else if (persist.getParent() instanceof TableNode) {
                clientState.getFoundSetManager().reloadFoundsetMethod(((TableNode) persist.getParent()).getDataSource(), (IScriptProvider) persist);
            }
            if (clientState instanceof DebugJ2DBClient) {
                // ((DebugJ2DBClient)clientState).clearUserWindows();  no need for this as window API was refactored and it allows users to clean up dialogs
                ((DebugSwingFormMananger) ((DebugJ2DBClient) clientState).getFormManager()).fillScriptMenu();
            }
        } else if (persist instanceof ScriptVariable) {
            ScriptVariable sv = (ScriptVariable) persist;
            if (persist.getParent() instanceof Solution) {
                clientState.getScriptEngine().getScopesScope().getGlobalScope(sv.getScopeName()).put(sv);
            }
            if (persist.getParent() instanceof Form) {
                Form form = (Form) persist.getParent();
                List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
                for (IFormController formController : cachedFormControllers) {
                    FormScope scope = formController.getFormScope();
                    scope.put(sv);
                }
            }
        } else if (persist.getAncestor(IRepository.FORMS) != null) {
            final Form form = (Form) persist.getAncestor(IRepository.FORMS);
            if (form != null && form.isFormComponent().booleanValue()) {
                // if the changed form is a reference form we need to check if that is referenced by a loaded form..
                List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
                for (IFormController fc : cachedFormControllers) {
                    fc.getForm().acceptVisitor(new IPersistVisitor() {

                        @Override
                        public Object visit(IPersist o) {
                            if (o instanceof WebComponent) {
                                WebComponent wc = (WebComponent) o;
                                WebObjectSpecification spec = FormTemplateGenerator.getWebObjectSpecification(wc);
                                Collection<PropertyDescription> properties = spec != null ? spec.getProperties(FormComponentPropertyType.INSTANCE) : null;
                                if (properties != null && properties.size() > 0) {
                                    Form persistForm = (Form) wc.getAncestor(IRepository.FORMS);
                                    for (PropertyDescription pd : properties) {
                                        Form frm = FormComponentPropertyType.INSTANCE.getForm(wc.getProperty(pd.getName()), clientState.getFlattenedSolution());
                                        if (frm != null && (form.equals(frm) || FlattenedForm.hasFormInHierarchy(frm, form) || isReferenceFormUsedInForm(clientState, form, frm)) && !formsUpdated.contains(persistForm)) {
                                            formsUpdated.add(persistForm);
                                            List<IFormController> cfc = clientState.getFormManager().getCachedFormControllers(persistForm);
                                            for (IFormController formController : cfc) {
                                                formsToReload.add(formController);
                                            }
                                        }
                                    }
                                }
                            }
                            return IPersistVisitor.CONTINUE_TRAVERSAL;
                        }
                    });
                }
            } else if (!formsUpdated.contains(form)) {
                formsUpdated.add(form);
                List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
                for (IFormController formController : cachedFormControllers) {
                    formsToReload.add(formController);
                }
            }
            if (persist instanceof Form && clientState.getFormManager() instanceof DebugUtils.DebugUpdateFormSupport) {
                ((DebugUtils.DebugUpdateFormSupport) clientState.getFormManager()).updateForm((Form) persist);
            }
        } else if (persist instanceof ScriptCalculation) {
            ScriptCalculation sc = (ScriptCalculation) persist;
            if (((RemoteDebugScriptEngine) clientState.getScriptEngine()).recompileScriptCalculation(sc)) {
                List<String> al = new ArrayList<String>();
                al.add(sc.getDataProviderID());
                try {
                    String dataSource = clientState.getFoundSetManager().getDataSource(sc.getTable());
                    ((FoundSetManager) clientState.getFoundSetManager()).getRowManager(dataSource).clearCalcs(null, al);
                    ((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet(dataSource);
                } catch (Exception e) {
                    Debug.error(e);
                }
            }
        // if (clientState instanceof DebugJ2DBClient)
        // {
        // ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
        // }
        } else if (persist instanceof Relation) {
            ((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet((Relation) persist);
            List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
            try {
                String primary = ((Relation) persist).getPrimaryDataSource();
                for (IFormController formController : cachedFormControllers) {
                    if (primary.equals(formController.getDataSource())) {
                        final IFormController finalController = formController;
                        final Relation finalRelation = (Relation) persist;
                        formController.getForm().acceptVisitor(new IPersistVisitor() {

                            @Override
                            public Object visit(IPersist o) {
                                if (o instanceof Tab && Utils.equalObjects(finalRelation.getName(), ((Tab) o).getRelationName())) {
                                    formsToReload.add(finalController);
                                    return o;
                                }
                                if (o instanceof Field && ((Field) o).getValuelistID() > 0) {
                                    ValueList vl = clientState.getFlattenedSolution().getValueList(((Field) o).getValuelistID());
                                    if (vl != null && Utils.equalObjects(finalRelation.getName(), vl.getRelationName())) {
                                        formsToReload.add(finalController);
                                        return o;
                                    }
                                }
                                if (o instanceof WebComponent) {
                                    WebComponent webComponent = (WebComponent) o;
                                    WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
                                    if (spec != null) {
                                        Collection<PropertyDescription> properties = spec.getProperties(RelationPropertyType.INSTANCE);
                                        for (PropertyDescription pd : properties) {
                                            if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalRelation.getName())) {
                                                formsToReload.add(finalController);
                                                return o;
                                            }
                                        }
                                    }
                                }
                                return CONTINUE_TRAVERSAL;
                            }
                        });
                    }
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        } else if (persist instanceof ValueList) {
            ComponentFactory.flushValueList(clientState, (ValueList) persist);
            List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
            for (IFormController formController : cachedFormControllers) {
                final IFormController finalController = formController;
                final ValueList finalValuelist = (ValueList) persist;
                formController.getForm().acceptVisitor(new IPersistVisitor() {

                    @Override
                    public Object visit(IPersist o) {
                        if (o instanceof Field && ((Field) o).getValuelistID() > 0 && ((Field) o).getValuelistID() == finalValuelist.getID()) {
                            formsToReload.add(finalController);
                            return o;
                        }
                        if (o instanceof WebComponent) {
                            WebComponent webComponent = (WebComponent) o;
                            WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
                            if (spec != null) {
                                Collection<PropertyDescription> properties = spec.getProperties(ValueListPropertyType.INSTANCE);
                                for (PropertyDescription pd : properties) {
                                    if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalValuelist.getUUID().toString())) {
                                        formsToReload.add(finalController);
                                        return o;
                                    }
                                }
                            }
                        }
                        return CONTINUE_TRAVERSAL;
                    }
                });
            }
        } else if (persist instanceof Style) {
            ComponentFactory.flushStyle(null, ((Style) persist));
            List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
            String styleName = ((Style) persist).getName();
            for (IFormController formController : cachedFormControllers) {
                if (styleName.equals(formController.getForm().getStyleName())) {
                    formsToReload.add(formController);
                }
            }
        }
    }
    return new Set[] { scopesToReload, formsToReload };
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Set(java.util.Set) HashSet(java.util.HashSet) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ValueList(com.servoy.j2db.persistence.ValueList) LazyCompilationScope(com.servoy.j2db.scripting.LazyCompilationScope) FormScope(com.servoy.j2db.scripting.FormScope) WebComponent(com.servoy.j2db.persistence.WebComponent) Field(com.servoy.j2db.persistence.Field) Relation(com.servoy.j2db.persistence.Relation) Style(com.servoy.j2db.persistence.Style) ValueList(com.servoy.j2db.persistence.ValueList) List(java.util.List) ArrayList(java.util.ArrayList) Solution(com.servoy.j2db.persistence.Solution) HashSet(java.util.HashSet) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) DebugSwingFormMananger(com.servoy.j2db.debug.DebugJ2DBClient.DebugSwingFormMananger) RhinoException(org.mozilla.javascript.RhinoException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServoyException(com.servoy.j2db.util.ServoyException) PropertyDescription(org.sablo.specification.PropertyDescription) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) SpecProviderState(org.sablo.specification.SpecProviderState) Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) IScriptProvider(com.servoy.j2db.persistence.IScriptProvider) TableNode(com.servoy.j2db.persistence.TableNode) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) Collection(java.util.Collection) IFormController(com.servoy.j2db.IFormController) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3