use of com.servoy.j2db.persistence.IDataProvider in project servoy-client by Servoy.
the class FlattenedSolution method getGlobalDataProviderEx.
private IDataProvider getGlobalDataProviderEx(String id, boolean quiet) throws RepositoryException {
if (id == null)
return null;
Pair<String, String> scope = ScopesUtils.getVariableScope(id);
if (scope.getLeft() != null) /* global scope */
{
// search all objects,will return globals
ScriptVariable global = AbstractBase.selectByName(getScriptVariables(scope.getLeft(), false), scope.getRight());
if (global != null) {
return global;
}
// try @enum global variables
return getEnumDataProvider(id);
}
// in case of multi-level relations we have more that 1 dot
int indx = id.lastIndexOf('.');
if (indx > 0) {
String rel_name = id.substring(0, indx);
String col = id.substring(indx + 1);
Relation[] relations = getRelationSequence(rel_name);
if (relations == null) {
return null;
}
Relation r = relations[relations.length - 1];
if (quiet) {
boolean missingSrv = true;
String ds = r.getForeignDataSource();
if (ds != null) {
String[] st = DataSourceUtilsBase.getDBServernameTablename(ds);
if (st != null && st.length == 2) {
try {
missingSrv = (r.getRootObject().getServer(st[0]) == null);
} catch (RemoteException e) {
// we are in developer here - shouldn't happen
}
}
}
if (missingSrv)
return null;
}
// TODO if this is refactord out to be resolved outside the relation also look at the DataProviderConverter
// the call from that class to flattenedSolution.getGlobalDataProvider(value);
Column[] cols = r.getForeignColumns(this);
if (cols == null || cols.length == 0)
return null;
IDataProvider c = getDataProviderForTable(getTable(r.getForeignDataSource()), col);
if (r != null && c instanceof IColumn) {
return new ColumnWrapper((IColumn) c, relations);
}
return c;
}
return null;
}
use of com.servoy.j2db.persistence.IDataProvider 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;
}
use of com.servoy.j2db.persistence.IDataProvider in project servoy-client by Servoy.
the class UsedDataProviderTracker method usedFromRecord.
/**
* Used name from Record,
* @param record may be null (for global relations)
* @param name
*/
protected void usedFromRecord(IRecordInternal record, String name) {
IRecordInternal currentRecord = record;
try {
// $NON-NLS-1$
String[] parts = name.split("\\.");
for (String part : parts) {
Relation relation = flattenedSolution.getRelation(part);
if (relation != null) {
// calc depends on the relation, add a dependency for the primary data providers for the relation
IDataProvider[] primaryDataProviders = relation.getPrimaryDataProviders(flattenedSolution);
for (IDataProvider prim : primaryDataProviders) {
if (prim instanceof LiteralDataprovider)
continue;
String primdp = prim.getDataProviderID();
if (ScopesUtils.isVariableScope(primdp)) {
// global
usedGlobal(primdp);
} else {
// column
if (currentRecord != null) {
if (currentRecord.getRawData() == null) {
if (currentRecord instanceof PrototypeState) {
Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
} else {
// should not happen
Debug.error("Unexpected state: calculation '" + name + "' depends on column '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
}
} else {
usedColumn(currentRecord.getParentFoundSet().getDataSource(), currentRecord.getRawData().getPKHashKey(), primdp);
}
}
}
}
IFoundSetInternal foundSet = null;
if (currentRecord != null)
foundSet = currentRecord.getRelatedFoundSet(relation.getName());
currentRecord = null;
if (foundSet instanceof RelatedFoundSet) {
usedRelatedFoundSet(relation.getName(), (RelatedFoundSet) foundSet);
currentRecord = foundSet.getRecord(foundSet.getSelectedIndex());
}
} else {
if (currentRecord != null) {
IFoundSetInternal foundSet = currentRecord.getParentFoundSet();
if (foundSet.getSQLSheet().containsAggregate(part)) {
// aggregate
usedAggregate(foundSet, part);
} else {
// field or calc
if (currentRecord.has(part)) {
if (currentRecord.getRawData() == null) {
if (currentRecord instanceof PrototypeState) {
Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
} else {
// should not happen
Debug.error("Unexpected state: calculation '" + name + "' depends on field '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
}
} else {
usedColumn(foundSet.getDataSource(), currentRecord.getRawData().getPKHashKey(), part);
}
}
}
}
return;
}
if (currentRecord == null) {
return;
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
use of com.servoy.j2db.persistence.IDataProvider in project servoy-client by Servoy.
the class DataAdapterList method valueChanged.
@Override
public void valueChanged(ModificationEvent e) {
if (record != null && e != null && e.getName() != null) {
for (Entry<IWebFormController, String> relatedFormEntry : getVisibleChildFormCopy().entrySet()) {
IWebFormController relatedForm = relatedFormEntry.getKey();
String relatedFormRelation = relatedFormEntry.getValue();
boolean depends = false;
Relation[] relations = getApplication().getFlattenedSolution().getRelationSequence(relatedFormRelation);
for (int r = 0; !depends && relations != null && r < relations.length; r++) {
try {
IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(getApplication().getFlattenedSolution());
for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
}
} catch (RepositoryException ex) {
Debug.log(ex);
}
}
if (depends) {
relatedForm.loadRecords(record.getRelatedFoundSet(relatedFormRelation, ((BasicFormController) relatedForm).getDefaultSortColumns()));
}
}
}
if (!findMode && this.record != null && e.getName() != null && (e.getRecord() == null || e.getRecord() == this.record) && this.lookupDependency.containsKey(e.getName()) && !(this.record instanceof PrototypeState)) {
if (this.record.startEditing()) {
List<Pair<String, String>> lookupDepencies = this.lookupDependency.get(e.getName());
for (Pair<String, String> dependency : lookupDepencies) {
Object obj = this.record.getValue(dependency.getRight());
this.record.setValue(dependency.getLeft(), obj);
}
}
}
// one of the relations could be changed make sure they are recreated.
createRelationListeners();
if (getForm().isFormVisible()) {
pushChangedValues(e.getName(), true);
}
}
use of com.servoy.j2db.persistence.IDataProvider in project servoy-client by Servoy.
the class ComponentFactory method createGraphicalComponent.
private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
int style_halign = -1;
int style_valign = -1;
int textTransform = 0;
int mediaid = 0;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_valign = ss.getVAlign(s);
style_halign = ss.getHAlign(s);
boolean parseMedia = true;
// anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
if (application.getApplicationType() == IApplication.WEB_CLIENT) {
parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
}
if (parseMedia) {
Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
if (mediaUrl != null && mediaUrl.toString() != null) {
String mediaUrlString = mediaUrl.toString();
int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
if (start != -1) {
String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
if (name.endsWith("')") || name.endsWith("\")"))
name = name.substring(0, name.length() - 2);
if (name.endsWith(")"))
name = name.substring(0, name.length() - 1);
Media media = application.getFlattenedSolution().getMedia(name);
if (media != null) {
mediaid = media.getID();
}
}
}
}
String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
if (transform != null) {
if ("uppercase".equals(transform)) {
textTransform = ILabel.UPPERCASE;
} else if ("lowercase".equals(transform)) {
textTransform = ILabel.LOWERCASE;
} else if ("capitalize".equals(transform)) {
textTransform = ILabel.CAPITALIZE;
}
}
}
}
ILabel l;
AbstractRuntimeLabel<? extends ILabel> scriptable;
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
if (ComponentFactory.isButton(label)) {
IButton button;
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
} else {
scriptable = new RuntimeDataButton(jsChangeRecorder, application);
button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
}
((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
button.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
button.setRolloverIcon(label.getRolloverImageMediaID());
button.setRolloverEnabled(true);
} catch (Exception ex) {
Debug.error(ex);
}
}
l = button;
} else {
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
} else {
scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
}
((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
l.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
l.setRolloverIcon(label.getRolloverImageMediaID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
if (mnemonic != null && mnemonic.length() > 0) {
l.setDisplayedMnemonic(mnemonic.charAt(0));
}
l.setTextTransform(textTransform);
if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
l.addScriptExecuter(el);
if (label.getOnActionMethodID() > 0)
l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
if (label.getOnDoubleClickMethodID() > 0)
l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
if (label.getOnRightClickMethodID() > 0)
l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
}
if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
int onRenderMethodID = label.getOnRenderMethodID();
AbstractBase onRenderPersist = label;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
}
l.setRotation(label.getRotation());
l.setFocusPainted(label.getShowFocus());
l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
try {
int halign = label.getHorizontalAlignment();
if (halign != -1) {
l.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
l.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
int valign = label.getVerticalAlignment();
if (valign != -1) {
l.setVerticalAlignment(valign);
} else if (style_valign != -1) {
l.setVerticalAlignment(style_valign);
}
try {
if (!label.getDisplaysTags()) {
l.setText(application.getI18NMessageIfPrefixed(label.getText()));
}
} catch (RuntimeException e1) {
// ignore
}
l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
if (label.getImageMediaID() > 0) {
try {
l.setMediaIcon(label.getImageMediaID());
} catch (Exception e) {
Debug.error(e);
}
} else if (mediaid > 0) {
try {
l.setMediaIcon(mediaid);
} catch (Exception e) {
Debug.error(e);
}
}
if (label.getDataProviderID() != null) {
scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
}
applyBasicComponentProperties(application, l, label, styleInfo);
Border border = null;
Insets insets = null;
if (label.getBorderType() != null) {
border = ComponentFactoryHelper.createBorder(label.getBorderType());
}
if (label.getMargin() != null) {
insets = label.getMargin();
}
if (styleInfo != null && (border == null || insets == null)) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (border == null && ss.hasBorder(s)) {
border = ss.getBorder(s);
}
if (insets == null && ss.hasMargin(s)) {
insets = ss.getMargin(s);
}
}
}
if (border != null && insets != null) {
l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
} else if (border == null && insets != null && l instanceof IButton) {
((IButton) l).setMargin(insets);
} else // supports setMargin, then fake the margins through empty border. (issue 166391)
if (border == null && insets != null) {
l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}
if (l instanceof IAnchoredComponent) {
((IAnchoredComponent) l).setAnchors(label.getAnchors());
}
return l;
}
Aggregations