Search in sources :

Example 46 with Relation

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

the class RowManager method unregister.

void unregister(IRowListener fs) {
    if (fsm.config.optimizedNotifyChange() && fs instanceof RelatedFoundSet) {
        FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
        RelatedFoundSet relatedFoundSet = (RelatedFoundSet) fs;
        Relation relation = flattenedSolution.getRelation(relatedFoundSet.getRelationName());
        if (relation != null && Relation.isValid(relation, flattenedSolution)) {
            Object[] eqArgs = relatedFoundSet.getWhereArgs(true);
            if (eqArgs != null) {
                ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> listenersByEqualValues = listenersByRelationEqualValues.get(relation.getName());
                if (listenersByEqualValues != null) {
                    listenersByEqualValues.remove(createPKHashKey(eqArgs), relatedFoundSet);
                }
            }
        }
    }
    listeners.remove(fs);
}
Also used : Relation(com.servoy.j2db.persistence.Relation) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 47 with Relation

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

the class RowManager method fireNotifyChange.

void fireNotifyChange(IRowListener skip, Row row, String pkHashKey, Object[] changedColumns, int eventType, boolean isAggregateChange, boolean skipFSM) {
    List<IRowListener> toNotify = new ArrayList<>();
    if (eventType == RowEvent.INSERT && fsm.config.optimizedNotifyChange()) {
        FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
        listenersByRelationEqualValues.entrySet().stream().forEach(entry -> {
            Relation relation = flattenedSolution.getRelation(entry.getKey());
            List<Column> columns = relation.getForeignColumnsForEqualConditions(flattenedSolution);
            if (!columns.isEmpty()) {
                Object[] eqArgs = columns.stream().map(column -> row.getValue(column.getDataProviderID())).toArray();
                String eqHash = RowManager.createPKHashKey(eqArgs);
                toNotify.addAll(entry.getValue().get(eqHash));
            }
        });
    } else {
        // add all related foundsets
        listenersByRelationEqualValues.values().stream().map(ConcurrentSoftvaluesMultimap::allValues).forEach(toNotify::addAll);
    }
    toNotify.addAll(listeners.keySet());
    toNotify.remove(skip);
    if (!toNotify.isEmpty()) {
        RowEvent e = new RowEvent(this, row, pkHashKey, eventType, changedColumns, isAggregateChange);
        toNotify.forEach(listener -> listener.notifyChange(e));
    }
    if (!skipFSM)
        fsm.notifyChange(sheet.getTable());
}
Also used : ISQLUpdate(com.servoy.j2db.query.ISQLUpdate) Arrays(java.util.Arrays) Pair(com.servoy.j2db.util.Pair) Date(java.util.Date) QueryColumn(com.servoy.j2db.query.QueryColumn) Debug(com.servoy.j2db.util.Debug) SetCondition(com.servoy.j2db.query.SetCondition) QueryTable(com.servoy.j2db.query.QueryTable) Utils(com.servoy.j2db.util.Utils) Map(java.util.Map) IBaseSQLCondition(com.servoy.base.query.IBaseSQLCondition) AbstractBaseQuery(com.servoy.j2db.query.AbstractBaseQuery) IRepository(com.servoy.j2db.persistence.IRepository) Collection(java.util.Collection) QueryDelete(com.servoy.j2db.query.QueryDelete) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Streams(com.google.common.collect.Streams) Table(com.servoy.j2db.persistence.Table) RemoteException(java.rmi.RemoteException) List(java.util.List) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) Entry(java.util.Map.Entry) CacheBuilder(com.google.common.cache.CacheBuilder) Arrays.stream(java.util.Arrays.stream) UUID(com.servoy.j2db.util.UUID) Types(java.sql.Types) QueryInsert(com.servoy.j2db.query.QueryInsert) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) HashMap(java.util.HashMap) GlobalScope(com.servoy.j2db.scripting.GlobalScope) ReferenceQueue(java.lang.ref.ReferenceQueue) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SafeArrayList(com.servoy.j2db.util.SafeArrayList) Relation(com.servoy.j2db.persistence.Relation) ServoyException(com.servoy.j2db.util.ServoyException) QueryUpdate(com.servoy.j2db.query.QueryUpdate) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Iterator(java.util.Iterator) CalculationDependencyData(com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData) QuerySelect(com.servoy.j2db.query.QuerySelect) SoftReferenceWithData(com.servoy.j2db.util.SoftReferenceWithData) IServer(com.servoy.j2db.persistence.IServer) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentSoftvaluesMultimap(com.servoy.j2db.util.ConcurrentSoftvaluesMultimap) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) BlobMarkerValue(com.servoy.j2db.dataprocessing.ValueFactory.BlobMarkerValue) Column(com.servoy.j2db.persistence.Column) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Collections(java.util.Collections) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Relation(com.servoy.j2db.persistence.Relation) QueryColumn(com.servoy.j2db.query.QueryColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column)

