T
- The result type of the translator. Commonly this will be a string,
but there are cases where you might need to return a more complex
data structure. For example if you are building a SQL query, you
will need not *just* the base WHERE clause but a list of tables
that need to be joined together.public abstract class AbstractFilterTranslator<T> extends Object implements FilterTranslator<T>
AbstractFilterTranslator
in order to declare which
filter operations the connector does support. This allows the
FilterTranslator
instance to analyze a specified search filter
and reduce the filter to its most efficient form. The default (and
worst-case) behavior is to return a null expression, which means that the
connector should return "everything" (that is, should return all values for
every requested attribute) and rely on the common code in the framework to
perform filtering. This "fallback" behavior is good (in that it ensures
consistency of search behavior across connector implementations) but it is
obviously better for performance and scalability if each connector performs
as much filtering as the native API of the target can support.
A subclass should override each of the following methods where possible:
createAndExpression(T, T)
createOrExpression(T, T)
createContainsExpression(ContainsFilter, boolean)
createEndsWithExpression(EndsWithFilter, boolean)
createEqualsExpression(EqualsFilter, boolean)
createEqualsIgnoreCaseExpression(EqualsIgnoreCaseFilter, boolean)
createGreaterThanExpression(GreaterThanFilter, boolean)
createGreaterThanOrEqualExpression(GreaterThanOrEqualFilter, boolean)
createStartsWithExpression(StartsWithFilter, boolean)
createContainsAllValuesExpression(ContainsAllValuesFilter, boolean)
Translation can then be performed using translate(Filter)
.
Constructor and Description |
---|
AbstractFilterTranslator() |
Modifier and Type | Method and Description |
---|---|
protected T |
createAndExpression(T leftExpression,
T rightExpression)
Should be overridden by subclasses to create an AND expression if the
native resource supports AND.
|
protected T |
createContainsAllValuesExpression(ContainsAllValuesFilter filter,
boolean not)
Should be overridden by subclasses to create a CONTAINS-ALL-VALUES
expression if the native resource supports a contains all values.
|
protected T |
createContainsExpression(ContainsFilter filter,
boolean not)
Should be overridden by subclasses to create a CONTAINS expression if the
native resource supports CONTAINS.
|
protected T |
createEndsWithExpression(EndsWithFilter filter,
boolean not)
Should be overridden by subclasses to create a ENDS-WITH expression if
the native resource supports ENDS-WITH.
|
protected T |
createEqualsExpression(EqualsFilter filter,
boolean not)
Should be overridden by subclasses to create a EQUALS expression if the
native resource supports EQUALS.
|
protected T |
createEqualsIgnoreCaseExpression(EqualsIgnoreCaseFilter filter,
boolean not)
Should be overridden by subclasses to create a EQUALSIGNORECASE expression if the
native resource supports EQUALSIGNORECASE.
|
protected T |
createGreaterThanExpression(GreaterThanFilter filter,
boolean not)
Should be overridden by subclasses to create a GREATER-THAN expression if
the native resource supports GREATER-THAN.
|
protected T |
createGreaterThanOrEqualExpression(GreaterThanOrEqualFilter filter,
boolean not)
Should be overridden by subclasses to create a GREATER-THAN-EQUAL
expression if the native resource supports GREATER-THAN-EQUAL.
|
protected T |
createLessThanExpression(LessThanFilter filter,
boolean not)
Should be overridden by subclasses to create a LESS-THAN expression if
the native resource supports LESS-THAN.
|
protected T |
createLessThanOrEqualExpression(LessThanOrEqualFilter filter,
boolean not)
Should be overridden by subclasses to create a LESS-THAN-EQUAL expression
if the native resource supports LESS-THAN-EQUAL.
|
protected T |
createOrExpression(T leftExpression,
T rightExpression)
Should be overridden by subclasses to create an OR expression if the
native resource supports OR.
|
protected T |
createStartsWithExpression(StartsWithFilter filter,
boolean not)
Should be overridden by subclasses to create a STARTS-WITH expression if
the native resource supports STARTS-WITH.
|
List<T> |
translate(Filter filter)
Main method to be called to translate a filter
|
public final List<T> translate(Filter filter)
translate
in interface FilterTranslator<T>
filter
- The filter to translate.size()
may be one of the following:
create*
methods
returned null.create*
methods returned null. That is OK from a
behavior standpoint since ConnectorFacade
performs a
second level of filtering. However it is undesirable from a
performance standpoint.createOrExpression(T, T)
method can return
null. If this happens, it is the responsibility of the connector
implementor to perform each query and combine the results. In
order to eliminate duplicates, the connector implementation must
keep an in-memory HashSet
of those UID that have
been visited thus far. This will not scale well if your result
sets are large. Therefore it is recommended that if at all
possible you implement createOrExpression(T, T)
protected T createAndExpression(T leftExpression, T rightExpression)
leftExpression
- The left expression. Will never be null.rightExpression
- The right expression. Will never be null.protected T createOrExpression(T leftExpression, T rightExpression)
leftExpression
- The left expression. Will never be null.rightExpression
- The right expression. Will never be null.translate(org.identityconnectors.framework.common.objects.filter.Filter)
may return multiple queries, each of which
must be run and results combined.protected T createContainsExpression(ContainsFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT CONTAINStranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createEndsWithExpression(EndsWithFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT ENDS-WITHtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createEqualsExpression(EqualsFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT EQUALStranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createEqualsIgnoreCaseExpression(EqualsIgnoreCaseFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT EQUALSIGNORECASEtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createGreaterThanExpression(GreaterThanFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT GREATER-THANtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set,
meaning fetch everything. The filter will be re-applied in
memory to the resulting object stream. This does not scale well,
so if possible, you should implement this method.protected T createGreaterThanOrEqualExpression(GreaterThanOrEqualFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT GREATER-THAN-EQUALtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty
query set, meaning fetch everything. The filter will be
re-applied in memory to the resulting object stream. This does
not scale well, so if possible, you should implement this method.protected T createLessThanExpression(LessThanFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT LESS-THANtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createLessThanOrEqualExpression(LessThanOrEqualFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT LESS-THAN-EQUALtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty
query set, meaning fetch everything. The filter will be
re-applied in memory to the resulting object stream. This does
not scale well, so if possible, you should implement this method.protected T createStartsWithExpression(StartsWithFilter filter, boolean not)
filter
- The contains filter. Will never be null.not
- True if this should be a NOT STARTS-WITHtranslate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an empty query set, meaning
fetch everything. The filter will be re-applied in memory
to the resulting object stream. This does not scale well, so if
possible, you should implement this method.protected T createContainsAllValuesExpression(ContainsAllValuesFilter filter, boolean not)
filter
- The contains all filter. Will never be null.not
- True if this should be a NOT CONTAINS-ALL-VALUES.translate(org.identityconnectors.framework.common.objects.filter.Filter)
may return an
empty query set, meaning fetch everything. The filter will
be re-applied in memory to the resulting object stream. This does
not scale well, so if possible, you should implement this method.Copyright © 2019. All rights reserved.