Search in sources :

Example 11 with Pair

use of com.servoy.j2db.util.Pair 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 12 with Pair

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

the class RowManager method deleteRow.

void deleteRow(IRowListener src, Row r, boolean tracking, boolean partOfBiggerDelete) throws ServoyException {
    // $NON-NLS-1$
    if (r.getRowManager() != this)
        throw new IllegalArgumentException("I'm not the row manager from row");
    // prevent it processed by any update, changed is false now
    r.flagExistInDB();
    if (!partOfBiggerDelete) {
        QueryDelete sqlDelete = AbstractBaseQuery.deepClone((QueryDelete) sheet.getSQLDescription(SQLSheet.DELETE).getSQLQuery());
        Object[] pk = r.getPK();
        if (!sqlDelete.setPlaceholderValue(new TablePlaceholderKey(sqlDelete.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY), pk)) {
            Debug.error(new RuntimeException(// $NON-NLS-1$
            "Could not set placeholder " + new TablePlaceholderKey(sqlDelete.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY) + " in query " + sqlDelete + // $NON-NLS-1$ //$NON-NLS-2$
            "-- continuing"));
        }
        IDataSet pks = new BufferedDataSet();
        pks.addRow(pk);
        ISQLStatement[] stats_a = new ISQLStatement[1];
        String tid = null;
        GlobalTransaction gt = fsm.getGlobalTransaction();
        if (gt != null) {
            tid = gt.getTransactionID(sheet.getServerName());
        }
        SQLStatement statement = new SQLStatement(ISQLActionTypes.DELETE_ACTION, sheet.getServerName(), sheet.getTable().getName(), pks, tid, sqlDelete, fsm.getTableFilterParams(sheet.getServerName(), sqlDelete));
        // check that 1 record is deleted
        statement.setExpectedUpdateCount(1);
        stats_a[0] = statement;
        if (tracking) {
            statement.setTrackingData(sheet.getColumnNames(), r.getRawColumnData() != null ? new Object[][] { r.getRawColumnData() } : null, null, fsm.getApplication().getUserUID(), fsm.getTrackingInfo(), fsm.getApplication().getClientID());
        }
        try {
            Object[] results = fsm.getDataServer().performUpdates(fsm.getApplication().getClientID(), stats_a);
            for (int i = 0; results != null && i < results.length; i++) {
                if (results[i] instanceof ServoyException) {
                    throw (ServoyException) results[i];
                }
            }
        } catch (RemoteException e) {
            throw new RepositoryException(e);
        }
        SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> removed;
        synchronized (this) {
            removed = pkRowMap.remove(r.getPKHashKey());
        }
        fireDependingCalcs(removed, null, null);
    } else {
        synchronized (this) {
            pkRowMap.remove(r.getPKHashKey());
        }
    }
    fireNotifyChange(src, r, r.getPKHashKey(), null, RowEvent.DELETE);
}
Also used : QueryDelete(com.servoy.j2db.query.QueryDelete) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) RepositoryException(com.servoy.j2db.persistence.RepositoryException) 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) RemoteException(java.rmi.RemoteException) Pair(com.servoy.j2db.util.Pair)

Example 13 with Pair

use of com.servoy.j2db.util.Pair 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 14 with Pair

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

the class WebObjectImpl method getNewIdAndUUID.

public static Pair<Integer, UUID> getNewIdAndUUID(IPersist persist) {
    UUID uuid = UUID.randomUUID();
    int id;
    try {
        id = ((IPersistFactory) ((Solution) persist.getAncestor(IRepository.SOLUTIONS)).getRepository()).getNewElementID(uuid);
    } catch (RepositoryException e) {
        Debug.error(e);
        id = 0;
    }
    return new Pair<>(Integer.valueOf(id), uuid);
}
Also used : UUID(com.servoy.j2db.util.UUID) Pair(com.servoy.j2db.util.Pair)

Example 15 with Pair

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

the class AbstractBaseQuery method acceptVisitor.

public static <T> T acceptVisitor(T o, IVisitor visitor) {
    if (o == null) {
        return null;
    }
    Object v = visitor.visit(o);
    T o2;
    if (v instanceof VisitorResult) {
        o2 = (T) ((VisitorResult) v).object;
        if (!((VisitorResult) v).continueTraversal) {
            return o2;
        }
    } else {
        o2 = (T) v;
        if (o2 != o) {
            // the visitor returned something else then the input, visting stops.
            return o2;
        }
    }
    if (o2 instanceof List) {
        for (int i = 0; i < ((List) o2).size(); i++) {
            ((List<Object>) o2).set(i, acceptVisitor(((List) o2).get(i), visitor));
        }
    } else if (o2 instanceof Map) {
        Iterator<Map.Entry> it = ((Map) o2).entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = it.next();
            entry.setValue(acceptVisitor(entry.getValue(), visitor));
        }
    } else if (o2 instanceof Object[]) {
        for (int i = 0; i < ((Object[]) o2).length; i++) {
            ((Object[]) o2)[i] = acceptVisitor(((Object[]) o2)[i], visitor);
        }
    } else if (o2 instanceof Pair) {
        Pair pair = (Pair) o2;
        pair.setLeft(acceptVisitor(pair.getLeft(), visitor));
        pair.setRight(acceptVisitor(pair.getRight(), visitor));
    } else if (o2 instanceof IVisitable) {
        ((IVisitable) o2).acceptVisitor(visitor);
    }
    return o2;
}
Also used : VisitorResult(com.servoy.j2db.util.visitor.IVisitor.VisitorResult) Iterator(java.util.Iterator) ReplacedObject(com.servoy.j2db.util.serialize.ReplacedObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.servoy.j2db.util.Pair) IVisitable(com.servoy.j2db.util.visitor.IVisitable)

Aggregations

Pair (com.servoy.j2db.util.Pair)29 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 Map (java.util.Map)8 List (java.util.List)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 SafeArrayList (com.servoy.j2db.util.SafeArrayList)6 Point (java.awt.Point)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)5 Collectors.toList (java.util.stream.Collectors.toList)5 FlattenedSolution (com.servoy.j2db.FlattenedSolution)4 CalculationDependencyData (com.servoy.j2db.dataprocessing.RowManager.RowFireNotifyChange.CalculationDependencyData)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 PropertyDescription (org.sablo.specification.PropertyDescription)4 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)2 FormController (com.servoy.j2db.FormController)2 IForm (com.servoy.j2db.IForm)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 IRepository (com.servoy.j2db.persistence.IRepository)2