Search column in condition

Contains useful source code for specific use cases.

Search column in condition

Postby rjahn » Wed Dec 10, 2014 4:25 pm

If you create your own IStorage impelementation, it could be useful to know how to find the value for a specific column:

Syntax: [ Download ] [ Hide ]
public static Object getEqualsValue(ICondition pFilter, String pColumn)
{
        if (pFilter instanceof OperatorCondition)
        {
                for (ICondition cond : ((OperatorCondition)pFilter).getConditions())
                {
                        if (cond instanceof Equals)
                        {
                                if (pColumn.equals(((Equals)cond).getColumnName()))
                                {
                                        return ((Equals)cond).getValue();
                                }
                        }
                }
        }
        else if (pFilter instanceof Equals)
        {
                if (pColumn.equals(((Equals)pFilter).getColumnName()))
                {
                        return ((Equals)pFilter).getValue();
                }
        }
       
        return null;
}

Above method tries to find the first Equals condition with the given column name.

The method doesn't work with recursion because usually this is not necessary. If you want to know the different condition types, simply check toString() of javax.rad.model.condition.BaseCondition.
rjahn
 
Posts: 29
Joined: Sun Sep 13, 2009 1:54 pm

Return to Code snippets