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);
}
}
}
}
}
}
Aggregations