Search in sources :

Example 1 with SoftReferenceWithData

use of com.servoy.j2db.util.SoftReferenceWithData in project servoy-client by Servoy.

the class RowManager method foundSetChanged.

/*
	 * Called from FoundsetManager GlobalFoundSetEventListener
	 */
public void foundSetChanged(FoundSetEvent e) {
    IFoundSet sourceFoundset = e.getSourceFoundset();
    // only act on new foundsets or size changes for related foundsets
    if (e.getType() == FoundSetEvent.NEW_FOUNDSET || (e.getType() == FoundSetEvent.CONTENTS_CHANGED && (e.getChangeType() == FoundSetEvent.CHANGE_INSERT || e.getChangeType() == FoundSetEvent.FOUNDSET_INVALIDATED || e.getChangeType() == FoundSetEvent.CHANGE_DELETE))) {
        if (sourceFoundset instanceof RelatedFoundSet && !sourceFoundset.isInFindMode()) {
            String relationName = sourceFoundset.getRelationName();
            // related foundset changed
            List<String> calcs = null;
            // first test if there are calcs that depend on this relation, to filter out relations that are never used in calcs
            synchronized (relationsUsedInCalcs) {
                Set<String> calcSet = relationsUsedInCalcs.get(relationName);
                if (calcSet != null) {
                    calcs = new ArrayList<String>(calcSet);
                }
            }
            if (calcs != null) {
                // some calcs depend on a related foundset with this name, search by whereArgs
                String whereArgsHash = ((RelatedFoundSet) sourceFoundset).getWhereArgsHash();
                List<CalculationDependency> calculationDependencies = new ArrayList<CalculationDependency>();
                // go over each row to see if there are calcs depending on the RFS(whereArgs)
                Iterator<Map.Entry<String, SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>>>> it = pkRowMap.entrySet().iterator();
                while (it.hasNext()) {
                    Entry<String, SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>>> entry = it.next();
                    String pkHash = entry.getKey();
                    SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = entry.getValue();
                    synchronized (sr) {
                        Row row = sr.get();
                        if (row != null) {
                            Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
                            if (data != null) {
                                CalculationDependencyData calcRowrefs = data.getRight();
                                if (calcRowrefs != null) {
                                    for (String calc : calcs) {
                                        List<RelationDependency> deps = calcRowrefs.getRelationDependencies(calc);
                                        if (deps != null) {
                                            for (RelationDependency dep : deps) {
                                                if (relationName.equals(dep.relationName) && whereArgsHash.equals(dep.whereArgsHash)) {
                                                    // the calc depends on this related foundset
                                                    calculationDependencies.add(new CalculationDependency(sheet.getTable().getDataSource(), pkHash, calc));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (calculationDependencies.size() > 0) {
                    List<RowFireNotifyChange> fires = new ArrayList<RowFireNotifyChange>();
                    for (CalculationDependency dep : calculationDependencies) {
                        fireCalculationFlagged(dep.pkHashKey, dep.calc, fires);
                    }
                    if (fires.size() > 0) {
                        fireRowNotifyChanges(fires);
                        ArrayList<String> calcColumns = new ArrayList<String>();
                        for (RowFireNotifyChange f : fires) {
                            calcColumns.add(f.name);
                        }
                        fireNotifyChange(null, null, null, calcColumns.toArray(new String[0]), RowEvent.UPDATE);
                    }
                }
            }
        }
    }
}
Also used : CalculationDependencyData(com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) SoftReferenceWithData(com.servoy.j2db.util.SoftReferenceWithData) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Pair(com.servoy.j2db.util.Pair)

Aggregations

CalculationDependencyData (com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData)1 Pair (com.servoy.j2db.util.Pair)1 SafeArrayList (com.servoy.j2db.util.SafeArrayList)1 SoftReferenceWithData (com.servoy.j2db.util.SoftReferenceWithData)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors.toList (java.util.stream.Collectors.toList)1