Class JdbcFilterDao

  • All Implemented Interfaces:
    FilterDao, org.springframework.beans.factory.InitializingBean

    @Transactional
    public class JdbcFilterDao
    extends java.lang.Object
    implements FilterDao, org.springframework.beans.factory.InitializingBean

    JdbcFilterDao class.

    Version:
    $Id: $
    Author:
    DJ Gregor
    • Constructor Summary

      Constructors 
      Constructor Description
      JdbcFilterDao()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()
      afterPropertiesSet
      void destroy()  
      void flushActiveIpAddressListCache()  
      protected java.net.InetAddress getActiveIPAddress​(java.lang.String rule, java.lang.String address)  
      java.util.List<java.net.InetAddress> getActiveIPAddressList​(java.lang.String rule)
      Get the (non-deleted) IP addresses that match the specified rule.
      DatabaseSchemaConfig getDatabaseSchemaConfigFactory()
      getDatabaseSchemaConfigFactory
      javax.sql.DataSource getDataSource()
      getDataSource
      java.lang.String getInterfaceWithServiceStatement​(java.lang.String rule)
      getInterfaceWithServiceStatement
      java.util.List<java.net.InetAddress> getIPAddressList​(java.lang.String rule)
      Get the IP addresses (including deleted) that match the specified rule.
      java.util.Map<java.net.InetAddress,​java.util.Set<java.lang.String>> getIPAddressServiceMap​(java.lang.String rule)
      getIPServiceMap
      java.util.Map<java.lang.Integer,​java.util.Map<java.net.InetAddress,​java.util.Set<java.lang.String>>> getNodeIPAddressServiceMap​(java.lang.String rule)
      Retrieve a mapping of IP-services scoped by node that match the given rule.
      java.lang.String getNodeIPServiceMappingStatement​(java.lang.String rule)
      getNodeIPServiceMappingStatement
      java.util.SortedMap<java.lang.Integer,​java.lang.String> getNodeMap​(java.lang.String rule)
      This method returns a map of all node IDs and node labels that match the rule that is passed in, sorted by node ID.
      java.lang.String getNodeMappingStatement​(java.lang.String rule)
      getNodeMappingStatement
      protected java.lang.String getSQLStatement​(java.lang.String rule)
      This method parses a rule and returns the SQL select statement equivalent of the rule.
      protected java.lang.String getSQLStatement​(java.lang.String rule, long nodeId, java.lang.String ipaddr, java.lang.String service)
      This method should be called if you want to put constraints on the node, interface or service that is returned in the rule.
      boolean isRuleMatching​(java.lang.String rule)
      Does this rule match anything in the database? In particular, does it return at least one record from the database?
      boolean isValid​(java.lang.String addr, java.lang.String rule)
      isValid
      void setDatabaseSchemaConfigFactory​(DatabaseSchemaConfig factory)
      setDatabaseSchemaConfigFactory
      void setDataSource​(javax.sql.DataSource dataSource)
      setDataSource
      void validateRule​(java.lang.String rule)
      validateRule
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JdbcFilterDao

        public JdbcFilterDao()
    • Method Detail

      • setDataSource

        public void setDataSource​(javax.sql.DataSource dataSource)

        setDataSource

        Parameters:
        dataSource - a DataSource object.
      • getDataSource

        public javax.sql.DataSource getDataSource()

        getDataSource

        Returns:
        a DataSource object.
      • afterPropertiesSet

        public void afterPropertiesSet()

        afterPropertiesSet

        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • destroy

        @PreDestroy
        @Transactional(propagation=NOT_SUPPORTED)
        public void destroy()
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getNodeMap

        public java.util.SortedMap<java.lang.Integer,​java.lang.String> getNodeMap​(java.lang.String rule)
                                                                                 throws FilterParseException
        This method returns a map of all node IDs and node labels that match the rule that is passed in, sorted by node ID. This method returns a map of all nodeids and nodelabels that match the rule that is passed in, sorted by nodeid.
        Specified by:
        getNodeMap in interface FilterDao
        Parameters:
        rule - an expression rule to be parsed and executed.
        Returns:
        SortedMap containing all node IDs and node labels selected by the rule.
        Throws:
        FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement
      • getIPAddressServiceMap

        public java.util.Map<java.net.InetAddress,​java.util.Set<java.lang.String>> getIPAddressServiceMap​(java.lang.String rule)
                                                                                                         throws FilterParseException

        getIPServiceMap

        Specified by:
        getIPAddressServiceMap in interface FilterDao
        Parameters:
        rule - a String object.
        Returns:
        a Map object.
        Throws:
        FilterParseException - if any.
      • getNodeIPAddressServiceMap

        public java.util.Map<java.lang.Integer,​java.util.Map<java.net.InetAddress,​java.util.Set<java.lang.String>>> getNodeIPAddressServiceMap​(java.lang.String rule)
                                                                                                                                                    throws FilterParseException
        Description copied from interface: FilterDao
        Retrieve a mapping of IP-services scoped by node that match the given rule.
        Specified by:
        getNodeIPAddressServiceMap in interface FilterDao
        Parameters:
        rule - filter rule to evaluate
        Returns:
        map of IP-services
        Throws:
        FilterParseException - if the rule is invalid
      • flushActiveIpAddressListCache

        @CacheEvict(value="activeIpAddressList",
                    allEntries=true)
        public void flushActiveIpAddressListCache()
        Specified by:
        flushActiveIpAddressListCache in interface FilterDao
      • getActiveIPAddressList

        @Cacheable("activeIpAddressList")
        public java.util.List<java.net.InetAddress> getActiveIPAddressList​(java.lang.String rule)
                                                                    throws FilterParseException
        Get the (non-deleted) IP addresses that match the specified rule.
        Specified by:
        getActiveIPAddressList in interface FilterDao
        Parameters:
        rule - the filter rule
        Returns:
        a List of IP addresses.
        Throws:
        FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement.
      • getActiveIPAddress

        protected java.net.InetAddress getActiveIPAddress​(java.lang.String rule,
                                                          java.lang.String address)
      • getIPAddressList

        public java.util.List<java.net.InetAddress> getIPAddressList​(java.lang.String rule)
                                                              throws FilterParseException
        Get the IP addresses (including deleted) that match the specified rule.
        Specified by:
        getIPAddressList in interface FilterDao
        Parameters:
        rule - the filter rule
        Returns:
        a List of IP addresses.
        Throws:
        FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement.
      • isValid

        public boolean isValid​(java.lang.String addr,
                               java.lang.String rule)
                        throws FilterParseException

        isValid

        This method verifies if an ip address adheres to a given rule.
        Specified by:
        isValid in interface FilterDao
        Parameters:
        addr - a String object.
        rule - a String object.
        Returns:
        a boolean.
        Throws:
        FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement.
      • isRuleMatching

        public boolean isRuleMatching​(java.lang.String rule)
                               throws FilterParseException
        Does this rule match anything in the database? In particular, does it return at least one record from the database?
        Specified by:
        isRuleMatching in interface FilterDao
        Parameters:
        rule - rule to match on
        Returns:
        true if there is at least one match, false otherwise
        Throws:
        FilterParseException - if any.
      • getNodeMappingStatement

        public java.lang.String getNodeMappingStatement​(java.lang.String rule)
                                                 throws FilterParseException

        getNodeMappingStatement

        Parameters:
        rule - a String object.
        Returns:
        a String object.
        Throws:
        FilterParseException - if any.
      • getNodeIPServiceMappingStatement

        public java.lang.String getNodeIPServiceMappingStatement​(java.lang.String rule)
                                                          throws FilterParseException

        getNodeIPServiceMappingStatement

        Parameters:
        rule - a String object.
        Returns:
        a String object.
        Throws:
        FilterParseException - if any.
      • getInterfaceWithServiceStatement

        public java.lang.String getInterfaceWithServiceStatement​(java.lang.String rule)
                                                          throws FilterParseException

        getInterfaceWithServiceStatement

        Parameters:
        rule - a String object.
        Returns:
        a String object.
        Throws:
        FilterParseException - if any.
      • getSQLStatement

        protected java.lang.String getSQLStatement​(java.lang.String rule)
                                            throws FilterParseException
        This method parses a rule and returns the SQL select statement equivalent of the rule.
        Parameters:
        rule - a String object.
        Returns:
        the SQL select statement
        Throws:
        FilterParseException - if any.
      • getSQLStatement

        protected java.lang.String getSQLStatement​(java.lang.String rule,
                                                   long nodeId,
                                                   java.lang.String ipaddr,
                                                   java.lang.String service)
                                            throws FilterParseException
        This method should be called if you want to put constraints on the node, interface or service that is returned in the rule. This is useful to see if a particular node, interface, or service matches in the rule, and is primarily used to filter notices. A sub-select is built containing joins constrained by node, interface, and service if they are not null or blank. This select is then ANDed with the filter rule to get the complete SQL statement.
        Parameters:
        nodeId - a node id to constrain against
        ipaddr - an ipaddress to constrain against
        service - a service name to constrain against
        rule - a String object.
        Returns:
        a String object.
        Throws:
        FilterParseException - if any.