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");
}
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;
}
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;
}
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());
}
}
}
}
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);
}
}
}
Aggregations