Search in sources :

Example 26 with Pair

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

the class AngularIndexPageWriter method getFlattenedSolution.

private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
    INGClientWebsocketSession wsSession = null;
    HttpSession httpSession = request.getSession(false);
    if (clientnr != null && httpSession != null) {
        wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
    }
    FlattenedSolution fs = null;
    boolean closeFS = false;
    if (wsSession != null) {
        fs = wsSession.getClient().getFlattenedSolution();
    }
    if (fs == null) {
        try {
            closeFS = true;
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            if (applicationServerUnavailable(response, as)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
            if (solutionMissing(response, solutionName, solutionMetaData)) {
                return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
            }
            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
        } catch (Exception e) {
            Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
        }
    }
    return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
Also used : AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) HttpSession(javax.servlet.http.HttpSession) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) IOException(java.io.IOException) Pair(com.servoy.j2db.util.Pair)

Example 27 with Pair

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

the class RelatedValueList method createRelatedValuelistQuery.

public static Pair<QuerySelect, BaseQueryTable> createRelatedValuelistQuery(IServiceProvider application, ValueList valueList, Relation[] relations, IRecordInternal parentState) throws ServoyException {
    if (parentState == null) {
        return null;
    }
    FoundSetManager foundSetManager = (FoundSetManager) application.getFoundSetManager();
    SQLGenerator sqlGenerator = foundSetManager.getSQLGenerator();
    IGlobalValueEntry scopesScopeProvider = foundSetManager.getScopesScopeProvider();
    SQLSheet childSheet = sqlGenerator.getCachedTableSQLSheet(relations[0].getPrimaryDataSource());
    // this returns quickly if it already has a sheet for that relation, but optimize further?
    sqlGenerator.makeRelatedSQL(childSheet, relations[0]);
    QuerySelect select = AbstractBaseQuery.deepClone((QuerySelect) childSheet.getRelatedSQLDescription(relations[0].getName()).getSQLQuery());
    Object[] relationWhereArgs = foundSetManager.getRelationWhereArgs(parentState, relations[0], false);
    if (relationWhereArgs == null) {
        return null;
    }
    TablePlaceholderKey placeHolderKey = SQLGenerator.createRelationKeyPlaceholderKey(select.getTable(), relations[0].getName());
    if (!select.setPlaceholderValue(placeHolderKey, relationWhereArgs)) {
        // $NON-NLS-1$//$NON-NLS-2$
        Debug.error(new RuntimeException("Could not set relation placeholder " + placeHolderKey + " in query " + select));
        return null;
    }
    FlattenedSolution fs = application.getFlattenedSolution();
    BaseQueryTable lastTable = select.getTable();
    ITable foreignTable = fs.getTable(relations[0].getForeignDataSource());
    for (int i = 1; i < relations.length; i++) {
        foreignTable = fs.getTable(relations[i].getForeignDataSource());
        ISQLTableJoin join = SQLGenerator.createJoin(application.getFlattenedSolution(), relations[i], lastTable, new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema()), true, scopesScopeProvider);
        select.addJoin(join);
        lastTable = join.getForeignTable();
    }
    List<SortColumn> defaultSort = foundSetManager.getSortColumns(relations[relations.length - 1].getForeignDataSource(), valueList.getSortOptions());
    foundSetManager.getSQLGenerator().addSorts(select, lastTable, scopesScopeProvider, foreignTable, defaultSort, true, true);
    int showValues = valueList.getShowDataProviders();
    int returnValues = valueList.getReturnDataProviders();
    int total = (showValues | returnValues);
    ArrayList<IQuerySelectValue> columns = new ArrayList<IQuerySelectValue>();
    if ((total & 1) != 0) {
        columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID1()));
    }
    if ((total & 2) != 0) {
        columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID2()));
    }
    if ((total & 4) != 0) {
        columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID3()));
    }
    select.setColumns(columns);
    // not allowed in all situations
    select.setDistinct(false);
    return new Pair<QuerySelect, BaseQueryTable>(select, lastTable);
}
Also used : TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) QuerySelect(com.servoy.j2db.query.QuerySelect) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) BaseQueryTable(com.servoy.base.query.BaseQueryTable) ISQLTableJoin(com.servoy.j2db.query.ISQLTableJoin) ITable(com.servoy.j2db.persistence.ITable) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) Pair(com.servoy.j2db.util.Pair)

Example 28 with Pair

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

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

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