org.opennms.netmgt.dao.support
Class JdbcFilterDao

java.lang.Object
  extended by org.opennms.netmgt.dao.support.JdbcFilterDao
All Implemented Interfaces:
FilterDao, org.springframework.beans.factory.InitializingBean

public class JdbcFilterDao
extends Object
implements FilterDao, org.springframework.beans.factory.InitializingBean

Author:
DJ Gregor

Constructor Summary
JdbcFilterDao()
           
 
Method Summary
 void afterPropertiesSet()
           
 DatabaseSchemaConfigFactory getDatabaseSchemaConfigFactory()
           
 DataSource getDataSource()
           
protected  String getInterfaceWithServiceStatement(String rule)
           
 List<String> getIPList(String rule)
          This method returns a list of all ip addresses that match the rule that is passed in.
 Map<String,Set<String>> getIPServiceMap(String rule)
           
protected  String getIPServiceMappingStatement(String rule)
           
 NodeDao getNodeDao()
           
 SortedMap<Integer,String> getNodeMap(String rule)
          This method returns a map of all nodeids and nodelabels that match the rule that is passed in, sorted by nodeid.
protected  String getNodeMappingStatement(String rule)
           
protected  String getSQLStatement(String rule)
          This method parses a rule and returns the SQL select statement equivalent of the rule.
protected  String getSQLStatement(String rule, long nodeId, String ipaddr, 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(String rule)
          Does this rule match anything in the database? In particular, does it return at least one record from the database?
 boolean isValid(String addr, String rule)
          This method verifies if an ip address adheres to a given rule.
 void setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory factory)
           
 void setDataSource(DataSource dataSource)
           
 void setNodeDao(NodeDao nodeDao)
           
 void validateRule(String rule)
           
 void walkMatchingNodes(String rule, EntityVisitor visitor)
           
 
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(DataSource dataSource)

getDataSource

public DataSource getDataSource()

setDatabaseSchemaConfigFactory

public void setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory factory)

getDatabaseSchemaConfigFactory

public DatabaseSchemaConfigFactory getDatabaseSchemaConfigFactory()

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

setNodeDao

public void setNodeDao(NodeDao nodeDao)

getNodeDao

public NodeDao getNodeDao()

walkMatchingNodes

public void walkMatchingNodes(String rule,
                              EntityVisitor visitor)
Specified by:
walkMatchingNodes in interface FilterDao

getNodeMap

public SortedMap<Integer,String> getNodeMap(String rule)
                                     throws FilterParseException
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 nodeids/nodelabels selected by the rule.
Throws:
FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement

getIPServiceMap

public Map<String,Set<String>> getIPServiceMap(String rule)
                                        throws FilterParseException
Specified by:
getIPServiceMap in interface FilterDao
Throws:
FilterParseException

getIPList

public List<String> getIPList(String rule)
                       throws FilterParseException
This method returns a list of all ip addresses that match the rule that is passed in.

Specified by:
getIPList in interface FilterDao
Parameters:
rule - an expression rule to be parsed and executed.
Returns:
interface containing all ip addresses selected by the rule.
Throws:
FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement

isValid

public boolean isValid(String addr,
                       String rule)
                throws FilterParseException
This method verifies if an ip address adheres to a given rule.

Specified by:
isValid in interface FilterDao
Parameters:
addr - an octet string ip to be validated against a rule.
rule - an expression rule to be parsed and executed.
Returns:
indicating that the ip is included in the rule
Throws:
FilterParseException - if a rule is syntactically incorrect or failed in executing the SQL statement.

isRuleMatching

public boolean isRuleMatching(String rule)
                       throws FilterParseException
Description copied from interface: FilterDao
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

validateRule

public void validateRule(String rule)
                  throws FilterParseException
Specified by:
validateRule in interface FilterDao
Throws:
FilterParseException

getNodeMappingStatement

protected String getNodeMappingStatement(String rule)
                                  throws FilterParseException
Throws:
FilterParseException

getIPServiceMappingStatement

protected String getIPServiceMappingStatement(String rule)
                                       throws FilterParseException
Throws:
FilterParseException

getInterfaceWithServiceStatement

protected String getInterfaceWithServiceStatement(String rule)
                                           throws FilterParseException
Throws:
FilterParseException

getSQLStatement

protected String getSQLStatement(String rule)
                          throws FilterParseException
This method parses a rule and returns the SQL select statement equivalent of the rule.

Returns:
the SQL select statement
Throws:
FilterParseException

getSQLStatement

protected String getSQLStatement(String rule,
                                 long nodeId,
                                 String ipaddr,
                                 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
Throws:
FilterParseException


Copyright © 2009. All Rights Reserved.