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

JdbcFilterDao class.

Version:
$Id: $
Author:
DJ Gregor

Constructor Summary
JdbcFilterDao()
           
 
Method Summary
 void afterPropertiesSet()
          afterPropertiesSet
 DatabaseSchemaConfigFactory getDatabaseSchemaConfigFactory()
          getDatabaseSchemaConfigFactory
 DataSource getDataSource()
          getDataSource
protected  String getInterfaceWithServiceStatement(String rule)
          getInterfaceWithServiceStatement
 List<String> getIPList(String rule)
          getIPList
 Map<String,Set<String>> getIPServiceMap(String rule)
          getIPServiceMap
protected  String getIPServiceMappingStatement(String rule)
          getIPServiceMappingStatement
 NodeDao getNodeDao()
          getNodeDao
 SortedMap<Integer,String> getNodeMap(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.
protected  String getNodeMappingStatement(String rule)
          getNodeMappingStatement
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)
          isValid
 void setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory factory)
          setDatabaseSchemaConfigFactory
 void setDataSource(DataSource dataSource)
          setDataSource
 void setNodeDao(NodeDao nodeDao)
          setNodeDao
 void validateRule(String rule)
          validateRule
 void walkMatchingNodes(String rule, EntityVisitor visitor)
          walkMatchingNodes
 
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)

setDataSource

Parameters:
dataSource - a DataSource object.

getDataSource

public DataSource getDataSource()

getDataSource

Returns:
a DataSource object.

setDatabaseSchemaConfigFactory

public void setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory factory)

setDatabaseSchemaConfigFactory

Parameters:
factory - a DatabaseSchemaConfigFactory object.

getDatabaseSchemaConfigFactory

public DatabaseSchemaConfigFactory getDatabaseSchemaConfigFactory()

getDatabaseSchemaConfigFactory

Returns:
a DatabaseSchemaConfigFactory object.

afterPropertiesSet

public void afterPropertiesSet()

afterPropertiesSet

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

setNodeDao

public void setNodeDao(NodeDao nodeDao)

setNodeDao

Parameters:
nodeDao - a NodeDao object.

getNodeDao

public NodeDao getNodeDao()

getNodeDao

Returns:
a NodeDao object.

walkMatchingNodes

public void walkMatchingNodes(String rule,
                              EntityVisitor visitor)

walkMatchingNodes

Specified by:
walkMatchingNodes in interface FilterDao
Parameters:
rule - a String object.
visitor - a EntityVisitor object.

getNodeMap

public SortedMap<Integer,String> getNodeMap(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

getIPServiceMap

public Map<String,Set<String>> getIPServiceMap(String rule)
                                        throws FilterParseException

getIPServiceMap

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

getIPList

public List<String> getIPList(String rule)
                       throws FilterParseException

getIPList

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 - a String object.
Returns:
a List object.
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

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(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.

validateRule

public void validateRule(String rule)
                  throws FilterParseException

validateRule

Specified by:
validateRule in interface FilterDao
Parameters:
rule - a String object.
Throws:
FilterParseException - if any.

getNodeMappingStatement

protected String getNodeMappingStatement(String rule)
                                  throws FilterParseException

getNodeMappingStatement

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

getIPServiceMappingStatement

protected String getIPServiceMappingStatement(String rule)
                                       throws FilterParseException

getIPServiceMappingStatement

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

getInterfaceWithServiceStatement

protected String getInterfaceWithServiceStatement(String rule)
                                           throws FilterParseException

getInterfaceWithServiceStatement

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

getSQLStatement

protected String getSQLStatement(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 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
rule - a String object.
Returns:
a String object.
Throws:
FilterParseException - if any.


Copyright © 2011. All Rights Reserved.