Search in sources :

Example 1 with EnumDataProvider

use of com.servoy.j2db.persistence.EnumDataProvider 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

IBaseColumn (com.servoy.base.persistence.IBaseColumn)1 Column (com.servoy.j2db.persistence.Column)1 EnumDataProvider (com.servoy.j2db.persistence.EnumDataProvider)1 IColumn (com.servoy.j2db.persistence.IColumn)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1 LiteralDataprovider (com.servoy.j2db.persistence.LiteralDataprovider)1 ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)1 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1