Search in sources :

Example 16 with ScriptVariable

use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.

the class FoundSetManager method getRelationWhereArgs.

/**
 * Get relation where-args, not using column converters
 * @param state
 * @param relation
 * @param testForCalcs
 * @return
 * @throws RepositoryException
 */
public Object[] getRelationWhereArgs(IRecordInternal state, Relation relation, boolean testForCalcs) throws RepositoryException {
    boolean isNull = true;
    IDataProvider[] args = relation.getPrimaryDataProviders(application.getFlattenedSolution());
    Column[] columns = relation.getForeignColumns(application.getFlattenedSolution());
    Object[] array = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        Object value = null;
        if (args[i] instanceof LiteralDataprovider) {
            value = ((LiteralDataprovider) args[i]).getValue();
        } else if (args[i] instanceof EnumDataProvider) {
            value = getScopesScopeProvider().getDataProviderValue(args[i].getDataProviderID());
        } else {
            String dataProviderID = args[i].getDataProviderID();
            if (testForCalcs && state.getRawData().containsCalculation(dataProviderID) && state.getRawData().mustRecalculate(dataProviderID, true)) {
                // else this can just cascade through..
                return null;
            }
            // unconverted (todb value)
            value = state.getValue(dataProviderID, false);
        }
        if (value != Scriptable.NOT_FOUND) {
            array[i] = columns[i].getAsRightType(value);
        }
        if (array[i] != null) {
            isNull = false;
        } else {
            // Because null columns can't have a relation.
            if (args[i] instanceof IColumn) {
                return null;
            }
            if (isNull) {
                isNull = !(args[i] instanceof ScriptVariable);
            }
        }
    }
    // optimize for null keys (multiple all null!) but not empty pk (db ident)
    if (isNull)
        return null;
    return array;
}
Also used : IDataProvider(com.servoy.j2db.persistence.IDataProvider) LiteralDataprovider(com.servoy.j2db.persistence.LiteralDataprovider) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) IColumn(com.servoy.j2db.persistence.IColumn) EnumDataProvider(com.servoy.j2db.persistence.EnumDataProvider) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Aggregations

ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)16 JSFunction (org.mozilla.javascript.annotations.JSFunction)6 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3 Form (com.servoy.j2db.persistence.Form)3 ArrayList (java.util.ArrayList)3 Column (com.servoy.j2db.persistence.Column)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 IColumn (com.servoy.j2db.persistence.IColumn)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 IPersist (com.servoy.j2db.persistence.IPersist)2 IScriptProvider (com.servoy.j2db.persistence.IScriptProvider)2 ISupportScriptProviders (com.servoy.j2db.persistence.ISupportScriptProviders)2 Relation (com.servoy.j2db.persistence.Relation)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)2 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)2 TableNode (com.servoy.j2db.persistence.TableNode)2 LazyCompilationScope (com.servoy.j2db.scripting.LazyCompilationScope)2 IBaseColumn (com.servoy.base.persistence.IBaseColumn)1 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)1