Search in sources :

Example 1 with CalculationDependencyData

use of com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData in project servoy-client by Servoy.

the class RowManager method addCalculationDependencyBackReference.

/**
 * Rowmanager(dataSource) keeps a calculation dependency for my calc in row(pkHashKey).
 * @param dataSource
 * @param pkHashKey
 * @param calc
 */
private void addCalculationDependencyBackReference(RowReference rowReference, String pkHashKey, String calc) {
    SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(pkHashKey);
    if (sr != null) {
        synchronized (sr) {
            Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
            if (data == null) {
                data = new Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>(null, null);
                sr.setData(data);
            }
            CalculationDependencyData rowRefs = data.getRight();
            if (rowRefs == null) {
                rowRefs = new CalculationDependencyData();
                data.setRight(rowRefs);
            }
            rowRefs.addRowReference(calc, rowReference);
        }
    }
}
Also used : CalculationDependencyData(com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData) 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)

Example 2 with CalculationDependencyData

use of com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData 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)

Example 3 with CalculationDependencyData

use of com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData in project servoy-client by Servoy.

the class RowManager method addCalculationRelationDependency.

/**
 * Calculation depends on relation identified by whereArgsHash.
 * @param whereArgsHash
 * @param relationName
 * @param dependingDataSource
 * @param dependingPkHashKey
 * @param dependingCalc
 */
public void addCalculationRelationDependency(String whereArgsHash, String relationName, String dependingDataSource, String dependingPkHashKey, String dependingCalc) {
    // keep a global list of relations that some calcs depend on
    boolean first;
    synchronized (relationsUsedInCalcs) {
        first = relationsUsedInCalcs.size() == 0;
        Set<String> dependingCalcs = relationsUsedInCalcs.get(relationName);
        if (dependingCalcs == null) {
            dependingCalcs = new HashSet<String>();
            relationsUsedInCalcs.put(relationName, dependingCalcs);
        }
        dependingCalcs.add(dependingCalc);
    }
    // add a relation dependency for the calc
    SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(dependingPkHashKey);
    if (sr != null) {
        synchronized (sr) {
            Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
            if (data == null) {
                data = new Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>(null, null);
                sr.setData(data);
            }
            CalculationDependencyData rowRefs = data.getRight();
            if (rowRefs == null) {
                rowRefs = new CalculationDependencyData();
                data.setRight(rowRefs);
            }
            rowRefs.addRelationDependency(dependingCalc, new RelationDependency(relationName, whereArgsHash));
        }
    }
    if (first) {
        // listen for foundset events to all foundsets
        fsm.addGlobalFoundsetEventListener(this);
    }
}
Also used : CalculationDependencyData(com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData) 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)

Example 4 with CalculationDependencyData

use of com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData in project servoy-client by Servoy.

the class RowManager method removeRowReferences.

/**
 * Remove references in other RowManagers to this row.
 * @param pkHashKey
 * @param calc, null for all
 */
public void removeRowReferences(String pkHashKey, String calc) {
    SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(pkHashKey);
    if (sr != null) {
        CalculationDependencyData rowRefs = null;
        synchronized (sr) {
            // check the calculation dependencies registered for the calc
            Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
            if (data != null) {
                CalculationDependencyData calcRowrefs = data.getRight();
                if (calcRowrefs != null) {
                    // remove both row refs and relation dependencies
                    if (calc == null) {
                        rowRefs = calcRowrefs;
                        data.setRight(null);
                    } else {
                        List<RowReference> refs = calcRowrefs.removeReferences(calc);
                        if (refs != null) {
                            rowRefs = new CalculationDependencyData();
                            rowRefs.putRowReferences(calc, refs);
                        }
                    }
                }
            }
        }
        if (rowRefs != null) {
            String dataSource = fsm.getDataSource(sheet.getTable());
            for (Entry<String, List<RowReference>> entry : rowRefs.getRowReferencesEntrySet()) {
                for (RowReference reference : entry.getValue()) {
                    try {
                        getFoundsetManager().getRowManager(reference.dataSource).removeCalculationDependency(reference.pkHashKey, reference.dataproviderId, dataSource, pkHashKey, entry.getKey());
                    } catch (ServoyException e) {
                        Debug.log(e);
                    }
                }
            }
        }
    }
}
Also used : CalculationDependencyData(com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData) ServoyException(com.servoy.j2db.util.ServoyException) 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)4 Pair (com.servoy.j2db.util.Pair)4 SafeArrayList (com.servoy.j2db.util.SafeArrayList)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 Collectors.toList (java.util.stream.Collectors.toList)4 ServoyException (com.servoy.j2db.util.ServoyException)1 SoftReferenceWithData (com.servoy.j2db.util.SoftReferenceWithData)1 Entry (java.util.Map.Entry)1