Search in sources :

Example 1 with IColumn

use of com.servoy.j2db.persistence.IColumn 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;
}
Also used : ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) IDataProvider(com.servoy.j2db.persistence.IDataProvider) Relation(com.servoy.j2db.persistence.Relation) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IColumn(com.servoy.j2db.persistence.IColumn) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) RemoteException(java.rmi.RemoteException)

Example 2 with IColumn

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

the class NGUtils method getDataProviderPropertyDescription.

public static PropertyDescription getDataProviderPropertyDescription(String dataProviderName, ITable table, IApplication app, boolean parseHTML, boolean useLocalDateTime) {
    if (table == null || dataProviderName == null)
        return null;
    IColumn column = table.getColumn(dataProviderName);
    int dpType = 0;
    if (column != null) {
        ColumnInfo ci = column.getColumnInfo();
        if (ci != null && ci.hasFlag(IBaseColumn.UUID_COLUMN)) {
            return UUID_DATAPROVIDER_CACHED_PD;
        }
        if (app != null)
            dpType = app.getFoundSetManager().getConvertedTypeForColumn(column, true);
        else
            dpType = table.getColumnType(dataProviderName);
    }
    return getDataProviderPropertyDescription(dpType, parseHTML, useLocalDateTime);
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo)

Example 3 with IColumn

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

the class NGUtils method getDataProviderPropertyDescription.

public static PropertyDescription getDataProviderPropertyDescription(String dataProviderName, IApplication app, Form form, ITable table, boolean parseHTMLIfString, boolean useLocalDateTime) {
    FormAndTableDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(app.getFlattenedSolution(), form, table);
    IDataProvider dp = null;
    try {
        dp = dpLookup.getDataProvider(dataProviderName);
    } catch (RepositoryException e) {
        Debug.error(e);
    }
    if (dp != null) {
        int dpType;
        if (dp instanceof IColumn || dp instanceof ColumnWrapper) {
            IColumn column = (dp instanceof IColumn) ? (IColumn) dp : ((ColumnWrapper) dp).getColumn();
            ColumnInfo ci = column.getColumnInfo();
            if (ci != null && ci.hasFlag(IBaseColumn.UUID_COLUMN)) {
                return UUID_DATAPROVIDER_CACHED_PD;
            }
            dpType = app.getFoundSetManager().getConvertedTypeForColumn(column, true);
        } else
            dpType = dp.getDataProviderType();
        return getDataProviderPropertyDescription(dpType, parseHTMLIfString, useLocalDateTime);
    }
    return null;
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 4 with IColumn

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

the class ViewFoundSet method determineSortColumns.

private List<SortColumn> determineSortColumns() {
    List<IQuerySort> sorts = select.getSorts();
    if (sorts != null) {
        return sorts.stream().filter(QuerySort.class::isInstance).map(QuerySort.class::cast).map(sort -> {
            String name = sort.getColumn().getAliasOrName();
            IColumn column = getTable().getColumnBySqlname(name);
            if (column != null) {
                return new SortColumn(column, sort.isAscending() ? SortColumn.ASCENDING : SortColumn.DESCENDING);
            }
            return null;
        }).filter(Objects::nonNull).collect(Collectors.toList());
    }
    return null;
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) QuerySort(com.servoy.j2db.query.QuerySort) IQuerySort(com.servoy.j2db.query.IQuerySort) IQuerySort(com.servoy.j2db.query.IQuerySort)

Example 5 with IColumn

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

the class DataProviderEditor method fillDataProviderList.

protected void fillDataProviderList() {
    try {
        ITable table = null;
        if (definedTable == null) {
            FormManager fm = (FormManager) application.getFormManager();
            FormController fc = fm.getCurrentMainShowingFormController();
            if (fc != null) {
                Form form = fc.getForm();
                table = application.getFlattenedSolution().getTable(form.getDataSource());
            }
        } else {
            if (!showRelatedOptionsOnly)
                table = definedTable;
        }
        DefaultListModel model = (DefaultListModel) list.getModel();
        model.removeAllElements();
        if (showNoneOption)
            model.addElement("-none-");
        if (!showColumnsOnly)
            model.addElement("*columns");
        Object o = relationsComboBox.getSelectedItem();
        if (o != null) {
            if (o instanceof String) {
            // table = form.getTable();
            } else {
                table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
            }
            if (table != null) {
                Iterator<Column> it = table.getColumnsSortedByName();
                while (it.hasNext()) {
                    IColumn c = it.next();
                    ColumnInfo ci = c.getColumnInfo();
                    if (ci != null && ci.isExcluded()) {
                        continue;
                    }
                    if (hideMediaColumns) {
                        // use dataprovider type as defined by column converter
                        ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
                        if (componentFormat.dpType == IColumnTypes.MEDIA) {
                            continue;
                        }
                    }
                    model.addElement(c);
                }
            }
        }
        FlattenedSolution s = application.getFlattenedSolution();
        if (table != null && !showColumnsOnly) {
            Iterator it = s.getScriptCalculations(table, true);
            if (it.hasNext()) {
                model.addElement("*calculations");
            }
            while (it.hasNext()) {
                ScriptCalculation sc = (ScriptCalculation) it.next();
                for (int i = 0; i < model.size(); i++) {
                    Object obj = model.elementAt(i);
                    if (obj instanceof IDataProvider) {
                        IDataProvider dp = (IDataProvider) obj;
                        if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
                            // remove the column from the list if use by
                            model.remove(i);
                            // stored calc
                            break;
                        }
                    }
                }
                model.addElement(sc);
            }
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
            Iterator it3 = s.getAggregateVariables(table, true);
            if (it3.hasNext()) {
                model.addElement("*aggregates");
            }
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (table != null && showColumnsOnly && showSortableOnly) {
            Iterator it3 = s.getAggregateVariables(table, true);
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (showGlobalsOption && showColumnsOnly) {
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) DefaultListModel(javax.swing.DefaultListModel) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IDataProvider(com.servoy.j2db.persistence.IDataProvider) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Aggregations

IColumn (com.servoy.j2db.persistence.IColumn)19 Column (com.servoy.j2db.persistence.Column)10 ITable (com.servoy.j2db.persistence.ITable)7 ColumnWrapper (com.servoy.j2db.persistence.ColumnWrapper)6 IDataProvider (com.servoy.j2db.persistence.IDataProvider)6 Relation (com.servoy.j2db.persistence.Relation)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 BaseQueryTable (com.servoy.base.query.BaseQueryTable)5 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)5 QueryTable (com.servoy.j2db.query.QueryTable)5 AggregateVariable (com.servoy.j2db.persistence.AggregateVariable)4 QueryColumn (com.servoy.j2db.query.QueryColumn)4 IBaseColumn (com.servoy.base.persistence.IBaseColumn)3 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)3 Table (com.servoy.j2db.persistence.Table)3 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)3 IQuerySort (com.servoy.j2db.query.IQuerySort)3 QuerySort (com.servoy.j2db.query.QuerySort)3 SafeArrayList (com.servoy.j2db.util.SafeArrayList)3 ArrayList (java.util.ArrayList)3