Search in sources :

Example 1 with ColumnWrapper

use of com.servoy.j2db.persistence.ColumnWrapper 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 ColumnWrapper

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

the class FoundSet method determineSortColumns.

/**
 * @param sqlSelect
 * @return
 * @throws RepositoryException
 */
private List<SortColumn> determineSortColumns(QuerySelect sqlSelect) throws RepositoryException {
    List<SortColumn> sortColumns = null;
    for (IQuerySort qsort : iterate(sqlSelect.getSorts())) {
        if (qsort instanceof QuerySort) {
            IQuerySelectValue qcolumn = ((QuerySort) qsort).getColumn();
            if (qcolumn instanceof QueryColumn) {
                ColumnWrapper columnWrapper = findColumnWrapperForColumn(sqlSelect, (QueryColumn) qcolumn);
                if (columnWrapper != null) {
                    if (sortColumns == null) {
                        sortColumns = new ArrayList<>();
                    }
                    SortColumn sortColumn = new SortColumn(columnWrapper);
                    sortColumn.setSortOrder(((QuerySort) qsort).isAscending() ? SortColumn.ASCENDING : SortColumn.DESCENDING);
                    sortColumns.add(sortColumn);
                    // otherwise stop searching
                    continue;
                }
            }
        }
    }
    // stop searching when no match could be made to a valid column, return the ones found or null when nothing matched
    return sortColumns;
}
Also used : QueryColumn(com.servoy.j2db.query.QueryColumn) IQuerySort(com.servoy.j2db.query.IQuerySort) QuerySort(com.servoy.j2db.query.QuerySort) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) IQuerySort(com.servoy.j2db.query.IQuerySort) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 3 with ColumnWrapper

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

the class DataProviderEditor method getValue.

public Object getValue() {
    Object retval = null;
    Object[] selections = list.getSelectedValues();
    IDataProvider[] array = new IDataProvider[selections.length];
    for (int i = 0; i < selections.length; i++) {
        Object o = selections[i];
        if (o instanceof IDataProvider) {
            Object item = relationsComboBox.getSelectedItem();
            if (item instanceof Relation && o instanceof IColumn) {
                array[i] = new ColumnWrapper((IColumn) o, new Relation[] { ((Relation) item) });
            } else {
                array[i] = (IDataProvider) o;
            }
        }
    }
    if (selections.length == 1) {
        retval = array[0];
    } else {
        retval = array;
    }
    if (// if used to setDataProviderID
    returnValueAsString) {
        if (array != null && array.length != 0 && array[0] != null) {
            retval = array[0].getDataProviderID();
        } else {
            return null;
        }
    }
    relation = null;
    return retval;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) IColumn(com.servoy.j2db.persistence.IColumn) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 4 with ColumnWrapper

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

the class SortModel method right.

private void right() {
    flagChanged();
    Object o = dpe.getValue();
    if (o != null) {
        int currentSize = model.getRowCount();
        if (o instanceof Column) {
            if (model.addRow(new SortColumn((Column) o)))
                table.setRowSelectionInterval(currentSize, currentSize);
        } else if (o instanceof ColumnWrapper) {
            if (model.addRow(new SortColumn((ColumnWrapper) o)))
                table.setRowSelectionInterval(currentSize, currentSize);
        } else {
            boolean clear = false;
            IDataProvider[] array = (IDataProvider[]) o;
            for (IDataProvider element : array) {
                boolean added = false;
                if (element instanceof ColumnWrapper) {
                    added = model.addRow(new SortColumn((ColumnWrapper) element));
                } else if (element instanceof Column) {
                    added = model.addRow(new SortColumn((Column) element));
                }
                if (added) {
                    if (!clear) {
                        table.clearSelection();
                        clear = true;
                    }
                    table.addRowSelectionInterval(currentSize, currentSize);
                    currentSize++;
                }
            }
        }
    }
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) Column(com.servoy.j2db.persistence.Column) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 5 with ColumnWrapper

use of com.servoy.j2db.persistence.ColumnWrapper 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)

Aggregations

ColumnWrapper (com.servoy.j2db.persistence.ColumnWrapper)9 IColumn (com.servoy.j2db.persistence.IColumn)7 IDataProvider (com.servoy.j2db.persistence.IDataProvider)5 Relation (com.servoy.j2db.persistence.Relation)4 Column (com.servoy.j2db.persistence.Column)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)2 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)2 ITable (com.servoy.j2db.persistence.ITable)2 QueryColumn (com.servoy.j2db.query.QueryColumn)2 FindState (com.servoy.j2db.dataprocessing.FindState)1 FoundSetEvent (com.servoy.j2db.dataprocessing.FoundSetEvent)1 IFoundSetEventListener (com.servoy.j2db.dataprocessing.IFoundSetEventListener)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1 AggregateVariable (com.servoy.j2db.persistence.AggregateVariable)1 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)1 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)1 ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)1