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>>

public class RDBMSDataConnector
extends BaseDataConnector

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, net.sf.ehcache.Cache cache)
          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.
protected  void cacheResult(String principal, String query, Map<String,BaseAttribute> attributes)
          Caches the attributes resulting from a query.
 Map<String,RDBMSColumnDescriptor> getColumnDescriptor()
          Gets the set of column descriptors used to deal with result set data.
 int getQueryTimeout()
          Gets the timeout, in seconds, of the SQL query.
 boolean getUsesStoredProcedure()
          Gets whether queries made use stored procedures.
 boolean isCachingResuts()
          Gets whether this data connector is caching results.
 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.
protected  Map<String,BaseAttribute> processResultSet(ResultSet resultSet)
          Converts a SQL query results set into a set of BaseAttributes.
 void registerTemplate(TemplateEngine engine, String template)
          This sets the underlying template engine and registers the supplied template.
 Map<String,BaseAttribute> resolve(ShibbolethResolutionContext resolutionContext)
          Performs the attribute resolution for this plugin.
protected  Map<String,BaseAttribute> retrieveAttributesFromCache(String principal, 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 isError)
          This sets whether this connector will throw an exception if no search results are found.
 void setQueryTimeout(int timeout)
          Sets the timeout, in seconds, of the SQL query.
 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,
                          net.sf.ehcache.Cache cache)
Constructor.

Parameters:
source - data source used to retrieve connections
cache - cache used to cache results
Method Detail

registerTemplate

public void registerTemplate(TemplateEngine engine,
                             String template)
This sets the underlying template engine and registers the supplied template.

Parameters:
engine - template engine used to generate the query
template - template used to generate the query

isCachingResuts

public boolean isCachingResuts()
Gets whether this data connector is caching results.

Returns:
true if this data connector is caching results, false if not

getQueryTimeout

public int getQueryTimeout()
Gets the timeout, in seconds, of the SQL query.

Returns:
timeout, in seconds, of the SQL query

setQueryTimeout

public void setQueryTimeout(int timeout)
Sets the timeout, in seconds, of the SQL query.

Parameters:
timeout - timeout, in seconds, of the SQL query

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 isError)
This sets whether this connector will throw an exception if no search results are found.

Parameters:
isError - boolean

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

validate

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

Throws:
AttributeResolutionException - if the plug-in has an invalid internal state

resolve

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

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

retrieveAttributesFromCache

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

Parameters:
principal - 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

cacheResult

protected void cacheResult(String principal,
                           String query,
                           Map<String,BaseAttribute> attributes)
Caches the attributes resulting from a query.

Parameters:
principal - the principal name of the user the attributes are for
query - the query that generated the attributes
attributes - the results of the query


Copyright © 2006-2010 Internet2. All Rights Reserved.