OpenNMS API 1.2.3

org.opennms.netmgt.filter
Class SQLTranslation

java.lang.Object
  extended byorg.opennms.netmgt.filter.analysis.AnalysisAdapter
      extended byorg.opennms.netmgt.filter.analysis.DepthFirstAdapter
          extended byorg.opennms.netmgt.filter.SQLTranslation
All Implemented Interfaces:
Analysis, Switch

public class SQLTranslation
extends DepthFirstAdapter

This class is responsible for mapping the different parts of the filter expressions into the SQL equivalent. As pieces of the expression are parsed the from and where clauses will be built. This information will be passed on to a SQLConstruct object by the parser when the expression has been fully parsed.

Author:
Jason Johns , Weave , OpenNMS

Field Summary
private  java.lang.StringBuffer m_from
          The from part of the clause
private  java.lang.StringBuffer m_ipaddr
          The last ip address, this rebuild on a call to inAipaddr
private  Start m_node
          The starting node of the parse tree
private  DatabaseSchemaConfigFactory m_schemaFactory
           
private  java.util.List m_selectList
          The list of columns to be returned by the SQL.
private  java.lang.String m_selectModifier
          A modifier on the selectList (like 'DISTINCT')
private  java.util.List m_tables
          The list of tables required to create the approriate SQL statement
private  java.lang.StringBuffer m_where
          The where part of the clause
static java.lang.String VIRTUAL_COLUMN_PREFIX
          Constant to identify a virtual column for determining if an interface supports a service
 
Fields inherited from class org.opennms.netmgt.filter.analysis.AnalysisAdapter
 
Constructor Summary
SQLTranslation(Start node)
          Default constructor, initalizes the data structures
 
Method Summary
private  java.lang.String addColumnToStatement(java.lang.String colName)
          Adds a column to the statement.
private  java.lang.String addColumnToStatement(Table t, java.lang.String colName)
          Adds a column to the statement.
private  java.lang.String buildSelectClause()
           
 void caseAAndRule(AAndRule node)
           
 void caseACompareExprPart(ACompareExprPart node)
           
 void caseAGtrThanEqualExprPart(AGtrThanEqualExprPart node)
           
 void caseAGtrThanExprPart(AGtrThanExprPart node)
           
 void caseAIntegerCompareRight(AIntegerCompareRight node)
           
 void caseAIntegerOctet(AIntegerOctet node)
           
 void caseAIpaddrIpIdent(AIpaddrIpIdent node)
           
 void caseAIplikeExprPart(AIplikeExprPart node)
           
 void caseALessThanEqualExprPart(ALessThanEqualExprPart node)
           
 void caseALessThanExprPart(ALessThanExprPart node)
           
 void caseALikeExprPart(ALikeExprPart node)
           
 void caseANotEqualExprPart(ANotEqualExprPart node)
           
 void caseAOctetListOctet(AOctetListOctet node)
           
 void caseAOctetRangeListOctet(AOctetRangeListOctet node)
           
 void caseAOctetRangeOctet(AOctetRangeOctet node)
           
 void caseAOrRule(AOrRule node)
           
 void caseAStarOctet(AStarOctet node)
           
 void caseAStringCompareRight(AStringCompareRight node)
           
 void checkIPNum(java.lang.String octet)
          This method checks to ensure that a number appearing in an IP address is within the 0-255 range.
private  java.lang.String constructJoin()
          This method is used to build the join condtions to be added to the where clause of a complete select statement.
