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
Modifier and TypeFieldDescriptionprotected boolean
if error if limit is reachedstatic boolean
for testing if we should fail on testingprotected JdbcConnectionProvider
keep a reference to the object which gets our connections for usprotected Integer
if there is a limit to the number of resultsstatic int
increment a query count for testingprotected String
subject id attribute nameprotected String
subject 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
ConstructorDescriptionAllocates new JDBCSourceAdapter;JDBCSourceAdapter
(String id1, String name1) Allocates new JDBCSourceAdapter; -
Method Summary
Modifier and TypeMethodDescriptionvoid
make sure the config is ok, and log descriptive errors if notprotected void
max Page sizeprotected ResultSet
getSqlResults
(String searchValue, PreparedStatement stmt, Search search) Set the parameters in the prepared statement and execute the query.protected ResultSet
getSqlResults
(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.void
init()
Called by SourceManager when it loads this source.boolean
if we should change the query based on max resuuls or pageboolean
if we should use an in clause for id or identifier searchesLoads attributes for the argument subject.static void
loadDriver
(String sourceId, String driver) Loads the the JDBC driver.void
start logging the source low level actionsstop logging and get the outputprotected PreparedStatement
prepareStatement
(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 void
setupDataSource
(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:Source
start logging the source low level actions -
loggingStop
Description copied from interface:Source
stop logging and get the output -
retrieveAllSubjectIds
Description copied from interface:Source
get all subject ids- Specified by:
retrieveAllSubjectIds
in interfaceSource
- Overrides:
retrieveAllSubjectIds
in 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:
getSubject
in interfaceSource
- Overrides:
getSubject
in classBaseSourceAdapter
exceptionIfNull
- if SubjectNotFoundException should be throws if the subject is null, or if null should be returned- Returns:
- subject
- Throws:
SubjectNotFoundException
SubjectNotUniqueException
- See Also:
-
getSubjectByIdentifier
public Subject getSubjectByIdentifier(String id1, boolean exceptionIfNull) throws SubjectNotFoundException, SubjectNotUniqueException Description copied from class:BaseSourceAdapter
note, you should implement this method since this implementation will become abstract at some point- Specified by:
getSubjectByIdentifier
in interfaceSource
- Overrides:
getSubjectByIdentifier
in classBaseSourceAdapter
- Returns:
- subject
- Throws:
SubjectNotFoundException
SubjectNotUniqueException
- 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:
search
in interfaceSource
- Specified by:
search
in classBaseSourceAdapter
- Returns:
- set
-
searchPage
Description copied from interface:Source
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 if maxPageSize is set in subject.properties, then only return max that many, and if there are more, set the tooManyResults flag- Specified by:
searchPage
in interfaceSource
- Overrides:
searchPage
in 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:
InvalidQueryException
SQLException
-
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:Source
Get 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:
getSubjectsByIdentifiers
in interfaceSource
- Overrides:
getSubjectsByIdentifiers
in classBaseSourceAdapter
- Returns:
- a map of results never null indexed by the identifiers
- See Also:
-
getSubjectsByIds
Description copied from interface:Source
Get 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:
getSubjectsByIds
in interfaceSource
- Overrides:
getSubjectsByIds
in 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:
init
in interfaceSource
- Specified by:
init
in 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:Source
make sure the config is ok, and log descriptive errors if not- See Also:
-
printConfig
Description copied from interface:Source
in 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:Source
Gets a Subject by its ID.- Specified by:
getSubject
in interfaceSource
- Specified by:
getSubject
in classBaseSourceAdapter
- Returns:
- subject
- Throws:
SubjectNotFoundException
SubjectNotUniqueException
- See Also:
-
getSubjectByIdentifier
@Deprecated public Subject getSubjectByIdentifier(String id1) throws SubjectNotFoundException, SubjectNotUniqueException Deprecated.Description copied from interface:Source
Gets a Subject by other well-known identifiers, aside from the subject ID, for example, login ID.- Specified by:
getSubjectByIdentifier
in interfaceSource
- Specified by:
getSubjectByIdentifier
in classBaseSourceAdapter
- Returns:
- subject
- Throws:
SubjectNotFoundException
SubjectNotUniqueException
- See Also:
-
getSubjectIdentifierAttributes
Description copied from interface:Source
Get the names of attributes that are subject identifiers. This only returns the first- Specified by:
getSubjectIdentifierAttributes
in interfaceSource
- Overrides:
getSubjectIdentifierAttributes
in classBaseSourceAdapter
- Returns:
- subject identifiers
- See Also:
-
getSubjectIdentifierAttributesAll
Description copied from interface:Source
Get all the names of attributes that are subject identifiers.- Specified by:
getSubjectIdentifierAttributesAll
in interfaceSource
- Overrides:
getSubjectIdentifierAttributesAll
in classBaseSourceAdapter
- Returns:
- subject identifiers
- See Also:
-