Class JDBCSourceAdapter
java.lang.Object
edu.internet2.middleware.subject.provider.BaseSourceAdapter
edu.internet2.middleware.subject.provider.JDBCSourceAdapter
- All Implemented Interfaces:
Source
- Direct Known Subclasses:
HelperGrouperJdbcSourceAdapter,JDBCSourceAdapter2
JDBC Source
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanif error if limit is reachedstatic booleanfor testing if we should fail on testingprotected JdbcConnectionProviderkeep a reference to the object which gets our connections for usprotected Integerif there is a limit to the number of resultsstatic intincrement a query count for testingprotected Stringsubject id attribute nameprotected Stringsubject type stringFields inherited from class edu.internet2.middleware.subject.provider.BaseSourceAdapter
attributes, descriptionAttributeName, id, internalAttributes, name, nameAttributeName, params, searchAttributes, searches, sortAttributes, subjectIdentifierAttributes, subjectIdentifierAttributesAll, type, types -
Constructor Summary
ConstructorsConstructorDescriptionAllocates new JDBCSourceAdapter;JDBCSourceAdapter(String id1, String name1) Allocates new JDBCSourceAdapter; -
Method Summary
Modifier and TypeMethodDescriptionvoidmake sure the config is ok, and log descriptive errors if notprotected voidmax Page sizeprotected ResultSetgetSqlResults(String searchValue, PreparedStatement stmt, Search search) Set the parameters in the prepared statement and execute the query.protected ResultSetgetSqlResults(List<String> batchIdsOrIdentifiers, PreparedStatement stmt, int numParameters, String sql) Set the parameters in the prepared statement and execute the query.getSubject(String id1) Deprecated.getSubject(String id1, boolean exceptionIfNull) Gets a Subject by its ID.Deprecated.getSubjectByIdentifier(String id1, boolean exceptionIfNull) note, you should implement this method since this implementation will become abstract at some pointGet the names of attributes that are subject identifiers.Get all the names of attributes that are subject identifiers.getSubjectsByIdentifiers(Collection<String> identifiers) Get subjects by identifiers.getSubjectsByIds(Collection<String> ids) Get subjects by ids.voidinit()Called by SourceManager when it loads this source.booleanif we should change the query based on max resuuls or pagebooleanif we should use an in clause for id or identifier searchesLoads attributes for the argument subject.static voidloadDriver(String sourceId, String driver) Loads the the JDBC driver.voidstart logging the source low level actionsstop logging and get the outputprotected PreparedStatementprepareStatement(Search search, Connection conn, boolean searchAll, boolean firstPageOnly) Prepare a statement handle from the search object.in the startup on this i2mi app, print helpful and brief info about this sourceget all subject idsUnstructured search for Subjects.searchPage(String searchValue) Unstructured search for Subjects.protected voidsetupDataSource(Properties props) DataSource connection pool setup.tryToChangeQuery(String query, Connection conn, int resultSetLimit) try to change a paging query, note it will add one to the resultSetLimit so that the caller can see if there are too many recordsMethods inherited from class edu.internet2.middleware.subject.provider.BaseSourceAdapter
addAttribute, addInitParam, addInternalAttribute, addSubjectType, attributeNameToViewerGroupName, convertSourceAttributeToSubjectAttribute, convertSubjectAttributeToSourceAttribute, createSubject, equals, exportLabelToAttributeName, getAttributes, getConfigId, getId, getInitParam, getInternalAttributes, getName, getSearch, getSearchAttributes, getSearches, getSortAttributes, getSourceAttributesToLowerCase, getSubject, getSubjectByIdentifier, getSubjectByIdOrIdentifier, getSubjectByIdOrIdentifier, getSubjectsByIdentifiers, getSubjectsByIds, getSubjectsByIdsOrIdentifiers, getSubjectsByIdsOrIdentifiers, getSubjectStatusConfig, getSubjectType, getSubjectTypes, hashCode, initParams, isEditable, isEnabled, loadSearch, removeInitParam, resultSetLimit, search, searchPage, setConfigId, setId, setName, setSearchAttributes, setSearches, setSortAttributes, setSubjectIdentifierAttributes, setSubjectIdentifierAttributesAll, virtualAttributesForSource, virtualAttributesForSourceLegacy, virtualAttributeVariablesForSourceLegacy
-
Field Details
-
subjectIDAttributeName
subject id attribute name -
subjectTypeString
subject type string -
maxResults
if there is a limit to the number of results -
errorOnMaxResults
protected boolean errorOnMaxResultsif error if limit is reached -
jdbcConnectionProvider
keep a reference to the object which gets our connections for us -
failOnSearchForTesting
public static boolean failOnSearchForTestingfor testing if we should fail on testing -
queryCountforTesting
public static int queryCountforTestingincrement a query count for testing
-
-
Constructor Details
-
JDBCSourceAdapter
public JDBCSourceAdapter()Allocates new JDBCSourceAdapter; -
JDBCSourceAdapter
Allocates new JDBCSourceAdapter;- Parameters:
id1-name1-
-
-
Method Details
-
loggingStart
public void loggingStart()Description copied from interface:Sourcestart logging the source low level actions -
loggingStop
Description copied from interface:Sourcestop logging and get the output -
retrieveAllSubjectIds
Description copied from interface:Sourceget all subject ids- Specified by:
retrieveAllSubjectIdsin interfaceSource- Overrides:
retrieveAllSubjectIdsin classBaseSourceAdapter- Returns:
- all subjectIds
- See Also:
-
tryToChangeQuery
try to change a paging query, note it will add one to the resultSetLimit so that the caller can see if there are too many records- Parameters:
query-conn-resultSetLimit-- Returns:
- the query with paging or original query if cant change it
-
getDatabaseType
- Returns:
- the databaseType
-
isChangeSearchQueryForMaxResults
public boolean isChangeSearchQueryForMaxResults()if we should change the query based on max resuuls or page- Returns:
- the changeSearchQueryForMaxResults
-
getSubject
public Subject getSubject(String id1, boolean exceptionIfNull) throws SubjectNotFoundException, SubjectNotUniqueException Gets a Subject by its ID.- Specified by:
getSubjectin interfaceSource- Overrides:
getSubjectin classBaseSourceAdapterexceptionIfNull- if SubjectNotFoundException should be throws if the subject is null, or if null should be returned- Returns:
- subject
- Throws:
SubjectNotFoundExceptionSubjectNotUniqueException- See Also:
-
getSubjectByIdentifier
public Subject getSubjectByIdentifier(String id1, boolean exceptionIfNull) throws SubjectNotFoundException, SubjectNotUniqueException Description copied from class:BaseSourceAdapternote, you should implement this method since this implementation will become abstract at some point- Specified by:
getSubjectByIdentifierin interfaceSource- Overrides:
getSubjectByIdentifierin classBaseSourceAdapter- Returns:
- subject
- Throws:
SubjectNotFoundExceptionSubjectNotUniqueException- See Also:
-
search
Unstructured search for Subjects. Each implementation utilizes its own search algorithm tailored to the Subject repository and schema. Note if config param: throwErrorOnFindAllFailure is false, then swallow and log exceptions- Specified by:
searchin interfaceSource- Specified by:
searchin classBaseSourceAdapter- Returns:
- set
-
searchPage
Description copied from interface:SourceUnstructured search for Subjects. Each implementation utilizes its own search algorithm tailored to the Subject repository and schema. Note if config param: throwErrorOnFindAllFailure is false, then swallow and log exceptions if maxPageSize is set in subject.properties, then only return max that many, and if there are more, set the tooManyResults flag- Specified by:
searchPagein interfaceSource- Overrides:
searchPagein classBaseSourceAdapter- Returns:
- results and if there are too many, never return null!!!
- See Also:
-
prepareStatement
protected PreparedStatement prepareStatement(Search search, Connection conn, boolean searchAll, boolean firstPageOnly) throws InvalidQueryException, SQLException Prepare a statement handle from the search object.- Parameters:
search-conn-searchAll- true if a searchAll methodfirstPageOnly-- Returns:
- the prepared statement
- Throws:
InvalidQueryExceptionSQLException
-
getSqlResults
protected ResultSet getSqlResults(String searchValue, PreparedStatement stmt, Search search) throws SQLException Set the parameters in the prepared statement and execute the query.- Parameters:
searchValue-stmt-search-- Returns:
- resultSet
- Throws:
SQLException
-
getSqlResults
protected ResultSet getSqlResults(List<String> batchIdsOrIdentifiers, PreparedStatement stmt, int numParameters, String sql) throws SQLException Set the parameters in the prepared statement and execute the query.- Parameters:
searchValue-stmt-search-- Returns:
- resultSet
- Throws:
SQLException
-
getSubjectsByIdentifiers
Description copied from interface:SourceGet subjects by identifiers. Note, if the subjects arent found or arent unique, they wont be returned. Identifiers are unique ways to refer to a subject that isnt its id (e.g. netid). Duplicates are ok on the input, but will return one output.- Specified by:
getSubjectsByIdentifiersin interfaceSource- Overrides:
getSubjectsByIdentifiersin classBaseSourceAdapter- Returns:
- a map of results never null indexed by the identifiers
- See Also:
-
getSubjectsByIds
Description copied from interface:SourceGet subjects by ids. Note, if the subjects arent found or arent unique, they wont be returned. Duplicates are ok on the input, but will return one output.- Specified by:
getSubjectsByIdsin interfaceSource- Overrides:
getSubjectsByIdsin classBaseSourceAdapter- Returns:
- a map of results never null indexed by the id
- See Also:
-
loadAttributes
Loads attributes for the argument subject.- Parameters:
rs-- Returns:
- attributes
-
init
Called by SourceManager when it loads this source.- Specified by:
initin interfaceSource- Specified by:
initin classBaseSourceAdapter- Throws:
SourceUnavailableException
-
loadDriver
Loads the the JDBC driver.- Parameters:
sourceId-driver-- Throws:
SourceUnavailableException
-
setupDataSource
DataSource connection pool setup.- Parameters:
props-- Throws:
SourceUnavailableException
-
getMaxPage
max Page size- Returns:
- the maxPage
-
isUseInClauseForIdAndIdentifier
public boolean isUseInClauseForIdAndIdentifier()if we should use an in clause for id or identifier searches- Returns:
- true if should
-
closeStatement
- Parameters:
stmt-
-
getDescriptionAttributeName
- Returns:
- the descriptionAttributeName
-
getNameAttributeName
- Returns:
- the nameAttributeName
-
getSubjectIDAttributeName
- Returns:
- the subjectIDAttributeName
-
getSubjectTypeString
- Returns:
- the subjectTypeString
-
checkConfig
public void checkConfig()Description copied from interface:Sourcemake sure the config is ok, and log descriptive errors if not- See Also:
-
printConfig
Description copied from interface:Sourcein the startup on this i2mi app, print helpful and brief info about this source- Returns:
- the info
- See Also:
-
getSubject
@Deprecated public Subject getSubject(String id1) throws SubjectNotFoundException, SubjectNotUniqueException Deprecated.Description copied from interface:SourceGets a Subject by its ID.- Specified by:
getSubjectin interfaceSource- Specified by:
getSubjectin classBaseSourceAdapter- Returns:
- subject
- Throws:
SubjectNotFoundExceptionSubjectNotUniqueException- See Also:
-
getSubjectByIdentifier
@Deprecated public Subject getSubjectByIdentifier(String id1) throws SubjectNotFoundException, SubjectNotUniqueException Deprecated.Description copied from interface:SourceGets a Subject by other well-known identifiers, aside from the subject ID, for example, login ID.- Specified by:
getSubjectByIdentifierin interfaceSource- Specified by:
getSubjectByIdentifierin classBaseSourceAdapter- Returns:
- subject
- Throws:
SubjectNotFoundExceptionSubjectNotUniqueException- See Also:
-
getSubjectIdentifierAttributes
Description copied from interface:SourceGet the names of attributes that are subject identifiers. This only returns the first- Specified by:
getSubjectIdentifierAttributesin interfaceSource- Overrides:
getSubjectIdentifierAttributesin classBaseSourceAdapter- Returns:
- subject identifiers
- See Also:
-
getSubjectIdentifierAttributesAll
Description copied from interface:SourceGet all the names of attributes that are subject identifiers.- Specified by:
getSubjectIdentifierAttributesAllin interfaceSource- Overrides:
getSubjectIdentifierAttributesAllin classBaseSourceAdapter- Returns:
- subject identifiers
- See Also:
-