edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector
Class RDBMSDataConnector

java.lang.Object
  extended by edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.AbstractResolutionPlugIn<Map<String,BaseAttribute>>
      extended by edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.BaseDataConnector
          extended by edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.RDBMSDataConnector
All Implemented Interfaces:
DataConnector, ResolutionPlugIn<Map<String,BaseAttribute>>, EventListener, ApplicationListener

public class RDBMSDataConnector
extends BaseDataConnector
implements ApplicationListener

A data connector that can retrieve information from a relational database through JDBC, version 3.


Nested Class Summary
static class RDBMSDataConnector.DATA_TYPES
          Data types understood by this connector.
 
Constructor Summary
RDBMSDataConnector(DataSource source, boolean resultCaching)
          Constructor.
 
Method Summary
protected  void addValueByType(Collection values, RDBMSDataConnector.DATA_TYPES type, ResultSet resultSet, int columnIndex)
          Adds a value extracted from the result set as a specific type into the value set.
 void clearCache()
          Clears the result cache.
 boolean getCacheResults()
          Gets whether to cache query results.
 Map<String,RDBMSColumnDescriptor> getColumnDescriptor()
          Gets the set of column descriptors used to deal with result set data.
 String getQueryTemplate()
          Gets the template used to create queries.
 TemplateEngine getTemplateEngine()
          Gets the engine used to evaluate the query template.
 boolean getUsesStoredProcedure()
          Gets whether queries made use stored procedures.
 void initialize()
          Initializes the connector and prepares it for use.
 boolean isConnectionReadOnly()
          Gets whether this data connector uses read-only connections.
 boolean isNoResultIsError()
          This returns whether this connector will throw an exception if no search results are found.
 void onApplicationEvent(ApplicationEvent event)
          
protected  Map<String,BaseAttribute> processResultSet(ResultSet resultSet)
          Converts a SQL query results set into a set of BaseAttributes.
protected  void registerTemplate()
          Registers the query template with template engine.
 Map<String,BaseAttribute> resolve(ShibbolethResolutionContext resolutionContext)
          Performs the attribute resolution for this plugin.
protected  Map<String,BaseAttribute> retrieveAttributesFromCache(String princpal, String query)
          Attempts to retrieve the attributes from the cache.
protected  Map<String,BaseAttribute> retrieveAttributesFromDatabase(String query)
          Attempts to retrieve the attribute from the database.
 void setConnectionReadOnly(boolean isReadOnly)
          Sets whether this data connector uses read-only connections.
 void setNoResultIsError(boolean b)
          This sets whether this connector will throw an exception if no search results are found.
 void setQueryTemplate(String template)
          Sets the template used to create queries.
 void setTemplateEngine(TemplateEngine engine)
          Sets the engine used to evaluate the query template.
 void setUsesStoredProcedure(boolean storedProcedure)
          Sets whether queries made use stored procedures.
 void validate()
          Validate the internal state of this plug-in.
 
Methods inherited from class edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.BaseDataConnector
getFailoverDependencyId, setFailoverDependencyIds
 
Methods inherited from class edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.AbstractResolutionPlugIn
getDependencyIds, getId, getValuesFromAllDependencies, getValuesFromAttributeDependency, getValuesFromConnectorDependency, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ResolutionPlugIn
getDependencyIds, getId
 

Constructor Detail

RDBMSDataConnector

public RDBMSDataConnector(DataSource source,
                          boolean resultCaching)
Constructor.

Parameters:
source - data source used to retrieve connections
resultCaching - whether query results should be cached
Method Detail

initialize

public void initialize()
Initializes the connector and prepares it for use.


isConnectionReadOnly

public boolean isConnectionReadOnly()
Gets whether this data connector uses read-only connections.

Returns:
whether this data connector uses read-only connections

setConnectionReadOnly

public void setConnectionReadOnly(boolean isReadOnly)
Sets whether this data connector uses read-only connections.

Parameters:
isReadOnly - whether this data connector uses read-only connections

getUsesStoredProcedure

public boolean getUsesStoredProcedure()
Gets whether queries made use stored procedures.

Returns:
whether queries made use stored procedures

setUsesStoredProcedure