Example 48 with Relation

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

the class RowManager method register.

void register(IRowListener fs) {
    boolean listenersByEqualValuesAdded = false;
    if (fsm.config.optimizedNotifyChange() && fs instanceof RelatedFoundSet) {
        FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
        RelatedFoundSet relatedFoundSet = (RelatedFoundSet) fs;
        Relation relation = flattenedSolution.getRelation(relatedFoundSet.getRelationName());
        if (relation != null && Relation.isValid(relation, flattenedSolution)) {
            Object[] eqArgs = relatedFoundSet.getWhereArgs(true);
            if (eqArgs != null && !stream(eqArgs).anyMatch(DbIdentValue.class::isInstance)) {
                ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> listenersByEqualValues = listenersByRelationEqualValues.get(relation.getName());
                if (listenersByEqualValues == null) {
                    listenersByEqualValues = new ConcurrentSoftvaluesMultimap<String, RelatedFoundSet>();
                    ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> prevValue = listenersByRelationEqualValues.putIfAbsent(relation.getName(), listenersByEqualValues);
                    if (prevValue != null)
                        listenersByEqualValues = prevValue;
                }
                listenersByEqualValues.add(createPKHashKey(eqArgs), relatedFoundSet);
                listenersByEqualValuesAdded = true;
            }
        }
    }
    if (!listenersByEqualValuesAdded) {
        listeners.put(fs, dummy);
    }
}
Also used : Relation(com.servoy.j2db.persistence.Relation) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 49 with Relation

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

the class LookupListModel method fillRelatedValueListValues.

/**
 * @param txt
 * @throws RemoteException
 * @throws Exception
 */
private void fillRelatedValueListValues(IRecordInternal parentState, String filter) throws ServoyException {
    if (parentState == null)
        return;
    String txt = filter;
    ValueList valueList = ((LookupValueList) lookup).getValueList();
    Relation[] relations = application.getFlattenedSolution().getRelationSequence(valueList.getRelationName());
    Pair<QuerySelect, BaseQueryTable> pair = RelatedValueList.createRelatedValuelistQuery(application, valueList, relations, parentState);
    if (pair == null) {
        return;
    }
    QuerySelect select = pair.getLeft();
    BaseQueryTable qTable = pair.getRight();
    generateWherePart(txt, valueList, select, qTable);
    try {
        FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
        String transaction_id = foundSetManager.getTransactionID(table.getServerName());
        ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), select);
        if (// apply name as filter on column valuelist_name in creationSQLParts
        nameFilter != null) {
            if (tableFilterParams == null) {
                tableFilterParams = new ArrayList<TableFilter>();
            }
            tableFilterParams.add(nameFilter);
        }
        SQLStatement trackingInfo = null;
        if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
            trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), qTable.getName(), null, null);
            trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
        }
        IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, select, null, tableFilterParams, true, 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
        String[] displayFormat = (lookup instanceof LookupValueList) ? ((LookupValueList) lookup).getDisplayFormat() : null;
        for (int i = 0; i < set.getRowCount(); i++) {
            Object[] row = processRow(set.getRow(i));
            DisplayString display = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
            if (display != null) {
                alDisplay.add(display);
                alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
            }
        }
        hadMoreRows = set.hadMoreRows();
    } catch (RemoteException e) {
        throw new RepositoryException(e);
    }
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) DisplayString(com.servoy.j2db.dataprocessing.CustomValueList.DisplayString) QuerySelect(com.servoy.j2db.query.QuerySelect) Relation(com.servoy.j2db.persistence.Relation) BaseQueryTable(com.servoy.base.query.BaseQueryTable) DisplayString(com.servoy.j2db.dataprocessing.CustomValueList.DisplayString) RemoteException(java.rmi.RemoteException)

