Class JdbcSimpleUserDao

  • All Implemented Interfaces:
    DaoInterface

    public class JdbcSimpleUserDao
    extends Object
    implements DaoInterface
    This class encapsulates all the JDBC code used to access identity information in a database.
    • Constructor Detail

      • JdbcSimpleUserDao

        public JdbcSimpleUserDao()
    • Method Detail

      • initialize

        public void initialize​(String jndiName,
                               String userDataBaseTableName,
                               String membershipDataBaseTableName,
                               Debug idRepoDebugLog)
                        throws InstantiationException
        This class must be called before using the methods since the datasource must be set up. This version of initialize is used when connections are retreived using a Java EE datasource resource which is configured through the application server. For example if you use your server's ability to configure and pool connections. This also requires a java:comp/env resource-ref in web.xml
        Specified by:
        initialize in interface DaoInterface
        Throws:
        InstantiationException - when not able to instantiate this class, for example if parameters are bad or null or can not make a connection to datasource.
      • initialize

        public void initialize​(String jdbcDriver,
                               String jdbcDriverUrl,
                               String jdbcUser,
                               String jdbcPassword,
                               String userDataBaseTableName,
                               String membershipDataBaseTableName,
                               Debug idRepoDebugLog)
                        throws InstantiationException
        This class must be called before using the methods since the datasource must be set up. This version of initialize is used when connections are retreived using JDBC driver classes directly.
        Specified by:
        initialize in interface DaoInterface
        Throws:
        InstantiationException - when not able to instantiate this class, for example if parameters are bad or null or can not make a connection to datasource.
      • updateUser

        public void updateUser​(String userID,
                               String userIDAttributeName,
                               Map<String,​Set<String>> attrMap)
        Specified by:
        updateUser in interface DaoInterface
        Parameters:
        userID - is user id
        attrMap - is a Map that contains attribute/column names as keys and values are Sets of values
      • getAttributes

        public Map<String,​Set<String>> getAttributes​(String userID,
                                                           String userIDAttributeName,
                                                           Set<String> attributesToFetch)
        gets values for the user attributes specified in the atributesToFetch set. Normalizes the types by converting all the individual values into Strings.
        Specified by:
        getAttributes in interface DaoInterface
        Parameters:
        userID - is String of the users unique identifier
        userIDAttributeName - is the column name of the id field so is used for example in the where clause of SQL WHERE userIDAttributeName = userID
        attributesToFetch - is the set of column names for the attributes that should be fetched from the DB table.
        Returns:
        user a map of Maps where each map is a user and their attributes
      • search

        public Map<String,​Map<String,​Set<String>>> search​(String userIDAttributeName,
                                                                      int limit,
                                                                      String idPattern,
                                                                      Set<String> attributesToFetch,
                                                                      String filterOperand,
                                                                      Map<String,​Set<String>> avPairs)
        Fetch the set of users and including for each user all their attributes specified in attributesToFetch. If there is an attribute being asked for in attributesToFetch but that attribute is not present in the DB table then currently that attribute is not included in the returned Map of each user. For example, if the attributesToFetch includes "address" but there is no address column in the DB table and no "address" included in the result set for each row, then neither the attribute "address" of any value is put into the set of attributes for each user. Is this correct ????
        Specified by:
        search in interface DaoInterface
        Parameters:
        idPattern - which is used in an SQL LIKE query on the id attribute usually contains some SQL search chars like % to broaden matches WHERE id_attribute LIKE 'the_pattern_value' If idPattern is empty or null then it means to get all users so do not need to use a LIKE clause on query
        attributesToFetch - is set of desired attributes to fetch for each user. If EMPTY or NULL, then will not do anything, return empty map. Callers should be sure to specify which attributes to fetch.
        limit - is maximum number of results to return. This is added to the END of the WHERE clause using mysql LIMIT on a query. Default if no limit(if limit<0) is specified is LIMIT=1 Limit is ignored in this implementation since it is not portable SQL
        filterOperand - is a string of AND, or OR and is used to add extra attributes and values to the WHERE search clause, and it is applied between attribute = 'value' pairs in the parameter for avPairs.
        avPairs - is a map of attribute names as the keys and the associated values are a SET for each attribute name, and would be added to the WHERE clause after the isPattern part of clause and before the LIMIT part of the where clause, for example WHERE id_attribute LIKE 'the_pattern_value' AND (attr_1='value1' ...filterOperand/AND/OR... attr_2='value2' ) LIMIT 2
        Returns:
        a set of Maps where each map is a user and their attributes
      • search

        public Map<String,​Map<String,​Set<String>>> search​(String userIDAttributeName,
                                                                      int limit,
                                                                      org.forgerock.util.query.QueryFilter<org.forgerock.json.JsonPointer> queryFilter,
                                                                      Set<String> attributesToFetch,
                                                                      String filterOperand,
                                                                      Map<String,​Set<String>> avPairs)
                                                               throws IdRepoUnsupportedOpException
        Dealing with a query filter is not supported as yet and will give an empty map.
        Specified by:
        search in interface DaoInterface
        Parameters:
        userIDAttributeName - the name of the attribute which uniquely identifies users, e.g. "uid".
        limit - is maximum number of results to return. This is added to the END of the WHERE clause using mysql LIMIT on a query. Default if no limit(if limit<0) is specified is LIMIT=1 Limit is ignored in this implementation since it is not portable SQL
        queryFilter - the query filter sent, more or less directly, from a CREST endpoint _queryFilter value.
        attributesToFetch - is set of desired attributes to fetch for each user. If EMPTY or NULL, then will not do anything, return empty map. Callers should be sure to specify which attributes to fetch.
        filterOperand - is a string of AND, or OR and is used to add extra attributes and values to the WHERE search clause, and it is applied between attribute = 'value' pairs in the parameter for avPairs.
        avPairs - is a map of attribute names as the keys and the associated values are a SET for each attribute name, and would be added to the WHERE clause after the isPattern part of clause and before the LIMIT part of the where clause, for example WHERE id_attribute LIKE 'the_pattern_value' AND (attr_1='value1' ...filterOperand/AND/OR... attr_2='value2' ) LIMIT 2
        Returns:
        a set of Maps where each map is a user and their attributes
        Throws:
        IdRepoUnsupportedOpException
      • getDataSourceURL

        public String getDataSourceURL()
        get the url of the current database.
        Specified by:
        getDataSourceURL in interface DaoInterface
        Returns:
        a url of the current db connection, should be of the form jdbc:mysql://localhost:3306/seantestdb1 It is used by the IdRepo implementation to provide a fully qualified domain name for users, and this value serves as sort of the prefix.