Search in sources :

Example 76 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution 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 77 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution 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 78 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution 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 79 with FlattenedSolution

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

FlattenedSolution (com.servoy.j2db.FlattenedSolution)79 JSFunction (org.mozilla.javascript.annotations.JSFunction)27 Form (com.servoy.j2db.persistence.Form)20 RepositoryException (com.servoy.j2db.persistence.RepositoryException)17 ArrayList (java.util.ArrayList)17 Relation (com.servoy.j2db.persistence.Relation)15 Media (com.servoy.j2db.persistence.Media)10 Solution (com.servoy.j2db.persistence.Solution)10 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)9 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)7 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)7 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)7 FormController (com.servoy.j2db.FormController)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ValueList (com.servoy.j2db.persistence.ValueList)6 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)6 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)6 ITable (com.servoy.j2db.persistence.ITable)5 QueryTable (com.servoy.j2db.query.QueryTable)5 SafeArrayList (com.servoy.j2db.util.SafeArrayList)5