org.opennms.bb.common.filter.sql
Class SQLConstruct
java.lang.Object
|
+--org.opennms.bb.common.filter.sql.SQLConstruct
- public class SQLConstruct
- extends Object
This class is responsible for collecting the distinct
parts of an SQL Select statement of the form:
SELECT
FROM
WHERE ;
The SQLConstruct will be build in parts as more information
becomes available. Once all information is known it can
be combined into a proper Select statement complete with
the join conditions determined by the tables listed in
the FROM clause. The final statement can be accessed in
the form of a String.
- Version:
- $Revision: 1.6 $
- Author:
- Jason Johns, OpenNMS
Field Summary |
private HashMap |
fromClause
Holds a list of tables to be included
in the from clause by name along with the
FilterTable object associated with each table name. |
private HashMap |
selectClause
Holds the current select comma list. |
private StringBuffer |
whereClause
Holds the current where clause. |
Constructor Summary |
SQLConstruct()
Default constructor, initializes the where clause
buffer and allocates the HashMap for the select and
from clause. |
Method Summary |
void |
addToFromClause(FilterTable aTable)
This method adds a column name to from
clause. |
void |
addToSelectClause(String aClause)
This method adds a column name to the
select clause. |
void |
addToWhereClause(String aClause)
This method adds a conditon onto the end of the
where clause. |
private String |
buildJoinClause()
This method is used to build the join condtions to be
added to the where clause of a complete select statement. |
private String |
findDriverTableName()
This method is used to find the table that should
drive the construction of the join clauses between
all table in the from clause. |
String |
getFromClause()
This method returns the complete from clause in
string format by looping through the fromClause
map and concatenating each table name with the
"FROM" keyword and separating all table names with
a comma. |
String |
getSelectClause()
This method returns the complete select clause in
string format by looping through the selectClause
map and concatenating each table name with the
"SELECT" keyword and separating all column names with
a comma. |
String |
getWhereClause()
This method returns the complete where clause in
string format by concatenating the whereClause buffer
with the "WHERE" keyword and encloses the entire clause
in parenthesis. |
String |
toString()
This method builds the complete select statement and
returns it in the form of a string. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait |
selectClause
private HashMap selectClause
- Holds the current select comma list.
whereClause
private StringBuffer whereClause
- Holds the current where clause.
fromClause
private HashMap fromClause
- Holds a list of tables to be included
in the from clause by name along with the
FilterTable object associated with each table name.
SQLConstruct
public SQLConstruct()
- Default constructor, initializes the where clause
buffer and allocates the HashMap for the select and
from clause.
findDriverTableName
private String findDriverTableName()
- This method is used to find the table that should
drive the construction of the join clauses between
all table in the from clause. At least one table
has to be designated as the driver table.
- Returns:
- String, the name of the driver table
buildJoinClause
private String buildJoinClause()
- 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 tag indicating
a join condition between itself and the driver table.
(NOTE: in the case of the virtual columns in the ifServices
table the join condiontion will be included in the substitution.
The service table will not be joined to the driver table by
this method).
- Returns:
- String, the completed join clause for the WHERE clause
addToWhereClause
public void addToWhereClause(String aClause)
- This method adds a conditon onto the end of the
where clause. The clause string should already be
in the form of a correclty formatted SQL where condtion.
- Parameters:
String
- aClause, a where clause to be added
addToSelectClause
public void addToSelectClause(String aClause)
- This method adds a column name to the
select clause. The argument should be in the form
as it will appear in the finished statement. If the
string already exists in the clause it is not duplicated.
- Parameters:
String
- aClause, a select clause to be added
addToFromClause
public void addToFromClause(FilterTable aTable)
- This method adds a column name to from
clause. The argument should be in the form
as it will appear in the finished statement. If the
string already exists in the clause it is not duplicated.
- Parameters:
FilterTable
- aTable, a table to be added to the from clause
getWhereClause
public String getWhereClause()
- This method returns the complete where clause in
string format by concatenating the whereClause buffer
with the "WHERE" keyword and encloses the entire clause
in parenthesis.
- Returns:
- String, the where clause
getFromClause
public String getFromClause()
- This method returns the complete from clause in
string format by looping through the fromClause
map and concatenating each table name with the
"FROM" keyword and separating all table names with
a comma.
- Returns:
- String, the from clause
getSelectClause
public String getSelectClause()
- This method returns the complete select clause in
string format by looping through the selectClause
map and concatenating each table name with the
"SELECT" keyword and separating all column names with
a comma.
- Returns:
- String, the select clause
toString
public String toString()
- This method builds the complete select statement and
returns it in the form of a string.
- Overrides:
toString
in class Object
- Returns:
- String, the string representation of the entire SQL statement