private  java.lang.String convertString(java.lang.String string)
          This method removes any double quote characters from the start and end of a string and replaces them with single quotes.
 java.lang.String getStatement()
          This method returns the complete sql statement for the filter that was parsed.
 void inAExprParensExpr(AExprParensExpr node)
           
 void inAIdentExprPart(AIdentExprPart node)
           
 void inANotExprPart(ANotExprPart node)
           
 void outAExprParensExpr(AExprParensExpr node)
           
 void outStart(Start node)
           
 void setConstraintTranslation(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.
 void setDefaultTranslation()
          Initializes the pieces of the SQL statement to perform a default query to select distinct ip addresses based the query that is built from the rest of the rule.
 void setInterfaceWithServiceTranslation()
           
 void setIPServiceMappingTranslation()
           
private  java.lang.String validateIdent(java.lang.String ident)
          Validate the identifier by ensuring it is references in the schema.
 
Methods inherited from class org.opennms.netmgt.filter.analysis.DepthFirstAdapter
caseAExprParensExpr, caseAExprPartExpr, caseAIdentExprPart, caseANotExprPart, caseARuleExprRule, caseStart, defaultIn, defaultOut, inAAndRule, inACompareExprPart, inAExprPartExpr, inAGtrThanEqualExprPart, inAGtrThanExprPart, inAIntegerCompareRight, inAIntegerOctet, inAIpaddrIpIdent, inAIplikeExprPart, inALessThanEqualExprPart, inALessThanExprPart, inALikeExprPart, inANotEqualExprPart, inAOctetListOctet, inAOctetRangeListOctet, inAOctetRangeOctet, inAOrRule, inARuleExprRule, inAStarOctet, inAStringCompareRight, inStart, outAAndRule, outACompareExprPart, outAExprPartExpr, outAGtrThanEqualExprPart, outAGtrThanExprPart, outAIdentExprPart, outAIntegerCompareRight, outAIntegerOctet, outAIpaddrIpIdent, outAIplikeExprPart, outALessThanEqualExprPart, outALessThanExprPart, outALikeExprPart, outANotEqualExprPart, outANotExprPart, outAOctetListOctet, outAOctetRangeListOctet, outAOctetRangeOctet, outAOrRule, outARuleExprRule, outAStarOctet, outAStringCompareRight
 
Methods inherited from class org.opennms.netmgt.filter.analysis.AnalysisAdapter
caseEOF, caseTAnd, caseTBlank, caseTCompare, caseTDot, caseTGtrThan, caseTGtrThanEqual, caseTIdent, caseTInteger, caseTIplike, caseTLessThan, caseTLessThanEqual, caseTLike, caseTLparen, caseTNot, caseTNotEqual, caseTOctetList, caseTOctetRange, caseTOctetRangeList, caseTOr, caseTQuotedString, caseTRparen, caseTSemi, caseTStar, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_schemaFactory

private DatabaseSchemaConfigFactory m_schemaFactory

VIRTUAL_COLUMN_PREFIX

public static final java.lang.String VIRTUAL_COLUMN_PREFIX
Constant to identify a virtual column for determining if an interface supports a service

See Also:
Constant Field Values

m_tables

private java.util.List m_tables
The list of tables required to create the approriate SQL statement


m_selectList

private java.util.List m_selectList
The list of columns to be returned by the SQL.


m_selectModifier

private java.lang.String m_selectModifier
A modifier on the selectList (like 'DISTINCT')


m_from

private java.lang.StringBuffer m_from
The from part of the clause


m_where

private java.lang.StringBuffer m_where
The where part of the clause


m_ipaddr

private java.lang.StringBuffer m_ipaddr
The last ip address, this rebuild on a call to inAipaddr


m_node

private Start m_node
The starting node of the parse tree

Constructor Detail

SQLTranslation

public SQLTranslation(Start node)
Default constructor, initalizes the data structures

Method Detail

constructJoin

private java.lang.String constructJoin()
This method is used to build the join condtions to be added to the where clause of a complete select statement. A join condition will only be built between two tables if the table being looked at has a <join> reference indicating a join condition between itself and the driver table.

Returns:
The completed join clause for the WHERE clause

validateIdent

private java.lang.String validateIdent(java.lang.String ident)
Validate the identifier by ensuring it is references in the schema. Also checks for 'virtual columns' be checking the prefix. If it is this turns into a reference to the 'serviceName' column of the service table and the appropriate join.


addColumnToStatement

private java.lang.String addColumnToStatement(java.lang.String colName)
Adds a column to the statement. This means insuring that this column is valid, its table is listed in the m_tables list as well as any intermediate tables necessary to join this table to the primary table. It returns the tablename.colname used to reference this column in the SQL.

Parameters:
colName - the name of the column to add
Returns:
the 'tablename.column' expression used to reference the column in SQL.

addColumnToStatement

private java.lang.String addColumnToStatement(Table t,
                                              java.lang.String colName)
Adds a column to the statement. The column is assumed to be in the passed in table. This means insuring that this column is valid, its table is listed in the m_tables list as well as any intermediate tables necessary to join this table to the primary table. It returns the tablename.colname used to reference this column in the SQL.

Parameters:
t - A Table that must contain the column colName
colName - the name of the column to add
Returns:
the 'tablename.column' expression used to reference the column in SQL.

convertString

private java.lang.String convertString(java.lang.String string)
This method removes any double quote characters from the start and end of a string and replaces them with single quotes.

Parameters:
string - the string to replace quote characters in

checkIPNum

public void checkIPNum(java.lang.String octet)
This method checks to ensure that a number appearing in an IP address is within the 0-255 range.

Parameters:
octet - an integer from an ip octet
Throws:
java.lang.IndexOutOfBoundsException

buildSelectClause

private java.lang.String buildSelectClause()

setDefaultTranslation

public void setDefaultTranslation()
Initializes the pieces of the SQL statement to perform a default query to select distinct ip addresses based the query that is built from the rest of the rule.


setIPServiceMappingTranslation

public void setIPServiceMappingTranslation()

setConstraintTranslation

public void setConstraintTranslation(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. This is useful to see if a particular node, interface, or service matches in the rule, and is primarily used to filter notices. A subselect 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

setInterfaceWithServiceTranslation

public void setInterfaceWithServiceTranslation()

outStart

public void outStart(Start node)
Overrides:
outStart in class DepthFirstAdapter

caseAAndRule

public void caseAAndRule(AAndRule node)
Specified by:
caseAAndRule in interface Analysis
Overrides:
caseAAndRule in class DepthFirstAdapter

caseAOrRule

public void caseAOrRule(AOrRule node)
Specified by:
caseAOrRule in interface Analysis
Overrides:
caseAOrRule in class DepthFirstAdapter

inAExprParensExpr

public void inAExprParensExpr(AExprParensExpr node)
Overrides:
inAExprParensExpr in class DepthFirstAdapter

outAExprParensExpr

public void outAExprParensExpr(AExprParensExpr node)
Overrides:
outAExprParensExpr in class DepthFirstAdapter

inAIdentExprPart

public void inAIdentExprPart(AIdentExprPart node)
Overrides:
inAIdentExprPart in class DepthFirstAdapter

caseAGtrThanExprPart

public void caseAGtrThanExprPart(AGtrThanExprPart node)
Specified by:
caseAGtrThanExprPart in interface Analysis
Overrides:
caseAGtrThanExprPart in class DepthFirstAdapter

caseALessThanExprPart

public void caseALessThanExprPart(ALessThanExprPart node)
Specified by:
caseALessThanExprPart in interface Analysis
Overrides:
caseALessThanExprPart in class DepthFirstAdapter

caseAGtrThanEqualExprPart

public void caseAGtrThanEqualExprPart(AGtrThanEqualExprPart node)
Specified by:
caseAGtrThanEqualExprPart in interface Analysis
Overrides:
caseAGtrThanEqualExprPart in class DepthFirstAdapter

caseALessThanEqualExprPart

public void caseALessThanEqualExprPart(ALessThanEqualExprPart node)
Specified by:
caseALessThanEqualExprPart in interface Analysis
Overrides:
caseALessThanEqualExprPart in class DepthFirstAdapter

caseACompareExprPart

public void caseACompareExprPart(ACompareExprPart node)
Specified by:
caseACompareExprPart in interface Analysis
Overrides:
caseACompareExprPart in class DepthFirstAdapter

caseANotEqualExprPart

public void caseANotEqualExprPart(ANotEqualExprPart node)
Specified by:
caseANotEqualExprPart in interface Analysis
Overrides:
caseANotEqualExprPart in class DepthFirstAdapter

inANotExprPart

public void inANotExprPart(ANotExprPart node)
Overrides:
inANotExprPart in class DepthFirstAdapter

caseAIntegerCompareRight

public void caseAIntegerCompareRight(AIntegerCompareRight node)
Specified by:
caseAIntegerCompareRight in interface Analysis
Overrides:
caseAIntegerCompareRight in class DepthFirstAdapter

caseAStringCompareRight

public void caseAStringCompareRight(AStringCompareRight node)
Specified by:
caseAStringCompareRight in interface Analysis
Overrides:
caseAStringCompareRight in class DepthFirstAdapter

caseALikeExprPart

public void caseALikeExprPart(ALikeExprPart node)
Specified by:
caseALikeExprPart in interface Analysis
Overrides:
caseALikeExprPart in class DepthFirstAdapter

caseAIplikeExprPart

public void caseAIplikeExprPart(AIplikeExprPart node)
Specified by:
caseAIplikeExprPart in interface Analysis
Overrides:
caseAIplikeExprPart in class DepthFirstAdapter

caseAIpaddrIpIdent

public void caseAIpaddrIpIdent(AIpaddrIpIdent node)
Specified by:
caseAIpaddrIpIdent in interface Analysis
Overrides:
caseAIpaddrIpIdent in class DepthFirstAdapter

caseAStarOctet

public void caseAStarOctet(AStarOctet node)
Specified by:
caseAStarOctet in interface Analysis
Overrides:
caseAStarOctet in class DepthFirstAdapter

caseAOctetListOctet

public void caseAOctetListOctet(AOctetListOctet node)
Specified by:
caseAOctetListOctet in interface Analysis
Overrides:
caseAOctetListOctet in class DepthFirstAdapter

caseAOctetRangeOctet

public void caseAOctetRangeOctet(AOctetRangeOctet node)
Specified by:
caseAOctetRangeOctet in interface Analysis
Overrides:
caseAOctetRangeOctet in class DepthFirstAdapter

caseAOctetRangeListOctet

public void caseAOctetRangeListOctet(AOctetRangeListOctet node)
Specified by:
caseAOctetRangeListOctet in interface Analysis
Overrides:
caseAOctetRangeListOctet in class DepthFirstAdapter

caseAIntegerOctet

public void caseAIntegerOctet(AIntegerOctet node)
Specified by:
caseAIntegerOctet in interface Analysis
Overrides:
caseAIntegerOctet in class DepthFirstAdapter

getStatement

public java.lang.String getStatement()
This method returns the complete sql statement for the filter that was parsed. The SQL statement is the result of the select, from, and where components assembled from the code.


OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.