org.jasig.services.persondir.support
Class AbstractQueryPersonAttributeDao<QB>

java.lang.Object
  extended by org.jasig.services.persondir.support.BasePersonAttributeDao
      extended by org.jasig.services.persondir.support.AbstractFlatteningPersonAttributeDao
          extended by org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
              extended by org.jasig.services.persondir.support.AbstractQueryPersonAttributeDao<QB>
All Implemented Interfaces:
IPersonAttributeDao
Direct Known Subclasses:
AbstractJdbcPersonAttributeDao, ComplexStubPersonAttributeDao, LdapPersonAttributeDao

public abstract class AbstractQueryPersonAttributeDao<QB>
extends AbstractDefaultAttributePersonAttributeDao

Provides common functionality for DAOs using a set of attribute values from the seed to perform a query. Ensures the nessesary attributes to run the query exist on the seed and organizes the values into an argument array.

Configuration:

Property Description Required Default
queryAttributeMapping A Map from attribute names used in the query Map to attribute names to use in the SQL. The values can be either String or Collection to use a single Map attribute under multiple names as in the SQL. If set only Map attributes listed will be used in the SQL. If not set all Map attributes are used as-is in the SQL. No null
resultAttributeMapping A Map from SQL result names to returned attribute names. The values can be either String or Collection to use a single SQL result under multiple returned attributes. If set only SQL attributes listed will be returned. If not set all SQL attributes will be returned. No null
requireAllQueryAttributes If the SQL should only be run if all attributes listed in the queryAttributeMapping exist in the query Map. Ignored if queryAttributeMapping is null No false
unmappedUsernameAttribute The unmapped username attribute returned by the query. If null the value returned by the configured IUsernameAttributeProvider is used. No null

Version:
$Revision$
Author:
Eric Dalquist

Field Summary
 
Fields inherited from class org.jasig.services.persondir.support.BasePersonAttributeDao
logger
 
Fields inherited from interface org.jasig.services.persondir.IPersonAttributeDao
WILDCARD, WILDCARD_PATTERN
 
Constructor Summary
AbstractQueryPersonAttributeDao()
           
 
Method Summary
protected abstract  QB appendAttributeToQuery(QB queryBuilder, String dataAttribute, List<Object> queryValues)
          Append the attribute and value to the queryBuilder.
protected  QB generateQuery(Map<String,List<Object>> query)
          Generates a query using the queryBuilder object passed by the subclass.
 Set<String> getAvailableQueryAttributes()
           
protected  String getConfiguredUserNameAttribute()
           
protected abstract  List<IPersonAttributes> getPeopleForQuery(QB queryBuilder, String queryUserName)
          Executes the query for the generated queryBuilder object and returns a list where each entry is a Map of attributes for a single IPersonAttributes.
 Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(Map<String,List<Object>> query)
           
 Set<String> getPossibleUserAttributeNames()
           
 Map<String,Set<String>> getQueryAttributeMapping()
           
 Map<String,Set<String>> getResultAttributeMapping()
           
 String getUnmappedUsernameAttribute()
           
 boolean isRequireAllQueryAttributes()
           
 boolean isUseAllQueryAttributes()
           
protected  IPersonAttributes mapPersonAttributes(IPersonAttributes person)
          Uses resultAttributeMapping to return a copy of the IPersonAttributes with only the attributes specified in resultAttributeMapping mapped to their result attribute names.
 void setQueryAttributeMapping(Map<String,?> queryAttributeMapping)
          Map from query attribute names to data-layer attribute names to use when building the query.
 void setRequireAllQueryAttributes(boolean requireAllQueryAttributes)
          If all attributes specified in the queryAttributeMapping keySet must be present to actually run the query
 void setResultAttributeMapping(Map<String,?> resultAttributeMapping)
          Set the Map to use for mapping from a data layer name to an attribute name or Set of attribute names.
 void setUnmappedUsernameAttribute(String userNameAttribute)
          The returned attribute to use as the userName for the mapped IPersons.
 void setUseAllQueryAttributes(boolean useAllQueryAttributes)
          If setQueryAttributeMapping(Map) is null this determines if no parameters should be specified or if all query attributes should be used as parameters.
 
Methods inherited from class org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
getPerson, getUsernameAttributeProvider, setUsernameAttributeProvider, toSeedMap
 
Methods inherited from class org.jasig.services.persondir.support.AbstractFlatteningPersonAttributeDao
getPeople, toMultivaluedSeed
 
Methods inherited from class org.jasig.services.persondir.support.BasePersonAttributeDao
flattenResults, getMultivaluedUserAttributes, getMultivaluedUserAttributes, getUserAttributes, getUserAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractQueryPersonAttributeDao

public AbstractQueryPersonAttributeDao()
Method Detail

isUseAllQueryAttributes