Example 50 with Relation

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

the class DBValueList method getShowDataproviders.

public static List<String> getShowDataproviders(ValueList valueList, Table callingTable, String dataProviderID, IFoundSetManagerInternal foundSetManager) throws RepositoryException {
    if (valueList == null) {
        return null;
    }
    FlattenedSolution flattenedSolution = foundSetManager.getApplication().getFlattenedSolution();
    // Find destination table in case dataProviderID is related
    String[] split = dataProviderID.split("\\.");
    String dataSource = callingTable.getDataSource();
    for (// first parts are relation names, last part is column name
    int i = 0; // first parts are relation names, last part is column name
    i < split.length - 1; // first parts are relation names, last part is column name
    i++) {
        Relation relation = flattenedSolution.getRelation(split[i]);
        if (relation == null || !relation.getPrimaryDataSource().equals(dataSource)) {
            return null;
        }
        dataSource = relation.getForeignDataSource();
    }
    Table table = (Table) foundSetManager.getTable(dataSource);
    String columnName = split[split.length - 1];
    String prefix = dataProviderID.substring(0, dataProviderID.length() - columnName.length());
    // first try fallback value list,
    ValueList usedValueList = flattenedSolution.getValueList(valueList.getFallbackValueListID());
    Relation valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
    if (valuelistSortRelation == null) {
        // then try regular value list
        usedValueList = valueList;
        valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
    }
    if (valuelistSortRelation == null) {
        return null;
    }
    List<String> showDataproviders = new ArrayList<String>(3);
    int showValues = usedValueList.getShowDataProviders();
    if ((showValues & 1) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID1());
    }
    if ((showValues & 2) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID2());
    }
    if ((showValues & 4) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID3());
    }
    return showDataproviders;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) ValueList(com.servoy.j2db.persistence.ValueList) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Aggregations

Relation (com.servoy.j2db.persistence.Relation)53 ServoyException (com.servoy.j2db.util.ServoyException)16 ArrayList (java.util.ArrayList)16 FlattenedSolution (com.servoy.j2db.FlattenedSolution)15 RepositoryException (com.servoy.j2db.persistence.RepositoryException)15 Column (com.servoy.j2db.persistence.Column)11 ITable (com.servoy.j2db.persistence.ITable)11 RemoteException (java.rmi.RemoteException)10 BaseQueryTable (com.servoy.base.query.BaseQueryTable)9 IDataProvider (com.servoy.j2db.persistence.IDataProvider)8 QuerySelect (com.servoy.j2db.query.QuerySelect)8 QueryTable (com.servoy.j2db.query.QueryTable)8 IColumn (com.servoy.j2db.persistence.IColumn)7 Placeholder (com.servoy.j2db.query.Placeholder)7 ApplicationException (com.servoy.j2db.ApplicationException)6 Table (com.servoy.j2db.persistence.Table)6 QueryColumn (com.servoy.j2db.query.QueryColumn)6 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)5 ISQLTableJoin (com.servoy.j2db.query.ISQLTableJoin)5 SafeArrayList (com.servoy.j2db.util.SafeArrayList)5