Search in sources :

Example 6 with ISupportChilds

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

the class JSForm method getMethodId.

public static int getMethodId(IApplication application, AbstractBase base, ScriptMethod method) {
    ISupportChilds parent = method.getParent();
    Form f = getFormParent(base);
    // quick check if it is solution or own form..
    if (parent instanceof Solution || parent.getUUID().equals(f.getUUID())) {
        return method.getID();
    }
    // it could be a extends form
    while (f != null && f.getExtendsID() > 0) {
        f = application.getFlattenedSolution().getForm(f.getExtendsID());
        if (f != null && parent.getUUID().equals(f.getUUID())) {
            return method.getID();
        }
    }
    // or a foundset method
    Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(f.getDataSource(), false);
    while (foundsetMethods.hasNext()) {
        if (foundsetMethods.next().getID() == method.getID()) {
            return method.getID();
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    throw new RuntimeException("Method " + method.getName() + " must be a solution method, foundset method or a forms own method");
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 7 with ISupportChilds

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

the class JSBaseContainer method getCorrectIJSParent.

/**
 * When creating a JSWebComponent from a who-knows-how-deeply-nested (in case of responsive forms) webComponent in a form and we only know the form,
 * then we need to get step by step the solution model objects in order to use the correct direct parent for the child SM object creation.
 *
 * @param startingContainer
 * @param possiblyNestedChild nested child component
 * @return the direct parent (IJSParent) of the given webComponent.
 */
private IJSParent<?> getCorrectIJSParent(JSBaseContainer<?> startingContainer, IPersist possiblyNestedChild) {
    ArrayList<ISupportChilds> parentHierarchy = new ArrayList<>();
    ISupportChilds parent = possiblyNestedChild.getParent();
    while (parent != (startingContainer.getContainer() instanceof IFlattenedPersistWrapper<?> ? ((IFlattenedPersistWrapper<?>) startingContainer.getContainer()).getWrappedPersist() : startingContainer.getContainer()) && !(parent instanceof Form)) {
        parentHierarchy.add(parent);
        parent = parent.getParent();
    }
    for (int i = parentHierarchy.size(); --i >= 0; ) {
        ISupportChilds container = parentHierarchy.get(i);
        if (container instanceof LayoutContainer) {
            startingContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer((IJSParent<?>) startingContainer, (LayoutContainer) container);
        } else {
            // $NON-NLS-1$
            throw new RuntimeException("unexpected parent: " + container);
        }
    }
    return startingContainer;
}
Also used : IFlattenedPersistWrapper(com.servoy.j2db.persistence.IFlattenedPersistWrapper) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) Form(com.servoy.j2db.persistence.Form) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 8 with ISupportChilds

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

the class PersistHelper method hasOverrideChildren.

/**
 * Example if a superform has a tabPanel with a tab, and a derived form adds another tab to the tabpannel then  hasOverrideChildren(derivedTabPanel) returns true
 */
public static boolean hasOverrideChildren(IPersist persist) {
    if (persist instanceof ISupportChilds && persist instanceof ISupportExtendsID) {
        ISupportChilds p = (ISupportChilds) persist;
        ISupportChilds superPersist = (ISupportChilds) PersistHelper.getSuperPersist((ISupportExtendsID) persist);
        if (superPersist == null) {
            return false;
        }
        for (IPersist child : Utils.iterate(p.getAllObjects())) {
            if (child instanceof ISupportExtendsID && !PersistHelper.isOverrideElement((ISupportExtendsID) child)) {
                // is is an etra child element compared to it's super child elements
                return true;
            } else if (((AbstractBase) child).hasOverrideProperties()) {
                return true;
            }
        }
    }
    return false;
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) IPersist(com.servoy.j2db.persistence.IPersist)

Example 9 with ISupportChilds

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

the class FlattenedSolution method updatePersistInSolutionCopy.

public void updatePersistInSolutionCopy(final IPersist persist) {
    if (mainSolution == null && loginFlattenedSolution != null) {
        loginFlattenedSolution.updatePersistInSolutionCopy(persist);
        return;
    }
    if (copySolution == null)
        return;
    IPersist copyPersist = (IPersist) copySolution.acceptVisitor(new IPersistVisitor() {

        public Object visit(IPersist o) {
            if (o.getUUID().equals(persist.getUUID())) {
                return o;
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (copyPersist != null) {
        ((AbstractBase) copyPersist).copyPropertiesMap(((AbstractBase) persist).getPropertiesMap(), false);
        ISupportChilds parent = copyPersist.getParent();
        flush(persist);
        if (parent instanceof Form) {
            ((Form) parent).setLastModified(System.currentTimeMillis());
        } else if (copyPersist instanceof Form) {
            ((Form) copyPersist).setLastModified(System.currentTimeMillis());
        }
    } else if (persist.getParent() != null && !(persist.getParent() instanceof Solution)) {
        ISupportChilds copyParent = (ISupportChilds) copySolution.acceptVisitor(new IPersistVisitor() {

            public Object visit(IPersist o) {
                if (o.getUUID().equals(persist.getParent().getUUID())) {
                    return o;
                }
                return IPersistVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (copyParent != null) {
            if (persist instanceof ICloneable) {
                ((ICloneable) persist).clonePersist((AbstractBase) copyParent);
            } else {
                copyParent.addChild(persist);
            }
            flush(persist);
            if (copyParent instanceof Form) {
                ((Form) copyParent).setLastModified(System.currentTimeMillis());
            }
        }
    }
}
Also used : ICloneable(com.servoy.j2db.persistence.ICloneable) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) AbstractBase(com.servoy.j2db.persistence.AbstractBase) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

Example 10 with ISupportChilds

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

the class PersistIndex method initDatasourceCache.

protected void initDatasourceCache(String datasource) {
    if ((datasourceToPersist.size() == 0) || (datasource != null && datasourceToPersist.get(datasource) == null)) {
        visit((persist) -> {
            if (persist instanceof TableNode) {
                String tableDs = ((TableNode) persist).getDataSource();
                if (tableDs != null) {
                    ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(tableDs);
                    if (dsMap == null) {
                        dsMap = new ConcurrentHashMap<>(4);
                        dsMap.put(ScriptCalculation.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(TableNode.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(AggregateVariable.class, new ConcurrentHashMap<String, IPersist>(4));
                        dsMap.put(ScriptMethod.class, new ConcurrentHashMap<String, IPersist>(4));
                        datasourceToPersist.put(tableDs, dsMap);
                    }
                    ConcurrentMap<String, IPersist> tableNodeCache = dsMap.get(TableNode.class);
                    Solution solution = (Solution) ((TableNode) persist).getAncestor(IRepository.SOLUTIONS);
                    tableNodeCache.put(solution.getName(), persist);
                    return IPersistVisitor.CONTINUE_TRAVERSAL;
                }
            } else {
                ISupportChilds parent = persist.getParent();
                if (persist instanceof ScriptCalculation) {
                    if (parent instanceof TableNode) {
                        ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                        addInDatasourceCache(dsMap.get(ScriptCalculation.class), persist, datasource);
                    } else {
                        Debug.error("Something wrong with ScriptCalculation " + ((ScriptCalculation) persist).getName() + " should  have table as parent but the parent is: " + parent);
                    }
                } else if (persist instanceof AggregateVariable) {
                    if (parent instanceof TableNode) {
                        ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                        addInDatasourceCache(dsMap.get(AggregateVariable.class), persist, datasource);
                    } else {
                        Debug.error("Something wrong with AggregateVariable " + ((ScriptCalculation) persist).getName() + " should  have table as parent but the parent is: " + parent);
                    }
                } else if (persist instanceof ScriptMethod && parent instanceof TableNode) {
                    ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = datasourceToPersist.get(((TableNode) parent).getDataSource());
                    addInDatasourceCache(dsMap.get(ScriptMethod.class), persist, datasource);
                }
            }
            return persist instanceof Solution ? IPersistVisitor.CONTINUE_TRAVERSAL : IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        });
        if (datasource != null && datasourceToPersist.get(datasource) == null) {
            ConcurrentMap<Class<? extends IPersist>, ConcurrentMap<String, IPersist>> dsMap = new ConcurrentHashMap<>(4);
            dsMap.put(ScriptCalculation.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(TableNode.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(AggregateVariable.class, new ConcurrentHashMap<String, IPersist>(4));
            dsMap.put(ScriptMethod.class, new ConcurrentHashMap<String, IPersist>(4));
            datasourceToPersist.put(datasource, dsMap);
        }
    }
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ConcurrentMap(java.util.concurrent.ConcurrentMap) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) IPersist(com.servoy.j2db.persistence.IPersist) TableNode(com.servoy.j2db.persistence.TableNode) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)11 Form (com.servoy.j2db.persistence.Form)6 IPersist (com.servoy.j2db.persistence.IPersist)6 Solution (com.servoy.j2db.persistence.Solution)4 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 JSONObject (org.json.JSONObject)3 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 IPersistVisitor (com.servoy.j2db.persistence.IPersistVisitor)2 IRootObject (com.servoy.j2db.persistence.IRootObject)2 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 TableNode (com.servoy.j2db.persistence.TableNode)2 UUID (com.servoy.j2db.util.UUID)2 Point (java.awt.Point)2