public boolean isUseAllQueryAttributes()

setUseAllQueryAttributes

public void setUseAllQueryAttributes(boolean useAllQueryAttributes)
If setQueryAttributeMapping(Map) is null this determines if no parameters should be specified or if all query attributes should be used as parameters. Defaults to true.


getQueryAttributeMapping

public Map<String,Set<String>> getQueryAttributeMapping()
Returns:
the queryAttributeMapping

setQueryAttributeMapping

public void setQueryAttributeMapping(Map<String,?> queryAttributeMapping)
Map from query attribute names to data-layer attribute names to use when building the query. If an ordered Map is passed in the order of the attributes will be honored when building the query. If not set query attributes will be used directly from the query Map.

Parameters:
queryAttributeMapping - the queryAttributeMapping to set

getResultAttributeMapping

public Map<String,Set<String>> getResultAttributeMapping()
Returns:
the resultAttributeMapping

setResultAttributeMapping

public void setResultAttributeMapping(Map<String,?> resultAttributeMapping)
Set the Map to use for mapping from a data layer name to an attribute name or Set of attribute names. Data layer names that are specified but have null mappings will use the column name for the attribute name. Data layer names that are not specified as keys in this Map will be ignored.
The passed Map must have keys of type String and values of type String or a Set of String.

Parameters:
resultAttributeMapping - Map from column names to attribute names, may not be null.
Throws:
IllegalArgumentException - If the Map doesn't follow the rules stated above.
See Also:
MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)

isRequireAllQueryAttributes

public boolean isRequireAllQueryAttributes()
Returns:
the requireAllQueryAttributes

setRequireAllQueryAttributes

public void setRequireAllQueryAttributes(boolean requireAllQueryAttributes)
If all attributes specified in the queryAttributeMapping keySet must be present to actually run the query

Parameters:
requireAllQueryAttributes - the requireAllQueryAttributes to set

getUnmappedUsernameAttribute

public String getUnmappedUsernameAttribute()
Returns:
the userNameAttribute

setUnmappedUsernameAttribute

public void setUnmappedUsernameAttribute(String userNameAttribute)
The returned attribute to use as the userName for the mapped IPersons. If null the #setDefaultAttributeName(String) value will be used and if that is null the AttributeNamedPersonImpl.DEFAULT_USER_NAME_ATTRIBUTE value is used.

Parameters:
userNameAttribute - the userNameAttribute to set

getPeopleWithMultivaluedAttributes

public final Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(Map<String,List<Object>> query)

getAvailableQueryAttributes

public Set<String> getAvailableQueryAttributes()

getPossibleUserAttributeNames

public Set<String> getPossibleUserAttributeNames()

getPeopleForQuery

protected abstract List<IPersonAttributes> getPeopleForQuery(QB queryBuilder,
                                                             String queryUserName)
Executes the query for the generated queryBuilder object and returns a list where each entry is a Map of attributes for a single IPersonAttributes.

Parameters:
queryBuilder - The query generated by calls to appendAttributeToQuery(Object, String, List)
queryUserName - The username passed in the query map, if no username attribute existed in the query Map null is provided.
Returns:
The list of IPersons found by the query. The user attributes should be using the raw names from the data layer.

appendAttributeToQuery

protected abstract QB appendAttributeToQuery(QB queryBuilder,
                                             String dataAttribute,
                                             List<Object> queryValues)
Append the attribute and value to the queryBuilder.

Parameters:
queryBuilder - The sub-class specific query builder object
dataAttribute - The full attribute name to append
queryValues - The values for the data attribute
Returns:
An updated queryBuiler

generateQuery

protected final QB generateQuery(Map<String,List<Object>> query)
Generates a query using the queryBuilder object passed by the subclass. Attribute/Value pairs are added to the queryBuilder by calling #appendAttributeToQuery(Object, String, String). Attributes are only added if there is an attributed mapped in the queryAttributeMapping.

Parameters:
queryBuilder - The sub-class specific object to pass to #appendAttributeToQuery(Object, String, String) when building the query
query - The query Map to populate the queryBuilder with.
Returns:
The fully populated query builder.

mapPersonAttributes

protected final IPersonAttributes mapPersonAttributes(IPersonAttributes person)
Uses resultAttributeMapping to return a copy of the IPersonAttributes with only the attributes specified in resultAttributeMapping mapped to their result attribute names.

Parameters:
person - The IPersonAttributes to map attributes for
Returns:
A copy of the IPersonAttributes with mapped attributes, the original IPersonAttributes if resultAttributeMapping is null.

getConfiguredUserNameAttribute

protected String getConfiguredUserNameAttribute()
Returns:
The appropriate attribute to user for the user name. Since #getDefaultAttributeName() should never return null this method should never return null either.


Copyright © 2012 Jasig. All Rights Reserved.