public void setUsesStoredProcedure(boolean storedProcedure)
Sets whether queries made use stored procedures.

Parameters:
storedProcedure - whether queries made use stored procedures

isNoResultIsError

public boolean isNoResultIsError()
This returns whether this connector will throw an exception if no search results are found. The default is false.

Returns:
boolean

setNoResultIsError

public void setNoResultIsError(boolean b)
This sets whether this connector will throw an exception if no search results are found.

Parameters:
b - boolean

getCacheResults

public boolean getCacheResults()
Gets whether to cache query results.

Returns:
whether to cache query results

getTemplateEngine

public TemplateEngine getTemplateEngine()
Gets the engine used to evaluate the query template.

Returns:
engine used to evaluate the query template

setTemplateEngine

public void setTemplateEngine(TemplateEngine engine)
Sets the engine used to evaluate the query template.

Parameters:
engine - engine used to evaluate the query template

getQueryTemplate

public String getQueryTemplate()
Gets the template used to create queries.

Returns:
template used to create queries

setQueryTemplate

public void setQueryTemplate(String template)
Sets the template used to create queries.

Parameters:
template - template used to create queries

getColumnDescriptor

public Map<String,RDBMSColumnDescriptor> getColumnDescriptor()
Gets the set of column descriptors used to deal with result set data. The name of the database column is the map's key. This list is unmodifiable.

Returns:
column descriptors used to deal with result set data

onApplicationEvent

public void onApplicationEvent(ApplicationEvent event)

Specified by:
onApplicationEvent in interface ApplicationListener

resolve

public Map<String,BaseAttribute> resolve(ShibbolethResolutionContext resolutionContext)
                                  throws AttributeResolutionException
Performs the attribute resolution for this plugin.

Specified by:
resolve in interface ResolutionPlugIn<Map<String,BaseAttribute>>
Parameters:
resolutionContext - the context for the resolution
Returns:
the attributes made available by the resolution, never null
Throws:
AttributeResolutionException - the problem that occurred during the resolution

validate

public void validate()
              throws AttributeResolutionException
Validate the internal state of this plug-in. This process may not rely on information from any dependency.

Specified by:
validate in interface ResolutionPlugIn<Map<String,BaseAttribute>>
Throws:
AttributeResolutionException - if the plug-in has an invalid internal state

clearCache

public void clearCache()
Clears the result cache.


registerTemplate

protected void registerTemplate()
Registers the query template with template engine.


retrieveAttributesFromCache

protected Map<String,BaseAttribute> retrieveAttributesFromCache(String princpal,
                                                                String query)
                                                         throws AttributeResolutionException
Attempts to retrieve the attributes from the cache.

Parameters:
princpal - the principal name of the user the attributes are for
query - query used to generate the attributes
Returns:
cached attributes
Throws:
AttributeResolutionException - thrown if there is a problem retrieving data from the cache

retrieveAttributesFromDatabase

protected Map<String,BaseAttribute> retrieveAttributesFromDatabase(String query)
                                                            throws AttributeResolutionException
Attempts to retrieve the attribute from the database.

Parameters:
query - query used to get the attributes
Returns:
attributes gotten from the database
Throws:
AttributeResolutionException - thrown if there is a problem retrieving data from the database or transforming that data into BaseAttributes

processResultSet

protected Map<String,BaseAttribute> processResultSet(ResultSet resultSet)
                                              throws AttributeResolutionException
Converts a SQL query results set into a set of BaseAttributes.

Parameters:
resultSet - the result set to convert
Returns:
the resultant set of attributes
Throws:
AttributeResolutionException - thrown if there is a problem converting the result set into attributes

addValueByType

protected void addValueByType(Collection values,
                              RDBMSDataConnector.DATA_TYPES type,
                              ResultSet resultSet,
                              int columnIndex)
                       throws SQLException
Adds a value extracted from the result set as a specific type into the value set.

Parameters:
values - set to add values into
type - type the value should be extracted as
resultSet - result set, on the current row, to extract the value from
columnIndex - index of the column from which to extract the attribute
Throws:
SQLException - thrown if value can not retrieved from the result set


Copyright © 2006-2009 Internet2. All Rights Reserved.