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.
 
Field Summary
private  Map<String,RDBMSColumnDescriptor> columnDescriptors
          Set of column descriptors for managing returned data.
private  DataSource dataSource
          JDBC data source for retrieving connections.
private  org.slf4j.Logger log
          Class logger.
private  boolean noResultIsError
          Whether an empty result set is an error.
private  TemplateEngine queryCreator
          Template engine used to change query template into actual query.
private  String queryTemplate
          Template that produces the query to use.
private  String queryTemplateName
          Name the query template is registered under with the statement creator.
private  int queryTimeout
          SQL query timeout in seconds.
private  boolean readOnlyConnection
          Whether the JDBC connection is read-only.
private  net.sf.ehcache.Cache resultsCache
          Query result cache.
private  boolean usesStoredProcedure
          Whether queries might use stored procedures.
 
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
 

Field Detail

log

private final org.slf4j.Logger log
Class logger.


dataSource

private DataSource dataSource
JDBC data source for retrieving connections.


queryCreator

private TemplateEngine queryCreator
Template engine used to change query template into actual query.


queryTemplateName

private String queryTemplateName
Name the query template is registered under with the statement creator.


queryTemplate

private String queryTemplate
Template that produces the query to use.


queryTimeout

private int queryTimeout
SQL query timeout in seconds.


readOnlyConnection

private boolean readOnlyConnection
Whether the JDBC connection is read-only.


usesStoredProcedure

private boolean usesStoredProcedure
Whether queries might use stored procedures.


noResultIsError

private boolean noResultIsError
Whether an empty result set is an error.


columnDescriptors

private Map<String,RDBMSColumnDescriptor> columnDescriptors
Set of column descriptors for managing returned data. [columnName => colmentDescriptr]


resultsCache

private net.sf.ehcache.Cache resultsCache
Query result cache.

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 © 1999-2012. All Rights Reserved.